Commit graph

925 commits

Author SHA1 Message Date
Simon McVittie
4bce2c36f0 test: Expect TAP output for tests in name-test
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-13 20:36:13 +01:00
Simon McVittie
43927ea002 test: Don't run test-autolaunch directly
It's intended to be run from run-test.sh.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-13 20:36:13 +01:00
Simon McVittie
83fbc01dca test: Sort test executables
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-13 20:36:13 +01:00
Félix Piédallu
cd2e382610 Add Meson build system
Signed-off-by: Félix Piédallu <felix@piedallu.me>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-13 20:36:13 +01:00
Ralf Habacker
b1dd6fa7a6 Add a test application for autostart on Windows implementation
The test application performs several individual tests to detect possible
problems with the autostart support under Windows. Connections are tested
with the standard scope, a 'custom' scope, the 'install path' scope and
the 'user' scope.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-06-27 15:34:23 +02:00
Marc-André Lureau
e4d6b74b25 build-sys: drop DBUS_CMAKE
TEST_LISTEN is defined by the cmake/autotools (or meson) build systems.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-06-17 15:19:38 +04:00
Marc-André Lureau
708dd5a55e test: fix unused variable warnings
../../test/internals/assertions.c: In function ‘test_assert_error_is_set’:
../../test/internals/assertions.c:82:14: warning: unused variable ‘ep’ [-Wunused-variable]
   82 |   DBusError *ep = NULL;
      |              ^~
../../test/internals/assertions.c:81:13: warning: unused variable ‘e’ [-Wunused-variable]
   81 |   DBusError e = DBUS_ERROR_INIT;

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-19 17:57:31 +02:00
Ralf Habacker
5f1bc83d36 Add unit tests for platform-specific mutex implementation.
The tests are enabled with the embedded tests; the required
low-level functions from the dbus library are decorated with
DBUS_EMBEDDED_TESTS_EXPORT to indicate the appropriate usage.

On Windows, all tests are run; on unix-like operating systems,
individual tests are disabled:
- the tests on #NULL pointers of type DBus[C|R]Mutex, since they
  point to a data structure and would cause a segment violation
  when accessed.
- the multiple lock test for type DBusCMutex, since it would block
  the current thread.

Since the whole point of "rmutex" is to be able to lock multiple
times, the "rmutex double lock" test is enabled on unix-like
operating systems too.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-05-01 19:52:48 +02:00
Ralf Habacker
29946ad7c1 tests: Fix build warning "dereferencing type-punned pointer will break strict-aliasing rules"
To avoid that build break in test-marshall-recursive-util.c the newly
added function _dbus_string_append_buffer_as_hex() is used to print
the hex bytes.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-05-01 16:28:51 +00:00
Ralf Habacker
21a6441f33 _dbus_string_test(): Fix fatal build error caused by "-Wstrict-aliasing"
To fix this problem, the problematic code was replaced by a new function
_dbus_string_get_allocated_size(), which uses the existing macro
DBUS_CONST_STRING_PREAMBLE for these purposes.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
2022-04-21 13:55:38 +01:00
Ralf Habacker
3e8423d299 test-segfault: Fix build error caused by a null pointer dereference warning
Only do the deliberate crash via undefined behaviour (which the compiler
is quite right to warn us about!) if raise() isn't available.

The pointer needs to be volatile otherwise the compiler is free to remove
the store.

Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
2022-04-21 13:54:23 +01:00
Simon McVittie
63632eaf8d test: Add basic test coverage for _dbus_close_all and friends
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:44 +01:00
Simon McVittie
6a4a89ccea test-utils-glib: Add backports of some convenience macros
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:44 +01:00
Simon McVittie
b7c325e573 test-utils-glib: Ensure correct precedence in g_assert_nonnull()
It's best-practice to put macro arguments in parentheses so that they
are always treated as a unit.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:44 +01:00
Simon McVittie
6130ac4267 build: Define DBUS_INT64_MODIFIER, analogous to G_GINT64_MODIFIER
Using PRId64, etc. to print dbus_int64_t or dbus_uint64_t is not 100%
portable. On platforms where both long and long long are 64-bit (such as
Linux and macOS), we will prefer to define dbus_int64_t as long.
If the operating system has chosen to define int64_t as long long,
which is apparently the case on macOS, then the compiler can warn that
we are passing a long argument to PRId64, which is "lld" and therefore
expects a long long argument (even though that ends up with the same
bit-pattern being used).

We can't necessarily just use int64_t and uint64_t directly, even if all
our supported platforms have them available now, because swapping
dbus_int64_t between long and long long might change C++ name mangling,
causing ABI breaks in third-party libraries if they define C++ functions
that take a dbus_int64_t argument.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-19 18:27:47 +00:00
Simon McVittie
47a4bdfaf8 tests: Ensure session bus has started before integration test
The session dbus-daemon won't necessarily be run immediately on login
if we are using systemd socket activation for it, and the transient
services directory $XDG_RUNTIME_DIR/dbus-1/services isn't created until
it's actually run. Ping the dbus-daemon to make sure it's available.

