1570af302Sopenharmony_ci/* 2570af302Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3570af302Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4570af302Sopenharmony_ci * you may not use this file except in compliance with the License. 5570af302Sopenharmony_ci * You may obtain a copy of the License at 6570af302Sopenharmony_ci * 7570af302Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8570af302Sopenharmony_ci * 9570af302Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10570af302Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11570af302Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12570af302Sopenharmony_ci * See the License for the specific language governing permissions and 13570af302Sopenharmony_ci * limitations under the License. 14570af302Sopenharmony_ci */ 15570af302Sopenharmony_ci#include <errno.h> 16570af302Sopenharmony_ci#include <pthread.h> 17570af302Sopenharmony_ci#include <sched.h> 18570af302Sopenharmony_ci#include "pthread_util.h" 19570af302Sopenharmony_ci 20570af302Sopenharmony_cistatic pthread_rwlock_t w_rwlock1; 21570af302Sopenharmony_cistatic pthread_rwlock_t w_rwlock2; 22570af302Sopenharmony_cistatic pthread_rwlock_t w_rwlock3; 23570af302Sopenharmony_cistatic pthread_rwlock_t w_rwlock4; 24570af302Sopenharmony_cistatic pthread_rwlock_t w_rwlock5; 25570af302Sopenharmony_cistatic pthread_rwlock_t w_rwlock6; 26570af302Sopenharmony_ci 27570af302Sopenharmony_cistatic void *RwlockClockRealTimeOut1(void *arg) 28570af302Sopenharmony_ci{ 29570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock1), 0); 30570af302Sopenharmony_ci Msleep(SLEEP_50_MS); 31570af302Sopenharmony_ci Msleep(SLEEP_100_MS); 32570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock1), 0); 33570af302Sopenharmony_ci return arg; 34570af302Sopenharmony_ci} 35570af302Sopenharmony_ci 36570af302Sopenharmony_cistatic void *RwlockClockRealTimeOut2(void *arg) 37570af302Sopenharmony_ci{ 38570af302Sopenharmony_ci struct timespec ts = {0}; 39570af302Sopenharmony_ci struct timespec tsNow = {0}; 40570af302Sopenharmony_ci struct sched_param param; 41570af302Sopenharmony_ci param.sched_priority = sched_get_priority_max(SCHED_FIFO); // 获取最高优先级 42570af302Sopenharmony_ci if (pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) != 0) { 43570af302Sopenharmony_ci t_printf("pthread_setschedparam fail \n"); 44570af302Sopenharmony_ci return arg; 45570af302Sopenharmony_ci } 46570af302Sopenharmony_ci Msleep(SLEEP_20_MS); 47570af302Sopenharmony_ci GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_REALTIME); 48570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_clockwrlock(&w_rwlock1, CLOCK_REALTIME, &ts), ETIMEDOUT); 49570af302Sopenharmony_ci clock_gettime(CLOCK_REALTIME, &tsNow); 50570af302Sopenharmony_ci int timeDiff = GetTimeDiff(tsNow, ts); 51570af302Sopenharmony_ci EXPECT_GE(timeDiff, 0); 52570af302Sopenharmony_ci EXPECT_LE(timeDiff, SLEEP_20_MS); 53570af302Sopenharmony_ci return arg; 54570af302Sopenharmony_ci} 55570af302Sopenharmony_ci 56570af302Sopenharmony_cistatic void *RwlockClockRealTimeWait1(void *arg) 57570af302Sopenharmony_ci{ 58570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock2), 0); 59570af302Sopenharmony_ci Msleep(SLEEP_50_MS); 60570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock2), 0); 61570af302Sopenharmony_ci return arg; 62570af302Sopenharmony_ci} 63570af302Sopenharmony_ci 64570af302Sopenharmony_cistatic void *RwlockClockRealTimeWait2(void *arg) 65570af302Sopenharmony_ci{ 66570af302Sopenharmony_ci struct timespec ts = {0}; 67570af302Sopenharmony_ci clockid_t clock_id = CLOCK_REALTIME; 68570af302Sopenharmony_ci Msleep(SLEEP_20_MS); 69570af302Sopenharmony_ci GetDelayedTimeByClockid(&ts, SLEEP_100_MS, clock_id); 70570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_clockwrlock(&w_rwlock2, clock_id, &ts), 0); 71570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock2), 0); 72570af302Sopenharmony_ci return arg; 73570af302Sopenharmony_ci} 74570af302Sopenharmony_ci 75570af302Sopenharmony_cistatic void *RwlockClockMonotonicTimeOut1(void *arg) 76570af302Sopenharmony_ci{ 77570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock5), 0); 78570af302Sopenharmony_ci Msleep(SLEEP_50_MS); 79570af302Sopenharmony_ci Msleep(SLEEP_100_MS); 80570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock5), 0); 81570af302Sopenharmony_ci return arg; 82570af302Sopenharmony_ci} 83570af302Sopenharmony_ci 84570af302Sopenharmony_cistatic void *RwlockClockMonotonicTimeOut2(void *arg) 85570af302Sopenharmony_ci{ 86570af302Sopenharmony_ci struct timespec ts = {0}; 87570af302Sopenharmony_ci struct timespec tsNow = {0}; 88570af302Sopenharmony_ci 89570af302Sopenharmony_ci struct sched_param param; 90570af302Sopenharmony_ci param.sched_priority = sched_get_priority_max(SCHED_FIFO); // 获取最高优先级 91570af302Sopenharmony_ci if (pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) != 0) { 92570af302Sopenharmony_ci t_printf("pthread_setschedparam fail\n"); 93570af302Sopenharmony_ci return arg; 94570af302Sopenharmony_ci } 95570af302Sopenharmony_ci 96570af302Sopenharmony_ci Msleep(SLEEP_20_MS); 97570af302Sopenharmony_ci GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_MONOTONIC); 98570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_clockwrlock(&w_rwlock5, CLOCK_MONOTONIC, &ts), ETIMEDOUT); 99570af302Sopenharmony_ci clock_gettime(CLOCK_MONOTONIC, &tsNow); 100570af302Sopenharmony_ci int timeDiff = GetTimeDiff(tsNow, ts); 101570af302Sopenharmony_ci EXPECT_GE(timeDiff, 0); 102570af302Sopenharmony_ci EXPECT_LE(timeDiff, SLEEP_20_MS); 103570af302Sopenharmony_ci return arg; 104570af302Sopenharmony_ci} 105570af302Sopenharmony_ci 106570af302Sopenharmony_cistatic void *RwlockClockMonotonicTimeWait1(void *arg) 107570af302Sopenharmony_ci{ 108570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock6), 0); 109570af302Sopenharmony_ci Msleep(SLEEP_50_MS); 110570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock6), 0); 111570af302Sopenharmony_ci return arg; 112570af302Sopenharmony_ci} 113570af302Sopenharmony_ci 114570af302Sopenharmony_cistatic void *RwlockClockMonotonicTimeWait2(void *arg) 115570af302Sopenharmony_ci{ 116570af302Sopenharmony_ci struct timespec ts = {0}; 117570af302Sopenharmony_ci Msleep(SLEEP_20_MS); 118570af302Sopenharmony_ci GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_MONOTONIC); 119570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_clockwrlock(&w_rwlock6, CLOCK_MONOTONIC, &ts), 0); 120570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock6), 0); 121570af302Sopenharmony_ci return arg; 122570af302Sopenharmony_ci} 123570af302Sopenharmony_ci 124570af302Sopenharmony_cistatic void *RwlockMonotonicTime1(void *arg) 125570af302Sopenharmony_ci{ 126570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock3), 0); 127570af302Sopenharmony_ci Msleep(SLEEP_50_MS); 128570af302Sopenharmony_ci Msleep(SLEEP_100_MS); 129570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock3), 0); 130570af302Sopenharmony_ci return arg; 131570af302Sopenharmony_ci} 132570af302Sopenharmony_ci 133570af302Sopenharmony_cistatic void *RwlockMonotonicTime2(void *arg) 134570af302Sopenharmony_ci{ 135570af302Sopenharmony_ci struct timespec ts = {0}; 136570af302Sopenharmony_ci struct timespec tsNow = {0}; 137570af302Sopenharmony_ci 138570af302Sopenharmony_ci struct sched_param param; 139570af302Sopenharmony_ci param.sched_priority = sched_get_priority_max(SCHED_FIFO); // 获取最高优先级 140570af302Sopenharmony_ci if (pthread_setschedparam(pthread_self(), SCHED_FIFO, ¶m) != 0) { 141570af302Sopenharmony_ci t_printf("pthread_setschedparam fail\n"); 142570af302Sopenharmony_ci return arg; 143570af302Sopenharmony_ci } 144570af302Sopenharmony_ci 145570af302Sopenharmony_ci Msleep(SLEEP_20_MS); 146570af302Sopenharmony_ci GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_MONOTONIC); 147570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_timedwrlock_monotonic_np(&w_rwlock3, &ts), ETIMEDOUT); 148570af302Sopenharmony_ci clock_gettime(CLOCK_MONOTONIC, &tsNow); 149570af302Sopenharmony_ci int timeDiff = GetTimeDiff(tsNow, ts); 150570af302Sopenharmony_ci EXPECT_GE(timeDiff, 0); 151570af302Sopenharmony_ci EXPECT_LE(timeDiff, SLEEP_20_MS); 152570af302Sopenharmony_ci return arg; 153570af302Sopenharmony_ci} 154570af302Sopenharmony_ci 155570af302Sopenharmony_cistatic void *RwlockMonotonicTime3(void *arg) 156570af302Sopenharmony_ci{ 157570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w_rwlock4), 0); 158570af302Sopenharmony_ci Msleep(SLEEP_50_MS); 159570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock4), 0); 160570af302Sopenharmony_ci return arg; 161570af302Sopenharmony_ci} 162570af302Sopenharmony_ci 163570af302Sopenharmony_cistatic void *RwlockMonotonicTime4(void *arg) 164570af302Sopenharmony_ci{ 165570af302Sopenharmony_ci struct timespec ts = {0}; 166570af302Sopenharmony_ci Msleep(SLEEP_20_MS); 167570af302Sopenharmony_ci GetDelayedTimeByClockid(&ts, SLEEP_100_MS, CLOCK_MONOTONIC); 168570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_timedwrlock_monotonic_np(&w_rwlock4, &ts), 0); 169570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w_rwlock4), 0); 170570af302Sopenharmony_ci return arg; 171570af302Sopenharmony_ci} 172570af302Sopenharmony_ci 173570af302Sopenharmony_ci/** 174570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0010 175570af302Sopenharmony_ci * @tc.desc : Test whether all the interfaces to be used are normal 176570af302Sopenharmony_ci * @tc.level : Level 0 177570af302Sopenharmony_ci */ 178570af302Sopenharmony_ci 179570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0010(void) 180570af302Sopenharmony_ci{ 181570af302Sopenharmony_ci pthread_rwlock_t w; 182570af302Sopenharmony_ci struct timespec ts = {0}; 183570af302Sopenharmony_ci EXPECT_EQ(clock_gettime(CLOCK_MONOTONIC, &ts), 0); 184570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w, NULL), 0); 185570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w), 0); 186570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_timedwrlock_monotonic_np(&w, &ts), ETIMEDOUT); 187570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w), 0); 188570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w), 0); 189570af302Sopenharmony_ci} 190570af302Sopenharmony_ci 191570af302Sopenharmony_ci/** 192570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0020 193570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_cond_clockwait no timeout by CLOCK_REALTIME 194570af302Sopenharmony_ci * @tc.level : Level 0 195570af302Sopenharmony_ci */ 196570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0020(void) 197570af302Sopenharmony_ci{ 198570af302Sopenharmony_ci pthread_rwlock_t w; 199570af302Sopenharmony_ci struct timespec ts = {0}; 200570af302Sopenharmony_ci clockid_t clock_id = CLOCK_REALTIME; 201570af302Sopenharmony_ci EXPECT_EQ(clock_gettime(CLOCK_REALTIME, &ts), 0); 202570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w, NULL), 0); 203570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w), 0); 204570af302Sopenharmony_ci GetDelayedTimeByClockid(&ts, SLEEP_100_MS, clock_id); 205570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_clockwrlock(&w, clock_id, &ts), ETIMEDOUT); 206570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w), 0); 207570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w), 0); 208570af302Sopenharmony_ci} 209570af302Sopenharmony_ci 210570af302Sopenharmony_ci/** 211570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0030 212570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_cond_clockwait no timeout by CLOCK_REALTIME 213570af302Sopenharmony_ci * @tc.level : Level 0 214570af302Sopenharmony_ci */ 215570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0030(void) 216570af302Sopenharmony_ci{ 217570af302Sopenharmony_ci pthread_rwlock_t w; 218570af302Sopenharmony_ci struct timespec ts = {0}; 219570af302Sopenharmony_ci clockid_t clock_id = CLOCK_MONOTONIC; 220570af302Sopenharmony_ci EXPECT_EQ(clock_gettime(CLOCK_MONOTONIC, &ts), 0); 221570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w, NULL), 0); 222570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w), 0); 223570af302Sopenharmony_ci GetDelayedTimeByClockid(&ts, SLEEP_100_MS, clock_id); 224570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_clockwrlock(&w, clock_id, &ts), ETIMEDOUT); 225570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w), 0); 226570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w), 0); 227570af302Sopenharmony_ci} 228570af302Sopenharmony_ci 229570af302Sopenharmony_ci/** 230570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0040 231570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_cond_clockwait no timeout by CLOCK_REALTIME 232570af302Sopenharmony_ci * @tc.level : Level 2 233570af302Sopenharmony_ci */ 234570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0040(void) 235570af302Sopenharmony_ci{ 236570af302Sopenharmony_ci pthread_rwlock_t w; 237570af302Sopenharmony_ci struct timespec ts = {0}; 238570af302Sopenharmony_ci clockid_t clock_id = CLOCK_PROCESS_CPUTIME_ID; 239570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w, NULL), 0); 240570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_wrlock(&w), 0); 241570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_clockwrlock(&w, clock_id, &ts), EINVAL); 242570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_unlock(&w), 0); 243570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w), 0); 244570af302Sopenharmony_ci} 245570af302Sopenharmony_ci 246570af302Sopenharmony_ci/** 247570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0050 248570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_cond_clockwait no timeout by CLOCK_REALTIME 249570af302Sopenharmony_ci * @tc.level : Level 1 250570af302Sopenharmony_ci */ 251570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0050(void) 252570af302Sopenharmony_ci{ 253570af302Sopenharmony_ci pthread_t tid[2]; 254570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w_rwlock2, NULL), 0); 255570af302Sopenharmony_ci 256570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockClockRealTimeWait1, NULL), 0); 257570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockClockRealTimeWait2, NULL), 0); 258570af302Sopenharmony_ci 259570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[0], NULL), 0); 260570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[1], NULL), 0); 261570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock2), 0); 262570af302Sopenharmony_ci} 263570af302Sopenharmony_ci 264570af302Sopenharmony_ci/** 265570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0060 266570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_cond_clockwait timeout by CLOCK_REALTIME 267570af302Sopenharmony_ci * @tc.level : Level 1 268570af302Sopenharmony_ci */ 269570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0060(void) 270570af302Sopenharmony_ci{ 271570af302Sopenharmony_ci pthread_t tid[2]; 272570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w_rwlock1, NULL), 0); 273570af302Sopenharmony_ci 274570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockClockRealTimeOut1, NULL), 0); 275570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockClockRealTimeOut2, NULL), 0); 276570af302Sopenharmony_ci 277570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[0], NULL), 0); 278570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[1], NULL), 0); 279570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock1), 0); 280570af302Sopenharmony_ci} 281570af302Sopenharmony_ci 282570af302Sopenharmony_ci/** 283570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0070 284570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_cond_clockwait timeout by CLOCK_MONOTONIC 285570af302Sopenharmony_ci * @tc.level : Level 1 286570af302Sopenharmony_ci */ 287570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0070(void) 288570af302Sopenharmony_ci{ 289570af302Sopenharmony_ci pthread_t tid[2]; 290570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w_rwlock5, NULL), 0); 291570af302Sopenharmony_ci 292570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockClockMonotonicTimeOut1, NULL), 0); 293570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockClockMonotonicTimeOut2, NULL), 0); 294570af302Sopenharmony_ci 295570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[0], NULL), 0); 296570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[1], NULL), 0); 297570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock5), 0); 298570af302Sopenharmony_ci} 299570af302Sopenharmony_ci 300570af302Sopenharmony_ci/** 301570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0080 302570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_cond_clockwait timeout by CLOCK_MONOTONIC 303570af302Sopenharmony_ci * @tc.level : Level 1 304570af302Sopenharmony_ci */ 305570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0080(void) 306570af302Sopenharmony_ci{ 307570af302Sopenharmony_ci pthread_t tid[2]; 308570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w_rwlock6, NULL), 0); 309570af302Sopenharmony_ci 310570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockClockMonotonicTimeWait1, NULL), 0); 311570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockClockMonotonicTimeWait2, NULL), 0); 312570af302Sopenharmony_ci 313570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[0], NULL), 0); 314570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[1], NULL), 0); 315570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock6), 0); 316570af302Sopenharmony_ci} 317570af302Sopenharmony_ci 318570af302Sopenharmony_ci/** 319570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0090 320570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_rwlock_timedwrlock_monotonic_np no timeout 321570af302Sopenharmony_ci * @tc.level : Level 1 322570af302Sopenharmony_ci */ 323570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0090(void) 324570af302Sopenharmony_ci{ 325570af302Sopenharmony_ci pthread_t tid[2]; 326570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w_rwlock3, NULL), 0); 327570af302Sopenharmony_ci 328570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockMonotonicTime1, NULL), 0); 329570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockMonotonicTime2, NULL), 0); 330570af302Sopenharmony_ci 331570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[0], NULL), 0); 332570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[1], NULL), 0); 333570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock3), 0); 334570af302Sopenharmony_ci} 335570af302Sopenharmony_ci 336570af302Sopenharmony_ci/** 337570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0100 338570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_rwlock_timedwrlock_monotonic_np timeout 339570af302Sopenharmony_ci * @tc.level : Level 1 340570af302Sopenharmony_ci */ 341570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0100(void) 342570af302Sopenharmony_ci{ 343570af302Sopenharmony_ci pthread_t tid[2]; 344570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_init(&w_rwlock4, NULL), 0); 345570af302Sopenharmony_ci 346570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[0], NULL, RwlockMonotonicTime3, NULL), 0); 347570af302Sopenharmony_ci EXPECT_EQ(pthread_create(&tid[1], NULL, RwlockMonotonicTime4, NULL), 0); 348570af302Sopenharmony_ci 349570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[0], NULL), 0); 350570af302Sopenharmony_ci EXPECT_EQ(pthread_join(tid[1], NULL), 0); 351570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_destroy(&w_rwlock4), 0); 352570af302Sopenharmony_ci} 353570af302Sopenharmony_ci 354570af302Sopenharmony_ci/** 355570af302Sopenharmony_ci * @tc.number : pthread_rwlock_timedwrlock_0110 356570af302Sopenharmony_ci * @tc.desc : Test the case of pthread_rwlock_timedwrlock_monotonic_np with invalid rwlock 357570af302Sopenharmony_ci * @tc.level : Level 2 358570af302Sopenharmony_ci */ 359570af302Sopenharmony_civoid pthread_rwlock_timedwrlock_0110(void) 360570af302Sopenharmony_ci{ 361570af302Sopenharmony_ci struct timespec ts = {0}; 362570af302Sopenharmony_ci EXPECT_EQ(pthread_rwlock_timedwrlock_monotonic_np((pthread_rwlock_t *)NULL, &ts), EINVAL); 363570af302Sopenharmony_ci} 364570af302Sopenharmony_ci 365570af302Sopenharmony_ciTEST_FUN G_Fun_Array[] = { 366570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0010, 367570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0020, 368570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0030, 369570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0040, 370570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0050, 371570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0060, 372570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0070, 373570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0080, 374570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0090, 375570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0100, 376570af302Sopenharmony_ci pthread_rwlock_timedwrlock_0110, 377570af302Sopenharmony_ci}; 378570af302Sopenharmony_ci 379570af302Sopenharmony_ciint main(void) 380570af302Sopenharmony_ci{ 381570af302Sopenharmony_ci int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN); 382570af302Sopenharmony_ci for (int pos = 0; pos < num; ++pos) { 383570af302Sopenharmony_ci G_Fun_Array[pos](); 384570af302Sopenharmony_ci } 385570af302Sopenharmony_ci return t_status; 386570af302Sopenharmony_ci}