tests: Expand 'bundle with many ports' test.
[cascardo/ovs.git] / tests / test-atomic.c
index dcd0a73..efc5053 100644 (file)
 
 #include <config.h>
 #undef NDEBUG
+#include "fatal-signal.h"
 #include "ovs-atomic.h"
-#include "util.h"
 #include "ovstest.h"
 #include "ovs-thread.h"
+#include "timeval.h"
+#include "util.h"
+#include "openvswitch/vlog.h"
+
+VLOG_DEFINE_THIS_MODULE(test_atomic);
 
 #define TEST_ATOMIC_TYPE(ATOMIC_TYPE, BASE_TYPE)        \
     {                                                   \
@@ -180,12 +185,14 @@ static ATOMIC(struct atomic_aux *) paux = ATOMIC_VAR_INIT(NULL);
 static struct atomic_aux *auxes = NULL;
 
 #define ATOMIC_ITEM_COUNT 1000000
+#define        DURATION 5000
 
 static void *
 atomic_consumer(void * arg1 OVS_UNUSED)
 {
     struct atomic_aux *old_aux = NULL;
     uint64_t count;
+    long long int stop_time = time_msec() + DURATION;
 
     do {
         struct atomic_aux *aux;
@@ -202,7 +209,14 @@ atomic_consumer(void * arg1 OVS_UNUSED)
         ovs_assert(b == count + 42);
 
         old_aux = aux;
-    } while (count < ATOMIC_ITEM_COUNT - 1);
+    } while (count < ATOMIC_ITEM_COUNT - 1 && time_msec() < stop_time);
+
+    if (time_msec() >= stop_time) {
+        if (count < 10) {
+            VLOG_WARN("atomic_consumer test stopped due to excessive runtime. "
+                      "Count = %"PRIu64, count);
+        }
+    }
 
     return NULL;
 }
@@ -249,6 +263,8 @@ atomic_reader(void *aux_)
     struct atomic_aux *aux = aux_;
     uint64_t count;
     uint64_t data;
+    long long int now = time_msec();
+    long long int stop_time = now + DURATION;
 
     do {
         /* Non-synchronized add. */
@@ -256,7 +272,15 @@ atomic_reader(void *aux_)
 
         do {
             atomic_read_explicit(&aux->data64, &data, memory_order_acquire);
-        } while (!data);
+        } while (!data && (now = time_msec()) < stop_time);
+
+        if (now >= stop_time) {
+            if (count < 10) {
+                VLOG_WARN("atomic_reader test stopped due to excessive "
+                          "runtime. Count = %"PRIu64, count);
+            }
+            break;
+        }
 
         ovs_assert(data == a && data == aux->b && a == aux->b);
 
@@ -277,12 +301,22 @@ atomic_writer(void *aux_)
     uint64_t old_count;
     uint64_t data;
     size_t i;
+    long long int now = time_msec();
+    long long int stop_time = now + DURATION;
 
     for (i = 0; i < ATOMIC_ITEM_COUNT; i++) {
         /* Wait for the reader to be done with the data. */
         do {
             atomic_read_explicit(&aux->data64, &data, memory_order_acquire);
-        } while (data);
+        } while (data && (now = time_msec()) < stop_time);
+
+        if (now >= stop_time) {
+            if (i < 10) {
+                VLOG_WARN("atomic_writer test stopped due to excessive "
+                          "runtime, Count = %"PRIuSIZE, i);
+            }
+            break;
+        }
 
         a = i + 1;
         atomic_add_explicit(&aux->count, 1, &old_count, memory_order_relaxed);
@@ -381,6 +415,7 @@ test_atomic_seq_cst(void)
 static void
 test_atomic_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
 {
+    fatal_signal_init();
     test_atomic_plain();
     test_atomic_relaxed();
     test_atomic_consume();