summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2015-11-17 13:23:30 +0000
committerRalf Habacker <ralf.habacker@freenet.de>2015-11-17 14:48:23 +0100
commit32f966b9086e39c0dfaa80a87e739d2b9b4f869a (patch)
tree0692afd8a91d16f628ad74584dfbaaebcd81ed18
parentd00bbd9711fce5e5fc24254c247a4530ec750dfa (diff)
downloaddbus-32f966b9086e39c0dfaa80a87e739d2b9b4f869a.tar.gz
fdpass test: assert that TCP connections don't say they can pass fds
As well as slightly increasing our test coverage, this ensures that at least one test-case in this test is not skipped, working around CMake's lack of support for the Automake-style exit code produced by GTest executables (they exit 77 if everything was skipped). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92887 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
-rw-r--r--test/fdpass.c76
1 files changed, 58 insertions, 18 deletions
diff --git a/test/fdpass.c b/test/fdpass.c
index a74ce814..665b4a12 100644
--- a/test/fdpass.c
+++ b/test/fdpass.c
@@ -93,8 +93,6 @@ typedef struct {
int fd_before;
} Fixture;
-#ifdef HAVE_UNIX_FD_PASSING
-
static void oom (const gchar *doing) G_GNUC_NORETURN;
static void
@@ -170,7 +168,7 @@ new_conn_cb (DBusServer *server,
static void
test_connect (Fixture *f,
- gconstpointer data G_GNUC_UNUSED)
+ gboolean should_support_fds)
{
char *address;
@@ -225,6 +223,9 @@ test_connect (Fixture *f,
test_main_context_iterate (f->ctx, TRUE);
}
+ if (!should_support_fds)
+ return;
+
if (!dbus_connection_can_send_type (f->left_client_conn,
DBUS_TYPE_UNIX_FD))
g_error ("left client connection cannot send Unix fds");
@@ -241,26 +242,38 @@ test_connect (Fixture *f,
DBUS_TYPE_UNIX_FD))
g_error ("right server connection cannot send Unix fds");
}
-#endif
static void
-setup (Fixture *f,
- gconstpointer data G_GNUC_UNUSED)
+setup_common (Fixture *f,
+ const char *address)
{
-#ifdef HAVE_UNIX_FD_PASSING
- /* We assume that anything with fd-passing supports the unix: transport */
-
f->ctx = test_main_context_get ();
dbus_error_init (&f->e);
g_queue_init (&f->messages);
- f->server = dbus_server_listen ("unix:tmpdir=/tmp", &f->e);
+ f->server = dbus_server_listen (address, &f->e);
assert_no_error (&f->e);
g_assert (f->server != NULL);
dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL);
test_server_setup (f->ctx, f->server);
+}
+
+static void
+setup_unsupported (Fixture *f,
+ gconstpointer data G_GNUC_UNUSED)
+{
+ setup_common (f, "tcp:host=127.0.0.1");
+}
+
+static void
+setup (Fixture *f,
+ gconstpointer data G_GNUC_UNUSED)
+{
+#ifdef HAVE_UNIX_FD_PASSING
+ /* We assume that anything with fd-passing supports the unix: transport */
+ setup_common (f, "unix:tmpdir=/tmp");
f->fd_before = open ("/dev/null", O_RDONLY);
@@ -273,6 +286,29 @@ setup (Fixture *f,
}
static void
+test_unsupported (Fixture *f,
+ gconstpointer data)
+{
+ test_connect (f, FALSE);
+
+ if (dbus_connection_can_send_type (f->left_client_conn,
+ DBUS_TYPE_UNIX_FD))
+ g_error ("left client connection claims it can send Unix fds");
+
+ if (dbus_connection_can_send_type (f->left_server_conn,
+ DBUS_TYPE_UNIX_FD))
+ g_error ("left server connection claims it can send Unix fds");
+
+ if (dbus_connection_can_send_type (f->right_client_conn,
+ DBUS_TYPE_UNIX_FD))
+ g_error ("right client connection claims it can send Unix fds");
+
+ if (dbus_connection_can_send_type (f->right_server_conn,
+ DBUS_TYPE_UNIX_FD))
+ g_error ("right server connection claims it can send Unix fds");
+}
+
+static void
test_relay (Fixture *f,
gconstpointer data)
{
@@ -285,7 +321,7 @@ test_relay (Fixture *f,
struct stat stat_before;
struct stat stat_after;
- test_connect (f, data);
+ test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting");
@@ -365,7 +401,7 @@ test_limit (Fixture *f,
DBusMessage *outgoing, *incoming;
int i;
- test_connect (f, data);
+ test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting");
@@ -423,7 +459,7 @@ test_too_many (Fixture *f,
DBusMessage *outgoing;
unsigned int i;
- test_connect (f, data);
+ test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting");
@@ -495,7 +531,7 @@ test_too_many_split (Fixture *f,
}
#endif
- test_connect (f, data);
+ test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting");
@@ -605,7 +641,7 @@ test_flood (Fixture *f,
DBusMessage *outgoing[SOME_MESSAGES];
dbus_uint32_t serial;
- test_connect (f, data);
+ test_connect (f, TRUE);
for (j = 0; j < SOME_MESSAGES; j++)
{
@@ -677,7 +713,7 @@ test_odd_limit (Fixture *f,
DBusMessage *outgoing;
int i;
- test_connect (f, data);
+ test_connect (f, TRUE);
dbus_connection_set_max_message_unix_fds (f->left_server_conn, 7);
dbus_connection_set_max_message_unix_fds (f->right_server_conn, 7);
@@ -757,7 +793,6 @@ static void
teardown (Fixture *f,
gconstpointer data G_GNUC_UNUSED)
{
-#ifdef HAVE_UNIX_FD_PASSING
if (f->left_client_conn != NULL)
{
dbus_connection_close (f->left_client_conn);
@@ -793,8 +828,10 @@ teardown (Fixture *f,
f->server = NULL;
}
- test_main_context_unref (f->ctx);
+ if (f->ctx != NULL)
+ test_main_context_unref (f->ctx);
+#ifdef HAVE_UNIX_FD_PASSING
if (f->fd_before >= 0 && close (f->fd_before) < 0)
g_error ("%s", g_strerror (errno));
#endif
@@ -825,6 +862,9 @@ main (int argc,
}
#endif
+ g_test_add ("/unsupported", Fixture, NULL, setup_unsupported,
+ test_unsupported, teardown);
+
g_test_add ("/relay", Fixture, NULL, setup,
test_relay, teardown);
g_test_add ("/limit", Fixture, NULL, setup,