Commit graph

944 commits

Author SHA1 Message Date
Simon McVittie
3444ac4007 Test dbus_message_iter_abandon_container_if_open under OOM conditions
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101568
2017-07-05 16:22:54 +01:00
Simon McVittie
159fe82bd3 test/message: Add a targeted test for recently-fixed 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=101568
2017-07-05 13:13:44 +01:00
Simon McVittie
0354f5d48f internals: Decouple logging an error from exiting unsuccessfully
This lets _dbus_warn() and _dbus_warn_check_failed() fall through
to flushing stderr and calling _dbus_abort(), meaning that failed
checks and warnings can result in a core dump as intended.
By renaming the FATAL severity to ERROR, we ensure that any code
contributions that assumed the old semantics will fail to compile.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101568
2017-07-05 13:12:37 +01:00
Simon McVittie
3a6d144766 test/loopback: Exercise unix:dir addresses
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101567
2017-06-29 14:03:45 +01:00
Simon McVittie
063c505efb test/loopback: Assert that the connectable address makes sense
When we listen on a tcp: address we should get a connectable tcp:
address, and so on.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101567
2017-06-29 14:03:36 +01:00
Simon McVittie
fe19134bb6 test/loopback: Don't leak address strings
dbus_server_get_address() returns a copy. It isn't clear why.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101567
2017-06-29 14:03:30 +01:00
Shin-ichi MORITA
ad17155f26 Fix missing dbus_message_unref() in error reply path
The error message was leaked when blocking on a pending call after
the connection was disconnected.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: re-word commit message]
Reviewed-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101481
2017-06-27 18:20:52 +01:00
Shin-ichi MORITA
08bf0b1bbb Fix missing dbus_message_unref() in error reply path
The error message was leaked when blocking on a pending call after
the connection was disconnected.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: re-word commit message]
Reviewed-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101481
2017-06-27 18:11:24 +01:00
Simon McVittie
8633640ce1 test-pending-call-dispatch: Add copyright and license grant
According to git history, this test was written in 2006 by Red Hat
employee John Palmieri and has received only trivial changes since
then. Red Hat gave permission in 2007 for their contributions to
be relicensed under the MIT/X11 license. We cannot take advantage
of that permission to relicense the core library or the dbus-daemon
from GPL-2+|AFL-2.0 to MIT/X11, because one early copyright holder
(CodeFactory AB) could not be traced, but we might as well use a
permissive license for simple test code that has not had
CodeFactory AB contributions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101481
2017-06-27 18:05:54 +01:00
Simon McVittie
4d6495d03d test/internals/syslog: Switch to g_test_trap_subprocess()
This re-executes the same binary with special command-line options
instead of forking. As a result, it can work on Windows, and is less
dependent on Unix libraries continuing to work across a fork().

(This has been confirmed to work in Windows binaries running under Wine.)

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101362
2017-06-12 11:42:09 +01:00
Simon McVittie
8821af59c8 Bump GLib dependency for tests to 2.40
This is quite old (it's the version in Ubuntu 14.04 LTS, and older
than the version in Debian 8) but gives us g_test_skip(),
g_test_trap_subprocess() and GVariantDict, all of which will be
useful in the regression tests.

Remove workarounds for old versions.

After this commit we are still using the deprecated g_test_trap_fork(),
which will be removed in a subsequent commit. Don't opt-in to the new
deprecation warnings from 2.38 and 2.40 yet, because under our recommended
settings for dbus developers (-Werror) they would break the build.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101362
2017-06-12 11:40:18 +01:00
Simon McVittie
91c235e316 test-autolaunch: Make recently-added message similar to the others
Signed-off-by: Simon McVittie <smcv@collabora.com>
2017-06-08 18:43:38 +01:00
Simon McVittie
22bdf2365e Add dbus_try_get_local_machine_id()
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=13194
2017-06-08 18:31:10 +01:00
Simon McVittie
ffa410a040 tests: Don't exercise GetMachineId() or autolaunch if no machine ID
At the moment there is a hack in the implementation of GetMachineId()
to stop tests from failing during "make check" on a system where
dbus has never been installed, by silently generating a new unique
fake "machine ID" for each process. I'm about to change that
behaviour to report errors properly; skip affected test-cases if we
can't read the real machine ID.

The shell scripts to test dbus-launch are run both as "make check"
tests (for which it is valid for dbus to be not correctly installed)
and as installed-tests (for which that is not valid), so make them
pass during "make check" but fail during installed testing.
The tests in bus/ and test/name-test/ are only run during "make check"
so they only have the code path where they are skipped.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=13194
2017-06-08 18:30:39 +01:00
Simon McVittie
4256df5fb0 test/dbus-daemon: Exercise Properties, Features and Interfaces
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101257
2017-06-08 17:00:42 +01:00
Simon McVittie
cc1ee6c39d test/dbus-daemon: Exercise the Peer interface
We have to skip the GetMachineId() part during build-time testing
if it wouldn't work - there is no guarantee that dbus has ever been
installed on the build system. However, we can insist on it during
installed-tests, if we make sure to complete the installation for the
Travis-CI build by running dbus-uuidgen.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101257
2017-06-08 17:00:38 +01:00
Simon McVittie
2ee52a6a07 test/dbus-daemon: 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=101257
2017-06-08 16:58:40 +01:00
Simon McVittie
093ec67b8f bus/driver: Make non-core interfaces unavailable on most object paths
The o.fd.DBus interface needs to remain available on arbitrary object
paths for backwards compatibility, and the Introspectable interface
is genuinely useful, but everything else can be skipped.

