Commit graph

26 commits

Author SHA1 Message Date
Barnabás Pőcze 3d152db758 test: null terminate output buffers
Previously, the standard i/o stream and daemon logs
were not properly null terminated, which could cause
issues in `print_lines()` inside `log_test_result()`.

See #1710
2021-12-01 11:12:58 +01:00
Peter Hutterer 07c5511aed test: handle chdir errors correctly
When we get to this code, we already updated the environment variables
so we need to use the usual error path to restore them.

And where chdir does fail, print an error to the log. 256 chars should
be enough here, if your tmpdir exceeds that you just have the error
message cut off.
2021-10-26 11:15:35 +10:00
Peter Hutterer cf3c0431c3 test: fix tmpdir value after setenv
Introduced in a2856c6e0f

set_test_env() modifies TMPDIR so we must not use getenv until after
that call.

Fixes #1736
2021-10-26 11:15:34 +10:00
Peter Hutterer a2856c6e0f test: silence coverity warnings about potential tmpdir being NULL 2021-10-15 14:42:26 +10:00
Peter Hutterer 3f6521819f test: add a filter for iteration
Debugging is easier if we can explicitly run a single iteration only.
This filter could be a range but for now it's sufficient to be able to
run a single test only.
2021-10-08 07:06:42 +00:00
Peter Hutterer 6668d5bbc4 test: fix the environment variable name to disable systemd logging
Fixes 165bc7e289
2021-09-24 12:33:15 +10:00
Peter Hutterer 165bc7e289 test: disable the journal logger for tests
No point spamming the journal here.
2021-09-23 15:40:47 +10:00
Peter Hutterer 49f3d5842e test: replace all spa_assert() macros with spa_assert_se()
These are tests, we never want those to be optimized away.
2021-07-27 10:24:44 +10:00
Peter Hutterer 5ebfbccd16 pwtest: if a test expects a signal, skip it under valgrind
Running under valgrind enforces --no-fork so any signal will cause valgrind
to error out, failing the test abnormally. This prevents us from running
our test suite through valgrind, we'd have to mark every test specifically
whether it should run under valgrind or not.

Easier is just to automatically skip tests expecting signals.
2021-07-07 11:03:23 +00:00
Evgeniy Khramtsov c3d7561d17 test: unbreak FreeBSD 2021-06-21 09:28:02 +00:00
Peter Hutterer a4bdf83e39 test: explicitly ignore the read() result from the timerfd/pidfd
We don't care about the actual read() being successful - it won't be on pidfd
and on timerfd it's just a timestamp we don't need.
2021-06-21 07:17:10 +00:00
Peter Hutterer f9985636de test: fail if we can't chdir to $TMPDIR
Otherwise our tests may have unpredictable behavior depending on leftover
files in $PWD.
2021-06-21 07:17:10 +00:00
Peter Hutterer 3c798ea413 test: force TMPDIR to /tmp if it is unset
This way we can rely on it everywhere without having multiple checks for it.
2021-06-21 07:17:10 +00:00
Peter Hutterer 00bc5f0e3b test: drop duplicate init of test->result
Set to the same value 5 lines above
2021-06-21 07:17:10 +00:00
Peter Hutterer 7177d82c34 test: check for CAP_SYS_PTRACE before testing for an attached debugger
If we don't have the capability to ptrace, we are probably running inside a
container, not the debugger. Check this first so we don't disable forking
mode.

Make this conditional on libcap - where libcap is not available always assume
we *do not* have a debugger attached. This is easier than telling everyone who
runs the tests in a confined system to install libcap.

Fixes #1285
2021-06-10 09:36:12 +02:00
Peter Hutterer 14eb43ea86 meson.build: check for SYS_pidfd_open 2021-06-10 15:19:20 +10:00
Peter Hutterer 731f45ed50 test: add sigabbrev_np() for systems where it's not available
sigabbrev_np() was first added to glibc 2.32 (Aug 2020) which is too recent
for some of the distributions we support.
2021-06-10 15:13:57 +10:00
Peter Hutterer da339c286f meson.build: drop HAVE_CONFIG_H
This is an autotools leftover, with meson we're always guaranteed to have
the config.h file.
2021-06-10 09:04:16 +10:00
Peter Hutterer 28f74dc6b2 test: fall back to a timerfd if pidfd fails
Looks like we don't have pidfd in the CI runners, so let's fall back to a
timerfd that pings us every 20ms in case the test finished.
2021-06-09 18:00:06 +10:00
Peter Hutterer 9bc840efe2 test: detect if we're running through gdb and disable forking mode 2021-06-09 18:00:06 +10:00
Peter Hutterer dc5751b569 test: add a helper function for making tempfiles
Having a helper aids with the file being in the right directory and cleaned up
automatically on exit. Plus, failing the test with the sytem error status code
signals that it's not the actual test failing here.
2021-06-09 18:00:06 +10:00
Peter Hutterer dd3f14d9d6 test: add a function to load a SPA interface
Helper function to load a SPA interface. This enables a test to easily load a
specific interface and run tests against that interface without having to
instantiate a whole pipewire daemon.
2021-06-09 18:00:06 +10:00
Peter Hutterer 50180532a4 test: add errno check macros 2021-06-09 18:00:06 +10:00
Peter Hutterer 2073269f47 test: set PIPEWIRE_REMOTE to a garbage value if we didn't start a test daemon
Don't let tests connect to the system daemon which would happen if we don't
have PIPEWIRE_REMOTE set at all.
2021-06-09 18:00:06 +10:00
Peter Hutterer e01faf42a1 test: give each test its own XDG_RUNTIME_DIR and TMPDIR
On startup, create /tmp/pwtest-$TIME-$RANDOM/ and give each test an
XDG_RUNTIME_DIR and TMPDIR inside that (simply numerically numbered). This
avoids the tests interfering with the system like accidentally connecting to
the real pipewire instance or trying to create files where they shouldn't.
2021-06-09 18:00:06 +10:00
Peter Hutterer ed3f882fa9 test: add the pwtest test framework
Heavily inspired by libinput's litest framework (built around check), this is
a from-scratch framework that simplifies adding tests for various parts of
pipewire. See the pwtest.h documentation for details but the basics are:

- PW_TEST() and PWTEST_SUITE() specify the tests to be run
- Test are run in forked processes, any errors/signals are caught and printed
  to the log
- Tests have a custom pipewire daemon started on demand to talk to [1]. The
  daemon's log is available in the test output.
- Output is YAML to be processed into whatever format needed

[1] There are limits here, since we can't emulate devices yet there is only
so much we can rely on with the daemon.
2021-06-09 18:00:06 +10:00