test: Add missing error handling to some name-test tests
authorPhilip Withnall <withnall@endlessm.com>
Mon, 6 Feb 2017 13:07:21 +0000 (13:07 +0000)
committerSimon McVittie <simon.mcvittie@collabora.co.uk>
Mon, 13 Feb 2017 14:53:29 +0000 (14:53 +0000)
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 <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99694
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
test/name-test/test-pending-call-dispatch.c
test/name-test/test-threads-init.c

index c8462d0..a5f320b 100644 (file)
@@ -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);
   
index eb0ff96..a19b962 100644 (file)
@@ -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);
 }