[libc-commits] [libc] 5cddc31 - [libc] fix rwlock test (#100962)

via libc-commits libc-commits at lists.llvm.org
Sun Jul 28 21:36:20 PDT 2024


Author: Schrodinger ZHU Yifan
Date: 2024-07-28T21:36:17-07:00
New Revision: 5cddc314c8928ead12bb9c07cbefa45ee410de5c

URL: https://github.com/llvm/llvm-project/commit/5cddc314c8928ead12bb9c07cbefa45ee410de5c
DIFF: https://github.com/llvm/llvm-project/commit/5cddc314c8928ead12bb9c07cbefa45ee410de5c.diff

LOG: [libc] fix rwlock test (#100962)

Previous commit uses wrong clock id and forget to release an additional
rdlock. cc @Eric977
Sorry for missing this in my initial review.

Fixes https://github.com/llvm/llvm-project/issues/100960.

Notice that the timestamp is created via
```c++
  LIBC_NAMESPACE::clock_gettime(CLOCK_REALTIME, &ts);
  ts.tv_nsec += 50'000;
  if (ts.tv_nsec >= 1'000'000'000) {
    ts.tv_nsec -= 1'000'000'000;
    ts.tv_sec += 1;
  }
```

Added: 
    

Modified: 
    libc/test/integration/src/pthread/pthread_rwlock_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
index 8896f45d2c90a..9f5fba187713e 100644
--- a/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
+++ b/libc/test/integration/src/pthread/pthread_rwlock_test.cpp
@@ -217,13 +217,14 @@ static void timedlock_with_deadlock_test() {
             ETIMEDOUT);
   ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_timedrdlock(&rwlock, &ts), 0);
   ASSERT_EQ(
-      LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, CLOCK_MONOTONIC, &ts),
+      LIBC_NAMESPACE::pthread_rwlock_clockwrlock(&rwlock, CLOCK_REALTIME, &ts),
       ETIMEDOUT);
   ASSERT_EQ(
-      LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, CLOCK_MONOTONIC, &ts),
+      LIBC_NAMESPACE::pthread_rwlock_clockrdlock(&rwlock, CLOCK_REALTIME, &ts),
       0);
   ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(&rwlock), 0);
   ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(&rwlock), 0);
+  ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(&rwlock), 0);
   // notice that ts is already expired, but the following should still succeed.
   ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_tryrdlock(&rwlock), 0);
   ASSERT_EQ(LIBC_NAMESPACE::pthread_rwlock_unlock(&rwlock), 0);


        


More information about the libc-commits mailing list