Merge branch 'test-suite-fixes' into 'main'

tests: Various fixes for TAP output of tests

See merge request GNOME/glib!2749
This commit is contained in:
Marco Trevisan
2022-06-22 18:48:59 +00:00
17 changed files with 192 additions and 128 deletions

View File

@@ -91,7 +91,7 @@ print_foo (TestIface *tiobj,
{
if (!string)
string = "<NULL>";
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,

View File

@@ -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']

View File

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

View File

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

View File

@@ -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 ();
}