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 <pthread.h>
17 #include <time.h>
18 #include "functionalext.h"
19
20 int gthread_exit_flag = 0;
thread_func(void * arg)21 static void *thread_func(void *arg)
22 {
23 for (;;) {
24 if (gthread_exit_flag) {
25 break;
26 } else {
27 continue;
28 }
29 }
30 return (void *)0;
31 }
32
33 /**
34 * @tc.name : pthread_getcpuclockid_0100
35 * @tc.desc : Get the specified thread clock ID
36 * @tc.level : Level 0
37 */
pthread_getcpuclockid_0100(void)38 void pthread_getcpuclockid_0100(void)
39 {
40 pthread_t thread;
41 clockid_t cid;
42 int ret = pthread_create(&thread, NULL, thread_func, NULL);
43 EXPECT_EQ("pthread_getcpuclockid_0100", ret, 0);
44 ret = pthread_getcpuclockid(pthread_self(), &cid);
45 EXPECT_EQ("pthread_getcpuclockid_0100", ret, 0);
46 EXPECT_TRUE("pthread_getcpuclockid_0100", cid != 0);
47
48 ret = pthread_getcpuclockid(thread, &cid);
49 EXPECT_EQ("pthread_getcpuclockid_0100", ret, 0);
50 EXPECT_TRUE("pthread_getcpuclockid_0100", cid != 0);
51 gthread_exit_flag = 1;
52 sleep(1);
53 }
54
main(void)55 int main(void)
56 {
57 pthread_getcpuclockid_0100();
58 return t_status;
59 }