2011-03-11 13:13:17 +00:00
|
|
|
/* Integration tests for the dbus-daemon
|
|
|
|
|
*
|
|
|
|
|
* Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
|
2011-06-10 18:23:52 +01:00
|
|
|
* Copyright © 2010-2011 Nokia Corporation
|
2011-03-11 13:13:17 +00:00
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
|
* obtaining a copy of this software and associated documentation files
|
|
|
|
|
* (the "Software"), to deal in the Software without restriction,
|
|
|
|
|
* including without limitation the rights to use, copy, modify, merge,
|
|
|
|
|
* publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
|
* and to permit persons to whom the Software is furnished to do so,
|
|
|
|
|
* subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
|
|
#include <dbus/dbus.h>
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#ifdef DBUS_WIN
|
2011-08-05 13:55:09 +01:00
|
|
|
# include <io.h>
|
2011-03-11 13:13:17 +00:00
|
|
|
# include <windows.h>
|
|
|
|
|
#else
|
|
|
|
|
# include <signal.h>
|
|
|
|
|
# include <unistd.h>
|
2013-08-22 18:21:58 +01:00
|
|
|
# include <sys/types.h>
|
2011-03-11 13:13:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
#include "test-utils.h"
|
|
|
|
|
|
2011-03-11 13:13:17 +00:00
|
|
|
typedef struct {
|
2011-03-11 13:24:08 +00:00
|
|
|
gboolean skip;
|
|
|
|
|
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
TestMainContext *ctx;
|
|
|
|
|
|
2011-03-11 13:13:17 +00:00
|
|
|
DBusError e;
|
|
|
|
|
GError *ge;
|
|
|
|
|
|
2011-08-05 13:55:09 +01:00
|
|
|
GPid daemon_pid;
|
2011-03-11 13:13:17 +00:00
|
|
|
|
|
|
|
|
DBusConnection *left_conn;
|
|
|
|
|
|
|
|
|
|
DBusConnection *right_conn;
|
|
|
|
|
gboolean right_conn_echo;
|
2014-10-29 14:10:48 +00:00
|
|
|
gboolean wait_forever_called;
|
2011-03-11 13:13:17 +00:00
|
|
|
} Fixture;
|
|
|
|
|
|
|
|
|
|
#define assert_no_error(e) _assert_no_error (e, __FILE__, __LINE__)
|
|
|
|
|
static void
|
|
|
|
|
_assert_no_error (const DBusError *e,
|
|
|
|
|
const char *file,
|
|
|
|
|
int line)
|
|
|
|
|
{
|
|
|
|
|
if (G_UNLIKELY (dbus_error_is_set (e)))
|
|
|
|
|
g_error ("%s:%d: expected success but got error: %s: %s",
|
|
|
|
|
file, line, e->name, e->message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
|
spawn_dbus_daemon (gchar *binary,
|
|
|
|
|
gchar *configuration,
|
2011-08-05 13:55:09 +01:00
|
|
|
GPid *daemon_pid)
|
2011-03-11 13:13:17 +00:00
|
|
|
{
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
GString *address;
|
|
|
|
|
gint address_fd;
|
|
|
|
|
gchar *argv[] = {
|
|
|
|
|
binary,
|
|
|
|
|
configuration,
|
|
|
|
|
"--nofork",
|
|
|
|
|
"--print-address=1", /* stdout */
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
g_spawn_async_with_pipes (NULL, /* working directory */
|
|
|
|
|
argv,
|
|
|
|
|
NULL, /* envp */
|
2011-06-08 18:15:05 +01:00
|
|
|
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
|
2011-03-11 13:13:17 +00:00
|
|
|
NULL, /* child_setup */
|
|
|
|
|
NULL, /* user data */
|
|
|
|
|
daemon_pid,
|
|
|
|
|
NULL, /* child's stdin = /dev/null */
|
|
|
|
|
&address_fd,
|
|
|
|
|
NULL, /* child's stderr = our stderr */
|
|
|
|
|
&error);
|
|
|
|
|
g_assert_no_error (error);
|
|
|
|
|
|
|
|
|
|
address = g_string_new (NULL);
|
|
|
|
|
|
|
|
|
|
/* polling until the dbus-daemon writes out its address is a bit stupid,
|
|
|
|
|
* but at least it's simple, unlike dbus-launch... in principle we could
|
|
|
|
|
* use select() here, but life's too short */
|
|
|
|
|
while (1)
|
|
|
|
|
{
|
|
|
|
|
gssize bytes;
|
|
|
|
|
gchar buf[4096];
|
|
|
|
|
gchar *newline;
|
|
|
|
|
|
|
|
|
|
bytes = read (address_fd, buf, sizeof (buf));
|
|
|
|
|
|
|
|
|
|
if (bytes > 0)
|
|
|
|
|
g_string_append_len (address, buf, bytes);
|
|
|
|
|
|
|
|
|
|
newline = strchr (address->str, '\n');
|
|
|
|
|
|
|
|
|
|
if (newline != NULL)
|
|
|
|
|
{
|
2014-03-08 04:18:43 +00:00
|
|
|
if ((newline > address->str) && ('\r' == newline[-1]))
|
|
|
|
|
newline -= 1;
|
2011-03-11 13:13:17 +00:00
|
|
|
g_string_truncate (address, newline - address->str);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_usleep (G_USEC_PER_SEC / 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return g_string_free (address, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusConnection *
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
connect_to_bus (Fixture *f,
|
|
|
|
|
const gchar *address)
|
2011-03-11 13:13:17 +00:00
|
|
|
{
|
|
|
|
|
DBusConnection *conn;
|
|
|
|
|
DBusError error = DBUS_ERROR_INIT;
|
|
|
|
|
dbus_bool_t ok;
|
|
|
|
|
|
|
|
|
|
conn = dbus_connection_open_private (address, &error);
|
|
|
|
|
assert_no_error (&error);
|
|
|
|
|
g_assert (conn != NULL);
|
|
|
|
|
|
|
|
|
|
ok = dbus_bus_register (conn, &error);
|
|
|
|
|
assert_no_error (&error);
|
|
|
|
|
g_assert (ok);
|
|
|
|
|
g_assert (dbus_bus_get_unique_name (conn) != NULL);
|
|
|
|
|
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_connection_setup (f->ctx, conn);
|
2011-03-11 13:13:17 +00:00
|
|
|
return conn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusHandlerResult
|
|
|
|
|
echo_filter (DBusConnection *connection,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
2014-10-29 14:10:48 +00:00
|
|
|
Fixture *f = user_data;
|
2011-03-11 13:13:17 +00:00
|
|
|
DBusMessage *reply;
|
|
|
|
|
|
|
|
|
|
if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_METHOD_CALL)
|
|
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
|
|
|
|
2014-10-29 14:10:48 +00:00
|
|
|
/* WaitForever() never replies, emulating a service that has got stuck */
|
|
|
|
|
if (dbus_message_is_method_call (message, "com.example", "WaitForever"))
|
|
|
|
|
{
|
|
|
|
|
f->wait_forever_called = TRUE;
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:13:17 +00:00
|
|
|
reply = dbus_message_new_method_return (message);
|
|
|
|
|
|
|
|
|
|
if (reply == NULL)
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send (connection, reply, NULL))
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (reply);
|
|
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
typedef struct {
|
|
|
|
|
const char *bug_ref;
|
|
|
|
|
guint min_messages;
|
|
|
|
|
const char *config_file;
|
|
|
|
|
} Config;
|
|
|
|
|
|
2011-03-11 13:13:17 +00:00
|
|
|
static void
|
|
|
|
|
setup (Fixture *f,
|
2011-03-11 13:24:08 +00:00
|
|
|
gconstpointer context)
|
2011-03-11 13:13:17 +00:00
|
|
|
{
|
2011-03-11 13:24:08 +00:00
|
|
|
const Config *config = context;
|
2011-03-11 13:13:17 +00:00
|
|
|
gchar *dbus_daemon;
|
2011-03-11 13:24:08 +00:00
|
|
|
gchar *arg;
|
2011-03-11 13:13:17 +00:00
|
|
|
gchar *address;
|
|
|
|
|
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
f->ctx = test_main_context_get ();
|
2011-03-11 13:13:17 +00:00
|
|
|
f->ge = NULL;
|
|
|
|
|
dbus_error_init (&f->e);
|
|
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
if (config != NULL && config->config_file != NULL)
|
|
|
|
|
{
|
2013-09-02 16:36:46 +01:00
|
|
|
if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL)
|
|
|
|
|
{
|
|
|
|
|
g_message ("SKIP: cannot use DBUS_TEST_DAEMON_ADDRESS for "
|
|
|
|
|
"unusally-configured dbus-daemon");
|
|
|
|
|
f->skip = TRUE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
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;
|
|
|
|
|
}
|
2011-03-21 18:40:16 +00:00
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
arg = g_strdup_printf (
|
|
|
|
|
"--config-file=%s/%s",
|
|
|
|
|
g_getenv ("DBUS_TEST_DATA"), config->config_file);
|
|
|
|
|
}
|
|
|
|
|
else if (g_getenv ("DBUS_TEST_SYSCONFDIR") != NULL)
|
2011-06-08 18:15:05 +01:00
|
|
|
{
|
2011-03-11 13:24:08 +00:00
|
|
|
arg = g_strdup_printf ("--config-file=%s/dbus-1/session.conf",
|
2011-06-08 18:15:05 +01:00
|
|
|
g_getenv ("DBUS_TEST_SYSCONFDIR"));
|
2011-03-11 13:13:17 +00:00
|
|
|
}
|
2011-06-08 18:15:05 +01:00
|
|
|
else if (g_getenv ("DBUS_TEST_DATA") != NULL)
|
2011-03-11 13:13:17 +00:00
|
|
|
{
|
2011-03-11 13:24:08 +00:00
|
|
|
arg = g_strdup_printf (
|
2011-03-11 13:13:17 +00:00
|
|
|
"--config-file=%s/valid-config-files/session.conf",
|
|
|
|
|
g_getenv ("DBUS_TEST_DATA"));
|
|
|
|
|
}
|
2011-06-08 18:15:05 +01:00
|
|
|
else
|
|
|
|
|
{
|
2011-03-11 13:24:08 +00:00
|
|
|
arg = g_strdup ("--session");
|
2011-06-08 18:15:05 +01:00
|
|
|
}
|
2011-03-11 13:13:17 +00:00
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
dbus_daemon = g_strdup (g_getenv ("DBUS_TEST_DAEMON"));
|
|
|
|
|
|
|
|
|
|
if (dbus_daemon == NULL)
|
|
|
|
|
dbus_daemon = g_strdup ("dbus-daemon");
|
|
|
|
|
|
2013-09-02 16:36:46 +01:00
|
|
|
if (g_getenv ("DBUS_TEST_DAEMON_ADDRESS") != NULL)
|
|
|
|
|
{
|
|
|
|
|
address = g_strdup (g_getenv ("DBUS_TEST_DAEMON_ADDRESS"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
address = spawn_dbus_daemon (dbus_daemon, arg, &f->daemon_pid);
|
|
|
|
|
}
|
2011-03-11 13:13:17 +00:00
|
|
|
|
|
|
|
|
g_free (dbus_daemon);
|
2011-03-11 13:24:08 +00:00
|
|
|
g_free (arg);
|
2011-03-11 13:13:17 +00:00
|
|
|
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
f->left_conn = connect_to_bus (f, address);
|
|
|
|
|
f->right_conn = connect_to_bus (f, address);
|
2011-03-11 13:13:17 +00:00
|
|
|
g_free (address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
add_echo_filter (Fixture *f)
|
|
|
|
|
{
|
2014-10-29 14:10:48 +00:00
|
|
|
if (!dbus_connection_add_filter (f->right_conn, echo_filter, f, NULL))
|
2011-03-11 13:13:17 +00:00
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
f->right_conn_echo = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pc_count (DBusPendingCall *pc,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
guint *received_p = data;
|
|
|
|
|
|
|
|
|
|
(*received_p)++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_echo (Fixture *f,
|
2011-03-11 13:24:08 +00:00
|
|
|
gconstpointer context)
|
2011-03-11 13:13:17 +00:00
|
|
|
{
|
2011-03-11 13:24:08 +00:00
|
|
|
const Config *config = context;
|
2011-03-11 13:13:17 +00:00
|
|
|
guint count = 2000;
|
|
|
|
|
guint sent;
|
|
|
|
|
guint received = 0;
|
|
|
|
|
double elapsed;
|
|
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (config != NULL && config->bug_ref != NULL)
|
|
|
|
|
g_test_bug (config->bug_ref);
|
|
|
|
|
|
2011-03-11 13:13:17 +00:00
|
|
|
if (g_test_perf ())
|
|
|
|
|
count = 100000;
|
|
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
if (config != NULL)
|
|
|
|
|
count = MAX (config->min_messages, count);
|
|
|
|
|
|
2011-03-11 13:13:17 +00:00
|
|
|
add_echo_filter (f);
|
|
|
|
|
|
|
|
|
|
g_test_timer_start ();
|
|
|
|
|
|
|
|
|
|
for (sent = 0; sent < count; sent++)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *m = dbus_message_new_method_call (
|
|
|
|
|
dbus_bus_get_unique_name (f->right_conn), "/",
|
|
|
|
|
"com.example", "Spam");
|
|
|
|
|
DBusPendingCall *pc;
|
|
|
|
|
|
|
|
|
|
if (m == NULL)
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
2011-06-10 17:41:04 +01:00
|
|
|
if (!dbus_connection_send_with_reply (f->left_conn, m, &pc,
|
|
|
|
|
DBUS_TIMEOUT_INFINITE) ||
|
|
|
|
|
pc == NULL)
|
2011-03-11 13:13:17 +00:00
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
if (dbus_pending_call_get_completed (pc))
|
|
|
|
|
pc_count (pc, &received);
|
|
|
|
|
else if (!dbus_pending_call_set_notify (pc, pc_count, &received,
|
|
|
|
|
NULL))
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
dbus_pending_call_unref (pc);
|
|
|
|
|
dbus_message_unref (m);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (received < count)
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
2011-03-11 13:13:17 +00:00
|
|
|
|
|
|
|
|
elapsed = g_test_timer_elapsed ();
|
|
|
|
|
|
|
|
|
|
g_test_maximized_result (count / elapsed, "%u messages / %f seconds",
|
|
|
|
|
count, elapsed);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-22 18:21:58 +01:00
|
|
|
static void
|
|
|
|
|
pending_call_store_reply (DBusPendingCall *pc,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage **message_p = data;
|
|
|
|
|
|
|
|
|
|
*message_p = dbus_pending_call_steal_reply (pc);
|
|
|
|
|
g_assert (*message_p != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 14:10:48 +00:00
|
|
|
static void
|
|
|
|
|
test_no_reply (Fixture *f,
|
|
|
|
|
gconstpointer context)
|
|
|
|
|
{
|
|
|
|
|
const Config *config = context;
|
|
|
|
|
DBusMessage *m;
|
|
|
|
|
DBusPendingCall *pc;
|
|
|
|
|
DBusMessage *reply = NULL;
|
|
|
|
|
enum { TIMEOUT, DISCONNECT } mode;
|
|
|
|
|
gboolean ok;
|
|
|
|
|
|
|
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_test_bug ("76112");
|
|
|
|
|
|
|
|
|
|
if (config != NULL && config->config_file != NULL)
|
|
|
|
|
mode = TIMEOUT;
|
|
|
|
|
else
|
|
|
|
|
mode = DISCONNECT;
|
|
|
|
|
|
|
|
|
|
m = dbus_message_new_method_call (
|
|
|
|
|
dbus_bus_get_unique_name (f->right_conn), "/",
|
|
|
|
|
"com.example", "WaitForever");
|
|
|
|
|
|
|
|
|
|
add_echo_filter (f);
|
|
|
|
|
|
|
|
|
|
if (m == NULL)
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send_with_reply (f->left_conn, m, &pc,
|
|
|
|
|
DBUS_TIMEOUT_INFINITE) ||
|
|
|
|
|
pc == NULL)
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
if (dbus_pending_call_get_completed (pc))
|
|
|
|
|
pending_call_store_reply (pc, &reply);
|
|
|
|
|
else if (!dbus_pending_call_set_notify (pc, pending_call_store_reply, &reply,
|
|
|
|
|
NULL))
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
dbus_pending_call_unref (pc);
|
|
|
|
|
dbus_message_unref (m);
|
|
|
|
|
|
|
|
|
|
if (mode == DISCONNECT)
|
|
|
|
|
{
|
|
|
|
|
while (!f->wait_forever_called)
|
|
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
|
|
|
|
|
|
|
|
|
dbus_connection_remove_filter (f->right_conn, echo_filter, f);
|
|
|
|
|
dbus_connection_close (f->right_conn);
|
|
|
|
|
dbus_connection_unref (f->right_conn);
|
|
|
|
|
f->right_conn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (reply == NULL)
|
|
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
|
|
|
|
|
|
|
|
|
/* using inefficient string comparison for better assertion message */
|
|
|
|
|
g_assert_cmpstr (
|
|
|
|
|
dbus_message_type_to_string (dbus_message_get_type (reply)), ==,
|
|
|
|
|
dbus_message_type_to_string (DBUS_MESSAGE_TYPE_ERROR));
|
|
|
|
|
ok = dbus_set_error_from_message (&f->e, reply);
|
|
|
|
|
g_assert (ok);
|
|
|
|
|
g_assert_cmpstr (f->e.name, ==, DBUS_ERROR_NO_REPLY);
|
|
|
|
|
|
|
|
|
|
if (mode == DISCONNECT)
|
|
|
|
|
g_assert_cmpstr (f->e.message, ==,
|
|
|
|
|
"Message recipient disconnected from message bus without replying");
|
|
|
|
|
else
|
|
|
|
|
g_assert_cmpstr (f->e.message, ==,
|
|
|
|
|
"Message did not receive a reply (timeout by message bus)");
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-22 18:21:58 +01:00
|
|
|
static void
|
|
|
|
|
test_creds (Fixture *f,
|
|
|
|
|
gconstpointer context)
|
|
|
|
|
{
|
|
|
|
|
const char *unique = dbus_bus_get_unique_name (f->left_conn);
|
|
|
|
|
DBusMessage *m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
|
|
|
|
|
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "GetConnectionCredentials");
|
|
|
|
|
DBusPendingCall *pc;
|
|
|
|
|
DBusMessageIter args_iter;
|
|
|
|
|
DBusMessageIter arr_iter;
|
|
|
|
|
DBusMessageIter pair_iter;
|
|
|
|
|
DBusMessageIter var_iter;
|
|
|
|
|
enum {
|
|
|
|
|
SEEN_UNIX_USER = 1,
|
|
|
|
|
SEEN_PID = 2,
|
|
|
|
|
SEEN_WINDOWS_SID = 4
|
|
|
|
|
} seen = 0;
|
|
|
|
|
|
|
|
|
|
if (m == NULL)
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_append_args (m,
|
|
|
|
|
DBUS_TYPE_STRING, &unique,
|
|
|
|
|
DBUS_TYPE_INVALID))
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
if (!dbus_connection_send_with_reply (f->left_conn, m, &pc,
|
|
|
|
|
DBUS_TIMEOUT_USE_DEFAULT) ||
|
|
|
|
|
pc == NULL)
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (m);
|
|
|
|
|
m = NULL;
|
|
|
|
|
|
|
|
|
|
if (dbus_pending_call_get_completed (pc))
|
|
|
|
|
pending_call_store_reply (pc, &m);
|
|
|
|
|
else if (!dbus_pending_call_set_notify (pc, pending_call_store_reply,
|
|
|
|
|
&m, NULL))
|
|
|
|
|
g_error ("OOM");
|
|
|
|
|
|
|
|
|
|
while (m == NULL)
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
test_main_context_iterate (f->ctx, TRUE);
|
2013-08-22 18:21:58 +01:00
|
|
|
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_signature (m), ==, "a{sv}");
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_init (m, &args_iter);
|
|
|
|
|
g_assert_cmpuint (dbus_message_iter_get_arg_type (&args_iter), ==,
|
|
|
|
|
DBUS_TYPE_ARRAY);
|
|
|
|
|
g_assert_cmpuint (dbus_message_iter_get_element_type (&args_iter), ==,
|
|
|
|
|
DBUS_TYPE_DICT_ENTRY);
|
|
|
|
|
dbus_message_iter_recurse (&args_iter, &arr_iter);
|
|
|
|
|
|
|
|
|
|
while (dbus_message_iter_get_arg_type (&arr_iter) != DBUS_TYPE_INVALID)
|
|
|
|
|
{
|
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse (&arr_iter, &pair_iter);
|
|
|
|
|
g_assert_cmpuint (dbus_message_iter_get_arg_type (&pair_iter), ==,
|
|
|
|
|
DBUS_TYPE_STRING);
|
|
|
|
|
dbus_message_iter_get_basic (&pair_iter, &name);
|
|
|
|
|
dbus_message_iter_next (&pair_iter);
|
|
|
|
|
g_assert_cmpuint (dbus_message_iter_get_arg_type (&pair_iter), ==,
|
|
|
|
|
DBUS_TYPE_VARIANT);
|
|
|
|
|
dbus_message_iter_recurse (&pair_iter, &var_iter);
|
|
|
|
|
|
|
|
|
|
if (g_strcmp0 (name, "UnixUserID") == 0)
|
|
|
|
|
{
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
|
guint32 u32;
|
|
|
|
|
|
|
|
|
|
g_assert (!(seen & SEEN_UNIX_USER));
|
|
|
|
|
g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
|
|
|
|
|
DBUS_TYPE_UINT32);
|
|
|
|
|
dbus_message_iter_get_basic (&var_iter, &u32);
|
|
|
|
|
g_message ("%s of this process is %u", name, u32);
|
|
|
|
|
g_assert_cmpuint (u32, ==, geteuid ());
|
|
|
|
|
seen |= SEEN_UNIX_USER;
|
|
|
|
|
#else
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else if (g_strcmp0 (name, "ProcessID") == 0)
|
|
|
|
|
{
|
|
|
|
|
guint32 u32;
|
|
|
|
|
|
|
|
|
|
g_assert (!(seen & SEEN_PID));
|
|
|
|
|
g_assert_cmpuint (dbus_message_iter_get_arg_type (&var_iter), ==,
|
|
|
|
|
DBUS_TYPE_UINT32);
|
|
|
|
|
dbus_message_iter_get_basic (&var_iter, &u32);
|
|
|
|
|
g_message ("%s of this process is %u", name, u32);
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
|
g_assert_cmpuint (u32, ==, getpid ());
|
|
|
|
|
#elif defined(G_OS_WIN32)
|
|
|
|
|
g_assert_cmpuint (u32, ==, GetCurrentProcessId ());
|
|
|
|
|
#else
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
#endif
|
|
|
|
|
seen |= SEEN_PID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_next (&arr_iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
|
g_assert (seen & SEEN_UNIX_USER);
|
|
|
|
|
g_assert (seen & SEEN_PID);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
|
/* FIXME: when implemented:
|
|
|
|
|
g_assert (seen & SEEN_WINDOWS_SID);
|
|
|
|
|
*/
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:13:17 +00:00
|
|
|
static void
|
|
|
|
|
teardown (Fixture *f,
|
|
|
|
|
gconstpointer context G_GNUC_UNUSED)
|
|
|
|
|
{
|
|
|
|
|
dbus_error_free (&f->e);
|
|
|
|
|
g_clear_error (&f->ge);
|
|
|
|
|
|
|
|
|
|
if (f->left_conn != NULL)
|
|
|
|
|
{
|
|
|
|
|
dbus_connection_close (f->left_conn);
|
|
|
|
|
dbus_connection_unref (f->left_conn);
|
|
|
|
|
f->left_conn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f->right_conn != NULL)
|
|
|
|
|
{
|
|
|
|
|
if (f->right_conn_echo)
|
|
|
|
|
{
|
2014-10-29 14:10:48 +00:00
|
|
|
dbus_connection_remove_filter (f->right_conn, echo_filter, f);
|
2011-03-11 13:13:17 +00:00
|
|
|
f->right_conn_echo = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_connection_close (f->right_conn);
|
|
|
|
|
dbus_connection_unref (f->right_conn);
|
|
|
|
|
f->right_conn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
if (f->daemon_pid != 0)
|
|
|
|
|
{
|
2011-03-11 13:13:17 +00:00
|
|
|
#ifdef DBUS_WIN
|
2011-03-11 13:24:08 +00:00
|
|
|
TerminateProcess (f->daemon_pid, 1);
|
2011-03-11 13:13:17 +00:00
|
|
|
#else
|
2011-03-11 13:24:08 +00:00
|
|
|
kill (f->daemon_pid, SIGTERM);
|
2011-03-11 13:13:17 +00:00
|
|
|
#endif
|
|
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
g_spawn_close_pid (f->daemon_pid);
|
|
|
|
|
f->daemon_pid = 0;
|
|
|
|
|
}
|
Tests: allow dbus-glib to be replaced with use of libdbus-internal
We only use dbus-glib for its main loop; within dbus, DBusLoop is
available as an alternative, although it isn't thread-safe and
isn't public API.
For tests that otherwise only use libdbus public API, it's desirable to
be able to avoid DBusLoop, so we can run them against an installed
libdbus as an integration test. However, if we don't have dbus-glib,
we're going to have to use an in-tree main loop, which might as well
be DBusLoop.
The major disadvantage of using dbus-glib is that it isn't safe to
link both dbus-1 and dbus-internal at the same time. This is awkward
for a future test case that wants to use _dbus_getsid() in dbus-daemon.c,
but only on Windows (fd.o #54445). If we use the same API wrapper around
both dbus-glib and DBusLoop, we can compile that test against dbus-glib
or against DBusLoop, depending on the platform.
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68852
Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
2013-09-02 16:32:31 +01:00
|
|
|
|
|
|
|
|
test_main_context_unref (f->ctx);
|
2011-03-11 13:13:17 +00:00
|
|
|
}
|
|
|
|
|
|
2011-03-11 13:24:08 +00:00
|
|
|
static Config limited_config = {
|
|
|
|
|
"34393", 10000, "valid-config-files/incoming-limit.conf"
|
|
|
|
|
};
|
|
|
|
|
|
2014-10-29 14:10:48 +00:00
|
|
|
static Config finite_timeout_config = {
|
|
|
|
|
NULL, 1, "valid-config-files/finite-timeout.conf"
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-11 13:13:17 +00:00
|
|
|
int
|
|
|
|
|
main (int argc,
|
|
|
|
|
char **argv)
|
|
|
|
|
{
|
|
|
|
|
g_test_init (&argc, &argv, NULL);
|
|
|
|
|
g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id=");
|
|
|
|
|
|
|
|
|
|
g_test_add ("/echo/session", Fixture, NULL, setup, test_echo, teardown);
|
2011-03-11 13:24:08 +00:00
|
|
|
g_test_add ("/echo/limited", Fixture, &limited_config,
|
|
|
|
|
setup, test_echo, teardown);
|
2014-10-29 14:10:48 +00:00
|
|
|
g_test_add ("/no-reply/disconnect", Fixture, NULL,
|
|
|
|
|
setup, test_no_reply, teardown);
|
|
|
|
|
g_test_add ("/no-reply/timeout", Fixture, &finite_timeout_config,
|
|
|
|
|
setup, test_no_reply, teardown);
|
2013-08-22 18:21:58 +01:00
|
|
|
g_test_add ("/creds", Fixture, NULL, setup, test_creds, teardown);
|
2011-03-11 13:13:17 +00:00
|
|
|
|
|
|
|
|
return g_test_run ();
|
|
|
|
|
}
|