Commit graph

825 commits

Author SHA1 Message Date
Simon McVittie
c95873e537 .gitignore: Consolidate generic patterns at top level
Patterns in the top-level .gitignore match in all subdirectories, so
there's no need to repeat ourselves quite so much for generic
C, Autotools and gcov patterns.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-14 12:53:08 +00:00
Simon McVittie
9490e954d0 test-privserver: Move helper executable out of name-test/
This means we don't need to distinguish between DBUS_NAME_TEST_EXEC and
DBUS_TEST_EXEC any more, because all test helper executables are in the
same place, both during build and when installed (we don't install
test-privserver since no installed test requires it yet, but in
principle we could).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-13 13:08:00 +00:00
Simon McVittie
0d79fa68c0 test-privserver: Add copyright and licensing information
I've assumed that trivial changes from Scott James Remnant (correcting
some bus names) and Marcus Brinkmann (adding a <config.h> include
tree-wide) are not significant here. All the other potential copyright
holders from the git log are listed, and all have given permission to
relicense their dbus contributions under the MIT/X11 license.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-13 13:07:20 +00:00
Simon McVittie
17e6b1484a test-privserver: Remove all trailing whitespace
Otherwise the commit hook would forbid commits that move it to a new
location.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-13 12:42:11 +00:00
Simon McVittie
e80ff14c2d Merge branch 'wip/asan' into 'master'
Add AddressSanitizer and UBSan support

See merge request dbus/dbus!57

Reviewed-by: pwithnall
2018-12-12 12:01:40 +00:00
Simon McVittie
0c9f943277 build: Add a way to set CFLAGS for AddressSanitizer etc.
We don't want to set these globally via the normal CFLAGS, because if
we did, AddressSanitizer would catch test-segfault deliberately
segfaulting, and "helpfully" turn it into exit status 1, which in turn
makes our test fail because it asserts that the segfault is reported
as a segfault.

A typical use with gcc as compiler, on a reasonably recent Debian,
would be:

    ./configure SANITIZE_CFLAGS="-fsanitize=address -fsanitize=undefined -fPIE -pie"

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-11 12:47:22 +00:00
Simon McVittie
64f94d3f5b Move _dbus_disable_crash_handling() back into test/ directory
It's only used in test code. We have to put it in its own translation
unit with no non-libc dependencies so that we can compile a copy of it
without AddressSanitizer support, because in a subsequent commit we will
special-case test-segfault to be compiled without using AddressSanitizer,
which would make linking to an AddressSanitizer-instrumented libdbus fail.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-11 12:47:22 +00:00
Simon McVittie
c3d15a9ead tests: Allow timeout to be multiplied by an arbitrary factor
Running tests under instrumentation (libasan) or emulation (qemu)
is not fast.

Inspired by the --timeout-factor option in
<https://salsa.debian.org/ci-team/autopkgtest>.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-11 12:47:22 +00:00
Simon McVittie
552ad905f4 test-privserver: Don't leak the DBusServer
This results in (harmless) leak reports when running under the
AddressSanitizer, which could make real leaks harder to find.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-11 12:21:49 +00:00
Ralf Habacker
d9de6ab213 Add build system variable DBUS_NAME_TEST_EXEC to cover differences in executable paths
Autotools creates executable applications in the respective
subdirectory of the build directory, while cmake creates
them in <build-root>/bin.

This leads to different paths in the file created
from org.freedesktop.DBus.TestSuite.PrivServer.service.in,
which are fixed by the new variable.

Bug: https://gitlab.freedesktop.org/dbus/dbus/issues/135
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
Reviewed-by: Simon McVittie <smcv@collabora.com>
2018-12-11 10:41:07 +00:00
Ralf Habacker
a7d1e275e7 Refer to correct bus in test-ids error message
The test tries to connect to the session bus, not system bus.

Reviewed-by: Simon McVittie <smcv@collabora.com>
2018-12-11 10:39:26 +00:00
Ralf Habacker
0f5f95ab6e Skip server oom wildcard test on Windows to avoid firewall exception request
After starting the test on Windows 10, whether the local user is an
administrator or not, a dialog box appears with a warning that some
features of the app have been blocked by the firewall and prompts for
credentials for an administrator account while the test continues to
run and pass.

