2011-02-22 16:32:14 +00:00
|
|
|
/* Regression test for passing unmodified messages between connections
|
|
|
|
|
*
|
|
|
|
|
* Author: Simon McVittie <simon.mcvittie@collabora.co.uk>
|
2011-06-10 18:23:52 +01:00
|
|
|
* Copyright © 2010-2011 Nokia Corporation
|
2023-08-14 16:53:55 +01:00
|
|
|
* SPDX-License-Identifier: MIT
|
2011-02-22 16:32:14 +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>
|
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
|
|
|
|
2015-02-03 14:45:35 +00:00
|
|
|
#include "test-utils-glib.h"
|
2011-02-22 16:32:14 +00:00
|
|
|
|
|
|
|
|
/* This is basically a miniature dbus-daemon. We relay messages from the client
|
|
|
|
|
* on the left to the client on the right.
|
|
|
|
|
*
|
|
|
|
|
* left socket left dispatch right socket right
|
|
|
|
|
* client ===========> server --------------> server ===========> client
|
|
|
|
|
* conn conn conn conn
|
|
|
|
|
*
|
|
|
|
|
* In the real dbus-daemon, the client connections would be out-of-process,
|
|
|
|
|
* but here we're cheating and doing everything in-process.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
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-02-22 16:32:14 +00:00
|
|
|
DBusError e;
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
gboolean skip;
|
2011-02-22 16:32:14 +00:00
|
|
|
|
|
|
|
|
DBusServer *server;
|
|
|
|
|
|
|
|
|
|
DBusConnection *left_client_conn;
|
|
|
|
|
DBusConnection *left_server_conn;
|
|
|
|
|
|
|
|
|
|
DBusConnection *right_server_conn;
|
|
|
|
|
DBusConnection *right_client_conn;
|
|
|
|
|
/* queue of DBusMessage received by right_client_conn */
|
|
|
|
|
GQueue messages;
|
|
|
|
|
} Fixture;
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
assert_no_error (const DBusError *e)
|
|
|
|
|
{
|
|
|
|
|
if (G_UNLIKELY (dbus_error_is_set (e)))
|
|
|
|
|
g_error ("expected success but got error: %s: %s", e->name, e->message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusHandlerResult
|
|
|
|
|
server_message_cb (DBusConnection *server_conn,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
Fixture *f = data;
|
|
|
|
|
|
|
|
|
|
g_assert (server_conn == f->left_server_conn);
|
|
|
|
|
g_assert (f->right_server_conn != NULL);
|
|
|
|
|
|
|
|
|
|
dbus_connection_send (f->right_server_conn, message, NULL);
|
|
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static DBusHandlerResult
|
|
|
|
|
right_client_message_cb (DBusConnection *client_conn,
|
|
|
|
|
DBusMessage *message,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
Fixture *f = data;
|
|
|
|
|
|
|
|
|
|
g_assert (client_conn == f->right_client_conn);
|
|
|
|
|
g_queue_push_tail (&f->messages, dbus_message_ref (message));
|
|
|
|
|
|
|
|
|
|
return DBUS_HANDLER_RESULT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
new_conn_cb (DBusServer *server,
|
|
|
|
|
DBusConnection *server_conn,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
|
|
|
|
Fixture *f = data;
|
|
|
|
|
dbus_bool_t have_mem;
|
|
|
|
|
|
|
|
|
|
if (f->left_server_conn == NULL)
|
|
|
|
|
{
|
|
|
|
|
f->left_server_conn = dbus_connection_ref (server_conn);
|
|
|
|
|
|
|
|
|
|
have_mem = dbus_connection_add_filter (server_conn,
|
|
|
|
|
server_message_cb, f, NULL);
|
|
|
|
|
g_assert (have_mem);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
g_assert (f->right_server_conn == NULL);
|
|
|
|
|
f->right_server_conn = dbus_connection_ref (server_conn);
|
|
|
|
|
}
|
|
|
|
|
|
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, server_conn);
|
2011-02-22 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
setup (Fixture *f,
|
2018-06-04 16:27:49 +01:00
|
|
|
gconstpointer address)
|
2011-02-22 16:32:14 +00:00
|
|
|
{
|
2017-11-27 19:14:23 +00:00
|
|
|
test_timeout_reset (1);
|
2017-09-27 13:14:39 +01: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->ctx = test_main_context_get ();
|
2011-02-22 16:32:14 +00:00
|
|
|
dbus_error_init (&f->e);
|
|
|
|
|
g_queue_init (&f->messages);
|
|
|
|
|
|
2022-02-09 12:23:56 +04:00
|
|
|
if ((g_str_has_prefix (address, "unix:") && !test_check_af_unix_works ()) ||
|
|
|
|
|
((g_str_has_prefix (address, "tcp:") ||
|
|
|
|
|
g_str_has_prefix (address, "nonce-tcp:")) &&
|
|
|
|
|
!test_check_tcp_works ()))
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
{
|
|
|
|
|
f->skip = TRUE;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-04 16:27:49 +01:00
|
|
|
f->server = dbus_server_listen (address, &f->e);
|
2011-02-22 16:32:14 +00:00
|
|
|
assert_no_error (&f->e);
|
|
|
|
|
g_assert (f->server != NULL);
|
|
|
|
|
|
|
|
|
|
dbus_server_set_new_connection_function (f->server,
|
|
|
|
|
new_conn_cb, f, 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_server_setup (f->ctx, f->server);
|
2011-02-22 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_connect (Fixture *f,
|
|
|
|
|
gconstpointer data G_GNUC_UNUSED)
|
|
|
|
|
{
|
|
|
|
|
dbus_bool_t have_mem;
|
2011-08-04 13:13:24 +01:00
|
|
|
char *address;
|
2011-02-22 16:32:14 +00:00
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-22 16:32:14 +00:00
|
|
|
g_assert (f->left_server_conn == NULL);
|
|
|
|
|
g_assert (f->right_server_conn == NULL);
|
|
|
|
|
|
2011-08-04 13:13:24 +01:00
|
|
|
address = dbus_server_get_address (f->server);
|
|
|
|
|
g_assert (address != NULL);
|
|
|
|
|
|
|
|
|
|
f->left_client_conn = dbus_connection_open_private (address, &f->e);
|
2011-02-22 16:32:14 +00:00
|
|
|
assert_no_error (&f->e);
|
|
|
|
|
g_assert (f->left_client_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, f->left_client_conn);
|
2011-02-22 16:32:14 +00:00
|
|
|
|
|
|
|
|
while (f->left_server_conn == NULL)
|
|
|
|
|
{
|
2015-02-26 17:12:22 +00:00
|
|
|
test_progress ('.');
|
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-02-22 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
2011-08-04 13:13:24 +01:00
|
|
|
f->right_client_conn = dbus_connection_open_private (address, &f->e);
|
2011-02-22 16:32:14 +00:00
|
|
|
assert_no_error (&f->e);
|
|
|
|
|
g_assert (f->right_client_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, f->right_client_conn);
|
2011-02-22 16:32:14 +00:00
|
|
|
|
2011-08-04 13:13:24 +01:00
|
|
|
dbus_free (address);
|
|
|
|
|
|
2011-02-22 16:32:14 +00:00
|
|
|
while (f->right_server_conn == NULL)
|
|
|
|
|
{
|
2015-02-26 17:12:22 +00:00
|
|
|
test_progress ('.');
|
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-02-22 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
have_mem = dbus_connection_add_filter (f->right_client_conn,
|
|
|
|
|
right_client_message_cb, f, NULL);
|
|
|
|
|
g_assert (have_mem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static dbus_uint32_t
|
|
|
|
|
send_one (Fixture *f,
|
|
|
|
|
const char *member)
|
|
|
|
|
{
|
|
|
|
|
dbus_bool_t have_mem;
|
|
|
|
|
dbus_uint32_t serial;
|
|
|
|
|
DBusMessage *outgoing;
|
|
|
|
|
|
|
|
|
|
outgoing = dbus_message_new_signal ("/com/example/Hello",
|
|
|
|
|
"com.example.Hello", member);
|
|
|
|
|
g_assert (outgoing != NULL);
|
|
|
|
|
|
|
|
|
|
have_mem = dbus_connection_send (f->left_client_conn, outgoing, &serial);
|
|
|
|
|
g_assert (have_mem);
|
|
|
|
|
g_assert (serial != 0);
|
|
|
|
|
|
|
|
|
|
dbus_message_unref (outgoing);
|
|
|
|
|
return serial;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_relay (Fixture *f,
|
|
|
|
|
gconstpointer data)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *incoming;
|
|
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-22 16:32:14 +00:00
|
|
|
test_connect (f, data);
|
|
|
|
|
|
|
|
|
|
send_one (f, "First");
|
|
|
|
|
send_one (f, "Second");
|
|
|
|
|
|
|
|
|
|
while (g_queue_get_length (&f->messages) < 2)
|
|
|
|
|
{
|
2015-02-26 17:12:22 +00:00
|
|
|
test_progress ('.');
|
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-02-22 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert_cmpuint (g_queue_get_length (&f->messages), ==, 2);
|
|
|
|
|
|
|
|
|
|
incoming = g_queue_pop_head (&f->messages);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_member (incoming), ==, "First");
|
|
|
|
|
dbus_message_unref (incoming);
|
|
|
|
|
|
|
|
|
|
incoming = g_queue_pop_head (&f->messages);
|
|
|
|
|
g_assert_cmpstr (dbus_message_get_member (incoming), ==, "Second");
|
|
|
|
|
dbus_message_unref (incoming);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* An arbitrary number of messages */
|
|
|
|
|
#define MANY 8192
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_limit (Fixture *f,
|
|
|
|
|
gconstpointer data)
|
|
|
|
|
{
|
|
|
|
|
DBusMessage *incoming;
|
|
|
|
|
guint i;
|
|
|
|
|
|
test: Skip TCP tests if getaddrinfo doesn't work
For example, this can be the case in bubblewrap or Debian pbuilder after
unsharing the network namespace:
bwrap \
--bind / / \
--dev-bind /dev /dev \
--bind /dev/shm /dev/shm \
--bind /dev/pts /dev/pts \
--unshare-net \
${builddir}/test/test-loopback --tap
...
ok 1 /connect/tcp # SKIP Name resolution does not work here:
getaddrinfo("127.0.0.1", "0", {flags=ADDRCONFIG, family=INET,
socktype=STREAM, protocol=TCP}): Name or service not known
On some systems this can be circumvented by using nss_wrapper from
<https://cwrap.org/nss_wrapper.html>:
cat > hosts <<EOF
127.0.0.1 localhost
EOF
bwrap \
... \
env \
LD_PRELOAD=libnss_wrapper.so \
NSS_WRAPPER_HOSTS=$(pwd)/hosts \
${builddir}/test/test-loopback --tap
...
# listening at tcp:host=127.0.0.1,port=39219,family=ipv4,guid=...
but for systems where that does't work, we should be prepared to skip
the affected tests.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=106812
2018-06-04 16:27:50 +01:00
|
|
|
if (f->skip)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-02-22 16:32:14 +00:00
|
|
|
test_connect (f, data);
|
|
|
|
|
|
|
|
|
|
/* This was an attempt to reproduce fd.o #34393. It didn't work. */
|
|
|
|
|
g_test_bug ("34393");
|
|
|
|
|
dbus_connection_set_max_received_size (f->left_server_conn, 1);
|
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-02-22 16:32:14 +00:00
|
|
|
|
|
|
|
|
for (i = 0; i < MANY; i++)
|
|
|
|
|
{
|
|
|
|
|
gchar *buf = g_strdup_printf ("Message%u", i);
|
|
|
|
|
|
|
|
|
|
send_one (f, buf);
|
|
|
|
|
g_free (buf);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
|
|
while (i < MANY)
|
|
|
|
|
{
|
|
|
|
|
while (g_queue_is_empty (&f->messages))
|
|
|
|
|
{
|
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-02-22 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while ((incoming = g_queue_pop_head (&f->messages)) != NULL)
|
|
|
|
|
{
|
|
|
|
|
i++;
|
|
|
|
|
dbus_message_unref (incoming);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
teardown (Fixture *f,
|
|
|
|
|
gconstpointer data G_GNUC_UNUSED)
|
|
|
|
|
{
|
|
|
|
|
if (f->left_client_conn != NULL)
|
|
|
|
|
{
|
2015-04-13 15:04:20 +02:00
|
|
|
test_connection_shutdown(NULL, f->left_client_conn);
|
2011-02-22 16:32:14 +00:00
|
|
|
dbus_connection_close (f->left_client_conn);
|
|
|
|
|
dbus_connection_unref (f->left_client_conn);
|
|
|
|
|
f->left_client_conn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f->right_client_conn != NULL)
|
|
|
|
|
{
|
2015-04-13 15:04:20 +02:00
|
|
|
test_connection_shutdown(NULL, f->right_client_conn);
|
2011-02-22 16:32:14 +00:00
|
|
|
dbus_connection_close (f->right_client_conn);
|
|
|
|
|
dbus_connection_unref (f->right_client_conn);
|
|
|
|
|
f->right_client_conn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f->left_server_conn != NULL)
|
|
|
|
|
{
|
2015-04-13 15:04:20 +02:00
|
|
|
test_connection_shutdown(NULL, f->left_server_conn);
|
2011-02-22 16:32:14 +00:00
|
|
|
dbus_connection_close (f->left_server_conn);
|
|
|
|
|
dbus_connection_unref (f->left_server_conn);
|
|
|
|
|
f->left_server_conn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f->right_server_conn != NULL)
|
|
|
|
|
{
|
2015-04-13 15:04:20 +02:00
|
|
|
test_connection_shutdown(NULL, f->right_server_conn);
|
2011-02-22 16:32:14 +00:00
|
|
|
dbus_connection_close (f->right_server_conn);
|
|
|
|
|
dbus_connection_unref (f->right_server_conn);
|
|
|
|
|
f->right_server_conn = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f->server != NULL)
|
|
|
|
|
{
|
2018-07-11 16:22:49 +01:00
|
|
|
test_server_shutdown (f->ctx, f->server);
|
2011-02-22 16:32:14 +00:00
|
|
|
dbus_server_unref (f->server);
|
|
|
|
|
f->server = 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_unref (f->ctx);
|
2011-02-22 16:32:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main (int argc,
|
|
|
|
|
char **argv)
|
|
|
|
|
{
|
2018-07-11 16:40:12 +01:00
|
|
|
int ret;
|
2022-03-24 15:39:44 +04:00
|
|
|
#ifdef DBUS_UNIX
|
|
|
|
|
char *tmp = _dbus_strdup ("/tmp");
|
|
|
|
|
#else
|
|
|
|
|
char *tmp = dbus_address_escape_value (g_get_tmp_dir ());
|
|
|
|
|
#endif
|
|
|
|
|
gchar *unix_tmpdir = g_strdup_printf ("unix:tmpdir=%s", tmp);
|
2018-07-11 16:40:12 +01:00
|
|
|
|
2015-02-03 14:45:35 +00:00
|
|
|
test_init (&argc, &argv);
|
2011-02-22 16:32:14 +00:00
|
|
|
|
2018-06-04 16:27:49 +01:00
|
|
|
g_test_add ("/connect/tcp", Fixture, "tcp:host=127.0.0.1", setup,
|
|
|
|
|
test_connect, teardown);
|
|
|
|
|
g_test_add ("/relay/tcp", Fixture, "tcp:host=127.0.0.1", setup,
|
|
|
|
|
test_relay, teardown);
|
|
|
|
|
g_test_add ("/limit/tcp", Fixture, "tcp:host=127.0.0.1", setup,
|
|
|
|
|
test_limit, teardown);
|
|
|
|
|
|
2022-03-24 15:39:44 +04:00
|
|
|
g_test_add ("/connect/unix", Fixture, unix_tmpdir, setup,
|
2011-02-22 16:32:14 +00:00
|
|
|
test_connect, teardown);
|
2022-03-24 15:39:44 +04:00
|
|
|
g_test_add ("/relay/unix", Fixture, unix_tmpdir, setup,
|
2011-02-22 16:32:14 +00:00
|
|
|
test_relay, teardown);
|
2022-03-24 15:39:44 +04:00
|
|
|
g_test_add ("/limit/unix", Fixture, unix_tmpdir, setup,
|
2011-02-22 16:32:14 +00:00
|
|
|
test_limit, teardown);
|
|
|
|
|
|
2018-07-11 16:40:12 +01:00
|
|
|
ret = g_test_run ();
|
|
|
|
|
dbus_shutdown ();
|
2022-03-24 15:39:44 +04:00
|
|
|
g_free (unix_tmpdir);
|
|
|
|
|
dbus_free (tmp);
|
2018-07-11 16:40:12 +01:00
|
|
|
return ret;
|
2011-02-22 16:32:14 +00:00
|
|
|
}
|