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 <pwithnall@endlessos.org>
This commit is contained in:
Philip Withnall 2022-06-14 16:59:32 +01:00
parent 419f882952
commit e51c80591b
2 changed files with 9 additions and 9 deletions

View File

@ -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;

View File

@ -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;