If this request is aborted, the dialog disappears; no restrictions are
visible for the test case. When the test is restarted, the dialog is also
no longer displayed.

In the firewall configuration you can then see that test-server-oom.exe
has been added (but not enabled) for public networks, although no
confirmation has been received from an administrator account.
2018-12-06 17:08:29 +01:00
Simon McVittie
7db891482f sysdeps test: Wait for spawned process to exit
On Windows, the "out" parameter for the process handle isn't set
unless we specify G_SPAWN_FLAGS_DO_NOT_REAP_CHILD. That means we
can't terminate it, and the child process is leaked. When running the
test individually, the leaked process is harmless apart from its
resource cost, but when running under CTest, it holds a file descriptor
open (or something) which causes CTest to not exit.

If we *do* specify G_SPAWN_FLAGS_DO_NOT_REAP_CHILD, we become
responsible for "reaping" the child process by waiting for its exit
status, which is an OS-specific action.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/238
2018-12-05 15:30:47 +01:00
Simon McVittie
815fc62178 syslog test: Don't assert that we see plain LF newlines
In at least some build configurations that target Windows, we see CRLF
newlines in the stderr of the subprocess. Leave the newlines unspecified
and let "*" match them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/243
2018-12-05 15:27:43 +01:00
Simon McVittie
def9d2d051 Merge branch 'unprivileged-container' into 'master'
dbus-daemon test: Don't test fd limits if in an unprivileged container

See merge request dbus/dbus!58

Reviewed-by: pwithnall
2018-12-05 14:09:19 +00:00
Simon McVittie
a59eb6e944 Merge branch 'unpythonize' into 'master'
Translate Python-based tests to C

See merge request dbus/dbus!37

Reviewed-by: pwithnall
2018-12-05 14:09:00 +00:00
Ralf Habacker
83bdfea8a9 Fix test-shutdown bail out on Windows
test-shutdown expects a GUID in the bus address by default,
which is not available under Windows, because on this platform
an autolaunch address is provided by dbus-run-session and is
not returned by dbus-daemon.

Bug: https://gitlab.freedesktop.org/dbus/dbus/merge_requests/59
Reviewed-by: Simon McVittie <smcv@collabora.com>
2018-12-05 10:55:28 +00:00
Simon McVittie
3d380a3e93 dbus-daemon test: Don't test fd limits if in an unprivileged container
In an unprivileged container, uid 0 doesn't have CAP_SYS_RESOURCE, so
we can't expect the dbus-daemon to be able to escalate its fd limit.

This can be reproduced using bubblewrap:

    sudo bwrap \
        --cap-drop CAP_SYS_RESOURCE \
        --ro-bind / / \
        --dev /dev \
    env \
        DBUS_TEST_DAEMON=.../bus/dbus-daemon \
        DBUS_TEST_DATA=.../test/data \
    .../test/test-dbus-daemon \
        -p /fd-limit \
        --verbose

Bug-Debian: https://bugs.debian.org/908092
2018-12-04 12:18:19 +00:00
Simon McVittie
1191262f5e Translate Python-based tests to C
This simplifies bootstrapping: now you don't have to build dbus,
build dbus-python (with GLib), and use dbus-python to test dbus.

It also avoids test failures when using facilities like
AddressSanitizer. When libdbus is built with AddressSanitizer, but the
system copies of Python and dbus-python were not, dbus-python will exit
the Python interpreter on load, because libasan wasn't already
initialized. The simplest way to avoid this is to not use Python:
the scripts are not *that* hard to translate into C.

Both of these tests happen to be conditionally compiled for Unix only.
test_activation_forking() relies on code in TestSuiteForkingEchoService
that calls fork(), which can only work on Unix; meanwhile,
test_system_signals() tests the system bus configuration, which is
only relevant to Unix because we don't support using dbus-daemon as
a privilege boundary on Windows (and in any case D-Bus is not a Windows
OS feature, so the system bus cannot be used to communicate with OS
services like it can on most Linux systems).

