Commit graph

1000 commits

Author SHA1 Message Date
Ralf Habacker
20febb522b Add multithreaded unit test for DBusCounter to available build systems
The mentioned test is build on unix like platforms when embedded tests
are enabled.
2023-01-05 16:43:55 +01:00
Daniel Wagner
afb5bbaba4 meson: Introduce message_bus and tools command line option
To make the consume libdbus via Meson's subproject use case more useful,
introduce message_bus and tools command line options which control if
the D-Bus daemon and/or the tools are build. The idea here is that
depending projects are interested only in the library.

The strong recommendation is only to build libdbus as static library:

  libdbus_dep = dependency(
    'dbus-1',
    required: get_option('libdbus'),
    fallback: ['dbus', 'libdbus_dep'],
    default_options: [
      'default_library=static',
      'embedded_tests=false',
      'message_bus=false',
      'modular_tests=disabled',
      'tools=false',
    ],
  )

This ensures that any installed D-Bus infrastructure on the target
system is not overwritten.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
2023-01-04 09:35:06 +01:00
Ralf Habacker
2dee523608 Add SPDX license marker for the AFL-2.1 OR GPL-2.0-or-later license
The full license texts are not added because they were already
added in a previous commit.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>

see #394
2023-01-04 07:53:44 +00:00
Dave Jones
9950464761 Permit access to /tmp dbus socket
After 6e48c317 the test-apparmor-activation test fails as it can no
longer access the dbus socket in /tmp. This commit updates the apparmor
profile used within the test
2023-01-03 18:42:51 +00:00
Simon McVittie
a7e4bac015 Fix some stray filename references for GPL-2.0-or-later
The SPDX name for this license includes the `.0`.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-29 20:43:01 +00:00
Simon McVittie
54b56ab875 Use 'continue' keyword in preference to 'goto' where possible
In some more complicated loops, we do need to use 'goto' to exit from
an inner loop, or to jump to cleanup or an increment of an iterator
immediately before the next loop iteration. However, in these simple
cases, jumping to a label immediately before the 'while' keyword is
unnecessary: we can use an equivalent 'continue' statement for flow
control.

This makes it easier for maintainers to notice the loops where we are
doing something more complicated, which still use 'goto', and know
that they need to pay more attention in those cases.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-29 18:50:06 +00:00
Simon McVittie
eae69d2c1a dbus-hash: Add (AFL-2.1 OR GPL-2.0-or-later) AND TCL SPDX license identifier
The TCL-derived code is under its own license, so the overall license
of the file is (AFL-2.1 OR GPL-2.0-or-later) AND TCL.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-11-29 13:33:53 +00:00
Simon McVittie
4aa7052c6f test-exit: Add a permissive license
Red Hat have previously given permission for relicensing, and all
subsequent contributions to this file were trivial.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
fb1460ee32 test-threads-init: Add a permissive license
With permission from Philip Withnall on behalf of Endless, me on behalf
of Collabora, and relying on previous permission from Red Hat
representatives.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
2e705c9b49 manual-tcp: Add a permissive license
With permission from Ralf Habacker via dbus!304 and the mailing list.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
31a2624796 manual-paths: Apply a permissive license
This was contributed by Ralf Habacker and later edited by me, with a
trivial change from Thomas Zimmermann which I don't think affects its
copyright.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
82b3c6b7dd manual-dir-iter: Apply a permissive license
This was contributed by Ralf Habacker, with a trivial change from
Philip Withnall which I don't think affects its copyright.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
ada440c5ba test-shutdown: Apply a permissive license
All significant contributions to this file were from companies or
individuals that gave permission for relicensing to MIT (I have assumed
that trivial changes from Marcus Brinkmann and Kjartan Maraas were too
small to affect copyright status).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
812a690d62 test-ids: Apply a permissive license
All significant contributions to this file were from companies that gave
permission for relicensing to MIT (I have assumed that trivial changes
from Marcus Brinkmann and Ralf Habacker were too small to affect
copyright status).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
21763bfd41 test-autolaunch: Add a permissive license
The license for this file was never stated, but all contributions to it
have been from Red Hat or Collabora, and representatives of both
companies gave permission for MIT relicensing in 2007.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Simon McVittie
fdd589c8d8 launch-helper-for-tests: Add a permissive license
I wrote this, and it hasn't changed since.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-12 12:08:38 +00:00
Ralf Habacker
7724bf574c test-autolaunch-win.c: Prevent assertion in dbus_message_unref()
dbus_message_unref() is in principle able to handle a NULL parameter, but
causes the program to abort when `fatal_warnings_on_check_failed` is set.

Therefore the call with a NULL parameter is avoided from now on.

