]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add test for deadlock
authorStella Lau <laus@fb.com>
Wed, 2 Aug 2017 18:27:50 +0000 (11:27 -0700)
committerStella Lau <laus@fb.com>
Wed, 2 Aug 2017 18:27:50 +0000 (11:27 -0700)
tests/poolTests.c

index 09e6d6adf08ab485931d5fda9f6e6b203509b450..d5c37aee03cf4ca3abd11c31eb1afed868936d49 100644 (file)
@@ -2,6 +2,7 @@
 #include "threading.h"
 #include <stddef.h>
 #include <stdio.h>
+#include <unistd.h>
 
 #define ASSERT_TRUE(p)                                                         \
   do {                                                                         \
@@ -50,6 +51,26 @@ int testOrder(size_t numThreads, size_t queueSize) {
   return 0;
 }
 
+void waitFn(void *opaque) {
+  (void)opaque;
+  usleep(100);
+}
+
+/* Tests for deadlock */
+int testWait(size_t numThreads, size_t queueSize) {
+  struct data data;
+  POOL_ctx *ctx = POOL_create(numThreads, queueSize);
+  ASSERT_TRUE(ctx);
+  {
+    size_t i;
+    for (i = 0; i < 16; ++i) {
+        POOL_add(ctx, &waitFn, &data);
+    }
+  }
+  POOL_free(ctx);
+  return 0;
+}
+
 int main(int argc, const char **argv) {
   size_t numThreads;
   for (numThreads = 1; numThreads <= 4; ++numThreads) {
@@ -59,6 +80,10 @@ int main(int argc, const char **argv) {
         printf("FAIL: testOrder\n");
         return 1;
       }
+      if (testWait(numThreads, queueSize)) {
+        printf("FAIL: testWait\n");
+        return 1;
+      }
     }
   }
   printf("PASS: testOrder\n");