From 1b377e6574edc8a35256c96347d735239e52b016 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 21 Jun 2022 12:49:15 +0100 Subject: [PATCH 01/15] build: Drop MALLOC_PERTURB_ from test environments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s set already by Meson, to an actually random value. Signed-off-by: Philip Withnall --- glib/tests/meson.build | 4 ---- gmodule/tests/meson.build | 1 - gobject/tests/meson.build | 4 ---- tests/meson.build | 4 ---- 4 files changed, 13 deletions(-) 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/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/meson.build b/gobject/tests/meson.build index 84132518a..c5e28b0a0 100644 --- a/gobject/tests/meson.build +++ b/gobject/tests/meson.build @@ -109,15 +109,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/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'] From f977ddf34f3973be8486ed664d4deef7b10d05ca Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 15:19:47 +0100 Subject: [PATCH 02/15] tests: Fix non-TAP output from debugcontroller test When running under a strict TAP parser this was previously producing problematic non-conforming output. Signed-off-by: Philip Withnall --- gio/tests/debugcontroller.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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); From 8dde15a5b328e370a8d28ddfda065d103db1dee9 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 15:20:39 +0100 Subject: [PATCH 03/15] tests: Fix gengiotypefuncs.py helper script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems this script has potentially never worked properly under Python 3. It’s supposed to list all the `_get_type()` functions it can find in the GIO headers, but since the regex string passed to `re.search()` was not a Python regex, nothing was matching. Fix that, and do another few small cleanups to the script. This makes the `defaultvalue` test not skip all the types. Signed-off-by: Philip Withnall --- gio/tests/gengiotypefuncs.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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") From 75a39114d82af44711f4647e6af700bffa4b8ec1 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 15:23:21 +0100 Subject: [PATCH 04/15] tests: Fix non-TAP output from socket test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was breaking strict TAP parsers, such as Meson’s. Signed-off-by: Philip Withnall --- gio/tests/socket.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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); } From d48470df52d62c13d4b34beea8185725a0bb79fb Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 18:32:07 +0100 Subject: [PATCH 05/15] tests: Fix TAP output from spawn-singlethread test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The output from the echo program ends up being outputted with the stdout from the unit test in some tests. Ensure that the input to the echo program is therefore a valid TAP comment, rather than garbage, so that it’s safely ignored by a TAP parser looking at the output from the test. Signed-off-by: Philip Withnall --- glib/tests/spawn-singlethread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From b82bfe7642e1ec06399853f7299dd58f6531c50f Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 18:33:49 +0100 Subject: [PATCH 06/15] tests: Fix an invalid UTF-8 sequence in the uri tests This sequence was meant to be valid, but was incorrectly just the octal form of the desired Unicode codepoint, not the UTF-8 encoding of that codepoint. This was causing `g_test_message()` to print an `[Invalid UTF-8]` warning. Signed-off-by: Philip Withnall --- glib/tests/uri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/tests/uri.c b/glib/tests/uri.c index 0152b1a76..0b9ca1a9f 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; From 011202dbc59bcf8480508370afc4776f31f1bb0e Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 18:34:55 +0100 Subject: [PATCH 07/15] tests: Encode invalid UTF-8 before outputted in a test message `g_test_message()` requires correctly encoded arguments, but some of the strings in the `uri` test are (deliberately) not valid UTF-8. Encode them before printing them. Signed-off-by: Philip Withnall --- glib/tests/uri.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/glib/tests/uri.c b/glib/tests/uri.c index 0b9ca1a9f..cf209efd0 100644 --- a/glib/tests/uri.c +++ b/glib/tests/uri.c @@ -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); } } From 74e71c78c013e58bbea4a2263513ea59432529c7 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 18:36:17 +0100 Subject: [PATCH 08/15] tests: Fix a non-TAP formatted debug message in the basics-gobject test Signed-off-by: Philip Withnall --- gobject/tests/basics-gobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 6b8240f061e9d545bf2b3a8741ccdf73697f1600 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 15:26:51 +0100 Subject: [PATCH 09/15] tests: Fix performance-threaded test when run for zero seconds When running the test with `-s 0` it would previously crash. Fix that, and make it so that it only does a single test run in that case. This will be useful in an upcoming commit for smoketesting the test to avoid bitrot. Signed-off-by: Philip Withnall --- gobject/tests/performance/performance-threaded.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gobject/tests/performance/performance-threaded.c b/gobject/tests/performance/performance-threaded.c index 12a8b3d1e..97aa4384b 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); From 6747702d776535ed1f2aa3ace5e27a5a5ab567de Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 15:27:43 +0100 Subject: [PATCH 10/15] tests: Fix use of deprecated threading API in performance-threaded Signed-off-by: Philip Withnall --- gobject/tests/performance/performance-threaded.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gobject/tests/performance/performance-threaded.c b/gobject/tests/performance/performance-threaded.c index 97aa4384b..7e6ebc5eb 100644 --- a/gobject/tests/performance/performance-threaded.c +++ b/gobject/tests/performance/performance-threaded.c @@ -301,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); } From 6f435e40cd72d919ebe9effaaf34cc399e5c3529 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 15:28:15 +0100 Subject: [PATCH 11/15] tests: Run GObject performance tests under meson test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pass arguments to them so that they take minimal time. This will not produce useful performance profiling results, but will smoketest that the tests still run, don’t crash, and therefore probably aren’t bitrotting too badly. This is useful because a fair amount of work has gone into these performance tests, and they’re useful every few years to analyse and compare GObject performance. We don’t want them to bitrot between uses. Signed-off-by: Philip Withnall --- gobject/tests/performance/meson.build | 59 ++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 11 deletions(-) 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 From 419f882952153a2bc6fd1548b2c551531209f622 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 16:58:34 +0100 Subject: [PATCH 12/15] tests: Allow bitlock performance test to be smoketested Allow it to be run with a reduced iteration count when not run as `-m perf`, in order to check that the test still works. Previously it would do nothing when run without `-m perf`. Signed-off-by: Philip Withnall --- glib/tests/bitlock.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) 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 (); } From e51c80591be0fa7e39afe7c997f73a08eb9cb59c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 16:59:32 +0100 Subject: [PATCH 13/15] 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; From 421c238e810ad0de4ddf13f81233459ea46b5f64 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 18:35:52 +0100 Subject: [PATCH 14/15] tests: Allow utf8-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/utf8-performance.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) 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 (); } From 1aaf1e7de119c1727d0115951876afb3bf0daa34 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 14 Jun 2022 15:24:17 +0100 Subject: [PATCH 15/15] tests: Allow signal-handler 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 --- gobject/tests/signal-handler.c | 125 ++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 56 deletions(-) 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 (); }