Commit graph

119 commits

Author SHA1 Message Date
Wim Taymans 2f5bba112f spa: Improve PropInfo fields
The PropInfo either has a registered id (and then also a name from the
type-info) or a custom name as a string.
In all cases, the description contains a free form text that clarifies
the property.

Use the description in the stream controls name.
2022-03-30 17:09:08 +02:00
Wim Taymans b225fe1d54 pipewire: improve pw_init/pw_deinit
Keep a counter for the amount of times pw_init() was called and
only clear everything when pw_deinit() was called an equal amount of
times.
Also ensure that pw_init() can be called again after pw_deinit().

Fixes #2238
2022-03-26 21:20:07 +01:00
Wim Taymans 2b16df4e89 spa: add locale independent spa_dtoa
And use this in spa_json_format_float() where we also avoid invalid
json floats.
Use json float format in some places where we serialize json floats.
Add a unit test.

See #2223
2022-03-21 10:41:44 +01:00
Wim Taymans 93b5d440bc json: add locale independent parse and format functions
Use them in pw-dump.
Add some unit tests.

See #2223
2022-03-20 21:04:33 +01:00
Wim Taymans 947d15a60a json: empty string should not give a valid number 2022-03-20 20:37:26 +01:00
Wim Taymans b868ec36c5 SPA_DATA_DIR is the source root when uninstalled
Add some more error logging to bluez5 quirk loading.
2022-03-18 21:33:02 +01:00
Barnabás Pőcze 6e705da101 test: loop: add helper functions to simplify eventfd use
Add the `read_eventfd()` and `write_eventfd()` functions.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze 529b6fd1b8 test: loop: add test which destroys managed source before reentering
Add a test which triggers two event sources in the loop's "before"
control hook, and destroys the second source in the loop's "after"
control hook, and then reenters the loop in the event handler of
the first source. At the moment, this test triggers a use-after-free.

==2973914==ERROR: AddressSanitizer: heap-use-after-free on address 0x608000000440 [...]
READ of size 4 at 0x608000000440 thread T0
    #0 0x7fa97f60c6b7 in loop_iterate ../spa/plugins/support/loop.c:376
    #1 0x7fa98472c1eb in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #2 0x559995af7a76 in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:355
    #3 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #4 0x559995b06191 in run_test ../test/pwtest.c:1087
    #5 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #6 0x559995b0aea4 in main ../test/pwtest.c:1482
    #7 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)
    #8 0x7fa9836013c0 in __libc_start_main@GLIBC_2.2.5 (/usr/lib/libc.so.6+0x2d3c0)
    #9 0x559995aed754 in _start (/home/pb/temp/src/pipewire/build/test/test-loop+0x26754)

0x608000000440 is located 32 bytes inside of 96-byte region [0x608000000420,0x608000000480)
freed by thread T0 here:
    #0 0x7fa984ffda79 in __interceptor_free /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x7fa97f60b03a in process_destroy ../spa/plugins/support/loop.c:344
    #2 0x7fa97f60cbf8 in loop_iterate ../spa/plugins/support/loop.c:387
    #3 0x559995af5b62 in dmsbd_recurse_on_event ../test/test-loop.c:298
    #4 0x7fa97f60d826 in source_io_func ../spa/plugins/support/loop.c:396
    #5 0x7fa97f60c7e7 in loop_iterate ../spa/plugins/support/loop.c:377
    #6 0x7fa98472c1eb in pw_main_loop_run ../src/pipewire/main-loop.c:148
    #7 0x559995af7a76 in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:355
    #8 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #9 0x559995b06191 in run_test ../test/pwtest.c:1087
    #10 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #11 0x559995b0aea4 in main ../test/pwtest.c:1482
    #12 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)

previously allocated by thread T0 here:
    #0 0x7fa984ffdfb9 in __interceptor_calloc /usr/src/debug/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x7fa97f60d883 in loop_add_io ../spa/plugins/support/loop.c:408
    #2 0x559995af75de in destroy_managed_source_before_dispatch_recurse ../test/test-loop.c:349
    #3 0x559995b02678 in start_test_nofork ../test/pwtest.c:882
    #4 0x559995b06191 in run_test ../test/pwtest.c:1087
    #5 0x559995b0948a in run_tests ../test/pwtest.c:1283
    #6 0x559995b0aea4 in main ../test/pwtest.c:1482
    #7 0x7fa98360130f in __libc_start_call_main (/usr/lib/libc.so.6+0x2d30f)

