summaryrefslogtreecommitdiff
path: root/test/internals
Commit message (Collapse)AuthorAgeFilesLines
* Add test for _dbus_string_skip_blank()Ralf Habacker2023-02-081-0/+45
| | | | | | [smcv: Fix a memory leak] Reproduces: https://gitlab.freedesktop.org/dbus/dbus/-/issues/421
* Add multithreaded unit test for DBusCounter to available build systemsRalf Habacker2023-01-051-0/+120
| | | | | The mentioned test is build on unix like platforms when embedded tests are enabled.
* Add SPDX license marker for the AFL-2.1 OR GPL-2.0-or-later licenseRalf Habacker2023-01-0422-0/+44
| | | | | | | | | 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
* Use 'continue' keyword in preference to 'goto' where possibleSimon McVittie2022-11-294-18/+25
| | | | | | | | | | | | | | | 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>
* dbus-hash: Add (AFL-2.1 OR GPL-2.0-or-later) AND TCL SPDX license identifierSimon McVittie2022-11-291-0/+1
| | | | | | | 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>
* test: Add infrastructure to parse valid raw message blobsSimon McVittie2022-10-051-0/+4
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Use DBUS_TEST_SOCKET_DIR to create the test socketAlex Richardson2022-09-151-39/+81
| | | | | | | 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.
* test: enable AF_UNIX server-oom test on !unixMarc-André Lureau2022-07-151-2/+4
| | | | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* test/server-oom: do not hardcode /tmpMarc-André Lureau2022-07-151-1/+9
| | | | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* test: fix unused variable warningsMarc-André Lureau2022-05-191-1/+1
| | | | | | | | | | | ../../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>
* tests: Fix build warning "dereferencing type-punned pointer will break ↵Ralf Habacker2022-05-011-7/+22
| | | | | | | | | | 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>
* _dbus_string_test(): Fix fatal build error caused by "-Wstrict-aliasing"Ralf Habacker2022-04-211-1/+1
| | | | | | | | | | 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>
* test: Add basic test coverage for _dbus_close_all and friendsSimon McVittie2022-04-211-5/+137
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* build: Define DBUS_INT64_MODIFIER, analogous to G_GINT64_MODIFIERSimon McVittie2022-04-192-5/+34
| | | | | | | | | | | | | | | | | | | 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>
* desktop-file test: Free result on all code pathsRalf Habacker2020-04-271-1/+1
| | | | | | | | 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
* test: Replace some _dbus_assert() with _dbus_test_check()Simon McVittie2020-04-202-163/+163
| | | | | | | | | | 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>
* test: Replace _dbus_assert_not_reached()Simon McVittie2020-04-201-2/+2
| | | | | | | | | | | 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>
* test: Enable more tests when embedded tests are disabledSimon McVittie2020-04-202-9/+20
| | | | | | | | | 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>
* Add a trivial sanity-check for the atomic primitivesRalf Habacker2019-12-131-0/+91
| | | | | | | | | | | | | | | | | | | | 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>
* Merge branch 'break-out-more-tests' into 'master'Simon McVittie2019-07-035-1/+975
|\ | | | | | | | | Break out more tests from libdbus See merge request dbus/dbus!121
| * tests: Move userdb test out of libdbusSimon McVittie2019-07-031-1/+55
| | | | | | | | | | | | All the functions under test turn out to be DBUS_PRIVATE_EXPORT already. Signed-off-by: Simon McVittie <smcv@collabora.com>
| * tests: Move mempool test out of libdbusSimon McVittie2019-07-032-0/+224
| | | | | | | | | | | | All the functions under test turn out to be DBUS_PRIVATE_EXPORT already. Signed-off-by: Simon McVittie <smcv@collabora.com>
| * tests: Move address test out of libdbusSimon McVittie2019-07-032-0/+204
| | | | | | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
| * tests: Move _dbus_sha_test outside libdbusSimon McVittie2019-07-032-0/+492
| | | | | | | | | | | | | | | | 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>
* | tests: Improve messages when fd leaks are diagnosedSimon McVittie2019-07-021-9/+11
| | | | | | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* | Move _dbus_check_fdleaks_* from dbus-message-util to testsSimon McVittie2019-07-021-0/+2
|/ | | | | | This is only called from test code. Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Add basic test coverage for DBUS_COOKIE_SHA1Simon McVittie2019-06-091-2/+71
| | | | | | | | | 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>
* test-spawn-oom: Separate single spawn tests from oom relatedRalf Habacker2019-03-151-23/+63
| | | | This makes it possible to run each test independent from oom condition.
* test: Move _dbus_list_test() hereSimon McVittie2019-01-211-0/+570
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Move _dbus_transport_unix_test() hereSimon McVittie2019-01-211-0/+28
| | | | | | | This requires exposing _dbus_connection_get_address() as an internal symbol, but that seems worth it. Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Move _dbus_server_test() hereSimon McVittie2019-01-211-0/+52
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Move _dbus_misc_test() hereSimon McVittie2019-01-211-0/+62
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Move _dbus_signature_test() hereSimon McVittie2019-01-211-1/+176
| | | | | | This is all public API, so there's no need to embed it in the library. Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Move sysdeps tests hereSimon McVittie2019-01-212-0/+157
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Move string tests (most of dbus-string-util.c) hereSimon McVittie2019-01-212-0/+882
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Move marshalling tests into test/Simon McVittie2019-01-217-0/+4182
| | | | | | | 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>
* test: Move dbus-message-factory and most of dbus-message-util into test/Simon McVittie2019-01-215-0/+3090
| | | | | | | 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>
* test: Move auth, credentials tests from libdbus-internal into test/Simon McVittie2019-01-216-0/+1416
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>
* test: Unembed hash test from libdbus and move it into test/Simon McVittie2019-01-211-0/+486
| | | | | | | | 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>
* test: Split slow parts of the former test-dbus into their own executablesSimon McVittie2019-01-214-3/+117
| | | | | | | 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>
* _dbus_test_main: Move to test-utilsSimon McVittie2019-01-212-2/+2
| | | | | | | | | | | | | | | | | 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>
* test: Move libdbus embedded tests from dbus/ to test/Simon McVittie2019-01-211-0/+69
| | | | | | | | | | | | | | 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>
* Convert spawn test into a standalone test executableSimon McVittie2019-01-211-0/+304
| | | | | | | 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>
* Increase the number of references/threads to be tested under Windows by ↵Ralf Habacker2018-12-141-2/+3
| | | | default to detect errors
* Decrease the runtime of test refs under Windows by defaultRalf Habacker2018-12-141-5/+11
| | | | | | | | | | | | | 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
* Move _dbus_disable_crash_handling() back into test/ directorySimon McVittie2018-12-111-0/+1
| | | | | | | | | | 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>
* Skip server oom wildcard test on Windows to avoid firewall exception requestRalf Habacker2018-12-061-0/+9
| | | | | | | | | | | | | | | | 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.
* sysdeps test: Wait for spawned process to exitSimon McVittie2018-12-051-9/+54
| | | | | | | | | | | | | | | | 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
* syslog test: Don't assert that we see plain LF newlinesSimon McVittie2018-12-051-6/+10
| | | | | | | | | 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
* Add a test for assertionsSimon McVittie2018-11-201-0/+235
| | | | Signed-off-by: Simon McVittie <smcv@collabora.com>