From a0cf4dc3f9695d39f8c1ba423bf806d5eee173a1 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Thu, 26 Feb 2015 17:12:22 +0000 Subject: [PATCH 1/9] tests: avoid noise on stdout when not --verbose This makes life easier for frameworks like LAVA that screen-scrape test results. g_test_message() is not displayed by default, but each test can be run with either --tap or --verbose to get these messages displayed. --- test/corrupt.c | 8 ++++---- test/dbus-daemon.c | 10 +++++----- test/fdpass.c | 20 ++++++++++---------- test/loopback.c | 12 ++++++------ test/monitor.c | 18 +++++++++--------- test/relay.c | 6 +++--- test/test-utils-glib.c | 11 +++++++++++ test/test-utils-glib.h | 2 ++ 8 files changed, 50 insertions(+), 37 deletions(-) diff --git a/test/corrupt.c b/test/corrupt.c index 500cbeb..d106fcc 100644 --- a/test/corrupt.c +++ b/test/corrupt.c @@ -110,7 +110,7 @@ test_connect (Fixture *f, while (f->server_conn == NULL) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -139,7 +139,7 @@ test_message (Fixture *f, while (g_queue_is_empty (&f->client_messages)) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -231,7 +231,7 @@ test_corrupt (Fixture *f, * rubbish, so it should disconnect */ while (g_queue_is_empty (&f->client_messages)) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -320,7 +320,7 @@ test_byte_order (Fixture *f, * message, so it should disconnect */ while (g_queue_is_empty (&f->client_messages)) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c index f33eba1..72bcd08 100644 --- a/test/dbus-daemon.c +++ b/test/dbus-daemon.c @@ -406,7 +406,7 @@ test_creds (Fixture *f, g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==, DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&var_iter, &u32); - g_message ("%s of this process is %u", name, u32); + g_test_message ("%s of this process is %u", name, u32); g_assert_cmpuint (u32, ==, geteuid ()); seen |= SEEN_UNIX_USER; #else @@ -423,7 +423,7 @@ test_creds (Fixture *f, g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==, DBUS_TYPE_STRING); dbus_message_iter_get_basic (&var_iter, &sid); - g_message ("%s of this process is %s", name, sid); + g_test_message ("%s of this process is %s", name, sid); if (_dbus_getsid (&self_sid, 0)) { g_assert_cmpstr (self_sid, ==, sid); @@ -442,7 +442,7 @@ test_creds (Fixture *f, g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==, DBUS_TYPE_UINT32); dbus_message_iter_get_basic (&var_iter, &u32); - g_message ("%s of this process is %u", name, u32); + g_test_message ("%s of this process is %u", name, u32); #ifdef G_OS_UNIX g_assert_cmpuint (u32, ==, getpid ()); #elif defined(G_OS_WIN32) @@ -466,7 +466,7 @@ test_creds (Fixture *f, g_assert_cmpuint (dbus_message_iter_get_arg_type (&ay_iter), ==, DBUS_TYPE_BYTE); dbus_message_iter_get_fixed_array (&ay_iter, &label, &len); - g_message ("%s of this process is %s", name, label); + g_test_message ("%s of this process is %s", name, label); g_assert_cmpuint (strlen (label) + 1, ==, len); seen |= SEEN_LINUX_SECURITY_LABEL; #else @@ -533,7 +533,7 @@ test_processid (Fixture *f, g_assert_cmpstr (dbus_message_get_signature (m), ==, "u"); test_assert_no_error (&error); - g_message ("GetConnectionUnixProcessID returned %u", pid); + g_test_message ("GetConnectionUnixProcessID returned %u", pid); #ifdef G_OS_UNIX g_assert_cmpuint (pid, ==, getpid ()); diff --git a/test/fdpass.c b/test/fdpass.c index 74235c6..9a9d0ed 100644 --- a/test/fdpass.c +++ b/test/fdpass.c @@ -199,7 +199,7 @@ test_connect (Fixture *f, while (f->left_server_conn == NULL) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -212,7 +212,7 @@ test_connect (Fixture *f, while (f->right_server_conn == NULL) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -229,7 +229,7 @@ test_connect (Fixture *f, !dbus_connection_get_is_authenticated (f->left_server_conn) || !dbus_connection_get_is_authenticated (f->right_server_conn)) { - g_printerr ("*"); + test_progress ('*'); test_main_context_iterate (f->ctx, TRUE); } @@ -311,7 +311,7 @@ test_relay (Fixture *f, while (g_queue_get_length (&f->messages) < 1) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -394,7 +394,7 @@ test_limit (Fixture *f, while (g_queue_get_length (&f->messages) < 1) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -454,7 +454,7 @@ test_too_many (Fixture *f, while (dbus_connection_get_is_connected (f->left_client_conn) || dbus_connection_get_is_connected (f->left_server_conn)) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -587,7 +587,7 @@ test_too_many_split (Fixture *f, while (dbus_connection_get_is_connected (f->left_client_conn) || dbus_connection_get_is_connected (f->left_server_conn)) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -643,7 +643,7 @@ test_flood (Fixture *f, while (g_queue_get_length (&f->messages) < SOME_MESSAGES) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -711,7 +711,7 @@ test_odd_limit (Fixture *f, while (dbus_connection_get_is_connected (f->left_client_conn) || dbus_connection_get_is_connected (f->left_server_conn)) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -730,7 +730,7 @@ test_odd_limit (Fixture *f, /* We're at or under the limit. The message gets through intact. */ while (g_queue_get_length (&f->messages) < 1) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } diff --git a/test/loopback.c b/test/loopback.c index 930008c..bf0542a 100644 --- a/test/loopback.c +++ b/test/loopback.c @@ -125,7 +125,7 @@ setup_runtime (Fixture *f, setup (f, addr); listening_at = dbus_server_get_address (f->server); - g_message ("listening at %s", listening_at); + g_test_message ("listening at %s", listening_at); g_assert (g_str_has_prefix (listening_at, "unix:path=")); g_assert (strstr (listening_at, "dbus%3ddaemon%3dtest.") != NULL); g_assert (strstr (listening_at, "/bus,") != NULL || @@ -147,7 +147,7 @@ setup_no_runtime (Fixture *f, setup (f, addr); listening_at = dbus_server_get_address (f->server); - g_message ("listening at %s", listening_at); + g_test_message ("listening at %s", listening_at); /* we have fallen back to something in /tmp, either abstract or not */ g_assert (g_str_has_prefix (listening_at, "unix:")); g_assert (strstr (listening_at, "=/tmp/") != NULL); @@ -170,7 +170,7 @@ test_connect (Fixture *f, while (f->server_conn == NULL) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } } @@ -204,7 +204,7 @@ test_bad_guid (Fixture *f, while (f->server_conn == NULL) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -212,7 +212,7 @@ test_bad_guid (Fixture *f, while (g_queue_is_empty (&f->server_messages)) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -255,7 +255,7 @@ test_message (Fixture *f, while (g_queue_is_empty (&f->server_messages)) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } diff --git a/test/monitor.c b/test/monitor.c index 6983772..6c77bab 100644 --- a/test/monitor.c +++ b/test/monitor.c @@ -164,22 +164,22 @@ _log_message (DBusMessage *m, const char *file, int line) { - g_message ("%s:%d: message type %d (%s)", file, line, + g_test_message ("%s:%d: message type %d (%s)", file, line, dbus_message_get_type (m), dbus_message_type_to_string (dbus_message_get_type (m))); - g_message ("\tfrom: %s", + g_test_message ("\tfrom: %s", not_null2 (dbus_message_get_sender (m), "(dbus-daemon)")); - g_message ("\tto: %s", + g_test_message ("\tto: %s", not_null2 (dbus_message_get_destination (m), "(broadcast)")); - g_message ("\tpath: %s", + g_test_message ("\tpath: %s", not_null (dbus_message_get_path (m))); - g_message ("\tinterface: %s", + g_test_message ("\tinterface: %s", not_null (dbus_message_get_interface (m))); - g_message ("\tmember: %s", + g_test_message ("\tmember: %s", not_null (dbus_message_get_member (m))); - g_message ("\tsignature: %s", + g_test_message ("\tsignature: %s", not_null (dbus_message_get_signature (m))); - g_message ("\terror name: %s", + g_test_message ("\terror name: %s", not_null (dbus_message_get_error_name (m))); if (strcmp ("s", dbus_message_get_signature (m)) == 0) @@ -191,7 +191,7 @@ _log_message (DBusMessage *m, DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID); test_assert_no_error (&e); - g_message ("\tstring payload: %s", s); + g_test_message ("\tstring payload: %s", s); } } diff --git a/test/relay.c b/test/relay.c index a6ccb41..ca3c385 100644 --- a/test/relay.c +++ b/test/relay.c @@ -155,7 +155,7 @@ test_connect (Fixture *f, while (f->left_server_conn == NULL) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -168,7 +168,7 @@ test_connect (Fixture *f, while (f->right_server_conn == NULL) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } @@ -210,7 +210,7 @@ test_relay (Fixture *f, while (g_queue_get_length (&f->messages) < 2) { - g_print ("."); + test_progress ('.'); test_main_context_iterate (f->ctx, TRUE); } diff --git a/test/test-utils-glib.c b/test/test-utils-glib.c index 609f24e..e112f8e 100644 --- a/test/test-utils-glib.c +++ b/test/test-utils-glib.c @@ -45,6 +45,10 @@ #include +#ifdef G_OS_WIN +# define isatty(x) _isatty(x) +#endif + void _test_assert_no_error (const DBusError *e, const char *file, @@ -428,3 +432,10 @@ test_init (int *argcp, char ***argvp) } #endif } + +void +test_progress (char symbol) +{ + if (g_test_verbose () && isatty (1)) + g_print ("%c", symbol); +} diff --git a/test/test-utils-glib.h b/test/test-utils-glib.h index fd14fd1..ce1b297 100644 --- a/test/test-utils-glib.h +++ b/test/test-utils-glib.h @@ -81,4 +81,6 @@ void test_kill_pid (GPid pid); void test_init (int *argcp, char ***argvp); +void test_progress (char symbol); + #endif -- 2.1.4