]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Helgrind regtest: add asserts to cond_timedwait_test.c
authorPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 22 Dec 2025 09:19:30 +0000 (10:19 +0100)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Mon, 22 Dec 2025 09:19:30 +0000 (10:19 +0100)
This test fails on Darwin, It looks like Darwin uses another mutex
and it's complaining that the condition mutex is not locked when
the unlock call is made. I made these changes when checking that the
testcase has the same behaviour on FreeBSD.

helgrind/tests/cond_timedwait_test.c

index e9b9be8a283e4049378dde3a6dc71421a82b8480..3b755917b4800a3ced2152ff1a4fc04c06b7309e 100644 (file)
@@ -1,20 +1,28 @@
 #include <pthread.h>
 #include <string.h>
+#include <assert.h>
+#include <errno.h>
 
-int main() {
-  pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-  pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+int main(void)
+{
+   pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+   pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+   int res;
 
-  // This time has most definitely passed already. (Epoch)
-  struct timespec now;
-  memset(&now, 0, sizeof(now));
+   // This time has most definitely passed already. (Epoch)
+   struct timespec now;
+   memset(&now, 0, sizeof(now));
 
-  pthread_mutex_lock(&mutex);
-  pthread_cond_timedwait(&cond, &mutex, &now);
-  pthread_mutex_unlock(&mutex);
+   res = pthread_mutex_lock(&mutex);
+   assert(res == 0);
+   res = pthread_cond_timedwait(&cond, &mutex, &now);
+   assert(res == ETIMEDOUT);
 
-  pthread_mutex_destroy(&mutex);
-  pthread_cond_destroy(&cond);
+   res = pthread_mutex_unlock(&mutex);
+   assert(res == 0);
 
-  return 0;
+   res = pthread_mutex_destroy(&mutex);
+   assert(res == 0);
+   res = pthread_cond_destroy(&cond);
+   assert(res == 0);
 }