Signed-off-by: Simon McVittie <smcv@debian.org>
Bug-Debian: https://bugs.debian.org/1005889
2022-02-21 18:09:22 +00:00
Simon McVittie
632831c959 test-utils: Don't assume all arrays of tests are zero-terminated
Fixes: dbus!233
Resolves: dbus#366
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-12-15 17:47:32 +00:00
Simon McVittie
9d60676ae0 Disable the Containers interface
We've had a request for a 1.14.x stable-branch, but the Containers
interface is only partially implemented, not yet described in the
D-Bus Specification, and not ready to be part of our API guarantees.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-12-10 16:48:51 +00:00
Ralf Habacker
77375263f5 cmake: add option ENABLE_VERBOSE_CONFIG
Checking the filenames of generated configuration files is now optionally
possible with this cmake option. They are no longer displayed by default
to avoid unnecessarily flooding the output.
2021-12-10 14:16:52 +00:00
Ralf Habacker
0d0649145f In _dbus_test_main() check if a specified test name is available
Fixes #362
2021-12-10 10:36:37 +01:00
Ralf Habacker
febafd863e test/test-utils.c: Add command line option --list-tests to test applications
With this command line option a list of available tests is printed to
stdout.
2021-12-10 10:36:28 +01:00
Ralf Habacker
3432cd938d test/test-utils.c: Add command line option --help to test applications 2021-12-10 10:21:35 +01:00
Simon McVittie
ac5e65ef43 test: Exercise successful and failed RemoveMatch calls
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/351
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-11-22 16:10:51 +00:00
David King
7dc6b64d98 test/thread-blocking.c: Fix a memory leak
Free name inside the for loop. Found by Coverity.

Bug-RedHat: https://bugzilla.redhat.com/show_bug.cgi?id=1938701
2021-10-29 18:03:13 +00:00
Ralf Habacker
ee24cadf2e Apply cmake formatting rules 2021-10-25 15:56:46 +02:00
Ralf Habacker
5b1870a5bd cmake: make support for traditional activation optional
Traditional activation is enabled/disabled with the cmake configure
parameter -DENABLE_TRADITIONAL_ACTIVATION, which is enabled by default.

This was added to the Autotools build system as part of dbus/dbus!107
but until now was not possible to disable when building with CMake.
2020-09-23 17:21:40 +02:00
Ralf Habacker
b698fb7639 cmake: move up checking DBUS_ENABLE_EMBEDDED_TESTS from subdir test/name-test to test
The whole file is only added with the mentioned variable
set, so it can also be skipped completly one level up.
2020-09-23 14:27:53 +00:00
Simon McVittie
f0e526bca8 tests: On Unix, include <netinet/in.h> for IPPROTO_TCP
Otherwise, dbus doesn't compile on FreeBSD if the GLib-based tests
are enabled (which suggests that no FreeBSD user has run those tests
successfully).

