• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <time.h>
17 #include <unistd.h>
18 #include "functionalext.h"
19 
20 const int SUCCESS = 0;
21 
22 extern int __clock_nanosleep_time64(clockid_t, int, const struct timespec *, struct timespec *);
23 
24 /**
25  * @tc.name      : clock_nanosleep_0100
26  * @tc.desc      : Each parameter is valid, clk is CLOCK_REALTIME, which can specify the sleep of the clock.
27  * @tc.level     : Level 0
28  */
clock_nanosleep_0100(void)29 void clock_nanosleep_0100(void)
30 {
31     struct timespec ts;
32     ts.tv_sec = ts.tv_nsec / 1000000000;
33     ts.tv_nsec = 200000000;
34     int ret = -1;
35     ret = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL);
36     EXPECT_EQ("clock_nanosleep_0100", ret, SUCCESS);
37 }
38 
39 /**
40  * @tc.name      : clock_nanosleep_0200
41  * @tc.desc      : Each parameter is valid, clk is CLOCK_TAI, which can specify the sleep of the clock.
42  * @tc.level     : Level 0
43  */
clock_nanosleep_0200(void)44 void clock_nanosleep_0200(void)
45 {
46     struct timespec ts;
47     ts.tv_sec = ts.tv_nsec / 1000000000;
48     ts.tv_nsec = 200000000;
49     int ret = -1;
50     ret = clock_nanosleep(CLOCK_TAI, TIMER_ABSTIME, &ts, NULL);
51     EXPECT_EQ("clock_nanosleep_0200", ret, SUCCESS);
52 }
53 
54 /**
55  * @tc.name      : clock_nanosleep_0300
56  * @tc.desc      : Each parameter is valid, clk is CLOCK_MONOTONIC, which can specify the sleep of the clock
57  * @tc.level     : Level 0
58  */
clock_nanosleep_0300(void)59 void clock_nanosleep_0300(void)
60 {
61     struct timespec ts;
62     ts.tv_sec = ts.tv_nsec / 1000000000;
63     ts.tv_nsec = 200000000;
64     int ret = -1;
65     ret = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL);
66     EXPECT_EQ("clock_nanosleep_0300", ret, SUCCESS);
67 }
68 
69 /**
70  * @tc.name      : clock_nanosleep_0400
71  * @tc.desc      : Each parameter is valid, clk is CLOCK_BOOTTIME, which can specify the sleep of the clock
72  * @tc.level     : Level 0
73  */
clock_nanosleep_0400(void)74 void clock_nanosleep_0400(void)
75 {
76     struct timespec ts;
77     ts.tv_sec = ts.tv_nsec / 1000000000;
78     ts.tv_nsec = 200000000;
79     int ret = -1;
80     ret = clock_nanosleep(CLOCK_BOOTTIME, TIMER_ABSTIME, &ts, NULL);
81     EXPECT_EQ("clock_nanosleep_0400", ret, SUCCESS);
82 }
83 
84 /**
85  * @tc.name      : clock_nanosleep_0500
86  * @tc.desc      : Each parameter is valid, clk is CLOCK_REALTIME, and flags is 0,
87  *                 which can specify the sleep of the clock
88  * @tc.level     : Level 1
89  */
clock_nanosleep_0500(void)90 void clock_nanosleep_0500(void)
91 {
92     struct timespec ts;
93     ts.tv_sec = ts.tv_nsec / 1000000000;
94     ts.tv_nsec = 200000000;
95     int ret = -1;
96     ret = clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL);
97     EXPECT_EQ("clock_nanosleep_0500", ret, SUCCESS);
98 }
99 
100 /**
101  * @tc.name      : clock_nanosleep_0600
102  * @tc.desc      : The clk parameter is invalid, clk is CLOCK_THREAD_CPUTIME_ID,
103  *                 the sleep of the clock cannot be specified
104  * @tc.level     : Level 2
105  */
clock_nanosleep_0600(void)106 void clock_nanosleep_0600(void)
107 {
108     struct timespec ts;
109     ts.tv_sec = ts.tv_nsec / 1000000000;
110     ts.tv_nsec = 200000000;
111     int ret = -1;
112     ret = clock_nanosleep(CLOCK_THREAD_CPUTIME_ID, TIMER_ABSTIME, &ts, NULL);
113     EXPECT_EQ("clock_nanosleep_0600", ret, EINVAL);
114 }
115 
116 /**
117  * @tc.name      : clock_nanosleep_time64_0100
118  * @tc.desc      : Each parameter is valid, clk is CLOCK_REALTIME, which can specify the sleep of the clock.
119  * @tc.level     : Level 0
120  */
clock_nanosleep_time64_0100(void)121 void clock_nanosleep_time64_0100(void)
122 {
123     struct timespec ts;
124     ts.tv_sec = ts.tv_nsec / 1000000000;
125     ts.tv_nsec = 200000000;
126     int ret = -1;
127     ret = __clock_nanosleep_time64(CLOCK_REALTIME, TIMER_ABSTIME, &ts, NULL);
128     EXPECT_EQ("clock_nanosleep_time64_0100", ret, SUCCESS);
129 }
130 
main(int argc,char * argv[])131 int main(int argc, char *argv[])
132 {
133     clock_nanosleep_0100();
134     clock_nanosleep_0200();
135     clock_nanosleep_0300();
136     clock_nanosleep_0400();
137     clock_nanosleep_0500();
138     clock_nanosleep_0600();
139     clock_nanosleep_time64_0100();
140     return t_status;
141 }