This is arguably an incompatible change for the undocumented Verbose
interface, and for the GetAllMatchRules method on the undocumented
Stats interface: previously those were available at all object paths.

Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: Adjust comments, enum order, variable naming as per Philip's review]
Signed-off-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101256
2017-06-02 10:43:29 +01:00
Simon McVittie
36893e76c4 test/monitor: Assert that BecomeMonitor() on wrong object path fails
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101256
2017-06-02 10:38:30 +01:00
Simon McVittie
36fcd43005 Pass in DBUS_TEST_EXEC via environment, not hard-coded into binaries
This avoids "capturing" the build directory in the built binaries
when built with embedded tests, which is good for reproducible builds.
See <https://reproducible-builds.org/> for more information.

Signed-off-by: Simon McVittie <smcv@debian.org>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100692
2017-04-18 17:20:30 +01:00
Simon McVittie
01019f2bb4 Ensure hyphen/minus is treated as literal in regexes
Each U+002D HYPHEN-MINUS in [0-9A-Za-z_-/.\] is treated as a member of a
range. The third one, which appears to have been intended to be a
literal, is part of an empty range because the starting point
U+005F LOW LINE is greater than the endpoint U+002F SOLIDUS, resulting
in at least some grep implementations not considering U+002D, U+002F
or U+005F to match the pattern. This resulted in one of the
dbus-launch tests being unintentionally skipped when it used a
regex based on the one in the spec.

regex(7) suggests "To include a literal '-' [in a bracketed character
set], make it the first or last character".

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100686
2017-04-18 12:46:20 +01:00
Simon McVittie
ef628c3b0a transient-services integration test: Create the right directory
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100686
2017-04-18 12:46:18 +01:00
Simon McVittie
5be3d5faac AppArmor test: Allow writing to our temporary XDG_RUNTIME_DIR
Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100686
2017-04-18 12:45:16 +01:00
Simon McVittie
40560fa0c7 test, tools: assert impossible values of local enums are not reached
Based on part of a patch from Thomas Zimmermann.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=98191
2017-04-07 12:07:01 +01:00
Simon McVittie
eb56619aed Merge branch 'dbus-1.10' 2017-04-05 21:40:57 +01:00
Philip Withnall
bb43433b63 test: Fix a couple of memory leaks in test-corrupt
Spotted while testing bug #100568.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: Simon McVittie <smcv@collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100568
2017-04-05 16:22:52 +01:00
Philip Withnall
9e864c2e4b test: Fix reading off the end of an array in test-corrupt
One level of pointer indirection too many when passing the arguments to
dbus_message_append_args().

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100568
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: Simon McVittie <smcv@collabora.com>
2017-04-05 16:22:22 +01:00
Philip Withnall
d42905bc04 test: Remove an unnecessary NULL check in sd-activation
test_transient_services() was checking whether (config == NULL), then
shortly afterwards dereferencing config->bus_name (which is in fact
dereferenced on all branches of the function). Remove the check and add
some assertions to ensure a Config struct is always passed into the test
(which it currently is).

Coverity ID: 141877

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99999
Reviewed-by: Simon McVittie <smcv@collabora.com>
2017-03-20 14:54:40 +00:00
Philip Withnall
f6cee5f046 test: Fix copy-paste error in waiting for a message in the tests
The parameters to the test_pending_call_store_reply() call should match
those to the dbus_pending_call_set_notify() immediately after.

Coverity ID: 141876

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99999
Reviewed-by: Simon McVittie <smcv@collabora.com>
2017-03-20 14:53:37 +00:00
Simon McVittie
6b17dd68df Add a simple integration test for transient services
Because this is in a subdirectory, it requires some extra `mkdir -p`
and some `nobase_` variables. Make all the installed-tests `nobase_`
for consistency.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Andre Moreira Magalhaes <andre.magalhaes@collabora.co.uk>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-21 18:09:04 +00:00
Simon McVittie
3d5bc65333 sd-activation test: Exercise transient services
To do this, we have to use the <standard_session_servicedirs/>.
A previous commit ensured that those don't provide any service files
we don't expect.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-21 13:24:02 +00:00
Simon McVittie
ff03660715 config-parser: Add transient service directories
For configuration purposes these are treated as part of the standard
session service directories, to avoid having to add new configuration
syntax which would prevent an old dbus-daemon from reloading
successfully. From an API perspective, they're separate, though.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-21 13:23:37 +00:00
Simon McVittie
f2b6cc4207 sd-activation test: Create and destroy a temporary XDG_RUNTIME_DIR
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-21 13:23:34 +00:00
Simon McVittie
ec9d39b95c test-utils-glib: Wait for the killed process to exit
Otherwise, removing transient service directories that are being
watched by the dbus-daemon can fail with EAGAIN.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-21 11:57:15 +00:00
Simon McVittie
06904a8d96 tests: Consistently don't try to kill pid 0
daemon_pid will still be 0 if any tests were skipped. In particular
this happens during `make installcheck`.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-21 11:56:56 +00:00
Simon McVittie
ef5d7264f1 config-parser test: Exercise the full config-parser
Don't just exercise _dbus_get_standard_session_servicedirs(), but
also its integration into the BusConfigParser.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-20 18:20:26 +00:00
Simon McVittie
024bcd407b config-parser: Don't use dbus_setenv() to test service directories
We can rely on the Autotools build system to pass in some safe values
for XDG_DATA_HOME and XDG_DATA_DIRS that match DBUS_TEST_BUILDDIR.

