Commit Graph

119 Commits

Author SHA1 Message Date
Chrissie Caulfield
a3aedbc419
tests: allow -j to work (#485)
build: fix several issues with building tests

- MAINTAINERCLEANFILES should not rely on conditionals
  that could or could not clean files.

- EXTRA_DIST should not rely on conditonals that could
  or could not add files to the final tarball.
  sources should always ship.

- CLEANFILES should not rely on conditionals as
  ./configure can be done in between builds leaving
  stray files around.

- (cosmetic) move distclean-local: target with clean-local.

- drop old ipc_sock.test, start.test and resources.test
  shell files.

- fix make distcheck -j:
  - stop shipping or not shipping libstat_wrapper.so.
    libtool will only generate the .so when installing
    a shared library (--enable-install-tests).
  - make libstat_wrapper a module in a similar fashion
    of _failure_injection.
  - build ipc_sock.test in a similar fashion as ipc.test
    and link as module _libstat_wrapper.la.
    this solves multiple issues of having the binary
    in the final test builddir, no need to detect if
    libstat_wrapper.so is installed or not and workaround
    libtool different linking methods for inst vs noinst
    libraries.

- fix ipc.test linking with GLIB that should not be
  dependent on HAVE_FAILURE_INJECTION.

Run tests in parallel with dependancies
Make sure the two IPC tests use different socket names
Shortedn some names so they fit with the new ipc-names
remove ipc-test-name-sock
Fix resources.test now that ipc_sock is being run properly

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2023-05-26 20:21:43 +02:00
Chrissie Caulfield
8325d84047
tests: Fix tests on FreeBSD-devel (#469)
FreeBSD-devel can allocate more space than requested which causes
the check to fail. So check for >= allocated rather than ==
2022-07-07 08:30:38 +01:00
Chrissie Caulfield
0eb0991ad6
tests: cleanup the last of the empty directories (#467)
This should, FINALLY, allow the libqb tests to run
and properly cleanup up after themselves.
2022-06-16 07:17:59 +01:00
Chrissie Caulfield
2d3cd761cf
test: Clean /dev/shm a bit better (#459)
* test: Clean /dev/shm a bit better

This isn't perfect, but it does tidy more of /dev/shm than
previously. Because some of the tests leave empty directories
we have no way of telling (in resources.test) whether they
belong to this test run, another test run, or a running
application.
2022-03-18 10:04:23 +00:00
Chrissie Caulfield
2d03793eb0
unix: Don't fail on FreeBSD running ZFS (#461)
* unix: Don't fail on FreeBSD running ZFS

ZFS doesn't support posix_fallocate() so libqb IPC or RB would
always fail with EINVAL.

As there seems to be no prospect of a more useful return code,
trap it in a QB_BSD #ifdef. That way if we do have actual errors
in the posix_fallocate() call the Linux tests should still find them.

Also, stick a small sleep in the test_ipc_disconnect_after_created
test to allow the server to shutdown before killing it with SIGTERM
and causing a test failure. all the other uses of it seem to have this
sleep!
2022-03-17 07:47:39 +00:00
Chrissie Caulfield
73472e0b13
Tidy some scripts (#454)
* Tidy some scripts

Errors reported by Centos covscan

I changed %N to %s as BSD's date command doesn't support %N.
Seconds + PID should be enough ....

* Shrink the name of the dlock tests as they cause random failures

When the PID numbers get big, the socket name overflows the allowed
limit

* Increase timeout of thread check.

It's been seen to time out too early and fail the tests
2022-01-19 12:50:45 +00:00
Chrissie Caulfield
de5ab3029c
ipcc: Add an async connect API (#450) 2022-01-05 10:53:09 +00:00
Chrissie Caulfield
680db526f6
ipc: add qb_ipcc_auth_get() API call (#418)
* ipc: addd qb_ipcc_auth_get() API call

We can't use SO_PEERCRED on the client fd when using socket IPC
becayse it's a DGRAM socket (pacemaker tries this). So provide
an API to get the server credentials that libqb has already
squirreled away for its own purposes.

Also, fix some unused-variable compiler warnings in unix.c
when building on systems without posix_fallocate().
2020-09-28 09:53:21 +01:00
Chrissie Caulfield
d01a9e0adf
tests: Remove deprecated check macros (#412)
fail_if() and fail_unless() macros are deprecated in more
recent versions of check and are buggy in 0.15, so replace
them with ck_assert() instead.
2020-07-29 14:06:22 +01:00
Chrissie Caulfield
08a165dc2c
test: Add unit test for ipcs_connection_auth_set() (#397)
Only if we are root
2020-06-03 08:26:51 +01:00
Chrissie Caulfield
33b79ebc47 tests: Shorted deadlock test names (#372)
On newer Fedora systems that can have 32 bit PIDs, these long test
names can get truncated in the libqb internal buffers and thus break the
tests, so I've shortened the names.
2019-12-06 14:38:02 +01:00
Christine Caulfield
8e50d0a4f1 tests: Speed up IPC tests, especially on FreeBSD
After much discussion on IRC it was decided that 70000 iterations
of the stress patch didn't achieve anything significant over a
reasonable but smaller number. So it has been reduced to 5000 on
all platforms.

This patch also fixes a bug where test_ipc_disconnect_after_created
committed a use-after-free which could cause a crash on FreeBSD-devel.
2019-06-27 13:19:08 +01:00
Jan Pokorný
d5adc0cbc8
tests: ipc: fix the no-GLib conditionalizing
In particular, qb_ipcs_rate_limit() needs to be outside the
"#ifdef HAVE_GLIB" conditional, since it gets used regardless.
This should have been like this as of 28e7259.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-12 16:54:22 +02:00
Jan Pokorný
28e725938a
tests: ipc: check deadlock-like situation due to mixing priorities
Compared to the outer world, libqb brings rather unintuitive approach
to priorities within a native event loop (qbloop.h) -- it doesn't do
an exhaustive high-to-low priorities in a batched (clean-the-level)
manner, but rather linearly adds a possibility to pick the handling
task from the higher priority level as opposed to lower priority ones.

This has the advantage of limiting the chances of starvation and
deadlock opportunities in the incorrectly constructed SW, on the other
hand, it means that libqb is not fulfilling the architected intentions
regarding what deserves a priority truthfully, so these priorities are
worth just a hint rather than urgency-based separation.

And consequently, a discovery of these deadlocks etc. is deferred to
the (as Murphy's laws have it) least convenient moment, e.g., when
said native event loop is exchanged for other (this time priority
trully abiding, like GLib) implementation, while retaining the same
basic notion and high-level handling of priorities on libqb
side, in IPC server (service handling) context.

Hence, demonstration of such a degenerate blocking is not trivial,
and we must defer such other event loop implementation.  After this
hassle, we are rewarded with a practical proof said "high-level
handling [...] in IPC server (service handling) context" contains
a bug (which we are going to subsequently fix) -- this is contrasted
with libqb's native loop implementation that works just fine even
prior that fix.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:07:27 +02:00
Jan Pokorný
2ced1b4341
tests: ipc: refactor/split test_ipc_dispatch part into client_dispatch
This way, this core part can be easily reused where needed.
Note that "ready_signaller" similarity with run_ipc_server is not
accidental, following commit will justify it.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:54 +02:00
Jan Pokorný
c54e2712a6
tests: ipc: allow for easier tests debugging by discerning PIDs/roles
Roles specifications are currently not applied and are rather
a preparation for the actual meaningful use to come.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:52 +02:00
Jan Pokorný
c3175eabd3
tests: ipc: speed the suite up with avoiding expendable sleep(3)s
Using i7-6820HQ CPU yields these results:

Before: ~2:54
After: ~2:26
Speedup: ~16%

The main optimization lies in how run_function_in_new_process helper is
constructed, since now, there's an actual synchronization between the
parent and its child (that needs to be prioritized here, which is
furthermore help with making the parent immediately give up it's
processor possession) after the fork, so that a subsequent sleep is
completely omitted -- at worst (unlikely), additional sleep round(s)
will need to be undertaken as already arranged for (and now, just
400 ms is waited rather than excessive 1 second).

Another slight optimization is likewise in omission of sleep where
the control gets returned to once the waited for process has been
suceesfully examined post-mortem, without worries it's previous
life is still resounding.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:48 +02:00
Jan Pokorný
571e162990
tests: ipc: avoid problems when UNIX_PATH_MAX (108) limits is hit
There's some slight reserve for when bigger PID ranges are in use.
The method to yield the limit on prefix string was derived from
practical experience (rather than based on exact calculations).

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:44 +02:00
Chrissie Caulfield
75ab31bdd0
ipc_shm: Don't truncate SHM files of an active server (#307)
* ipc_shm: Don't truncate SHM files of an active server

I've put in an extra check so that clients don't truncate the
SHM file if the server still exists. Sadly on FreeBSD we can't
get the server PID for the client (unless someone has a patch handy!)
so we still do the truncate when disconnected. As a backstop (and also
to cover the BSD issue) I've added a SIGBUS trap to the server shutdown
so that it doesn't cause a server crash.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed by: Jan Friesse <jfriesse@redhat.com>
2018-04-20 09:48:04 +01:00
Chrissie Caulfield
3730644c35
test: Fix 'make distcheck' (#303)
Miscellaneous fixes and cleanups to get 'make distcheck' to work on most
platforms.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2018-03-27 13:11:20 +01:00
Chrissie Caulfield
67e739e83f
tests: Improve test isolation (#298)
* tests: Improve test isolation

Make all the IPC tests run with a common date/pid stamp name, so that
the final resource.test only fails if it finds one of OUR files left
lying around and not those from another test.

Falls back to old IPC naming style if we can't create the file.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed-by:  Jan Friesse <jfriesse@redhat.com>
2018-03-08 15:30:02 +00:00
Jan Pokorný
499a7f7ea6
warnings cleanup: Wunused-function: leave the test commented out
... as well as the test inclusion itself in make_soc_suite.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2017-12-21 01:53:26 +01:00
Jan Pokorný
ef5b1cf4cb
warnings cleanup: Wformat: sign-correct PRIu32 specifiers as appropriate
Looks like these are not accepted with splint checker.  Also fix some
other minor type -- print format specifier discrepancies.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2017-12-21 01:50:15 +01:00
Christine Caulfield
5889f1ea46 tests: make qb logging under check always dispose the memory
examples/tests: make qb logging dispose the memory

A.k.a. "be a good example of using this very library".

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
2017-09-18 10:30:40 +01:00
Jan Pokorný
1fa701489a Low hanging bits (#264)
* Low: log: prevent static vs. implicit non-static declaration clash
...of qb_log_callsites_dump_sect, that could happen when its usage
in qb_log_callsites_register was uncommented.

* Low: tests: fix duplicate "const" declaration specifier
This is a follow-up for d69cc7b (making the pointer itself constant was
meant as a self-defense, no-overwrite measure).

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2017-08-07 10:18:30 +01:00
Christine Caulfield
8cbfeec9f4 test: Disable test_max_dgram_size() test as it often breaks on CI
Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2017-05-23 14:38:34 +01:00
Christine Caulfield
9123d9a242 tests: Fix signal handling in check_ipc.c
Also return pid_t from run_ipc_server()

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2017-05-23 14:11:01 +01:00
Chrissie Caulfield
41a24a3df7 Allow Linux to use filesystem sockets (#248)
* IPC: Allow filesystem sockets to be chosen at run-time on Linux

Most of this patch came from Andrew Beekhof.
Keep a global variable that decides whether or not to use filesystem sockets
or abstract sockets for IPC connections. This variable is set by the presence of a file (default /etc/libqb/force-filesystem-sockets).

* tests: Fix test_ipcc_truncate_when_unlink_fails_shm test using FS sockets

When using filesystem sockets, the
test_ipcc_truncate_when_unlink_fails_shm test always fails, this was
because the unlink() call is wrapped to fail and so it never cleans up
the old version of the socket.
The fix is to preemptively remove the file before unlink gets wrapped.

* doc: Explain the force-filesystem-sockets option

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2017-04-28 16:13:02 +01:00
Jan Pokorný
d69cc7b3f6
test: Fix random number generation in IPC tests
The sockets are named using a random() suffix in at attempt to isolate
concurrent test.  However random() always returns the same random number
by design ... unless pre-seeded with some value being unique enough for
the particular execution.

Borrowing the most of the above message from original "srandom" fix by
Chrissie who also discovered this issue (nice!), I thought it would be
more viable if we encoded such "unique enough" variables directly to
IPC name being generated, not relying on pseudorandom generators in any
way.  Hence this other fix.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2017-04-28 14:55:06 +02:00
Jan Pokorný
524042d797
CI: travis: fix du -> df and capture it also directly from test 2016-12-16 15:48:10 +01:00
Jan Pokorný
6fad6b7b2d
tests: better diagnose test_max_dgram_size test failures 2016-11-28 15:16:04 +01:00
Jan Pokorný
f610b1b161
tests: start stdlib failures injection effort with unlink{,at} + test
There are not many ways to test alternate code paths having failure of
some function from standard library as a precondition.

For a starter, we need to test failing unlink{,at} functions in a
controlled manner to mimic client and server path of the IPC connection
having different privileges to validate the previous commit.  But the
test suite cannot assume it has root privileges (so as to add artificial
user system-wide, which is a pretty stupid idea on its own), cannot
generally use stuff like chroot/namespacing (not to speak about
synergies of the former like docker).  So what's left is to make our
own playground, or better yet, use existing playground but just to
modify the rules of the game a bit when it's desired -- a variation
of old good LD_PRELOAD trick.

Note that this concept was already used in syslog tests (see commit
642f74d) and is now further extended using dlsym(RTLD_NEXT, "symbol")
to resolve the standard library symbol being shadowed by our little
"module".  This hence yields a customized wrapping we use to either
inject a call failure or to increase an invocation counter so as to
assure something has indeed been called.  As the mechanisms used are
not supposed to be available everywhere, the build system is
conditionalized respectively.

Back to our test when unlink{,at} fails, with the help of the described
mechanism, it was actually easy to massage test_ipc_server_fail_shm
into test_ipcc_truncate_when_unlink_fails_shm desired addition, which
is also featured in this commit, together with a modification to
resources.test script so that it expects particular number of empty
file leftovers (see previous commit).

It's expected that the module for failure injections will keep growing
so as to enable better overall coverage of the code (on the platforms
where this provision is available).
2016-11-04 19:06:08 +01:00
Jan Pokorný
0d90bcb0ad
tests: SIGSTOP cannot be caught, blocked, or ignored
...per signal(7), so it is foolish trying to do so.
2016-10-19 00:40:56 +02:00
Jan Pokorný
b7f6dae97a
Fix typos: availabi{l -> li}ty, explici{lt -> tl}y 2016-10-12 20:10:22 +02:00
Jan Pokorný
485885597c
Fix typos: differ{ne -> en}t, is -> if 2016-10-07 21:13:17 +02:00
Jan Pokorný
c61ee802d9
tests: make clang-friendly (avoid using run-time VLAs)
This is to also get libqb from the Debian's shame list:
http://clang.debian.net/status.php?version=3.4.2&key=VARIABLE_LENGTH_ARRAY
2016-05-05 16:19:28 +02:00
Jan Pokorný
3d6135967a
tests: refactor test case defs using versatile add_tcase macro
This reduces repeated code significantly, and allows for easier
supervision of what's being grouped to the suites + possibly what
timeouts apply.

Note that some artificial test case identifiers (in check_array.c,
check_log.c, check_loop.c, check_rb.c, check_utils.c) got changed
so they now follow 1:1 the test (function) name that is being run
for the case at hand without the "test_" prefix (strict convention).
Exception to this are test_ipc_disp_* tests in check_ipc.c that got,
conversely, changed to test_ipc_dispatch_* to follow the test case
identifiers.
2016-03-01 15:11:38 +01:00
Christine Caulfield
b635cc9703 tests: Allow more time for stress_connections tests
On *BSD and other platforms the stress_connections can timeout and
fail the tests. I've increased the timeout here to an hour as it
takes nearly that long on my VM environment but it seems that's not
common, luckily.

This was also seen on mips/mipsel.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2015-09-25 15:12:36 +01:00
Christine Caulfield
aec4cde431 Fix check_ipc tests so they exit correctly
On some platforms the check_ipc test can fail due to SIGTERM
being delivered to to exiting server process. There is a race
condition between the server main loop quitting and the
signal being delivered.

This patch closes that race loophole in two places, firstly
it makes SIGTERM/SIGSTOP exit immediately rather than just signalling
the mainloop, secondly it calls exit() rather than return when the server
mainloop completes to that the client code does not start executing!

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2015-09-11 09:16:52 +01:00
David Vossel
378be495e8 Low: check_ipc: generate unique server names for tests
Package builders that run multiple builds of libqb in parallel
will fail because the IPC unit tests stomp on each other's namespace.
We have to give each IPC server a randomized unique name during
'make check' to avoid this.
2015-04-16 09:53:15 -05:00
David Vossel
340ed23772 Low: check_ipc: give connection stress tests for shm and socket unique names 2015-04-16 09:40:08 -05:00
David Vossel
c6c9a9ed6f Low: tests: regression tests for stress testing loop_poll ipc create/destroy 2015-04-14 15:10:28 -04:00
David Vossel
614c0de1f1 Low: check_ipc.c: improve error checking during ipc stress tests 2014-08-21 12:08:16 -05:00
David Vossel
9d198a9b64 Low: check_ipc: Verify ipc recv times out correctly 2014-03-12 14:07:19 -04:00
David Vossel
d8e2505016 Low: check_ipc.c: Correctly check the event queue length for bulk events 2014-02-25 23:31:07 -06:00
David Vossel
331cd031c6 Low: check_ipc.c: Correctly wait for server process to exit 2014-02-25 22:51:58 -06:00
David Vossel
e4cac9eb95 Low: check_ipc.c: Avoid using MAX_MSG_SIZE macro directly in calculations 2014-02-25 16:43:41 -06:00
David Vossel
d17d6b3a06 Low: Client side buffer retrieval regression test 2013-11-18 16:53:39 -06:00
David Vossel
ab2cd60c01 Low: check_ipc.c: Verify server enforced buffer sizes work 2013-11-18 16:53:35 -06:00
David Vossel
2b11b783c7 High: ipcs: Api function allowing server to retrieve client connection's ipc buffer size 2013-10-08 17:11:53 -05:00