Commit graph

944 commits

Author SHA1 Message Date
Simon McVittie
053a62122b test: Unembed hash test from libdbus and move it into test/
This required exposing one additional internal symbol:
_dbus_hash_table_ref(). I think that's a reasonable trade-off for not
compiling this test into the library.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:20:06 +00:00
Simon McVittie
24a1f3406a test: Split slow parts of the former test-dbus into their own executables
This makes it easier for a developer to run just the fast parts while
debugging some issue reproduced by the faster tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:20:04 +00:00
Simon McVittie
b7f11c17d1 _dbus_test_main: Move to test-utils
Now that there is no code outside test/ that calls into this, we can
move it into test/, reducing the size of libdbus.

dbus-test-tap.[ch] still need to stay in dbus/ as long as there is
code in dbus/ or bus/ relying on them, and also need to be linked into
libdbus as long as there is other code in libdbus relying on them,
so they stay where they are for now. Similarly, dbus-tests.h lists
the tests that are still embedded in libdbus, and must stay where
it is for the moment.

With this move, various tests now need to be linked to the dbus-testutils
convenience library.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:19:36 +00:00
Simon McVittie
e23bba929a test: Move dbus-daemon-launch-helper-test here, and rename
The -test suffix does not indicate that this is a test, but rather that
it is for tests (similar to the -unix and -win suffixes on modules like
dbus-sysdeps). This seems unnecessarily confusing, so rename it to end
with -for-tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:18:46 +00:00
Simon McVittie
b28e0886ed test: Move libdbus embedded tests from dbus/ to test/
This groups them with the rest of the tests, and enables parts of
the test code to be unembedded from libdbus and moved to test/ too.

Rename the executable to test-misc-internals, not test-dbus. The name
test-dbus made some sense as "the executable that contains the code in
dbus/", but makes a lot less sense in test/: dbus is the name of the
entire project, so this test has no particular special claim to that
name. test-libdbus doesn't seem right either, because all the tests
exercise libdbus one way or another.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:18:18 +00:00
Simon McVittie
3b512610c0 test: Break out the slow parts of test-bus into their own executables
This makes it more convenient to re-run the rest of test-bus as
required when debugging.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:17:36 +00:00
Simon McVittie
a15839da9b test: Move dbus-daemon and d-d-launch-helper tests from bus/
This groups them with the other tests, and avoids having them influence
the test coverage stats in bus/.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:16:51 +00:00
Simon McVittie
037d19a328 Convert spawn test into a standalone test executable
This test is sufficiently well-separated that there's no real need
to embed it in libdbus. Move it into the test directory instead.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:15:16 +00:00
Simon McVittie
651a82e685 test-utils: Add copyright and licensing
As far as I can tell, the only significant contributions have been
from Red Hat and Collabora, both of which have given permission to
relicense their parts of the dbus codebase to MIT/X11; so let's go
with that.

I'm assuming here that tree-wide changes from
_DBUS_GNUC_WARN_UNUSED_RESULT to _DBUS_WARN_UNUSED_RESULT, and tree-wide
changes to how we include config.h, are not significant for copyright
purposes.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:14:29 +00:00
Ralf Habacker
602f4506a8 Add glib 2.38 support 2019-01-06 21:24:10 +01:00
Simon McVittie
c3f401a673 Merge branch 'gitignore' into 'master'
trivial: Clean up .gitignore files

See merge request dbus/dbus!70

Reviewed-by: pwithnall
2018-12-14 15:11:51 +00:00
Simon McVittie
fa63c16346 .gitignore: Ignore many more generated files
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-14 13:28:50 +00:00
Simon McVittie
5e66241c77 Merge branch 'reduce-test-refs-run-time' into 'master'
Decrease the runtime of test-refs under Windows

Closes #244

See merge request dbus/dbus!65
2018-12-14 13:08:01 +00:00
Simon McVittie
d3fffaa72f .gitignore: Normalize into LC_ALL=C sort order
If lists are in a completely arbitrary order, sorting them consistently
means that there is only one correct place to insert a new entry, avoiding
the merge conflicts that would occur if we always append new entries.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-14 12:53:08 +00:00
Simon McVittie
0c62a9a5f4 .gitignore: Make match patterns more specific
In subdirectories we mostly only want to match at the current level,
not in nested subdirectories.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-14 12:53:08 +00:00
Simon McVittie
dfd09355ef valid-config-files-system .gitignore: Don't ignore many-rules.conf
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-14 12:53:08 +00:00
Simon McVittie
2fd386245b .gitignore: Remove obsolete patterns
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-12-14 12:53:08 +00:00
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
Ralf Habacker
48538357c6 Increase the number of references/threads to be tested under Windows by default to detect errors 2018-12-14 11:04:21 +01:00
Ralf Habacker
95171f4f1a Decrease the runtime of test refs under Windows by default
If the environment variable DBUS_TEST_SLOW is not set or is 0
fewer iterations are performed in test-refs enough to demonstrate
that it works, rather than seriously trying to reproduce race
conditions.

This solves the long runtime that Wine 3.x (4 times longer than
native Windows 7) or Windows 7 as a VirtualBox 5.22 guest (10
times longer) is to be seen.

Fixes #244
2018-12-14 10:54:52 +01: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