This test will now be skipped when running test-bus manually,
or under the CMake build system. Under CMake it could be reinstated
by setting the right environment variables.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: add missing newline as requested]
[smcv: align DBUS_TEST_BUILDDIR with G_TEST_BUILDDIR]
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-20 18:16:43 +00:00
Simon McVittie
867a600bf7 test: Redirect XDG_DATA_HOME, XDG_DATA_DIRS somewhere harmless
We want to be able to use <standard_system_datadirs/> in tests
without picking up someone else's .service files.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-20 18:05:26 +00:00
Simon McVittie
898ae926df tests: Wrap file-deletion functions to handle EINTR
The GLib functions we're using don't, and it seems to be possible to be
interrupted during cleanup for our tests.

Windows apparently has and uses ENOENT for _unlink(), so just do the
same on Windows there; but EINTR is very much a POSIX thing, so ignore
that on Windows.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
[smcv: add Windows fixes from a later commit, also reviewed by Philip]
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-20 16:48:23 +00:00
Simon McVittie
eef176eb72 test_get_dbus_daemon: Take a custom XDG_RUNTIME_DIR as an argument
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-20 12:52:38 +00:00
Simon McVittie
84c8403197 sd-activation test: Use a struct for the test context
This is going to be necessary to be able to influence setup() and
teardown() as well as just the individual tests.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99825
Reviewed-by: Philip Withnall <withnall@endlessm.com>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-20 12:52:10 +00:00
Simon McVittie
e354380e82 shell-test: Don't use _dbus_get_tmpdir()
There's no particular reason to be using a temporary directory (it's
just some arbitrary string), and it will be harder for future changes
to eradicate uses of a temporary directory that is shared between users
if we list it here.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99828
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
2017-02-16 16:00:14 +00:00
Simon McVittie
e80835bb0a test: Delete directories like directories, not files
Directories can't usefully appear in CLEANFILES, we have to delete
them recursively in clean-local.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99828
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Reviewed-by: Philip Withnall <withnall@endlessm.com>
2017-02-16 16:00:06 +00:00
Philip Withnall
1c390c0ce4 test: Add a missing OOM path in manual-dir-iter test
Odd that this one was missing but all the other ones were in place.

Coverity ID: 54721
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99724
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-14 17:45:08 +00:00
Philip Withnall
c5a5c4047d test: Add some OOM paths to the shell-test
I am increasingly of the opinion that this is a gigantic waste of time.
But at least Coverity will be happy.

Coverity IDs: 60585, 60586
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99724
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-13 16:04:18 +00:00
Philip Withnall
cee80c92b6 test: Add some OOM paths to the test-pending-call-timeout test
This is mostly pointless, but will shut Coverity up.

Coverity ID: 54718
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99724
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-13 16:03:37 +00:00
Philip Withnall
f88c8a8c39 test: Simplify error checking path in test-service slightly
This should shut up Coverity from complaining about not checking the
return value of dbus_set_error_from_message(), which is equivalent to
the (type == DBUS_MESSAGE_TYPE_ERROR) check.

Coverity ID: 54697
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99723
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-13 16:03:05 +00:00
Philip Withnall
84cd6243b3 test: Add some OOM paths to the test-privserver test
This is mostly pointless, but should shut Coverity up.

Coverity ID: 54693
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99722
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-13 16:01:56 +00:00
Philip Withnall
bbc1ab8d2a test: Add some OOM paths to the dbus-daemon-eavesdrop path
This will shut Coverity up. All the paths are checks on the return value
from dbus_message_set_destination().

Coverity IDs: 54822, 54823, 54824, 54825

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99712
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-13 14:54:05 +00:00
Philip Withnall
f1de9905b1 test: Add missing error handling to some name-test tests
Also take the opportunity to tweak the test-threads-init messages
slightly to make it more TAP-compliant. It is not entirely TAP compliant
because it doesn’t print a test plan before starting its tests.

Coverity IDs: 54701, 54714, 54726

Signed-off-by: Philip Withnall <withnall@endlessm.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99694
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
2017-02-13 14:53:29 +00:00