From e51c80591be0fa7e39afe7c997f73a08eb9cb59c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 16:59:32 +0100 Subject: [PATCH] tests: Allow mutex performance tests to be smoketested As with the previous commit, allow them to be smoketested when run without `-m perf`. Signed-off-by: Philip Withnall --- glib/tests/mutex.c | 9 +++++---- glib/tests/rec-mutex.c | 9 ++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/glib/tests/mutex.c b/glib/tests/mutex.c index 120229e42..cce4c593f 100644 --- a/glib/tests/mutex.c +++ b/glib/tests/mutex.c @@ -157,7 +157,7 @@ test_mutex5 (void) g_assert (owners[i] == NULL); } -#define COUNT_TO 100000000 +static gint count_to = 0; static gboolean do_addition (gint *value) @@ -167,7 +167,7 @@ do_addition (gint *value) /* test performance of "good" cases (ie: short critical sections) */ g_mutex_lock (&lock); - if ((more = *value != COUNT_TO)) + if ((more = *value != count_to)) if (*value != -1) (*value)++; g_mutex_unlock (&lock); @@ -193,6 +193,8 @@ test_mutex_perf (gconstpointer data) gint x = -1; guint i; + count_to = g_test_perf () ? 100000000 : 1; + g_assert (n_threads <= G_N_ELEMENTS (threads)); for (i = 0; n_threads > 0 && i < n_threads - 1; i++) @@ -202,7 +204,7 @@ test_mutex_perf (gconstpointer data) start_time = g_get_monotonic_time (); g_atomic_int_set (&x, 0); addition_thread (&x); - g_assert_cmpint (g_atomic_int_get (&x), ==, COUNT_TO); + g_assert_cmpint (g_atomic_int_get (&x), ==, count_to); rate = g_get_monotonic_time () - start_time; rate = x / rate; @@ -223,7 +225,6 @@ main (int argc, char *argv[]) g_test_add_func ("/thread/mutex4", test_mutex4); g_test_add_func ("/thread/mutex5", test_mutex5); - if (g_test_perf ()) { guint i; diff --git a/glib/tests/rec-mutex.c b/glib/tests/rec-mutex.c index f5be71523..de925f329 100644 --- a/glib/tests/rec-mutex.c +++ b/glib/tests/rec-mutex.c @@ -157,8 +157,7 @@ test_rec_mutex4 (void) g_assert (owners[i] == NULL); } -#define COUNT_TO 100000000 - +static gint count_to = 0; static gint depth; static gboolean @@ -172,7 +171,7 @@ do_addition (gint *value) for (i = 0; i < depth; i++) g_rec_mutex_lock (&lock); - if ((more = *value != COUNT_TO)) + if ((more = *value != count_to)) if (*value != -1) (*value)++; @@ -203,6 +202,7 @@ test_mutex_perf (gconstpointer data) n_threads = c / 256; depth = c % 256; + count_to = g_test_perf () ? 100000000 : 1; for (i = 0; i < n_threads - 1; i++) threads[i] = g_thread_new ("test", addition_thread, &x); @@ -211,7 +211,7 @@ test_mutex_perf (gconstpointer data) start_time = g_get_monotonic_time (); g_atomic_int_set (&x, 0); addition_thread (&x); - g_assert_cmpint (g_atomic_int_get (&x), ==, COUNT_TO); + g_assert_cmpint (g_atomic_int_get (&x), ==, count_to); rate = g_get_monotonic_time () - start_time; rate = x / rate; @@ -232,7 +232,6 @@ main (int argc, char *argv[]) g_test_add_func ("/thread/rec-mutex3", test_rec_mutex3); g_test_add_func ("/thread/rec-mutex4", test_rec_mutex4); - if (g_test_perf ()) { gint i, j;