summaryrefslogtreecommitdiff
path: root/test/dbus-daemon.c
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2011-03-11 13:24:08 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2011-07-28 18:23:52 +0100
commit63c93a1165af46b219775d4ab2618147c7f6c22e (patch)
tree3d07088809071f6c313acda12e6fff300e78792f /test/dbus-daemon.c
parent4437ddb4731092985182bfe2f83ef2e9452d92e5 (diff)
downloaddbus-63c93a1165af46b219775d4ab2618147c7f6c22e.tar.gz
Add a regression test that can reproduce fd.o #34393
The number of messages is arbitrary; the more messages, the more likely the crash is. 2000 messages seem to cause it reliably on this laptop, but I've set it to 10000 to be safe. Reviewed-by: Colin Walters <walters@verbum.org> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=34393
Diffstat (limited to 'test/dbus-daemon.c')
-rw-r--r--test/dbus-daemon.c75
1 files changed, 59 insertions, 16 deletions
diff --git a/test/dbus-daemon.c b/test/dbus-daemon.c
index ed10d098..c190cb43 100644
--- a/test/dbus-daemon.c
+++ b/test/dbus-daemon.c
@@ -41,6 +41,8 @@
#endif
typedef struct {
+ gboolean skip;
+
DBusError e;
GError *ge;
@@ -167,42 +169,63 @@ echo_filter (DBusConnection *connection,
return DBUS_HANDLER_RESULT_HANDLED;
}
+typedef struct {
+ const char *bug_ref;
+ guint min_messages;
+ const char *config_file;
+} Config;
+
static void
setup (Fixture *f,
- gconstpointer context G_GNUC_UNUSED)
+ gconstpointer context)
{
+ const Config *config = context;
gchar *dbus_daemon;
- gchar *config;
+ gchar *arg;
gchar *address;
f->ge = NULL;
dbus_error_init (&f->e);
- dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
-
- if (dbus_daemon == NULL)
- dbus_daemon = g_strdup ("dbus-daemon");
+ if (config != NULL && config->config_file != NULL)
+ {
+ if (g_getenv ("DBUS_TEST_DATA") == NULL)
+ {
+ g_message ("SKIP: set DBUS_TEST_DATA to a directory containing %s",
+ config->config_file);
+ f->skip = TRUE;
+ return;
+ }
- if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL)
+ arg = g_strdup_printf (
+ "--config-file=%s/%s",
+ g_getenv ("DBUS_TEST_DATA"), config->config_file);
+ }
+ else if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL)
{
- config = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
+ arg = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
g_getenv ("DBUS_TEST_SYSCONFDIR"));
}
else if (g_getenv ("DBUS_TEST_DATA") != NULL)
{
- config = g_strdup_printf (
+ arg = g_strdup_printf (
"--config-file=%s/valid-config-files/session.conf",
g_getenv ("DBUS_TEST_DATA"));
}
else
{
- config = g_strdup ("--session");
+ arg = g_strdup ("--session");
}
- address = spawn_dbus_daemon (dbus_daemon, config, &f->daemon_pid);
+ dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
+
+ if (dbus_daemon == NULL)
+ dbus_daemon = g_strdup ("dbus-daemon");
+
+ address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid);
g_free (dbus_daemon);
- g_free (config);
+ g_free (arg);
f->left_conn = connect_to_bus (address);
f->right_conn = connect_to_bus (address);
@@ -229,16 +252,26 @@ pc_count (DBusPendingCall *pc,
static void
test_echo (Fixture *f,
- gconstpointer context G_GNUC_UNUSED)
+ gconstpointer context)
{
+ const Config *config = context;
guint count = 2000;
guint sent;
guint received = 0;
double elapsed;
+ if (f->skip)
+ return;
+
+ if (config != NULL && config->bug_ref != NULL)
+ g_test_bug (config->bug_ref);
+
if (g_test_perf ())
count = 100000;
+ if (config != NULL)
+ count = MAX (config->min_messages, count);
+
add_echo_filter (f);
g_test_timer_start ();
@@ -304,15 +337,23 @@ teardown (Fixture *f,
f->right_conn = NULL;
}
+ if (f->daemon_pid != 0)
+ {
#ifdef DBUS_WIN
- TerminateProcess (f->daemon_pid, 1);
+ TerminateProcess (f->daemon_pid, 1);
#else
- kill (f->daemon_pid, SIGTERM);
+ kill (f->daemon_pid, SIGTERM);
#endif
- g_spawn_close_pid (f->daemon_pid);
+ g_spawn_close_pid (f->daemon_pid);
+ f->daemon_pid = 0;
+ }
}
+static Config limited_config = {
+ "34393", 10000, "valid-config-files/incoming-limit.conf"
+};
+
int
main (int argc,
char **argv)
@@ -321,6 +362,8 @@ main (int argc,
g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
g_test_add ("/echo/session", Fixture, NULL, setup, test_echo, teardown);
+ g_test_add ("/echo/limited", Fixture, &limited_config,
+ setup, test_echo, teardown);
return g_test_run ();
}