diff options
author | Simon McVittie <smcv@collabora.com> | 2017-11-14 14:09:59 +0000 |
---|---|---|
committer | Simon McVittie <smcv@collabora.com> | 2017-11-15 12:11:54 +0000 |
commit | ed40af9284b4ea658b8b7debfa42530a1c28bbf1 (patch) | |
tree | dd2b770ecec0a6437808ecc1fd7ce4efc6d24e5c /bus | |
parent | 5ffb709b42783b0d13a49b8c9a84c75f556c88a2 (diff) |
Embedded tests: Emit TAP diagnostics instead of printf
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
Diffstat (limited to 'bus')
-rw-r--r-- | bus/config-parser-trivial.c | 27 | ||||
-rw-r--r-- | bus/config-parser.c | 53 | ||||
-rw-r--r-- | bus/test-launch-helper.c | 40 | ||||
-rw-r--r-- | bus/test-main.c | 57 | ||||
-rw-r--r-- | bus/test-system.c | 30 |
5 files changed, 85 insertions, 122 deletions
diff --git a/bus/config-parser-trivial.c b/bus/config-parser-trivial.c index dd65c6d4..bb163928 100644 --- a/bus/config-parser-trivial.c +++ b/bus/config-parser-trivial.c @@ -28,6 +28,7 @@ #include "utils.h" #include <dbus/dbus-list.h> #include <dbus/dbus-internals.h> +#include <dbus/dbus-test-tap.h> #include <string.h> /** @@ -400,7 +401,7 @@ check_return_values (const DBusString *full_path) dbus_error_init (&error); retval = FALSE; - printf ("Testing values from: %s\n", _dbus_string_get_const_data (full_path)); + _dbus_test_diag ("Testing values from: %s", _dbus_string_get_const_data (full_path)); parser = bus_config_load (full_path, TRUE, NULL, &error); if (parser == NULL) @@ -426,7 +427,7 @@ check_return_values (const DBusString *full_path) _dbus_warn ("User was invalid; '%s'!", user); goto finish; } - printf (" <user>dbus</user> OKAY!\n"); + _dbus_test_diag (" <user>dbus</user> OKAY!"); #endif /* check type return value is okay */ @@ -441,7 +442,7 @@ check_return_values (const DBusString *full_path) _dbus_warn ("Type was invalid; '%s'!", user); goto finish; } - printf (" <type>system</type> OKAY!\n"); + _dbus_test_diag (" <type>system</type> OKAY!"); /* check dirs return value is okay */ dirs = bus_config_parser_get_service_paths (parser); @@ -450,7 +451,7 @@ check_return_values (const DBusString *full_path) _dbus_warn ("Service dirs are NULL!"); goto finish; } - printf (" <standard_system_service_dirs/> OKAY!\n"); + _dbus_test_diag (" <standard_system_service_dirs/> OKAY!"); /* NOTE: We tested the specific return values in the config-parser tests */ /* woohoo! */ @@ -570,11 +571,11 @@ process_test_valid_subdir (const DBusString *test_base_dir, } if (validity == VALID) - printf ("Testing valid files:\n"); + _dbus_test_diag ("Testing valid files:"); else if (validity == INVALID) - printf ("Testing invalid files:\n"); + _dbus_test_diag ("Testing invalid files:"); else - printf ("Testing unknown files:\n"); + _dbus_test_diag ("Testing unknown files:"); next: while (_dbus_directory_get_next_file (dir, &filename, &error)) @@ -599,7 +600,7 @@ process_test_valid_subdir (const DBusString *test_base_dir, goto next; } - printf (" %s\n", _dbus_string_get_const_data (&filename)); + _dbus_test_diag (" %s", _dbus_string_get_const_data (&filename)); _dbus_verbose (" expecting %s\n", validity == VALID ? "valid" : @@ -695,14 +696,14 @@ check_file_valid (DBusString *full_path, dbus_bool_t retval; if (validity == VALID) - printf ("Testing valid file:\n"); + _dbus_test_diag ("Testing valid file:"); else if (validity == INVALID) - printf ("Testing invalid file:\n"); + _dbus_test_diag ("Testing invalid file:"); else - printf ("Testing unknown file:\n"); + _dbus_test_diag ("Testing unknown file:"); /* print the filename, just so we match the other output */ - printf (" %s\n", _dbus_string_get_const_data (full_path)); + _dbus_test_diag (" %s", _dbus_string_get_const_data (full_path)); /* only test one file */ retval = do_load (full_path, validity, TRUE); @@ -721,7 +722,7 @@ bus_config_parser_trivial_test (const DBusString *test_data_dir) if (test_data_dir == NULL || _dbus_string_get_length (test_data_dir) == 0) { - printf ("No test data\n"); + _dbus_test_diag ("No test data"); return TRUE; } diff --git a/bus/config-parser.c b/bus/config-parser.c index 8752fdef..254e3fa2 100644 --- a/bus/config-parser.c +++ b/bus/config-parser.c @@ -33,6 +33,7 @@ #include <dbus/dbus-internals.h> #include <dbus/dbus-misc.h> #include <dbus/dbus-sysdeps.h> +#include <dbus/dbus-test-tap.h> #include <string.h> typedef enum @@ -3081,7 +3082,7 @@ do_check_own_rules (BusPolicy *policy) _dbus_assert_not_reached ("couldn't append string"); ret = bus_policy_check_can_own (policy, &service_name); - printf (" Check name %s: %s\n", checks[i].name, + _dbus_test_diag (" Check name %s: %s", checks[i].name, ret ? "allowed" : "not allowed"); if (checks[i].allowed && !ret) { @@ -3216,11 +3217,11 @@ process_test_valid_subdir (const DBusString *test_base_dir, } if (validity == VALID) - printf ("Testing valid files:\n"); + _dbus_test_diag ("Testing valid files:"); else if (validity == INVALID) - printf ("Testing invalid files:\n"); + _dbus_test_diag ("Testing invalid files:"); else - printf ("Testing unknown files:\n"); + _dbus_test_diag ("Testing unknown files:"); next: while (_dbus_directory_get_next_file (dir, &filename, &error)) @@ -3245,7 +3246,7 @@ process_test_valid_subdir (const DBusString *test_base_dir, goto next; } - printf (" %s\n", _dbus_string_get_const_data (&filename)); + _dbus_test_diag (" %s", _dbus_string_get_const_data (&filename)); _dbus_verbose (" expecting %s\n", validity == VALID ? "valid" : @@ -3537,7 +3538,7 @@ all_are_equiv (const DBusString *target_directory) goto finished; } - printf ("Comparing equivalent files:\n"); + _dbus_test_diag ("Comparing equivalent files:"); next: while (_dbus_directory_get_next_file (dir, &filename, &error)) @@ -3561,7 +3562,7 @@ all_are_equiv (const DBusString *target_directory) goto next; } - printf (" %s\n", _dbus_string_get_const_data (&filename)); + _dbus_test_diag (" %s", _dbus_string_get_const_data (&filename)); parser = bus_config_load (&full_path, TRUE, NULL, &error); @@ -3778,9 +3779,9 @@ test_default_session_servicedirs (const DBusString *test_base_dir) if (dbus_test_builddir == NULL || xdg_data_home == NULL || xdg_runtime_dir == NULL) { - printf ("Not testing default session service directories because a " + _dbus_test_diag ("Not testing default session service directories because a " "build-time testing environment variable is not set: " - "see AM_TESTS_ENVIRONMENT in tests/Makefile.am\n"); + "see AM_TESTS_ENVIRONMENT in tests/Makefile.am"); ret = TRUE; goto out; } @@ -3832,17 +3833,17 @@ test_default_session_servicedirs (const DBusString *test_base_dir) BusConfigServiceDir *dir = link->data; BusServiceDirFlags expected = BUS_SERVICE_DIR_FLAGS_NONE; - printf (" test service dir: '%s'\n", dir->path); - printf (" current standard service dir: '%s'\n", test_session_service_dir_matches[i]); + _dbus_test_diag (" test service dir: '%s'", dir->path); + _dbus_test_diag (" current standard service dir: '%s'", test_session_service_dir_matches[i]); if (test_session_service_dir_matches[i] == NULL) { - printf ("more directories parsed than in match set\n"); + _dbus_test_diag ("more directories parsed than in match set"); goto out; } if (strcmp (test_session_service_dir_matches[i], dir->path) != 0) { - printf ("'%s' directory does not match '%s' in the match set\n", + _dbus_test_diag ("'%s' directory does not match '%s' in the match set", dir->path, test_session_service_dir_matches[i]); goto out; } @@ -3857,7 +3858,7 @@ test_default_session_servicedirs (const DBusString *test_base_dir) if (dir->flags != expected) { - printf ("'%s' directory has flags 0x%x, should be 0x%x\n", + _dbus_test_diag ("'%s' directory has flags 0x%x, should be 0x%x", dir->path, dir->flags, expected); goto out; } @@ -3865,7 +3866,7 @@ test_default_session_servicedirs (const DBusString *test_base_dir) if (test_session_service_dir_matches[i] != NULL) { - printf ("extra data %s in the match set was not matched\n", + _dbus_test_diag ("extra data %s in the match set was not matched", test_session_service_dir_matches[i]); goto out; } @@ -3887,20 +3888,20 @@ test_default_session_servicedirs (const DBusString *test_base_dir) link != NULL; link = _dbus_list_get_next_link (&watched_dirs, link), i++) { - printf (" watched service dir: '%s'\n", (const char *) link->data); - printf (" current standard service dir: '%s'\n", + _dbus_test_diag (" watched service dir: '%s'", (const char *) link->data); + _dbus_test_diag (" current standard service dir: '%s'", test_session_service_dir_matches[i]); if (test_session_service_dir_matches[i] == NULL) { - printf ("more directories parsed than in match set\n"); + _dbus_test_diag ("more directories parsed than in match set"); goto out; } if (strcmp (test_session_service_dir_matches[i], (const char *) link->data) != 0) { - printf ("'%s' directory does not match '%s' in the match set\n", + _dbus_test_diag ("'%s' directory does not match '%s' in the match set", (const char *) link->data, test_session_service_dir_matches[i]); goto out; @@ -3909,7 +3910,7 @@ test_default_session_servicedirs (const DBusString *test_base_dir) if (test_session_service_dir_matches[i] != NULL) { - printf ("extra data %s in the match set was not matched\n", + _dbus_test_diag ("extra data %s in the match set was not matched", test_session_service_dir_matches[i]); goto out; } @@ -3957,10 +3958,10 @@ test_default_system_servicedirs (void) i = 0; while ((link = _dbus_list_pop_first_link (&dirs))) { - printf (" test service dir: %s\n", (char *)link->data); + _dbus_test_diag (" test service dir: %s", (char *)link->data); if (test_system_service_dir_matches[i] == NULL) { - printf ("more directories parsed than in match set\n"); + _dbus_test_diag ("more directories parsed than in match set"); dbus_free (link->data); _dbus_list_free_link (link); return FALSE; @@ -3969,7 +3970,7 @@ test_default_system_servicedirs (void) if (strcmp (test_system_service_dir_matches[i], (char *)link->data) != 0) { - printf ("%s directory does not match %s in the match set\n", + _dbus_test_diag ("%s directory does not match %s in the match set", (char *)link->data, test_system_service_dir_matches[i]); dbus_free (link->data); @@ -3985,7 +3986,7 @@ test_default_system_servicedirs (void) if (test_system_service_dir_matches[i] != NULL) { - printf ("extra data %s in the match set was not matched\n", + _dbus_test_diag ("extra data %s in the match set was not matched", test_system_service_dir_matches[i]); return FALSE; @@ -4001,7 +4002,7 @@ bus_config_parser_test (const DBusString *test_data_dir) if (test_data_dir == NULL || _dbus_string_get_length (test_data_dir) == 0) { - printf ("No test data\n"); + _dbus_test_diag ("No test data"); return TRUE; } @@ -4009,7 +4010,7 @@ bus_config_parser_test (const DBusString *test_data_dir) return FALSE; #ifdef DBUS_WIN - printf("default system service dir skipped\n"); + _dbus_test_diag ("default system service dir skipped"); #else if (!test_default_system_servicedirs()) return FALSE; diff --git a/bus/test-launch-helper.c b/bus/test-launch-helper.c index 5872ab20..1d1985ae 100644 --- a/bus/test-launch-helper.c +++ b/bus/test-launch-helper.c @@ -29,31 +29,22 @@ #include <stdlib.h> #include <dbus/dbus-internals.h> #include <dbus/dbus-misc.h> +#include <dbus/dbus-test-tap.h> #if !defined(DBUS_ENABLE_EMBEDDED_TESTS) || !defined(DBUS_UNIX) #error This file is only relevant for the embedded tests on Unix #endif -static void die (const char *failure) _DBUS_GNUC_NORETURN; - -static void -die (const char *failure) -{ - fprintf (stderr, "Unit test failed: %s\n", failure); - exit (1); -} - static void check_memleaks (const char *name) { dbus_shutdown (); - - printf ("%s: checking for memleaks\n", name); + + _dbus_test_diag ("%s: checking for memleaks", name); if (_dbus_get_malloc_blocks_outstanding () != 0) { - _dbus_warn ("%d dbus_malloc blocks were not freed", - _dbus_get_malloc_blocks_outstanding ()); - die ("memleaks"); + _dbus_test_fatal ("%d dbus_malloc blocks were not freed", + _dbus_get_malloc_blocks_outstanding ()); } } @@ -110,19 +101,14 @@ main (int argc, char **argv) dir = _dbus_getenv ("DBUS_TEST_DATA"); if (dir == NULL) - { - fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); - return 1; - } + _dbus_test_fatal ("Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable"); - printf ("%s: Running launch helper OOM checks\n", argv[0]); + _dbus_test_diag ("%s: Running launch helper OOM checks", argv[0]); - if (!_dbus_string_init (&config_file)) - return 1; - if (!_dbus_string_append (&config_file, dir)) - return 1; - if (!_dbus_string_append (&config_file, "/valid-config-files-system/debug-allow-all-pass.conf")) - return 1; + if (!_dbus_string_init (&config_file) || + !_dbus_string_append (&config_file, dir) || + !_dbus_string_append (&config_file, "/valid-config-files-system/debug-allow-all-pass.conf")) + _dbus_test_fatal ("OOM during initialization"); /* use a config file that will actually work... */ dbus_setenv ("TEST_LAUNCH_HELPER_CONFIG", @@ -133,11 +119,11 @@ main (int argc, char **argv) if (!_dbus_test_oom_handling ("dbus-daemon-launch-helper", bus_activation_helper_oom_test, (char *) "org.freedesktop.DBus.TestSuiteEchoService")) - die ("OOM failed"); + _dbus_test_fatal ("OOM test failed"); test_post_hook (argv[0]); - printf ("%s: Success\n", argv[0]); + _dbus_test_diag ("%s: Success", argv[0]); return 0; } diff --git a/bus/test-main.c b/bus/test-main.c index 4d3df87a..bf37751c 100644 --- a/bus/test-main.c +++ b/bus/test-main.c @@ -29,6 +29,7 @@ #include <dbus/dbus-sysdeps.h> #include <dbus/dbus-internals.h> #include <dbus/dbus-message-internal.h> +#include <dbus/dbus-test-tap.h> #include "selinux.h" #ifndef DBUS_ENABLE_EMBEDDED_TESTS @@ -39,26 +40,16 @@ # include <dbus/dbus-sysdeps-unix.h> #endif -static void die (const char *failure) _DBUS_GNUC_NORETURN; - -static void -die (const char *failure) -{ - fprintf (stderr, "Unit test failed: %s\n", failure); - exit (1); -} - static void check_memleaks (const char *name) { dbus_shutdown (); - printf ("%s: checking for memleaks\n", name); + _dbus_test_diag ("%s: checking for memleaks", name); if (_dbus_get_malloc_blocks_outstanding () != 0) { - _dbus_warn ("%d dbus_malloc blocks were not freed", - _dbus_get_malloc_blocks_outstanding ()); - die ("memleaks"); + _dbus_test_fatal ("%d dbus_malloc blocks were not freed", + _dbus_get_malloc_blocks_outstanding ()); } } @@ -71,7 +62,7 @@ test_pre_hook (void) if (_dbus_getenv ("DBUS_TEST_SELINUX") && (!bus_selinux_pre_init () || !bus_selinux_full_init ())) - die ("could not init selinux support"); + _dbus_test_fatal ("Could not init selinux support"); initial_fds = _dbus_check_fdleaks_enter (); } @@ -109,10 +100,7 @@ main (int argc, char **argv) only = NULL; if (dir == NULL) - { - fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); - return 1; - } + _dbus_test_fatal ("Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable"); _dbus_string_init_const (&test_data_dir, dir); @@ -122,59 +110,59 @@ main (int argc, char **argv) #endif if (!_dbus_threads_init_debug ()) - die ("initializing debug threads"); + _dbus_test_fatal ("OOM initializing debug threads"); if (only == NULL || strcmp (only, "expire-list") == 0) { test_pre_hook (); - printf ("%s: Running expire list test\n", argv[0]); + _dbus_test_diag ("%s: Running expire list test", argv[0]); if (!bus_expire_list_test (&test_data_dir)) - die ("expire list"); + _dbus_test_fatal ("expire list test failed"); test_post_hook (); } if (only == NULL || strcmp (only, "config-parser") == 0) { test_pre_hook (); - printf ("%s: Running config file parser test\n", argv[0]); + _dbus_test_diag ("%s: Running config file parser test", argv[0]); if (!bus_config_parser_test (&test_data_dir)) - die ("parser"); + _dbus_test_fatal ("parser test failed"); test_post_hook (); } if (only == NULL || strcmp (only, "signals") == 0) { test_pre_hook (); - printf ("%s: Running signals test\n", argv[0]); + _dbus_test_diag ("%s: Running signals test", argv[0]); if (!bus_signals_test (&test_data_dir)) - die ("signals"); + _dbus_test_fatal ("signals test failed"); test_post_hook (); } if (only == NULL || strcmp (only, "dispatch-sha1") == 0) { test_pre_hook (); - printf ("%s: Running SHA1 connection test\n", argv[0]); + _dbus_test_diag ("%s: Running SHA1 connection test", argv[0]); if (!bus_dispatch_sha1_test (&test_data_dir)) - die ("sha1"); + _dbus_test_fatal ("sha1 test failed"); test_post_hook (); } if (only == NULL || strcmp (only, "dispatch") == 0) { test_pre_hook (); - printf ("%s: Running message dispatch test\n", argv[0]); + _dbus_test_diag ("%s: Running message dispatch test", argv[0]); if (!bus_dispatch_test (&test_data_dir)) - die ("dispatch"); + _dbus_test_fatal ("dispatch test failed"); test_post_hook (); } if (only == NULL || strcmp (only, "activation-service-reload") == 0) { test_pre_hook (); - printf ("%s: Running service files reloading test\n", argv[0]); + _dbus_test_diag ("%s: Running service files reloading test", argv[0]); if (!bus_activation_service_reload_test (&test_data_dir)) - die ("service reload"); + _dbus_test_fatal ("service reload test failed"); test_post_hook (); } @@ -182,15 +170,14 @@ main (int argc, char **argv) if (only == NULL || strcmp (only, "unix-fds-passing") == 0) { test_pre_hook (); - printf ("%s: Running unix fd passing test\n", argv[0]); + _dbus_test_diag ("%s: Running unix fd passing test", argv[0]); if (!bus_unix_fds_passing_test (&test_data_dir)) - die ("unix fd passing"); + _dbus_test_fatal ("unix fd passing test failed"); test_post_hook (); } #endif - printf ("%s: Success\n", argv[0]); + _dbus_test_diag ("%s: Success", argv[0]); - return 0; } diff --git a/bus/test-system.c b/bus/test-system.c index de1f003b..a434b6fa 100644 --- a/bus/test-system.c +++ b/bus/test-system.c @@ -28,31 +28,22 @@ #include <dbus/dbus-string.h> #include <dbus/dbus-sysdeps.h> #include <dbus/dbus-internals.h> +#include <dbus/dbus-test-tap.h> #if !defined(DBUS_ENABLE_EMBEDDED_TESTS) || !defined(DBUS_UNIX) #error This file is only relevant for the embedded tests on Unix #endif -static void die (const char *failure) _DBUS_GNUC_NORETURN; - -static void -die (const char *failure) -{ - fprintf (stderr, "Unit test failed: %s\n", failure); - exit (1); -} - static void check_memleaks (const char *name) { dbus_shutdown (); - printf ("%s: checking for memleaks\n", name); + _dbus_test_diag ("%s: checking for memleaks", name); if (_dbus_get_malloc_blocks_outstanding () != 0) { - _dbus_warn ("%d dbus_malloc blocks were not freed", - _dbus_get_malloc_blocks_outstanding ()); - die ("memleaks"); + _dbus_test_fatal ("%d dbus_malloc blocks were not freed", + _dbus_get_malloc_blocks_outstanding ()); } } @@ -82,23 +73,20 @@ main (int argc, char **argv) dir = _dbus_getenv ("DBUS_TEST_DATA"); if (dir == NULL) - { - fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n"); - return 1; - } + _dbus_test_fatal ("Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable"); _dbus_string_init_const (&test_data_dir, dir); if (!_dbus_threads_init_debug ()) - die ("initializing debug threads"); + _dbus_test_fatal ("OOM initializing debug threads"); test_pre_hook (); - printf ("%s: Running config file parser (trivial) test\n", argv[0]); + _dbus_test_diag ("%s: Running config file parser (trivial) test", argv[0]); if (!bus_config_parser_trivial_test (&test_data_dir)) - die ("parser"); + _dbus_test_fatal ("OOM creating parser"); test_post_hook (); - printf ("%s: Success\n", argv[0]); + _dbus_test_diag ("%s: Success", argv[0]); return 0; } |