Commit graph

84 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
Ralf Habacker
433d5c2471 test-spawn-oom: Separate single spawn tests from oom related
This makes it possible to run each test independent from oom condition.
2019-03-15 17:06:01 +00:00
Simon McVittie
1972390d42 test: Move _dbus_list_test() here
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:22:07 +00:00
Simon McVittie
0296c1fcbf test: Move _dbus_transport_unix_test() here
This requires exposing _dbus_connection_get_address() as an internal
symbol, but that seems worth it.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:22:07 +00:00
Simon McVittie
d9dfe4ee3e test: Move _dbus_server_test() here
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:22:07 +00:00
Simon McVittie
58fc8a0360 test: Move _dbus_misc_test() here
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:22:06 +00:00
Simon McVittie
0dd9853a37 test: Move _dbus_signature_test() here
This is all public API, so there's no need to embed it in the library.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:22:06 +00:00
Simon McVittie
cccb35dfef test: Move sysdeps tests here
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:22:05 +00:00
Simon McVittie
b1cfd892fc test: Move string tests (most of dbus-string-util.c) here
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:21:43 +00:00
Simon McVittie
8ead2011ac test: Move marshalling tests into test/
dbus-marshal-recursive-util.c contains utility functions used by the
other two, as well as tests. The others are purely test code.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:21:16 +00:00
Simon McVittie
f1f5294276 test: Move dbus-message-factory and most of dbus-message-util into test/
As with previous moves, I've tried to extract the possible copyright
holders from the git history.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:20:39 +00:00
Simon McVittie
9feeeaea9a test: Move auth, credentials tests from libdbus-internal into test/
Signed-off-by: Simon McVittie <smcv@collabora.com>
2019-01-21 15:20:22 +00:00
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
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
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
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
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
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
a889e5aa8c Add a test for assertions
Signed-off-by: Simon McVittie <smcv@collabora.com>
2018-11-20 12:58:17 +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
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
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
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