Commit b7e56c18 authored by Simon McVittie's avatar Simon McVittie

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.
Reviewed-by: Philip Withnall's avatarPhilip Withnall <philip.withnall@collabora.co.uk>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=89846
parent 54f92110
...@@ -110,7 +110,7 @@ test_connect (Fixture *f, ...@@ -110,7 +110,7 @@ test_connect (Fixture *f,
while (f->server_conn == NULL) while (f->server_conn == NULL)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -139,7 +139,7 @@ test_message (Fixture *f, ...@@ -139,7 +139,7 @@ test_message (Fixture *f,
while (g_queue_is_empty (&f->client_messages)) while (g_queue_is_empty (&f->client_messages))
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -231,7 +231,7 @@ test_corrupt (Fixture *f, ...@@ -231,7 +231,7 @@ test_corrupt (Fixture *f,
* rubbish, so it should disconnect */ * rubbish, so it should disconnect */
while (g_queue_is_empty (&f->client_messages)) while (g_queue_is_empty (&f->client_messages))
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -320,7 +320,7 @@ test_byte_order (Fixture *f, ...@@ -320,7 +320,7 @@ test_byte_order (Fixture *f,
* message, so it should disconnect */ * message, so it should disconnect */
while (g_queue_is_empty (&f->client_messages)) while (g_queue_is_empty (&f->client_messages))
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
......
...@@ -406,7 +406,7 @@ test_creds (Fixture *f, ...@@ -406,7 +406,7 @@ test_creds (Fixture *f,
g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==, g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
DBUS_TYPE_UINT32); DBUS_TYPE_UINT32);
dbus_message_iter_get_basic (&var_iter, &u32); 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 ()); g_assert_cmpuint (u32, ==, geteuid ());
seen |= SEEN_UNIX_USER; seen |= SEEN_UNIX_USER;
#else #else
...@@ -423,7 +423,7 @@ test_creds (Fixture *f, ...@@ -423,7 +423,7 @@ test_creds (Fixture *f,
g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==, g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
DBUS_TYPE_STRING); DBUS_TYPE_STRING);
dbus_message_iter_get_basic (&var_iter, &sid); 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)) if (_dbus_getsid (&self_sid, 0))
{ {
g_assert_cmpstr (self_sid, ==, sid); g_assert_cmpstr (self_sid, ==, sid);
...@@ -442,7 +442,7 @@ test_creds (Fixture *f, ...@@ -442,7 +442,7 @@ test_creds (Fixture *f,
g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==, g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
DBUS_TYPE_UINT32); DBUS_TYPE_UINT32);
dbus_message_iter_get_basic (&var_iter, &u32); 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 #ifdef G_OS_UNIX
g_assert_cmpuint (u32, ==, getpid ()); g_assert_cmpuint (u32, ==, getpid ());
#elif defined(G_OS_WIN32) #elif defined(G_OS_WIN32)
...@@ -466,7 +466,7 @@ test_creds (Fixture *f, ...@@ -466,7 +466,7 @@ test_creds (Fixture *f,
g_assert_cmpuint (dbus_message_iter_get_arg_type (&ay_iter), ==, g_assert_cmpuint (dbus_message_iter_get_arg_type (&ay_iter), ==,
DBUS_TYPE_BYTE); DBUS_TYPE_BYTE);
dbus_message_iter_get_fixed_array (&ay_iter, &label, &len); 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); g_assert_cmpuint (strlen (label) + 1, ==, len);
seen |= SEEN_LINUX_SECURITY_LABEL; seen |= SEEN_LINUX_SECURITY_LABEL;
#else #else
...@@ -533,7 +533,7 @@ test_processid (Fixture *f, ...@@ -533,7 +533,7 @@ test_processid (Fixture *f,
g_assert_cmpstr (dbus_message_get_signature (m), ==, "u"); g_assert_cmpstr (dbus_message_get_signature (m), ==, "u");
test_assert_no_error (&error); test_assert_no_error (&error);
g_message ("GetConnectionUnixProcessID returned %u", pid); g_test_message ("GetConnectionUnixProcessID returned %u", pid);
#ifdef G_OS_UNIX #ifdef G_OS_UNIX
g_assert_cmpuint (pid, ==, getpid ()); g_assert_cmpuint (pid, ==, getpid ());
......
...@@ -199,7 +199,7 @@ test_connect (Fixture *f, ...@@ -199,7 +199,7 @@ test_connect (Fixture *f,
while (f->left_server_conn == NULL) while (f->left_server_conn == NULL)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -212,7 +212,7 @@ test_connect (Fixture *f, ...@@ -212,7 +212,7 @@ test_connect (Fixture *f,
while (f->right_server_conn == NULL) while (f->right_server_conn == NULL)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -229,7 +229,7 @@ test_connect (Fixture *f, ...@@ -229,7 +229,7 @@ test_connect (Fixture *f,
!dbus_connection_get_is_authenticated (f->left_server_conn) || !dbus_connection_get_is_authenticated (f->left_server_conn) ||
!dbus_connection_get_is_authenticated (f->right_server_conn)) !dbus_connection_get_is_authenticated (f->right_server_conn))
{ {
g_printerr ("*"); test_progress ('*');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -311,7 +311,7 @@ test_relay (Fixture *f, ...@@ -311,7 +311,7 @@ test_relay (Fixture *f,
while (g_queue_get_length (&f->messages) < 1) while (g_queue_get_length (&f->messages) < 1)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -394,7 +394,7 @@ test_limit (Fixture *f, ...@@ -394,7 +394,7 @@ test_limit (Fixture *f,
while (g_queue_get_length (&f->messages) < 1) while (g_queue_get_length (&f->messages) < 1)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -454,7 +454,7 @@ test_too_many (Fixture *f, ...@@ -454,7 +454,7 @@ test_too_many (Fixture *f,
while (dbus_connection_get_is_connected (f->left_client_conn) || while (dbus_connection_get_is_connected (f->left_client_conn) ||
dbus_connection_get_is_connected (f->left_server_conn)) dbus_connection_get_is_connected (f->left_server_conn))
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -587,7 +587,7 @@ test_too_many_split (Fixture *f, ...@@ -587,7 +587,7 @@ test_too_many_split (Fixture *f,
while (dbus_connection_get_is_connected (f->left_client_conn) || while (dbus_connection_get_is_connected (f->left_client_conn) ||
dbus_connection_get_is_connected (f->left_server_conn)) dbus_connection_get_is_connected (f->left_server_conn))
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -643,7 +643,7 @@ test_flood (Fixture *f, ...@@ -643,7 +643,7 @@ test_flood (Fixture *f,
while (g_queue_get_length (&f->messages) < SOME_MESSAGES) while (g_queue_get_length (&f->messages) < SOME_MESSAGES)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -711,7 +711,7 @@ test_odd_limit (Fixture *f, ...@@ -711,7 +711,7 @@ test_odd_limit (Fixture *f,
while (dbus_connection_get_is_connected (f->left_client_conn) || while (dbus_connection_get_is_connected (f->left_client_conn) ||
dbus_connection_get_is_connected (f->left_server_conn)) dbus_connection_get_is_connected (f->left_server_conn))
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -730,7 +730,7 @@ test_odd_limit (Fixture *f, ...@@ -730,7 +730,7 @@ test_odd_limit (Fixture *f,
/* We're at or under the limit. The message gets through intact. */ /* We're at or under the limit. The message gets through intact. */
while (g_queue_get_length (&f->messages) < 1) while (g_queue_get_length (&f->messages) < 1)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
......
...@@ -125,7 +125,7 @@ setup_runtime (Fixture *f, ...@@ -125,7 +125,7 @@ setup_runtime (Fixture *f,
setup (f, addr); setup (f, addr);
listening_at = dbus_server_get_address (f->server); 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 (g_str_has_prefix (listening_at, "unix:path="));
g_assert (strstr (listening_at, "dbus%3ddaemon%3dtest.") != NULL); g_assert (strstr (listening_at, "dbus%3ddaemon%3dtest.") != NULL);
g_assert (strstr (listening_at, "/bus,") != NULL || g_assert (strstr (listening_at, "/bus,") != NULL ||
...@@ -147,7 +147,7 @@ setup_no_runtime (Fixture *f, ...@@ -147,7 +147,7 @@ setup_no_runtime (Fixture *f,
setup (f, addr); setup (f, addr);
listening_at = dbus_server_get_address (f->server); 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 */ /* we have fallen back to something in /tmp, either abstract or not */
g_assert (g_str_has_prefix (listening_at, "unix:")); g_assert (g_str_has_prefix (listening_at, "unix:"));
g_assert (strstr (listening_at, "=/tmp/") != NULL); g_assert (strstr (listening_at, "=/tmp/") != NULL);
...@@ -170,7 +170,7 @@ test_connect (Fixture *f, ...@@ -170,7 +170,7 @@ test_connect (Fixture *f,
while (f->server_conn == NULL) while (f->server_conn == NULL)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
} }
...@@ -204,7 +204,7 @@ test_bad_guid (Fixture *f, ...@@ -204,7 +204,7 @@ test_bad_guid (Fixture *f,
while (f->server_conn == NULL) while (f->server_conn == NULL)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -212,7 +212,7 @@ test_bad_guid (Fixture *f, ...@@ -212,7 +212,7 @@ test_bad_guid (Fixture *f,
while (g_queue_is_empty (&f->server_messages)) while (g_queue_is_empty (&f->server_messages))
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -255,7 +255,7 @@ test_message (Fixture *f, ...@@ -255,7 +255,7 @@ test_message (Fixture *f,
while (g_queue_is_empty (&f->server_messages)) while (g_queue_is_empty (&f->server_messages))
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
......
...@@ -164,22 +164,22 @@ _log_message (DBusMessage *m, ...@@ -164,22 +164,22 @@ _log_message (DBusMessage *m,
const char *file, const char *file,
int line) 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_get_type (m),
dbus_message_type_to_string (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)")); 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)")); not_null2 (dbus_message_get_destination (m), "(broadcast)"));
g_message ("\tpath: %s", g_test_message ("\tpath: %s",
not_null (dbus_message_get_path (m))); not_null (dbus_message_get_path (m)));
g_message ("\tinterface: %s", g_test_message ("\tinterface: %s",
not_null (dbus_message_get_interface (m))); not_null (dbus_message_get_interface (m)));
g_message ("\tmember: %s", g_test_message ("\tmember: %s",
not_null (dbus_message_get_member (m))); not_null (dbus_message_get_member (m)));
g_message ("\tsignature: %s", g_test_message ("\tsignature: %s",
not_null (dbus_message_get_signature (m))); 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))); not_null (dbus_message_get_error_name (m)));
if (strcmp ("s", dbus_message_get_signature (m)) == 0) if (strcmp ("s", dbus_message_get_signature (m)) == 0)
...@@ -191,7 +191,7 @@ _log_message (DBusMessage *m, ...@@ -191,7 +191,7 @@ _log_message (DBusMessage *m,
DBUS_TYPE_STRING, &s, DBUS_TYPE_STRING, &s,
DBUS_TYPE_INVALID); DBUS_TYPE_INVALID);
test_assert_no_error (&e); test_assert_no_error (&e);
g_message ("\tstring payload: %s", s); g_test_message ("\tstring payload: %s", s);
} }
} }
......
...@@ -155,7 +155,7 @@ test_connect (Fixture *f, ...@@ -155,7 +155,7 @@ test_connect (Fixture *f,
while (f->left_server_conn == NULL) while (f->left_server_conn == NULL)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -168,7 +168,7 @@ test_connect (Fixture *f, ...@@ -168,7 +168,7 @@ test_connect (Fixture *f,
while (f->right_server_conn == NULL) while (f->right_server_conn == NULL)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
...@@ -210,7 +210,7 @@ test_relay (Fixture *f, ...@@ -210,7 +210,7 @@ test_relay (Fixture *f,
while (g_queue_get_length (&f->messages) < 2) while (g_queue_get_length (&f->messages) < 2)
{ {
g_print ("."); test_progress ('.');
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
......
...@@ -45,6 +45,10 @@ ...@@ -45,6 +45,10 @@
#include <dbus/dbus.h> #include <dbus/dbus.h>
#ifdef G_OS_WIN
# define isatty(x) _isatty(x)
#endif
void void
_test_assert_no_error (const DBusError *e, _test_assert_no_error (const DBusError *e,
const char *file, const char *file,
...@@ -428,3 +432,10 @@ test_init (int *argcp, char ***argvp) ...@@ -428,3 +432,10 @@ test_init (int *argcp, char ***argvp)
} }
#endif #endif
} }
void
test_progress (char symbol)
{
if (g_test_verbose () && isatty (1))
g_print ("%c", symbol);
}
...@@ -81,4 +81,6 @@ void test_kill_pid (GPid pid); ...@@ -81,4 +81,6 @@ void test_kill_pid (GPid pid);
void test_init (int *argcp, char ***argvp); void test_init (int *argcp, char ***argvp);
void test_progress (char symbol);
#endif #endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment