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 <stdio.h>
17 #include <time.h>
18 #include "test.h"
19
20 #define NANOSECOND (1000000000)
21
22 extern int __timespec_get_time64(struct timespec *, int);
23
24 /**
25 * @tc.name : timespec_get_0100
26 * @tc.desc : Base is not TIME_UTC
27 * @tc.level : Level 0
28 */
timespec_get_0100(void)29 void timespec_get_0100(void)
30 {
31 struct timespec ts;
32 int result = timespec_get(&ts, 0);
33 if (result != 0) {
34 t_error("%s timespec_get failed, result is %d", __func__, result);
35 }
36 }
37
38 /**
39 * @tc.name : timespec_get_0200
40 * @tc.desc : Base is TIME_UTC
41 * @tc.level : Level 1
42 */
timespec_get_0200(void)43 void timespec_get_0200(void)
44 {
45 struct timespec ts;
46 int result = timespec_get(&ts, TIME_UTC);
47 if (result != TIME_UTC) {
48 t_error("%s timespec_get failed, result is %d", __func__, result);
49 }
50 if (ts.tv_nsec < 0 || ts.tv_nsec >= NANOSECOND) {
51 t_error("%s ts invalid", __func__);
52 }
53 }
54
55 /**
56 * @tc.name : timespec_get_time64_0200
57 * @tc.desc : Base is TIME_UTC
58 * @tc.level : Level 1
59 */
timespec_get_time64_0200(void)60 void timespec_get_time64_0200(void)
61 {
62 struct timespec ts;
63 int result = __timespec_get_time64(&ts, TIME_UTC);
64 if (result != TIME_UTC) {
65 t_error("%s __timespec_get_time64 failed, result is %d", __func__, result);
66 }
67 if (ts.tv_nsec < 0 || ts.tv_nsec >= NANOSECOND) {
68 t_error("%s ts invalid", __func__);
69 }
70 }
71
main(int argc,char * argv[])72 int main(int argc, char *argv[])
73 {
74 timespec_get_0100();
75 timespec_get_0200();
76 timespec_get_time64_0200();
77 return t_status;
78 }