Fixes #422
2022-10-12 09:38:46 +02:00
Simon McVittie
f325252e5e test-autolaunch-win: Remove redundant check for ERROR message
This seems to have been intended to give a more specific error message
if the method call failed, but it will not have been effective, because
dbus_connection_send_with_reply_and_block() ends with a check for ERROR
messages using dbus_set_error_from_message(). This means that if the
reply was an ERROR message, it will already have been converted into a
DBusError by the time call_method() regains control.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 18:20:53 +00:00
Simon McVittie
a7bbff5baf test-autolaunch-win: Don't overwrite an error with another error
An unrelated branch failed CI with this assertion failure:

    26: dbus[6768]: error: arguments to dbus_set_error() were incorrect,
    assertion "(error) == NULL || !dbus_error_is_set ((error))" failed in
    file ...\dbus-errors.c line 365.

Looking at the test, this seems to be the most likely candidate for
this bug in error handling, which is masking whatever the real cause
for the failure was (we can't tell from here). If
dbus_connection_send_with_reply_and_block() returns NULL, then it should
already have set the error.

Fixing this bug in the error handling will hopefully give us a better
error message for the actual failure if it happens again.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 18:20:53 +00:00
Ralf Habacker
4712a05874 dbus/dbus-macros-internal, test/test-platform-mutex.c: Use upper case for SPDX license operator
https://spdx.github.io/spdx-spec/SPDX-license-expressions/ says that
using upper-case operators is canonical.
2022-10-11 13:00:00 +00:00
Simon McVittie
3c0e63c10a dbus-message: Report OOM as OOM, not InvalidArgs
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/420
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-11 11:54:21 +00:00
Kai A. Hiller
bc23b03b5c dbus-connection: Test built-in filters 2022-10-11 10:50:08 +00:00
Kai A. Hiller
f1c17c74ac dbus-monitor: Disable automatic message filtering 2022-10-11 10:50:08 +00:00
Simon McVittie
bef693f442 test: Parse a message with a byteswapped Unix fd index
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/417
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:43 +01:00
Simon McVittie
7a2c13d21b test: Add infrastructure to parse valid raw message blobs
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:42 +01:00
Simon McVittie
3ef342410a test: Add targeted tests for dbus/dbus#413, dbus/dbus#418
Unlike the message-internals test, these do not rely on extra debug
instrumentation in libdbus, and so can be used for "as-installed"
testing. (However, they do require GLib.)

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:26 +01:00
Simon McVittie
37e0125943 test: Export G_TEST_BUILDDIR, G_TEST_SRCDIR
These environment variables are used by GLib's g_test_build_filename()
and related convenience functions, which make it easier for unit tests
to find data files in a way that works for both build-time tests and
"as-installed" tests. During "as-installed" testing, both variables
will normally be unset, and GLib uses the directory containing the
executable. In most cases that results in the right thing happening, and
this will also be true for dbus, since we install the test executables
in ${libexecdir}/installed-tests, helper executables in the same place,
and test data in ${libexecdir}/installed-tests/data.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:24 +01:00
Simon McVittie
d633016f73 test/data: Add messages that reproduce dbus/dbus#413, dbus/dbus#418
In debug builds with "embedded tests" enabled, these will automatically
be used as input for the message-internals test.

Some of the messages themselves are output from a fuzzer, others are
simplifications to include only one reason for lack of validity per
message.

I've included an annotated hex-dump for each message here, but the dbus
test suite doesn't currently know how to convert hex to binary, so I've
also committed the corresponding binary. See the comment at the top of
each hex-dump for how to create the binary version (which requires the
xxd tool shipped with vim).

It would be nice for the dbus test suite to be able to convert the
annotated hex-dump to binary, either at build-time with a Python script
or at runtime by loading the text file and decoding the hex, but I don't
want to block on that for dbus/dbus#413 and dbus/dbus#418.

Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/413
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:22 +01:00
Simon McVittie
67800ac5fe test-syntax: Exercise correctly- and incorrectly-nested structs, dicts
Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/418
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-10-05 10:24:04 +01:00
Alex Richardson
93203e9524 gitlab-ci: update FreeBSD CI image to 13.1
FreeBSD 13.0 has reached EOL and it appears packages
are built against a newer baseline now, so we end up
with missing symbol errors:
ld-elf.so.1: /lib/libc.so.7: version FBSD_1.7 required by /usr/local/lib/libpython3.9.so.1.0 not found

It also appears that the fdpass test still fails on 13.1, so update the
condition to less than 14.0
2022-09-21 09:01:56 +00:00
Alex Richardson
e1ff3c09d7 test: Use DBUS_TEST_SOCKET_DIR to create the test socket
I am trying to run cross-compiled tests in QEMU with the build directory
mounted via smbfs, and therefore creating the sockets in the CWD does not
work. Using DBUS_TEST_SOCKET_DIR (/tmp by default) allows me to run the
tests successfully.
2022-09-15 18:58:20 +00:00
Simon McVittie
52a8adf901 test: Don't use strict TAP parsing on Windows
Debug messages in a background thread can corrupt the machine-readable
TAP output, and in particular GWin32AppInfo emits debug messages from
a background thread when we link to libgio.

Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/414
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-12 19:36:16 +01:00
Simon McVittie
c9d0f7968f build: Only work around Meson 0.63.0 bugs for version 0.63.0
mesonbuild/meson#10577 was fixed in 0.63.1.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-09-12 19:23:54 +01:00
Alex Richardson
932b740826 test/fdpass.c: skip test that fails on FreeBSD 13.0
The /odd-limit/at test passes on 13.1 and 14.0 images, but fails on 13.1.
Debugging has not given me any useful hints why this may be the case, so
disable this test on 13.0 for now.

This allows us to drop the ci_test_fatal: "no" override which will ensure
that any FreeBSD regressions are caught.
2022-08-10 11:18:20 +00:00
Alex Richardson
aec2ad7efb test-utils-glibc.c: Fix -Werror,-Wmissing-noreturn on FreeBSD
Add a conditional _DBUS_GNUC_NORETURN to avoid
`error: function 'back_to_root' could be declared with attribute 'noreturn'`
2022-08-10 11:18:20 +00:00
Alex Richardson
cf51eeb555 test-utils-glib.c: Avoid using a non-portable errno value
ENODATA is not available on FreeBSD. Since the actual errno value here
does not matter, use EPERM instead.
This fixes the DBus build on FreeBSD.
2022-08-10 11:18:20 +00:00
Jordan Williams
fac146f44d
Use project relative paths in CMake files
This makes it possible for projects to incorporate D-Bus as a CMake sub-project in a larger CMake project.
Before this PR, doing so would result in many errors.
This is because CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR would point to directories above the D-Bus project.
Using paths relative to the project directory, PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR, corrects for this.
2022-07-25 14:14:57 -05:00
Simon McVittie
bef88fd562 test/bus: Break up dispatch test into three separate tests
This is really three separate test-cases: one for traditional
activation as a direct child process of the dbus-daemon, and two for
traditional activation (successful and failing) via the setuid
dbus-daemon-launch-helper on Unix.

The ones where activation succeeds extremely slow, as a result of the
instrumentation for simulating malloc() failures combined with a large
number of memory operations, particularly when using AddressSanitizer.

Splitting up "OOM" tests like these has a disproportionately good impact
on the time they take, because the simulated malloc() failure
instrumentation repeats the entire test making the first malloc() fail,
then making the second malloc() fail, and so on. For allocation failures
in the second half of the test, this means we repeat the first half of
the test with no malloc() failures a very large number of times, which
is not a good use of time, because we already tested it successfully.

Even when not using the "OOM" instrumentation, splitting up these tests
lets them run in parallel, which is also a major time saving.

Needless to say, this speeds up testing considerably. On my modern but
unexceptional x86 laptop, in a typical debug build with Meson, the old
dispatch test took just over 21 minutes, which drops to about 40 seconds
each for the new normal-activation and helper-activation tests (and for
most of that time, they're running in parallel, so the wall-clock time
taken for the whole test suite is somewhere around a minute).

In a debug build with Meson, gcc and AddressSanitizer, the old dispatch
test takes longer than my patience will allow, and the new separate
tests take about 5-6 minutes each. Reduce their timeout accordingly, but
not as far as the default for slow tests (5 minutes) to allow some
headroom for AddressSanitizer or slower systems.

The failed-helper-activation test is almost instantaneous, and no longer
needs to be marked as slow.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 11:15:54 +00:00
Simon McVittie
11e6c92e95 test/bus: Factor out common setup/teardown code
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 11:15:54 +00:00
Simon McVittie
8b08dd3264 test: Skip tests that involve switching uid if unable to do so
In a Linux user namespace, it is possible that we are uid 0 but are
unable to switch to some other uid like DBUS_USER or DBUS_TEST_USER,
because the other uid is not "mapped" in the user namespace, resulting
in setuid() or setresuid() failing with EINVAL "Invalid argument".
For example, it's easy for this to happen when running under the
bubblewrap tool.

Try to drop privileges in a child process, and skip the test if we
are unable to do so.

Resolves: dbus#407
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-07-18 10:31:40 +00:00
Marc-André Lureau
85694b5bb3 gitlab: skip failing runtime directory check, add FIXME
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
d08973f6d3 test: enable AF_UNIX server-oom test on !unix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
522cc62e02 test/server-oom: do not hardcode /tmp
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
01b293027e test: enable AF_UNIX relay tests on !unix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
03dac62937 test/relay: do not hardcode /tmp on !unix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
2be8c00a1d test: enable AF_UNIX loopback tests on !unix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
c6d6a2c9e6 tests/loopback: do not hardcode /tmp for !unix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
e05ff718a1 test: fix loopback AF_UNIX tests to work on Windows
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
b1213e3aee test: enable AF_UNIX corrupt test on !unix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00
Marc-André Lureau
a19d2e7f09 tests/corrupt: do not hardcode /tmp on !unix
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-07-15 16:26:54 +01:00