1 /*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <sys/resource.h>
17 #include "functionalext.h"
18
19 extern int __getrusage_time64 (int, struct rusage *);
20
21 /**
22 * @tc.name : getrusage_0100
23 * @tc.desc : Verify the program running time (parameter is RUSAGE_SELF)
24 * @tc.level : Level 0
25 */
getrusage_0100(void)26 void getrusage_0100(void)
27 {
28 struct rusage usage;
29 int result = getrusage(RUSAGE_SELF, &usage);
30 EXPECT_EQ("getrusage_0100", result, 0);
31 }
32
33 /**
34 * @tc.name : getrusage_0200
35 * @tc.desc : Verify the program running time (parameter is RUSAGE_CHILDREN)
36 * @tc.level : Level 1
37 */
getrusage_0200(void)38 void getrusage_0200(void)
39 {
40 struct rusage usage;
41 int result = getrusage(RUSAGE_CHILDREN, &usage);
42 EXPECT_EQ("getrusage_0200", result, 0);
43 }
44
45 /**
46 * @tc.name : getrusage_0300
47 * @tc.desc : Verify the program running time (parameter is RUSAGE_THREAD)
48 * @tc.level : Level 1
49 */
getrusage_0300(void)50 void getrusage_0300(void)
51 {
52 struct rusage usage;
53 int result = getrusage(RUSAGE_THREAD, &usage);
54 EXPECT_EQ("getrusage_0300", result, 0);
55 }
56
57 /**
58 * @tc.name : getrusage_0400
59 * @tc.desc : Verify that the program running time cannot be obtained (parameter is 100)
60 * @tc.level : Level 2
61 */
getrusage_0400(void)62 void getrusage_0400(void)
63 {
64 struct rusage usage;
65 int result = getrusage(100, &usage);
66 EXPECT_EQ("getrusage_0400", result, -1);
67 }
68
69 /**
70 * @tc.name : getrusage_0500
71 * @tc.desc : Verify that the program running time cannot be obtained (parameter is RUSAGE_SELF)
72 * @tc.level : Level 2
73 */
getrusage_0500(void)74 void getrusage_0500(void)
75 {
76 struct rusage usage;
77 int result = getrusage(RUSAGE_SELF, NULL);
78 EXPECT_EQ("getrusage_0500", result, -1);
79 }
80
81 /**
82 * @tc.name : getrusage_time64_0100
83 * @tc.desc : Verify the program running time (parameter is RUSAGE_SELF)
84 * @tc.level : Level 0
85 */
getrusage_time64_0100(void)86 void getrusage_time64_0100(void)
87 {
88 struct rusage usage;
89 int result = __getrusage_time64(RUSAGE_SELF, &usage);
90 EXPECT_EQ("getrusage_time64_0100", result, 0);
91 }
92
main(void)93 int main(void)
94 {
95 getrusage_0100();
96 getrusage_0200();
97 getrusage_0300();
98 getrusage_0400();
99 getrusage_0500();
100 getrusage_time64_0100();
101 return t_status;
102 }