Skip to contentSkip to conversation

tests: use g_usleep instead of rem = sleep(time)

RFC PATCH In review Alex Bennée 4 participants 4 messages Jan 14, 2019 – Jan 15, 2019

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 tests: use g_usleep instead of rem = sleep(time)

Relying on sleep to always return having slept isn't safe as a signal may have occurred. If signals are constantly incoming the program will never reach it's termination condition. This is believed to be the mechanism causing time outs for qht-test in Travis.

The glib g_usleep() deals with all of this for us so lets use it instead.

---
 tests/atomic64-bench.c   | 6 ++----
 tests/atomic_add-bench.c | 6 ++----
 tests/qht-bench.c        | 6 ++----
 3 files changed, 6 insertions(+), 12 deletions(-)
tests/atomic64-bench.c +2 -4
index 71692560ed..121a8c14f4 100644
@@ -74,16 +74,14 @@ static void *thread_func(void *arg)
 
 static void run_test(void)
 {
-    unsigned int remaining;
     unsigned int i;
 
     while (atomic_read(&n_ready_threads) != n_threads) {
         cpu_relax();
     }
+
     atomic_set(&test_start, true);
-    do {
-        remaining = sleep(duration);
-    } while (remaining);
+    g_usleep(duration * G_USEC_PER_SEC);
     atomic_set(&test_stop, true);
 
     for (i = 0; i < n_threads; i++) {
tests/atomic_add-bench.c +2 -4
index 2f6c72f63a..5666f6bbff 100644
@@ -76,16 +76,14 @@ static void *thread_func(void *arg)
 
 static void run_test(void)
 {
-    unsigned int remaining;
     unsigned int i;
 
     while (atomic_read(&n_ready_threads) != n_threads) {
         cpu_relax();
     }
+
     atomic_set(&test_start, true);
-    do {
-        remaining = sleep(duration);
-    } while (remaining);
+    g_usleep(duration * G_USEC_PER_SEC);
     atomic_set(&test_stop, true);
 
     for (i = 0; i < n_threads; i++) {
tests/qht-bench.c +2 -4
index ab4e708180..e3b512f26f 100644
@@ -398,16 +398,14 @@ static void pr_stats(void)
 
 static void run_test(void)
 {
-    unsigned int remaining;
     int i;
 
     while (atomic_read(&n_ready_threads) != n_rw_threads + n_rz_threads) {
         cpu_relax();
     }
+
     atomic_set(&test_start, true);
-    do {
-        remaining = sleep(duration);
-    } while (remaining);
+    g_usleep(duration * G_USEC_PER_SEC);
     atomic_set(&test_stop, true);
 
     for (i = 0; i < n_rw_threads; i++) {
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Alex Bennée

Relying on sleep to always return having slept isn't safe as a signal may have occurred. If signals are constantly incoming the program will never reach it's termination condition. This is believed to be the mechanism causing time outs for qht-test in Travis.

Quoted 8 lines

The glib g_usleep() deals with all of this for us so lets use it instead.

---
 tests/atomic64-bench.c   | 6 ++----
 tests/atomic_add-bench.c | 6 ++----
 tests/qht-bench.c        | 6 ++----
 3 files changed, 6 insertions(+), 12 deletions(-)

thanks
-- PMM

Reviewed-by on v1 1/1
#2 lore raw
In reply to Alex Bennée
Quoted 8 lines · Alex Bennée

Relying on sleep to always return having slept isn't safe as a signal may have occurred. If signals are constantly incoming the program will never reach it's termination condition. This is believed to be the mechanism causing time outs for qht-test in Travis.

The glib g_usleep() deals with all of this for us so lets use it instead.

Thanks,

		E.
Reviewed-by on v1 1/1
#3 lore raw
In reply to Alex Bennée
Quoted 5 lines · Alex Bennée

Relying on sleep to always return having slept isn't safe as a signal may have occurred. If signals are constantly incoming the program will never reach it's termination condition. This is believed to be the mechanism causing time outs for qht-test in Travis.

Quoted 8 lines

The glib g_usleep() deals with all of this for us so lets use it instead.

---
 tests/atomic64-bench.c   | 6 ++----
 tests/atomic_add-bench.c | 6 ++----
 tests/qht-bench.c        | 6 ++----
 3 files changed, 6 insertions(+), 12 deletions(-)

r~