diff --git a/gio/tests/debugcontroller.c b/gio/tests/debugcontroller.c index 01b8ebdef..862e8f666 100644 --- a/gio/tests/debugcontroller.c +++ b/gio/tests/debugcontroller.c @@ -383,6 +383,15 @@ test_dbus_properties (void) g_clear_object (&bus); } +static GLogWriterOutput +noop_log_writer_cb (GLogLevelFlags log_level, + const GLogField *fields, + gsize n_fields, + gpointer user_data) +{ + return G_LOG_WRITER_HANDLED; +} + int main (int argc, char *argv[]) @@ -390,6 +399,10 @@ main (int argc, setlocale (LC_ALL, ""); g_test_init (&argc, &argv, NULL); + /* Ignore the log messages, as the debug controller prints one when debug is + * enabled/disabled, and if debug is enabled then that will escape to stdout. */ + g_log_set_writer_func (noop_log_writer_cb, NULL, NULL); + g_test_add_func ("/debug-controller/dbus/basic", test_dbus_basic); g_test_add_func ("/debug-controller/dbus/duplicate", test_dbus_duplicate); g_test_add_func ("/debug-controller/dbus/properties", test_dbus_properties); diff --git a/gio/tests/gengiotypefuncs.py b/gio/tests/gengiotypefuncs.py index dbd8195e7..ab99df66a 100644 --- a/gio/tests/gengiotypefuncs.py +++ b/gio/tests/gengiotypefuncs.py @@ -25,10 +25,9 @@ for filename in in_files: with open(filename, "rb") as f: for line in f: line = line.rstrip(b"\n").rstrip(b"\r") - # print line - match = re.search(b"\bg_[a-zA-Z0-9_]*_get_type\b", line) + match = re.search(br"\bg_[a-zA-Z0-9_]*_get_type\b", line) if match: - func = match.group(0) + func = match.group(0).decode('utf-8') if func not in funcs: funcs.append(func) if debug: @@ -38,10 +37,23 @@ file_output = "G_GNUC_BEGIN_IGNORE_DEPRECATIONS\n" funcs = sorted(funcs) +# These types generally emit critical warnings if constructed in the wrong +# environment (for example, without D-Bus running), so skip them. +ignored_types = [ + "g_io_extension_get_type", + "g_settings_backend_get_type", + "g_debug_controller_dbus_get_type", + "g_file_icon_get_type", + "g_unix_credentials_message_get_type", + "g_unix_socket_address_get_type", +] + for f in funcs: - if f not in ["g_io_extension_get_type", "g_settings_backend_get_type"]: + if f not in ignored_types: file_output += "*tp++ = {0} ();\n".format(f) +file_output += "G_GNUC_END_IGNORE_DEPRECATIONS\n" + if debug: print(len(funcs), "functions") diff --git a/gio/tests/socket.c b/gio/tests/socket.c index ca81f9350..c1c1bcf41 100644 --- a/gio/tests/socket.c +++ b/gio/tests/socket.c @@ -2052,14 +2052,14 @@ test_credentials_tcp_client (void) if (creds != NULL) { gchar *str = g_credentials_to_string (creds); - g_print ("Supported on this OS: %s\n", str); + g_test_message ("Supported on this OS: %s", str); g_free (str); g_clear_object (&creds); } else { g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED); - g_print ("Unsupported on this OS: %s\n", error->message); + g_test_message ("Unsupported on this OS: %s", error->message); g_clear_error (&error); } @@ -2118,14 +2118,14 @@ test_credentials_tcp_server (void) if (creds != NULL) { gchar *str = g_credentials_to_string (creds); - g_print ("Supported on this OS: %s\n", str); + g_test_message ("Supported on this OS: %s", str); g_free (str); g_clear_object (&creds); } else { g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED); - g_print ("Unsupported on this OS: %s\n", error->message); + g_test_message ("Unsupported on this OS: %s", error->message); g_clear_error (&error); } @@ -2321,14 +2321,14 @@ test_credentials_unix_socketpair (void) if (creds != NULL) { gchar *str = g_credentials_to_string (creds); - g_print ("Supported on this OS: %s\n", str); + g_test_message ("Supported on this OS: %s", str); g_free (str); g_clear_object (&creds); } else { g_assert_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED); - g_print ("Unsupported on this OS: %s\n", error->message); + g_test_message ("Unsupported on this OS: %s", error->message); g_clear_error (&error); } diff --git a/glib/tests/bitlock.c b/glib/tests/bitlock.c index 694fe6dd1..a21672099 100644 --- a/glib/tests/bitlock.c +++ b/glib/tests/bitlock.c @@ -1,15 +1,16 @@ #include -#define ITERATIONS 100000000 - static void test_bitlocks (void) { guint64 start = g_get_monotonic_time (); gint lock = 0; - gint i; + guint i; + guint n_iterations; - for (i = 0; i < ITERATIONS; i++) + n_iterations = g_test_perf () ? 100000000 : 1; + + for (i = 0; i < n_iterations; i++) { g_bit_lock (&lock, 0); g_bit_unlock (&lock, 0); @@ -21,7 +22,7 @@ test_bitlocks (void) elapsed = g_get_monotonic_time () - start; elapsed /= 1000000; - rate = ITERATIONS / elapsed; + rate = n_iterations / elapsed; g_test_maximized_result (rate, "iterations per second"); } @@ -32,8 +33,7 @@ main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); - if (g_test_perf ()) - g_test_add_func ("/bitlock/performance/uncontended", test_bitlocks); + g_test_add_func ("/bitlock/performance/uncontended", test_bitlocks); return g_test_run (); } diff --git a/glib/tests/meson.build b/glib/tests/meson.build index df0d9f8dd..d16a071e5 100644 --- a/glib/tests/meson.build +++ b/glib/tests/meson.build @@ -231,15 +231,11 @@ if installed_tests_enabled install_subdir('time-zones', install_dir : installed_tests_execdir) endif -# Not entirely random of course, but at least it changes over time -random_number = minor_version + meson.version().split('.').get(1).to_int() - test_env = environment() test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) test_env.set('G_DEBUG', 'gc-friendly') test_env.set('MALLOC_CHECK_', '2') -test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256)) test_deps = [libm, thread_dep, libglib_dep] test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT'] 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; diff --git a/glib/tests/spawn-singlethread.c b/glib/tests/spawn-singlethread.c index d0e3537ef..fec9a69d1 100644 --- a/glib/tests/spawn-singlethread.c +++ b/glib/tests/spawn-singlethread.c @@ -201,7 +201,7 @@ test_spawn_async_with_fds (void) { NO_FD, PIPE, STDOUT_PIPE }, /* Test the same fd for stdout + stderr */ }; - arg = g_strdup_printf ("thread %d", tnum); + arg = g_strdup_printf ("# thread %d\n", tnum); argv = g_ptr_array_new (); g_ptr_array_add (argv, echo_prog_path); diff --git a/glib/tests/uri.c b/glib/tests/uri.c index 0152b1a76..cf209efd0 100644 --- a/glib/tests/uri.c +++ b/glib/tests/uri.c @@ -351,7 +351,7 @@ test_uri_unescape_string (void) { "%0", NULL, NULL }, { "%ra", NULL, NULL }, { "%2r", NULL, NULL }, - { "Timm B\344der", NULL, "Timm B\344der" }, + { "Timm B\303\244der", NULL, "Timm B\303\244der" }, { NULL, NULL, NULL }, /* actually a valid test, not a delimiter */ }; gsize i; @@ -479,14 +479,16 @@ test_uri_escape_string (void) for (i = 0; i < G_N_ELEMENTS (tests); i++) { gchar *s = NULL; + gchar *escaped = g_strescape (tests[i].unescaped, NULL); - g_test_message ("Test %" G_GSIZE_FORMAT ": %s", i, tests[i].unescaped); + g_test_message ("Test %" G_GSIZE_FORMAT ": %s", i, escaped); s = g_uri_escape_string (tests[i].unescaped, tests[i].reserved_chars_allowed, tests[i].allow_utf8); g_assert_cmpstr (s, ==, tests[i].expected_escaped); g_free (s); + g_free (escaped); } } diff --git a/glib/tests/utf8-performance.c b/glib/tests/utf8-performance.c index ea24badf6..8f48c6ca4 100644 --- a/glib/tests/utf8-performance.c +++ b/glib/tests/utf8-performance.c @@ -22,7 +22,7 @@ #include -#define NUM_ITERATIONS 500000 +static guint num_iterations = 0; static const char str_ascii[] = "The quick brown fox jumps over the lazy dog"; @@ -44,8 +44,8 @@ typedef int (* GrindFunc) (const char *, gsize); #define GRIND_LOOP_BEGIN \ { \ - int i; \ - for (i = 0; i < NUM_ITERATIONS; i++) + guint i; \ + for (i = 0; i < num_iterations; i++) #define GRIND_LOOP_END \ } @@ -189,7 +189,7 @@ perform (gconstpointer data) gdouble result; len = strlen (str); - bytes_ground = (gulong) len * NUM_ITERATIONS; + bytes_ground = (gulong) len * num_iterations; g_test_timer_start (); @@ -232,18 +232,17 @@ main (int argc, char **argv) { g_test_init (&argc, &argv, NULL); - if (g_test_perf ()) - { - add_cases ("/utf8/perf/get_char", grind_get_char); - add_cases ("/utf8/perf/get_char-backwards", grind_get_char_backwards); - add_cases ("/utf8/perf/get_char_validated", grind_get_char_validated); - add_cases ("/utf8/perf/utf8_to_ucs4", grind_utf8_to_ucs4); - add_cases ("/utf8/perf/utf8_to_ucs4-sized", grind_utf8_to_ucs4_sized); - add_cases ("/utf8/perf/utf8_to_ucs4_fast", grind_utf8_to_ucs4_fast); - add_cases ("/utf8/perf/utf8_to_ucs4_fast-sized", grind_utf8_to_ucs4_fast_sized); - add_cases ("/utf8/perf/utf8_validate", grind_utf8_validate); - add_cases ("/utf8/perf/utf8_validate-sized", grind_utf8_validate_sized); - } + num_iterations = g_test_perf () ? 500000 : 1; + + add_cases ("/utf8/perf/get_char", grind_get_char); + add_cases ("/utf8/perf/get_char-backwards", grind_get_char_backwards); + add_cases ("/utf8/perf/get_char_validated", grind_get_char_validated); + add_cases ("/utf8/perf/utf8_to_ucs4", grind_utf8_to_ucs4); + add_cases ("/utf8/perf/utf8_to_ucs4-sized", grind_utf8_to_ucs4_sized); + add_cases ("/utf8/perf/utf8_to_ucs4_fast", grind_utf8_to_ucs4_fast); + add_cases ("/utf8/perf/utf8_to_ucs4_fast-sized", grind_utf8_to_ucs4_fast_sized); + add_cases ("/utf8/perf/utf8_validate", grind_utf8_validate); + add_cases ("/utf8/perf/utf8_validate-sized", grind_utf8_validate_sized); return g_test_run (); } diff --git a/gmodule/tests/meson.build b/gmodule/tests/meson.build index 1650fe5e0..ad1893b90 100644 --- a/gmodule/tests/meson.build +++ b/gmodule/tests/meson.build @@ -41,7 +41,6 @@ test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) test_env.set('G_DEBUG', 'gc-friendly') test_env.set('MALLOC_CHECK_', '2') -test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256)) test_deps = [libm, thread_dep, libglib_dep, libgmodule_dep] test_cargs = ['-DG_LOG_DOMAIN="GModule"', '-UG_DISABLE_ASSERT'] diff --git a/gobject/tests/basics-gobject.c b/gobject/tests/basics-gobject.c index 416828c24..60ab00319 100644 --- a/gobject/tests/basics-gobject.c +++ b/gobject/tests/basics-gobject.c @@ -91,7 +91,7 @@ print_foo (TestIface *tiobj, { if (!string) string = ""; - g_print ("Iface-FOO: \"%s\" from %p\n", string, tiobj); + g_test_message ("Iface-FOO: \"%s\" from %p", string, tiobj); } static void test_object_test_iface_init (gpointer giface, diff --git a/gobject/tests/meson.build b/gobject/tests/meson.build index f701152ca..a5c656f4d 100644 --- a/gobject/tests/meson.build +++ b/gobject/tests/meson.build @@ -111,15 +111,11 @@ python_tests = [ ] # FIXME: put common bits of test environment() in one location -# Not entirely random of course, but at least it changes over time -random_number = minor_version + meson.version().split('.').get(1).to_int() - test_env = environment() test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) test_env.set('G_DEBUG', 'gc-friendly') test_env.set('MALLOC_CHECK_', '2') -test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256)) test_deps = [libm, thread_dep, libglib_dep, libgobject_dep] test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"', '-UG_DISABLE_ASSERT'] diff --git a/gobject/tests/performance/meson.build b/gobject/tests/performance/meson.build index 064e8cb3d..8ff47cc0b 100644 --- a/gobject/tests/performance/meson.build +++ b/gobject/tests/performance/meson.build @@ -1,13 +1,50 @@ -common_c_args = test_cargs + ['-DGLIB_DISABLE_DEPRECATION_WARNINGS'] -common_deps = [libm, thread_dep, libglib_dep, libgobject_dep] +gobject_tests = { + 'performance' : { 'args' : [ '--seconds', '0' ] }, + 'performance-threaded' : { 'args' : [ '--seconds', '0' ] }, +} -# Don't install these ones, and keep them out of 'meson test' because they take too long... -executable('performance', 'performance.c', - c_args : common_c_args, - dependencies : common_deps, - install : false) +# FIXME: put common bits of test environment() in one location +test_env = environment() +test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) +test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) +test_env.set('G_DEBUG', 'gc-friendly') +test_env.set('MALLOC_CHECK_', '2') -executable('performance-threaded', 'performance-threaded.c', - c_args : common_c_args, - dependencies : common_deps, - install : false) \ No newline at end of file +test_deps = [libm, thread_dep, libglib_dep, libgobject_dep] +test_cargs = ['-DG_LOG_DOMAIN="GLib-GObject"', '-UG_DISABLE_ASSERT'] + +foreach test_name, extra_args : gobject_tests + source = extra_args.get('source', test_name + '.c') + install = installed_tests_enabled and extra_args.get('install', true) + + if install + test_conf = configuration_data() + test_conf.set('installed_tests_dir', installed_tests_execdir) + test_conf.set('program', test_name) + test_conf.set('env', '') + configure_file( + input: installed_tests_template_tap, + output: test_name + '.test', + install_dir: installed_tests_metadir, + configuration: test_conf, + ) + endif + + exe = executable(test_name, source, + c_args : test_cargs + extra_args.get('c_args', []), + dependencies : test_deps + extra_args.get('dependencies', []), + install_dir: installed_tests_execdir, + install: install, + ) + + suite = ['gobject', 'performance'] + extra_args.get('suite', []) + timeout = suite.contains('slow') ? test_timeout_slow : test_timeout + args = extra_args.get('args', []) + + test(test_name, exe, + env : test_env, + timeout : timeout, + suite : suite, + args : args, + ) +endforeach diff --git a/gobject/tests/performance/performance-threaded.c b/gobject/tests/performance/performance-threaded.c index 12a8b3d1e..7e6ebc5eb 100644 --- a/gobject/tests/performance/performance-threaded.c +++ b/gobject/tests/performance/performance-threaded.c @@ -231,7 +231,7 @@ run_test_thread (gpointer user_data) results = g_array_new (FALSE, FALSE, sizeof (double)); /* Run the test */ - while (g_timer_elapsed (total, NULL) < test_length) + do { g_timer_reset (timer); g_timer_start (timer); @@ -241,6 +241,7 @@ run_test_thread (gpointer user_data) g_array_append_val (results, elapsed); test->reset (data); } + while (g_timer_elapsed (total, NULL) < test_length); /* Tear down */ test->teardown (data); @@ -300,7 +301,7 @@ run_test (const PerformanceTest *test) threads = g_new (GThread *, n_threads); for (i = 0; i < n_threads; i++) { - threads[i] = g_thread_create (run_test_thread, (gpointer) test, TRUE, NULL); + threads[i] = g_thread_new (NULL, run_test_thread, (gpointer) test); g_assert (threads[i] != NULL); } diff --git a/gobject/tests/signal-handler.c b/gobject/tests/signal-handler.c index 7a236eed9..de38e8d65 100644 --- a/gobject/tests/signal-handler.c +++ b/gobject/tests/signal-handler.c @@ -45,96 +45,101 @@ nop (void) { } -#define HANDLERS 500000 +static guint n_handlers = 0; static void test_connect_many (void) { MyObj *o; gdouble time_elapsed; - gint i; + guint i; o = g_object_new (my_obj_get_type (), NULL); g_test_timer_start (); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) g_signal_connect (o, "signal1", G_CALLBACK (nop), NULL); time_elapsed = g_test_timer_elapsed (); g_object_unref (o); - g_test_minimized_result (time_elapsed, "connected %u handlers in %6.3f seconds", HANDLERS, time_elapsed); + g_test_minimized_result (time_elapsed, "connected %u handlers in %6.3f seconds", n_handlers, time_elapsed); } static void test_disconnect_many_ordered (void) { MyObj *o; - gulong handlers[HANDLERS]; + gulong *handlers; gdouble time_elapsed; - gint i; + guint i; + handlers = g_malloc_n (n_handlers, sizeof (*handlers)); o = g_object_new (my_obj_get_type (), NULL); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) handlers[i] = g_signal_connect (o, "signal1", G_CALLBACK (nop), NULL); g_test_timer_start (); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) g_signal_handler_disconnect (o, handlers[i]); time_elapsed = g_test_timer_elapsed (); g_object_unref (o); + g_free (handlers); - g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", HANDLERS, time_elapsed); + g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", n_handlers, time_elapsed); } static void test_disconnect_many_inverse (void) { MyObj *o; - gulong handlers[HANDLERS]; + gulong *handlers; gdouble time_elapsed; - gint i; + guint i; + handlers = g_malloc_n (n_handlers, sizeof (*handlers)); o = g_object_new (my_obj_get_type (), NULL); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) handlers[i] = g_signal_connect (o, "signal1", G_CALLBACK (nop), NULL); g_test_timer_start (); - for (i = HANDLERS - 1; i >= 0; i--) - g_signal_handler_disconnect (o, handlers[i]); + for (i = n_handlers; i > 0; i--) + g_signal_handler_disconnect (o, handlers[i - 1]); time_elapsed = g_test_timer_elapsed (); g_object_unref (o); + g_free (handlers); - g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", HANDLERS, time_elapsed); + g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", n_handlers, time_elapsed); } static void test_disconnect_many_random (void) { MyObj *o; - gulong handlers[HANDLERS]; + gulong *handlers; gulong id; gdouble time_elapsed; - gint i, j; + guint i, j; + handlers = g_malloc_n (n_handlers, sizeof (*handlers)); o = g_object_new (my_obj_get_type (), NULL); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) handlers[i] = g_signal_connect (o, "signal1", G_CALLBACK (nop), NULL); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) { - j = g_test_rand_int_range (0, HANDLERS); + j = g_test_rand_int_range (0, n_handlers); id = handlers[i]; handlers[i] = handlers[j]; handlers[j] = id; @@ -142,28 +147,30 @@ test_disconnect_many_random (void) g_test_timer_start (); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) g_signal_handler_disconnect (o, handlers[i]); time_elapsed = g_test_timer_elapsed (); g_object_unref (o); + g_free (handlers); - g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", HANDLERS, time_elapsed); + g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", n_handlers, time_elapsed); } static void test_disconnect_2_signals (void) { MyObj *o; - gulong handlers[HANDLERS]; + gulong *handlers; gulong id; gdouble time_elapsed; - gint i, j; + guint i, j; + handlers = g_malloc_n (n_handlers, sizeof (*handlers)); o = g_object_new (my_obj_get_type (), NULL); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) { if (i % 2 == 0) handlers[i] = g_signal_connect (o, "signal1", G_CALLBACK (nop), NULL); @@ -171,9 +178,9 @@ test_disconnect_2_signals (void) handlers[i] = g_signal_connect (o, "signal2", G_CALLBACK (nop), NULL); } - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) { - j = g_test_rand_int_range (0, HANDLERS); + j = g_test_rand_int_range (0, n_handlers); id = handlers[i]; handlers[i] = handlers[j]; handlers[j] = id; @@ -181,30 +188,33 @@ test_disconnect_2_signals (void) g_test_timer_start (); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) g_signal_handler_disconnect (o, handlers[i]); time_elapsed = g_test_timer_elapsed (); g_object_unref (o); + g_free (handlers); - g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", HANDLERS, time_elapsed); + g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", n_handlers, time_elapsed); } static void test_disconnect_2_objects (void) { MyObj *o1, *o2, *o; - gulong handlers[HANDLERS]; - MyObj *objects[HANDLERS]; + gulong *handlers; + MyObj **objects; gulong id; gdouble time_elapsed; - gint i, j; + guint i, j; + handlers = g_malloc_n (n_handlers, sizeof (*handlers)); + objects = g_malloc_n (n_handlers, sizeof (*objects)); o1 = g_object_new (my_obj_get_type (), NULL); o2 = g_object_new (my_obj_get_type (), NULL); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) { if (i % 2 == 0) { @@ -218,9 +228,9 @@ test_disconnect_2_objects (void) } } - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) { - j = g_test_rand_int_range (0, HANDLERS); + j = g_test_rand_int_range (0, n_handlers); id = handlers[i]; handlers[i] = handlers[j]; handlers[j] = id; @@ -231,34 +241,37 @@ test_disconnect_2_objects (void) g_test_timer_start (); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) g_signal_handler_disconnect (objects[i], handlers[i]); time_elapsed = g_test_timer_elapsed (); g_object_unref (o1); g_object_unref (o2); + g_free (objects); + g_free (handlers); - g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", HANDLERS, time_elapsed); + g_test_minimized_result (time_elapsed, "disconnected %u handlers in %6.3f seconds", n_handlers, time_elapsed); } static void test_block_many (void) { MyObj *o; - gulong handlers[HANDLERS]; + gulong *handlers; gulong id; gdouble time_elapsed; - gint i, j; + guint i, j; + handlers = g_malloc_n (n_handlers, sizeof (*handlers)); o = g_object_new (my_obj_get_type (), NULL); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) handlers[i] = g_signal_connect (o, "signal1", G_CALLBACK (nop), NULL); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) { - j = g_test_rand_int_range (0, HANDLERS); + j = g_test_rand_int_range (0, n_handlers); id = handlers[i]; handlers[i] = handlers[j]; handlers[j] = id; @@ -266,17 +279,18 @@ test_block_many (void) g_test_timer_start (); - for (i = 0; i < HANDLERS; i++) + for (i = 0; i < n_handlers; i++) g_signal_handler_block (o, handlers[i]); - for (i = HANDLERS - 1; i >= 0; i--) - g_signal_handler_unblock (o, handlers[i]); + for (i = n_handlers; i > 0; i--) + g_signal_handler_unblock (o, handlers[i - 1]); time_elapsed = g_test_timer_elapsed (); g_object_unref (o); + g_free (handlers); - g_test_minimized_result (time_elapsed, "blocked and unblocked %u handlers in %6.3f seconds", HANDLERS, time_elapsed); + g_test_minimized_result (time_elapsed, "blocked and unblocked %u handlers in %6.3f seconds", n_handlers, time_elapsed); } int @@ -284,16 +298,15 @@ main (int argc, char *argv[]) { g_test_init (&argc, &argv, NULL); - if (g_test_perf ()) - { - g_test_add_func ("/signal/handler/connect-many", test_connect_many); - g_test_add_func ("/signal/handler/disconnect-many-ordered", test_disconnect_many_ordered); - g_test_add_func ("/signal/handler/disconnect-many-inverse", test_disconnect_many_inverse); - g_test_add_func ("/signal/handler/disconnect-many-random", test_disconnect_many_random); - g_test_add_func ("/signal/handler/disconnect-2-signals", test_disconnect_2_signals); - g_test_add_func ("/signal/handler/disconnect-2-objects", test_disconnect_2_objects); - g_test_add_func ("/signal/handler/block-many", test_block_many); - } + n_handlers = g_test_perf () ? 500000 : 1; + + g_test_add_func ("/signal/handler/connect-many", test_connect_many); + g_test_add_func ("/signal/handler/disconnect-many-ordered", test_disconnect_many_ordered); + g_test_add_func ("/signal/handler/disconnect-many-inverse", test_disconnect_many_inverse); + g_test_add_func ("/signal/handler/disconnect-many-random", test_disconnect_many_random); + g_test_add_func ("/signal/handler/disconnect-2-signals", test_disconnect_2_signals); + g_test_add_func ("/signal/handler/disconnect-2-objects", test_disconnect_2_objects); + g_test_add_func ("/signal/handler/block-many", test_block_many); return g_test_run (); } diff --git a/tests/meson.build b/tests/meson.build index 9fd1ab121..c2d927854 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,14 +1,10 @@ # tests -# Not entirely random of course, but at least it changes over time -random_number = minor_version + meson.version().split('.').get(1).to_int() - test_env = environment() test_env.set('G_TEST_SRCDIR', meson.current_source_dir()) test_env.set('G_TEST_BUILDDIR', meson.current_build_dir()) test_env.set('G_DEBUG', 'gc-friendly') test_env.set('MALLOC_CHECK_', '2') -test_env.set('MALLOC_PERTURB_', '@0@'.format(random_number % 256)) test_cargs = ['-DG_LOG_DOMAIN="GLib"', '-UG_DISABLE_ASSERT']