We already include <netinet/in.h> in other places with no conditions
or checks other than "is Unix", so apparently it's portable enough that
specifically testing for its presence is not necessary. POSIX requires it
to exist.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-08-14 17:02:46 +01:00
Simon McVittie
fc0f296583 fdpass test: Assert that we don't leak file descriptors
Reproduces: dbus#294
Reproduces: CVE-2020-12049
Reproduces: GHSL-2020-057
Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-06-02 10:42:54 +01:00
Félix Piédallu
362b22605c shell-test: Print diagnostics to stderr
Some of the command-lines that we print as diagnostics contain newlines,
which will cause warnings or errors under a strict TAP parser (and one of
them wasn't correctly prefixed with '#' anyway). TAP parsers only parse
stdout, not stderr, so we can use stderr for these diagnostic messages.

[smcv: Expand commit message]

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-04-28 11:50:23 +01:00
Ralf Habacker
44c8b03c34 desktop-file test: Free result on all code paths
Otherwise, Coverity will diagnose this as a resource leak,
because it doesn't understand that our assertions end up guaranteeing
that the result is freed if and only if it's non-`NULL`.

Coverity CID: 354884
2020-04-27 12:39:35 +00:00
Simon McVittie
9251d32206 test: Replace some _dbus_assert() with _dbus_test_check()
Assertions can be disabled, but in test code the assertions are the
whole point, so use checks that can't be disabled instead.

Because there's a lot of test code, I haven't done this globally, only
in the tests that I recently converted from "embedded" to "modular".

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-04-20 10:13:07 +01:00
Simon McVittie
e559663e03 test: Replace _dbus_assert_not_reached()
Assertions can be disabled; but in test code the assertions are the
entire point, so we don't want to disable them. Use _dbus_test_fatal()
instead.

test-service is actually a test helper rather than a test, so use its
pre-existing die() function instead.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-04-20 10:13:07 +01:00
Simon McVittie
c383f151be test: Enable more tests when embedded tests are disabled
These previously relied on embedding test-specific code in libdbus,
but they actually only need public APIs, private interfaces that get
exported anyway for the benefit of dbus-daemon, and the TAP helpers;
so we can run them even in production builds.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-04-20 10:13:07 +01:00
Simon McVittie
fcbb5e6586 test: Move TAP helpers into dbus-testutils if embedded tests are disabled
This lets us run a subset of the tests that previously relied on extra
test-only code being compiled into libdbus.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2020-04-20 10:13:04 +01:00
Ralf Habacker
e4feb9600e Add a trivial sanity-check for the atomic primitives
This doesn't verify that they're atomic, but does verify that they
return the right things.

This commit adds a new test function _dbus_test_check (a) to make
writing tests easier. It checks the given boolean expression and
generates a "not ok" test result if the expression is false.

Due to the current design of the test api, the test is only compiled
if embedded tests were enabled at the time of configuration.

It was also necessary to move the test_atomic target definitions in
test/Makefile.am to the --enable-embedded-tests section to avoid a
make distcheck build error.

The test case itself has been authored by smcv.

Co-authored-by: Simon McVittie <smcv@collabora.com>
2019-12-13 16:13:53 +01:00
Simon McVittie
ac5cdd281a Merge branch 'break-out-more-tests' into 'master'
Break out more tests from libdbus

See merge request dbus/dbus!121
2019-07-03 13:43:25 +00:00
Simon McVittie
f73b40b883 Merge branch 'pass-tests-if-root' into 'master'
Fix test failures when running as root

See merge request dbus/dbus!117
2019-07-03 13:42:07 +00:00
Simon McVittie
95db64700a tests: Move userdb test out of libdbus
All the functions under test turn out to be DBUS_PRIVATE_EXPORT already.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-03 11:19:50 +01:00
Simon McVittie
c1412056bb tests: Move mempool test out of libdbus
All the functions under test turn out to be DBUS_PRIVATE_EXPORT already.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-03 11:19:47 +01:00
Simon McVittie
7386456e4b tests: Move address test out of libdbus
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-03 11:19:19 +01:00
Simon McVittie
78d5af5ce9 tests: Move _dbus_sha_test outside libdbus
Instead of exposing _dbus_sha_test() as a private exported symbol,
we can expose _dbus_sha_compute(), which is the only thing called by
the test that isn't already exported.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-03 11:18:49 +01:00
Simon McVittie
8421d887aa bus tests: Shut down audit socket
Some CI environments run build-time tests as root with CAP_AUDIT_WRITE.
In this case we need to close the audit socket so that it will not be
reported as leaked.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-03 11:11:23 +01:00
Simon McVittie
e148aa47d3 tests: Skip if unable to launch uninstalled dbus-daemon as other uid
Some CI systems do the entire build as uid 0 in a throwaway container.
If this is done in a build directory for which the messagebus user
does not have search (+x) permission, then they will be unable to
execute the just-built dbus-daemon binary.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-03 11:11:23 +01:00
Simon McVittie
505bbfe4bd tests: Skip system bus test if we are root but messagebus does not exist
Some CI systems do the build as root in a disposable container, and
run tests without ever having installed dbus. This means we can't
expect to be able to drop privileges from root to the DBUS_USER (usually
named messagebus or dbus) unless we have checked that the
DBUS_USER exists.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-03 11:11:23 +01:00
Simon McVittie
e4e904a86b tests: Improve messages when fd leaks are diagnosed
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-02 20:44:33 +01:00
Simon McVittie
0ba41e071c Move _dbus_check_fdleaks_* from dbus-message-util to tests
This is only called from test code.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-07-02 20:44:33 +01:00
Simon McVittie
6231e7d75f test: Add basic test coverage for DBUS_COOKIE_SHA1
We don't actually complete successful authentication, because that
would require us to generate a cookie and compute the correct SHA1,
which is difficult to do in a deterministic authentication script.
However, we do assert that dbus#269 (CVE-2019-12749) has been fixed.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-06-09 13:08:53 +01:00
Simon McVittie
463ecfb4fd Merge branch 'send_destination_prefix' into 'master'
Send destination prefix

See merge request dbus/dbus!85
2019-05-30 14:49:09 +00:00
Adrian Szyndela
8fcc1f9a8a test: activation tests for send_destination_prefix
This adds a few tests for checking if activation is allowed
for names specified within send_destination_prefix namespaces.

Signed-off-by: Adrian Szyndela <adrian.s@samsung.com>
Change-Id: I7a5a66f82fc08ce6cb46e37de2c3dfae24d9ea67
2019-05-14 10:31:13 +02:00