SUMMARY: AddressSanitizer: heap-use-after-free ../spa/plugins/support/loop.c:376 in loop_iterate
2022-03-06 18:40:43 +00:00
Barnabás Pőcze b1c189fa86 test: rewrite test which destroys active source before dispatching
Rewrite the test that destroys an active managed source
right after polling is done. There is no need to use a
thread loop because the same thing can be simulated using
the before/after loop control hooks in a more controlled
manner.
2022-03-06 18:40:43 +00:00
Barnabás Pőcze 1e99551233 test: loop: do not use NULL as event handler 2022-03-06 18:40:43 +00:00
Pauli Virtanen 7ade8fa8fb pwtest: fix daemon log scrambling
Nonblocking pipes can scramble logs if we read too slow, so use max size
buffers.

Also use CLOEXEC for the pipes to be safer, and minor other fixes.
2022-03-06 02:29:35 +02:00
Pauli Virtanen 8673f8c03d pwtest: shorter default timeout 2022-03-05 17:51:22 +00:00
Pauli Virtanen f3831da67a pwtest: ARG_DAEMON tests don't work on valgrind 2022-03-05 17:51:22 +00:00
Pauli Virtanen c604f1608a test: add simple functional tests
Try running openal-info.
2022-03-05 17:51:22 +00:00
Pauli Virtanen 76bab25afb pwtest: handle SIGTERM/SIGINT in runner
Catch SIGTERM/SIGINT in test runner, and clean up any spawned processes.

Fixes printing test output on termination by signal (e.g. meson
timeout), and doesn't leave spawned processes running.
2022-03-05 17:51:22 +00:00
Pauli Virtanen ad3c90dbb9 pwtest: use default debug level 4 for spawned daemons 2022-03-05 17:51:22 +00:00
Pauli Virtanen a7bd52d07d pwtest/Makefile: set SPA_DATA_DIR 2022-03-05 17:51:22 +00:00
Pauli Virtanen 581f6c7f1d pwtest: add pwtest_spawn for running external programs 2022-03-05 17:51:22 +00:00
Pauli Virtanen df4f844daa pwtest: ensure all spawned daemons are terminated
Set process group, and send signal to them all.
2022-03-05 17:51:22 +00:00
Barnabás Pőcze d1f7e96f82 test: loop: add test for destroying source of thread loop
Add test which tries to destroy an active source precisely
after the loop has returned from polling but has not yet
acquired the thread loop lock.
2022-02-18 20:31:49 +01:00
Wim Taymans 231cc88cad test: don't leak the two objects 2022-02-08 19:04:08 +01:00
Barnabás Pőcze bf886ba209 support: also protect against recursive invocations
Add an extra private field to the source to store the pollevent of
the current iteration. This changes ABI but it seems an embedded source
is not used outside of our own plugins and the unit test doesn't test
this ABI case.

Whenever a source is removed, we can set the data field of the
pollevent to NULL so that it won't be handled in any iteration anymore.

Avoid dispatching the same event multiple times when doing recursive
iterations.

Add some more unit tests for this.

Fixes #2114
2022-02-08 17:21:10 +01:00
Wim Taymans 834ecd733d test: call pw_deinit() at end of test 2022-02-08 11:34:08 +01:00
Wim Taymans d28af43689 test: fix dll unload
Call spa_handle_clear() on the handle before freeing.
Actually store the loaded dll in the right array.
First clear the handle, then close the dll.
Fix iteration of the dlls.
2022-02-08 11:31:38 +01:00
Wim Taymans 5ac5ebfe19 test: add test for the loop 2022-02-08 11:08:16 +01:00
Barnabás Pőcze 15e7a61aa7 treewide: only define feature macros when the feature is available
Most feature checks already use #ifdef, and do not care about
the value of the macro. Convert all feature checks to do that,
and simplify the meson build scripts by replacing

  if cond
    cdata.set('X', 1)
  endif

with

  cdata.set('X', cond)
2022-02-04 00:15:59 +01:00
Wim Taymans 9bac90882d test: disable broken test
When a prefix is given, the file should not be found.
2022-02-01 18:15:16 +01:00
Wim Taymans 611591d0fc json: add spa_json_parse_stringn()
It also checks the destination size.
2022-01-04 12:37:00 +01:00
Barnabás Pőcze 8ed46a283f treewide: meson.build: use project_{build,source}_root()
Use `meson.project_{build,source}_root()` instead of
`meson.{build,source}_root()` because those functions
do not work as expected when used inside a subproject,
and they have been deprecated in meson 0.56.0.
2021-12-28 18:37:18 +01:00
Barnabás Pőcze 2b110af366 treewide: meson.build: use dependency variable for SPA
Use `spa_dep` everywhere instead of `spa_inc`,
and remove `spa_inc` altogether.
2021-12-28 18:34:06 +01:00
Barnabás Pőcze 0680e249e5 test: test-logger: ignore some systemd journal error codes
Some errors from `sd_journal_get_data()` are not (and
should not be considered) fatal from the point of view of
the test. Ignore them.