This is also a partial solution to
<https://gitlab.freedesktop.org/dbus/dbus/issues/135>, by reducing the
size of name-test/.

For this to work, we need to build the test-service helper executable
even if embedded tests are disabled.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 17:42:48 +00:00
Simon McVittie
ebe5744375 test-service: Write diagnostics to stderr
When run by a TAP test, stdout is reserved for machine-readable
TAP output.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-03 17:42:48 +00:00
Simon McVittie
6e87d52a46 test/dbus-daemon: Mark max-connections-per-user as unimplemented on Windows
The implementation of the max-connections-per-user limit works in terms
of Unix uids, so it doesn't apply on Windows.

This is not a problem in practice, because it only makes sense to limit
connections per user if you have multiple users, and we don't support
the well-known system bus on Windows.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-29 14:24:52 +00:00
Simon McVittie
a889e5aa8c Add a test for assertions
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 12:58:17 +00:00
Simon McVittie
77327b7bd8 _dbus_disable_crash_handling: Factor out from test-segfault
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 12:58:17 +00:00
Simon McVittie
e0f240e9e3 Merge branch 'containers-test-race' into 'master'
containers test: Wait a few more seconds for the socket to be deleted

See merge request dbus/dbus!47

Reviewed-by: pwithnall
2018-11-20 11:22:48 +00:00
Simon McVittie
c2ee90375a containers test: Wait a few more seconds for the socket to be deleted
Previously, we were waiting a few seconds for the dbus-daemon to stop
listening, then trying to connect again and asserting that it failed,
then immediately asserting that the socket had actually been deleted.
However, there is a race here: the dbus-daemon stops listening on the
socket, and then deletes it. If the test client wins the race by
probing to see whether the socket is present after the dbus-daemon
has stopped listening but before the dbus-daemon has deleted it, then
the test will fail.

This intermittently happens on Gitlab-CI, most recently in
<https://gitlab.freedesktop.org/smcv/dbus/-/jobs/45694>.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 13:53:52 +00:00
Simon McVittie
24d0be54cc desktop-file test: Don't leak errors
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-19 11:38:11 +00:00
Simon McVittie
e8cdb9171e tests: Assert that _dbus_command_for_pid() has correct error behaviour
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
d70040d8d2 tests: Assert that dbus#222 has been fixed 2018-10-31 16:56:36 +00:00
Simon McVittie
93c1d08300 tests: Add a unit test for _dbus_command_for_pid()
In particular this demonstrates that dbus#222 has been solved.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
6eb1c2cd53 test_get_helper_executable: Add function
This is basically the same as get_test_exec() in dbus-spawn-test.c,
but GLib-flavoured.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
2a2c6e6790 test_incomplete: Add function
This is a wrapper for g_test_incomplete(), which works around bugs in
that function prior to GLib 2.57.3. I originally wrote it for librsvg.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
d30188a135 tests: Build test-sleep-forever even if embedded tests are disabled
It will be used as a long-running subprocess to test
_dbus_command_for_pid().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
168bbe146c tests: Build installable helpers whenever any tests are enabled
We might need these to run tests at build-time, so we should build them
whenever either modular or embedded tests are enabled, even if
installed-tests aren't.

We haven't noticed this bug until now because $(installable_helpers)
only contained test-apparmor-activation, which isn't normally needed at
build-time because the AppArmor test can only work when run as root.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-31 16:56:36 +00:00
Simon McVittie
20e6eb7cd1 dbus-daemon test: Allow much longer for pending fd timeout
The timeout we're using here is 0.5s (500ms), but the actual time taken
is unbounded, because the OS scheduler might not schedule our process
for an arbitrary length of time after we become runnable.

We previously allowed up to 1 second, but in the CI jobs for dbus!9
and dbus!18 we've seen this take up to 3.4 seconds (presumably
because other tests, or other jobs running on the same shared
infrastructure, starved this process). Allow up to 10 seconds to guard
against spurious failures.

