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 <stdio.h>
18 #include <sys/time.h>
19 #include <time.h>
20 #include "test.h"
21
22 extern int __settimeofday_time64(const struct timeval *, const struct timezone *);
23
24 /**
25 * @tc.name : settimeofday_0100
26 * @tc.desc : Test that the function returns a value when tv points to a null pointer
27 * @tc.level : Level 0
28 */
settimeofday_0100(void)29 void settimeofday_0100(void)
30 {
31 int result = settimeofday(NULL, NULL);
32 if (result != 0) {
33 t_error("%s settimeofday failed", __func__);
34 }
35 }
36
37 /**
38 * @tc.name : settimeofday_0200
39 * @tc.desc : Test the return value of the function when usec in the parameter tv is 1000000ULL
40 * @tc.level : Level 1
41 */
settimeofday_0200(void)42 void settimeofday_0200(void)
43 {
44 struct timeval tv;
45 tv.tv_sec = 0;
46 tv.tv_usec = 1000000ULL;
47
48 int result = settimeofday(&tv, NULL);
49 if (result != -1) {
50 t_error("%s settimeofday failed", __func__);
51 }
52 }
53
54 /**
55 * @tc.name : settimeofday_0300
56 * @tc.desc : Set the time to 10:1 on January 11, 1970
57 * @tc.level : Level 1
58 */
settimeofday_0300(void)59 void settimeofday_0300(void)
60 {
61 struct timeval tv;
62 tv.tv_sec = 864000 + 36000 + 60;
63 tv.tv_usec = 0;
64
65 int result = settimeofday(&tv, NULL);
66 if (result == -1) {
67 t_error("%s settimeofday failed", __func__);
68 }
69 }
70
71 /**
72 * @tc.name : settimeofday_time64_0200
73 * @tc.desc : Test the return value of the function when usec in the parameter tv is 1000000ULL
74 * @tc.level : Level 1
75 */
settimeofday_time64_0200(void)76 void settimeofday_time64_0200(void)
77 {
78 struct timeval tv;
79 tv.tv_sec = 0;
80 tv.tv_usec = 1000000ULL;
81
82 int result = __settimeofday_time64(&tv, NULL);
83 if (result != -1) {
84 t_error("%s __settimeofday_time64 failed", __func__);
85 }
86 }
87
main(int argc,char * argv[])88 int main(int argc, char *argv[])
89 {
90 settimeofday_0100();
91 settimeofday_0200();
92 settimeofday_0300();
93 settimeofday_time64_0200();
94 return t_status;
95 }