See #1710
2021-12-01 11:13:50 +01:00
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
Wim Taymans c07f0ccb71 map: make _insert_at() fail on a removed item
You are only supposed to use _insert_new()/_remove() or _insert_at()
on the map, If we detect a _insert_at() to a removed item,
return an error because else we might corrupt the free list.

Update unit test accordingly.
2021-10-25 16:17:35 +02:00
Gleb Popov e26b40a75f Fix compiler warning by spelling the initializer properly. 2021-10-22 19:04:47 +03:00
Peter Hutterer a2856c6e0f test: silence coverity warnings about potential tmpdir being NULL 2021-10-15 14:42:26 +10:00
Peter Hutterer 04d32ba794 test: fix a variable initialization
Technically valid since it's a null pointer but let's not do this.
2021-10-12 08:58:39 +00:00
Peter Hutterer 36c1917a16 test: use a function-specific token instead of a common one
This avoid false detections of the MARK token from other tetsts when
tests are run in parallel.
2021-10-12 08:58:39 +00:00
Peter Hutterer e7ac8adaa5 test: wait up to a second for our MARK message to appear in the journal
The previous code exposed a race condition, it assumed that our MARK
message was in the next lot of messages by the journal. If something
else would write to the journal in the meantime and our message took
time to arrive, the test would fail.

Fixes #1710
2021-10-12 08:58:39 +00:00
Peter Hutterer 1f497f3248 test: call pw_deinit() at the end of the context tests 2021-10-12 09:45:33 +10:00
Peter Hutterer ff85c2835f test: enable debug logging for the valgrind test
Valgrind tests are running under different conditions than normal tests,
specifically they all run in the same process rather than running one
fork per test. This means one test can affect another test's result if
the test doesn't clean up propertly.

This makes them harder to debug from the logs, so let's give us a
fighting chance by having debug logging enabled.
2021-10-12 09:45:33 +10:00
Peter Hutterer 5ac456f294 test: match the meson test names with the binary names
Easier to find this way what caused a test suite failure.
2021-10-12 09:45:33 +10:00
Peter Hutterer c44d0a6bbc spa: declare a dependency for the dbus lib
When running meson test without a preceding ninja build, we end up with
missing libraries. This somehow happened to work until recently but now
it triggers an issue with libspa-dbus.so not being available during the
valgrind test run, causing a test case to fail.
2021-10-12 09:45:33 +10:00
Peter Hutterer 6df8ce3031 test: fix a race condition with the journal test
The docs are slightly ambiguous here but it appears a call to
sd_journal_next() is required at least once before the actual data
message.

journalctl positions the cursor with sd_journal_seek_tail() followed by
sd_journal_seek_previous(). The actual enty is then fetched with
sd_journal_next().

Let's do the same here and let's hope this fixes the current race
condition with the test sometimes failing.
2021-10-11 07:23:38 +00:00
Wim Taymans 5f7c4dec34 meson: make it possible to compile without dbus
Make an option to disable dbus and all the code that depends on
it.

Fixes #1685
2021-10-09 15:00:04 +02: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 626d30e4bd map: fix free_list corruption when re-using removed ids
Re-using an id after removing it is a bug in the caller but there are
two cases where we corrupt the free list without warning:

Removing an object twice:

   id = pw_map_insert_new(object);
   pw_map_remove(map, id);
   pw_map_remove(map, id);

And inserting an element at an index previously removed:

   id = pw_map_insert_new(object);
   pw_map_remove(map, id);
   pw_map_insert_at(map, id, new_object);

The latter is arguably valid code, or at least it'll look like it's
valid code.

For both cases, check if the id to remove/insert at is a free item and
handle that accordingly.
2021-10-08 12:40:23 +10:00
Peter Hutterer 5b9447c2a4 test: add some map tests 2021-10-08 12:40:23 +10:00
Björn Daase cf38b7bdc4 fix codespell issues 2021-10-07 15:26:18 +00:00