The timeout used in the production system.conf is 150 seconds (2½
minutes), and we're only using the shorter 500ms timeout here to make
the test complete more quickly, so ±10 seconds is relatively
insignificant: the main thing is that it's finite.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-23 18:46:12 +00:00
Simon McVittie
4b46e9cb0f desktop-file: Treat backslashes in section names as literal
The Desktop Entry Specification doesn't give any special meaning to
backslashes in section names: a line "[\n]" starts a section whose
name is the two characters (backslash, n), not a section whose name
is a newline. GKeyFile in GLib matches this interpretation.

In practice, the only section used by dbus-daemon is "D-BUS Service",
only way this could make a difference is if someone had written it
as "D-BUS\sService". According to
https://codesearch.debian.net/search?q=%5C%5BD-BUS%5C%5CsService%5C%5D
there is no instance of that pattern in Debian.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-19 11:11:55 +00:00
Simon McVittie
9ae7232573 desktop-file test: Expand coverage to include more corner-cases
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-19 11:11:55 +00:00
Simon McVittie
5defe7d9eb Add basic test coverage for the bus' desktop file parser
This doesn't cover backslash-escaping in values, or various other
corner cases, but it's a start.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-10-19 11:11:55 +00:00
Ralf Habacker
6d4639a333 Use separate bus configuration files for executing test cases with a temporary session bus
Instead of the previous adaptation of the existing template
for the session bus, a separate template is now used, which
can be more easily adapted to the requirements of the test
applications.

Bug: https://gitlab.freedesktop.org/dbus/dbus/issues/57
2018-10-18 20:06:43 +02:00
Simon McVittie
64a6366027 Add more test coverage for config file parsing
minimal.conf is a valid config file added to make it obvious why
the new invalid config files are invalid.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107739
2018-08-30 17:39:41 +01:00
Simon McVittie
488ed14cc0 containers test: Exercise GetConnectionInstance() on dbus-daemon itself
This is an easy bit of missing test coverage detected by running the
test suite with gcov.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107739
2018-08-30 17:39:37 +01:00
Simon McVittie
bb73c756f1 Skip name-test/ when running under valgrind for now
These tests are very reliant on their custom LOG_COMPILER,
which AX_VALGRIND_CHECK replaces.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:16:52 +01:00
Simon McVittie
8177bbcf52 tests: Detach most connections from main loop before closing
We don't need to do this for connections that were never set up
with the main loop.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:16:43 +01:00
Simon McVittie
620406f757 test/containers: Fix some memory leaks
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:16:27 +01:00
Simon McVittie
8095e52e5c test/marshal: Don't leak a message and its marshalled buffer
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:16:14 +01:00
Simon McVittie
b274bc13c3 test/dbus-daemon: Don't leak expected error for max connections
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:15:21 +01:00
Simon McVittie
d0413de71b test/dbus-daemon: Don't leak error if no machine ID was found
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:15:14 +01:00
Simon McVittie
07d6eab420 Allow longer for tests under valgrind
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:15:05 +01:00
Simon McVittie
e95dc1d58f tests: Call dbus_shutdown()
Not all of these tests will be fully valgrind-clean yet (or perhaps
ever), but it's easier to add this to all of them than to think
about it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:14:39 +01:00
Simon McVittie
769c367f73 tests: Interpret empty command-line arguments as --tap
AX_VALGRIND_CHECK overrides LOG_COMPILER, which means we can't rely
on running under glib-tap-test.sh. Default to TAP mode by modifying
our (effective) argv instead.

If you really want the default behaviour (unstructured output) this
can still be achieved by adding some arguments that are a no-op,
such as `-m quick`.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:14:21 +01:00
Simon McVittie
1c36fc0aa5 tests: Detach server from main loop during teardown
test_server_setup() takes a reference to the DBusServer, so we need
to release that ref by calling test_server_shutdown().
test_server_shutdown() also disconnects the server, so we don't need
to do that.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
2018-08-02 17:14:11 +01:00