test wfcqueue: enforce external mutex if needed by default
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 5 Dec 2012 11:12:42 +0000 (06:12 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 5 Dec 2012 11:12:42 +0000 (06:12 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/test_urcu_wfcq.c

index ccd5cf169436171baadd50d46ce261892764666b..939bf7a7bc77a5459d0ce683d9e72c0c40d9820b 100644 (file)
@@ -69,12 +69,14 @@ static inline pid_t gettid(void)
 #include <urcu/wfcqueue.h>
 
 enum test_sync {
-       TEST_SYNC_MUTEX = 0,
-       TEST_SYNC_NONE,
+       TEST_SYNC_NONE = 0,
+       TEST_SYNC_MUTEX,
 };
 
 static enum test_sync test_sync;
 
+static int test_force_sync;
+
 static volatile int test_go, test_stop_enqueue, test_stop_dequeue;
 
 static unsigned long rduration;
@@ -349,8 +351,8 @@ static void show_usage(int argc, char **argv)
        printf(" [-q] (test dequeue)");
        printf(" [-s] (test splice, enabled by default)");
        printf(" [-M] (use mutex external synchronization)");
-       printf(" [-0] (use no external synchronization)");
-       printf("      Note: default: mutex external synchronization used.");
+       printf("      Note: default: no external synchronization used.");
+       printf(" [-f] (force user-provided synchronization)");
        printf(" [-w] Wait for dequeuer to empty queue");
        printf("\n");
 }
@@ -432,12 +434,12 @@ int main(int argc, char **argv)
                case 'M':
                        test_sync = TEST_SYNC_MUTEX;
                        break;
-               case '0':
-                       test_sync = TEST_SYNC_NONE;
-                       break;
                case 'w':
                        test_wait_empty = 1;
                        break;
+               case 'f':
+                       test_force_sync = 1;
+                       break;
                }
        }
 
@@ -445,6 +447,17 @@ int main(int argc, char **argv)
        if (!test_dequeue && !test_splice)
                test_splice = 1;
 
+       if (test_sync == TEST_SYNC_NONE && nr_dequeuers > 1 && test_dequeue) {
+               if (test_force_sync) {
+                       fprintf(stderr, "[WARNING] Using dequeue concurrently "
+                               "with other dequeue or splice without external "
+                               "synchronization. Expect run-time failure.\n");
+               } else {
+                       printf("Enforcing mutex synchronization\n");
+                       test_sync = TEST_SYNC_MUTEX;
+               }
+       }
+
        printf_verbose("running test for %lu seconds, %u enqueuers, "
                       "%u dequeuers.\n",
                       duration, nr_enqueuers, nr_dequeuers);
This page took 0.037488 seconds and 4 git commands to generate.