From a9aa25cb98bb57645ff40dc109478c6a0eb3b49c Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 6 Feb 2017 13:07:21 +0000 Subject: [PATCH] test: Add missing error handling to some name-test tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also take the opportunity to tweak the test-threads-init messages slightly to make it more TAP-compliant. It is not entirely TAP compliant because it doesn’t print a test plan before starting its tests. Coverity IDs: 54701, 54714, 54726 Signed-off-by: Philip Withnall https://bugs.freedesktop.org/show_bug.cgi?id=99694 --- test/name-test/test-pending-call-dispatch.c | 7 ++++++- test/name-test/test-threads-init.c | 31 ++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/test/name-test/test-pending-call-dispatch.c b/test/name-test/test-pending-call-dispatch.c index c8462d0..a5f320b 100644 --- a/test/name-test/test-pending-call-dispatch.c +++ b/test/name-test/test-pending-call-dispatch.c @@ -28,7 +28,12 @@ _run_iteration (DBusConnection *conn) "org.freedesktop.TestSuite", "Echo"); - dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL); + if (!dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL)) + { + fprintf (stderr, "Bail out! Failed to append arguments: OOM\n"); + exit (1); + } + dbus_connection_send_with_reply (conn, method, &echo_pending, -1); dbus_message_unref (method); diff --git a/test/name-test/test-threads-init.c b/test/name-test/test-threads-init.c index eb0ff96..a19b962 100644 --- a/test/name-test/test-threads-init.c +++ b/test/name-test/test-threads-init.c @@ -26,7 +26,12 @@ _run_iteration (DBusConnection *conn) "org.freedesktop.TestSuite", "Echo"); - dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL); + if (!dbus_message_append_args (method, DBUS_TYPE_STRING, &echo, NULL)) + { + fprintf (stderr, "Bail out! Failed to append arguments: OOM\n"); + exit (1); + } + dbus_connection_send_with_reply (conn, method, &echo_pending, -1); dbus_message_unref (method); @@ -54,13 +59,13 @@ _run_iteration (DBusConnection *conn) if (reply == NULL) { - printf ("Failed: Reply is NULL ***\n"); + printf ("Bail out! Reply is NULL ***\n"); exit (1); } if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) { - printf ("Failed: Reply is error: %s ***\n", dbus_message_get_error_name (reply)); + printf ("Bail out! Reply is error: %s ***\n", dbus_message_get_error_name (reply)); exit (1); } @@ -118,13 +123,21 @@ main (int argc, char *argv[]) DBusCondVar *dispatch_cond2, *io_path_cond2; int test_num = 0; - printf ("*** Testing late thread init\n"); + printf ("# Testing late thread init\n"); dbus_error_init (&error); conn = dbus_bus_get (DBUS_BUS_SESSION, &error); - _dbus_connection_test_get_locks (conn, &mutex1, + if (conn == NULL) + { + fprintf (stderr, "Bail out! Failed to open connection to session bus: %s\n", + error.message); + dbus_error_free (&error); + return 1; + } + + _dbus_connection_test_get_locks (conn, &mutex1, &dispatch_mutex1, &io_path_mutex1, &dispatch_cond1, @@ -143,7 +156,11 @@ main (int argc, char *argv[]) check_condvar_lock (io_path_cond1, io_path_cond2, TRUE); printf ("ok %d\n", ++test_num); - dbus_threads_init_default (); + if (!dbus_threads_init_default ()) + { + fprintf (stderr, "Bail out! Failed to initialise threads: OOM\n"); + return 1; + } _dbus_connection_test_get_locks (conn, &mutex1, &dispatch_mutex1, @@ -172,6 +189,6 @@ main (int argc, char *argv[]) dbus_connection_send (conn, method, NULL); dbus_message_unref (method); - printf ("Testing completed\n1..%d\n", test_num); + printf ("# Testing completed\n1..%d\n", test_num); exit (0); } -- 2.9.3