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 <errno.h>
17 #include <sys/times.h>
18 
19 #include "test.h"
20 
21 /**
22  * @tc.name      : times_0100
23  * @tc.desc      : get process times
24  * @tc.level     : Level 0
25  */
times_0100(void)26 void times_0100(void)
27 {
28     struct tms buf;
29     clock_t result = times(&buf);
30     if (result < 0) {
31         t_error("%s failed: result = %d\n", __func__, result);
32         return;
33     }
34 
35     if (buf.tms_utime < 0) {
36         t_error("%s failed: buf.tms_utime = %d\n", __func__, buf.tms_utime);
37     }
38 
39     if (buf.tms_stime < 0) {
40         t_error("%s failed: buf.tms_stime = %d\n", __func__, buf.tms_stime);
41     }
42 
43     if (buf.tms_cutime < 0) {
44         t_error("%s failed: buf.tms_cutime = %d\n", __func__, buf.tms_cutime);
45     }
46 
47     if (buf.tms_cstime < 0) {
48         t_error("%s failed: buf.tms_cstime = %d\n", __func__, buf.tms_cstime);
49     }
50 }
51 
52 /**
53  * @tc.name      : times_0200
54  * @tc.desc      : get process times with NULL
55  * @tc.level     : Level 2
56  */
times_0200(void)57 void times_0200(void)
58 {
59     clock_t result = times(NULL);
60     if (result < 0) {
61         t_error("%s failed: result = %d\n", __func__, result);
62         return;
63     }
64 }
65 
main(int argc, char *argv[])66 int main(int argc, char *argv[])
67 {
68     times_0100();
69     times_0200();
70 
71     return t_status;
72 }
73