Commit 32f966b9 authored by Simon McVittie's avatar Simon McVittie Committed by Ralf Habacker

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=92887Signed-off-by: default avatarSimon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Ralf Habacker's avatarRalf Habacker <ralf.habacker@freenet.de>
parent d00bbd97
...@@ -93,8 +93,6 @@ typedef struct { ...@@ -93,8 +93,6 @@ typedef struct {
int fd_before; int fd_before;
} Fixture; } Fixture;
#ifdef HAVE_UNIX_FD_PASSING
static void oom (const gchar *doing) G_GNUC_NORETURN; static void oom (const gchar *doing) G_GNUC_NORETURN;
static void static void
...@@ -170,7 +168,7 @@ new_conn_cb (DBusServer *server, ...@@ -170,7 +168,7 @@ new_conn_cb (DBusServer *server,
static void static void
test_connect (Fixture *f, test_connect (Fixture *f,
gconstpointer data G_GNUC_UNUSED) gboolean should_support_fds)
{ {
char *address; char *address;
...@@ -225,6 +223,9 @@ test_connect (Fixture *f, ...@@ -225,6 +223,9 @@ test_connect (Fixture *f,
test_main_context_iterate (f->ctx, TRUE); test_main_context_iterate (f->ctx, TRUE);
} }
if (!should_support_fds)
return;
if (!dbus_connection_can_send_type (f->left_client_conn, if (!dbus_connection_can_send_type (f->left_client_conn,
DBUS_TYPE_UNIX_FD)) DBUS_TYPE_UNIX_FD))
g_error ("left client connection cannot send Unix fds"); g_error ("left client connection cannot send Unix fds");
...@@ -241,26 +242,38 @@ test_connect (Fixture *f, ...@@ -241,26 +242,38 @@ test_connect (Fixture *f,
DBUS_TYPE_UNIX_FD)) DBUS_TYPE_UNIX_FD))
g_error ("right server connection cannot send Unix fds"); g_error ("right server connection cannot send Unix fds");
} }
#endif
static void static void
setup (Fixture *f, setup_common (Fixture *f,
gconstpointer data G_GNUC_UNUSED) 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 (); f->ctx = test_main_context_get ();
dbus_error_init (&f->e); dbus_error_init (&f->e);
g_queue_init (&f->messages); 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); assert_no_error (&f->e);
g_assert (f->server != NULL); g_assert (f->server != NULL);
dbus_server_set_new_connection_function (f->server, dbus_server_set_new_connection_function (f->server,
new_conn_cb, f, NULL); new_conn_cb, f, NULL);
test_server_setup (f->ctx, f->server); 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); f->fd_before = open ("/dev/null", O_RDONLY);
...@@ -272,6 +285,29 @@ setup (Fixture *f, ...@@ -272,6 +285,29 @@ setup (Fixture *f,
#endif #endif
} }
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 static void
test_relay (Fixture *f, test_relay (Fixture *f,
gconstpointer data) gconstpointer data)
...@@ -285,7 +321,7 @@ test_relay (Fixture *f, ...@@ -285,7 +321,7 @@ test_relay (Fixture *f,
struct stat stat_before; struct stat stat_before;
struct stat stat_after; struct stat stat_after;
test_connect (f, data); test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello", outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting"); "com.example.Hello", "Greeting");
...@@ -365,7 +401,7 @@ test_limit (Fixture *f, ...@@ -365,7 +401,7 @@ test_limit (Fixture *f,
DBusMessage *outgoing, *incoming; DBusMessage *outgoing, *incoming;
int i; int i;
test_connect (f, data); test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello", outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting"); "com.example.Hello", "Greeting");
...@@ -423,7 +459,7 @@ test_too_many (Fixture *f, ...@@ -423,7 +459,7 @@ test_too_many (Fixture *f,
DBusMessage *outgoing; DBusMessage *outgoing;
unsigned int i; unsigned int i;
test_connect (f, data); test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello", outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting"); "com.example.Hello", "Greeting");
...@@ -495,7 +531,7 @@ test_too_many_split (Fixture *f, ...@@ -495,7 +531,7 @@ test_too_many_split (Fixture *f,
} }
#endif #endif
test_connect (f, data); test_connect (f, TRUE);
outgoing = dbus_message_new_signal ("/com/example/Hello", outgoing = dbus_message_new_signal ("/com/example/Hello",
"com.example.Hello", "Greeting"); "com.example.Hello", "Greeting");
...@@ -605,7 +641,7 @@ test_flood (Fixture *f, ...@@ -605,7 +641,7 @@ test_flood (Fixture *f,
DBusMessage *outgoing[SOME_MESSAGES]; DBusMessage *outgoing[SOME_MESSAGES];
dbus_uint32_t serial; dbus_uint32_t serial;
test_connect (f, data); test_connect (f, TRUE);
for (j = 0; j < SOME_MESSAGES; j++) for (j = 0; j < SOME_MESSAGES; j++)
{ {
...@@ -677,7 +713,7 @@ test_odd_limit (Fixture *f, ...@@ -677,7 +713,7 @@ test_odd_limit (Fixture *f,
DBusMessage *outgoing; DBusMessage *outgoing;
int i; 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->left_server_conn, 7);
dbus_connection_set_max_message_unix_fds (f->right_server_conn, 7); dbus_connection_set_max_message_unix_fds (f->right_server_conn, 7);
...@@ -757,7 +793,6 @@ static void ...@@ -757,7 +793,6 @@ static void
teardown (Fixture *f, teardown (Fixture *f,
gconstpointer data G_GNUC_UNUSED) gconstpointer data G_GNUC_UNUSED)
{ {
#ifdef HAVE_UNIX_FD_PASSING
if (f->left_client_conn != NULL) if (f->left_client_conn != NULL)
{ {
dbus_connection_close (f->left_client_conn); dbus_connection_close (f->left_client_conn);
...@@ -793,8 +828,10 @@ teardown (Fixture *f, ...@@ -793,8 +828,10 @@ teardown (Fixture *f,
f->server = NULL; 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) if (f->fd_before >= 0 && close (f->fd_before) < 0)
g_error ("%s", g_strerror (errno)); g_error ("%s", g_strerror (errno));
#endif #endif
...@@ -825,6 +862,9 @@ main (int argc, ...@@ -825,6 +862,9 @@ main (int argc,
} }
#endif #endif
g_test_add ("/unsupported", Fixture, NULL, setup_unsupported,
test_unsupported, teardown);
g_test_add ("/relay", Fixture, NULL, setup, g_test_add ("/relay", Fixture, NULL, setup,
test_relay, teardown); test_relay, teardown);
g_test_add ("/limit", Fixture, NULL, setup, g_test_add ("/limit", Fixture, NULL, setup,
......
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