Commit graph

87 commits

Author SHA1 Message Date
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
Peter Hutterer e36183d3cf array: re-initialize the array in pw_array_clear()
Leaving the data nonzero is a use-after-free bug waiting to happen.
2021-10-07 15:08:57 +10:00
Pauli Virtanen 8159797f89 doc: reorganize Doxygen groups/modules to make more sense
The Doxygen "Modules" page is not very illuminative, as different parts
of the API are mixed together and not all parts are included.

Try to address this:

Put all parts of the public API to some Doxygen group, usually one group
per header file. Use short, systematic names.

Make these groups sub-groups of a few top-level groups, roughly
corresponding to the different logical parts of the API (core, impl,
stream, filter, spa, utilities).
2021-10-03 15:39:27 +03:00
Wim Taymans 33787ffe1c tests: fix log test 2021-09-29 17:06:35 +02:00
Wim Taymans a9c64e1609 fix versions of the log interface 2021-09-29 17:03:26 +02:00
Peter Hutterer 52bd80aaa4 log: add topic loggers and a default topic
pw_log_log/logv now go through the topic-based logger using the
"default" topic. Log topics themselves can be allocated by the call
sites. The simplest way to use a topic from e.g. a module:

    PW_LOG_TOPIC_STATIC(mod_topic, "mod.foo");
    #define PW_LOG_TOPIC_DEFAULT mod_topic
    ...
    void pipewire__module_init() {
  	  PW_LOG_TOPIC_INIT(mod_topic);
  	  ...
    }

With the #define all pw_log_foo() are now routed through the custom
topic. For the cases where the log topic must be specified, a
pw_logt_foo() set of macros is available.

Log topics are enabled through the PIPEWIRE_DEBUG environment variable
which now supports globs, e.g. PIPEWIRE_DEBUG="*:I;mod.access:D"
to enable global INFO but DEBUG for the access module.

Namespaces documented are "pw", "mod" and "conn", for pipewire-internal
stuff, modules and connection dumping. The latter is special-cased to
avoid spamming the log files, it requires an expcit "conn.<glob>"
pattern to enable.

The "default" topic always exists and is the fallback for any
pw_log_foo() invocation that does not use a topic.
2021-09-28 09:35:38 +02:00
Peter Hutterer 59a5791d41 spa: implement the new topic logging for the provided loggers
Both simple log implementation now support the new topic-based
functions, and so does the journal logger too.
2021-09-28 09:35:38 +02:00
Peter Hutterer 0e60e9c063 spa: add topic-based logging
Add a struct spa_log_topic that allows for logical grouping of messages.
The new macros spa_log_logt() and spa_log_logtv() take a topic as
argument, the topic's level acts as filter.
A new macro spa_log_topic_init() initializes a topic. By default a topic
inherits its logger's debug level but a logger implementation may set
that topic to a specific fixed log level.

The various spa_log_*() macros transparently wrap new and old
implementations:
- if the implementation is version 0, the new logt() calls drop the
  topic and get routed into the old log() calls
- if the implementation is version 1, the old log() calls use a NULL
  topic and get routed into the new logt() calls

All spa_log_* macros use the SPA_LOG_DEFAULT_TOPIC topic (NULL), it is
up to the caller to redefine that. Alternatively, use spa_logt_* to pass
an explicit topic.

There is one crucial flaw in this implementation: log topics are
initialized to their target level by the current logger. Where a topic
is initialized but the logger is switched later, the topic is not
automatically re-initialized. Ultimately this shouldn't matter for
real-world use-cases.
2021-09-28 09:35:38 +02:00
Peter Hutterer cbcf62f341 spa: add a macro to check for a callback version
spa_interface_call() and friends will quietly do nothing if the version
doesn't match so we need an extra macro to know whether we can
spa_interface_call() for any given version.

This allows us to implement things like:
   if (spa_interface_callback_version_min(1)
        spa_interface_call(..., 1, func_v1)
   else
        spa_interface_call(..., 0, func_v0)
2021-09-28 09:35:38 +02: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 2b65fb36f2 test: simplify the logger test a bit
The tests using this function use the pw_log* macros which invoke
whichever logger pipewire has set. Since the default logging
implementation supports logging to a file anyway, let's just use that
instead of having to load the plugin ourselves.
2021-09-24 12:33:02 +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 29fdd10066 test: add two tests for the spa_interface callback versioning 2021-09-23 15:30:22 +10:00
Peter Hutterer c6f0ac7ff0 test: fix the calls to pw_deinit()
Missing from some tests, superfluous in the other test because it was
already called in the test_log_levels() helper function
2021-09-22 12:15:35 +10:00
Peter Hutterer 48cff597a6 test: don't try to log for LOG_LEVEL_NONE
We can only log for a level below our current one if we are two above
NONE. And by the same instance, we don't expect NONE messages to show
up.
2021-09-22 12:15:34 +10:00
Peter Hutterer b00bc81929 test: fix a use-of-uninitialized-variable compiler warning
False positive, we abort in the cases where this isn't initialized.

Fixes e1672f9762
2021-09-22 12:15:33 +10:00
Peter Hutterer dfb40fb714 test: implement a test for the journal logger 2021-09-20 07:29:03 +00:00
Peter Hutterer 0cbd56f0cd spa: declare a dependency for each used library in meson.build
For SPA libraries that we link against elsewhere in the tree, declare a
declare a dependency "foo_dep" for that library that specifies how to
link to it. Then use that dependency in the various targets.

This removes the knowledge of how to link with the library from the
target which can treat it as just another dependency.

In the case of optional libraries (e.g. the journal support lib) we can
then use declare_dependency() to declare an empty dependencies and thus
link them unconditionally in the target.
2021-09-20 07:29:03 +00:00
Peter Hutterer e1672f9762 pipewire: allow for log level names in PIPEWIRE_DEBUG
Allow one of "XEWIDT" to refer to none, errors, warnings, info, debug
and trace, respectively because they're immediately recognizable. Well,
except maybe the X.

PIPEWIRE_DEBUG="I" is equivalent to PIPEWIRE_DEBUG="3" for example.
2021-09-10 07:38:20 +00:00
Peter Hutterer 0a21d76334 test: add tests for the log levels to show up correctly
Two tests, once with pw_log_set_level(), once with PIPEWIRE_DEBUG
2021-09-10 07:38:20 +00:00
Nils Tonnätt dd12910769 Revert "[Meson] Fix all deprecation warnings"
This reverts commit f7e1175ef0.
2021-08-08 19:18:40 +00:00
Nils Tonnätt f7e1175ef0 [Meson] Fix all deprecation warnings 2021-08-06 07:56:16 +00:00
Nils Tonnätt 761fa6f59d meson: fix meson test without building pipewire before
This adds project internal dependencies to some tests to let all
tests succeed. It is not adding all dependencies those tests actually
need.
2021-08-04 20:38:30 +02:00
Peter Hutterer d0060fbddd test: move the client and utils tests over here 2021-08-04 07:45:06 +00: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 731888fcdd test: fix a memleak in the config tests
Fixes bba9edabee
2021-07-07 11:03:23 +00:00
Peter Hutterer 4f49e893c1 test: init the pod test buffer with a fixed value
Works around the valgrind complaints when we call spa_debug_mem() on the
buffer with various sizes.
2021-07-07 11:03:23 +00: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
Peter Hutterer bba9edabee conf: don't allow a NULL config name
No functional changes, this is enforced by the only in-tree callers of
pw_conf_load_conf() but let's enforce this properly.
2021-07-06 07:14:21 +00:00
Peter Hutterer fb2d35895e conf: ignore the prefix if the config file name is an absolute path
Fixes:
$ export PIPEWIRE_CONFIG_PREFIX=/usr/share/pipewire
$ pipewire -c /etc/pipewire/bar.conf
[W][11925.530591][          conf.c:  253 conf_load()] config 0x560039ac6510: error loading config '/usr/share/pipewire//etc/pipewire/pipewire.conf': No such file or directory
[W][11925.530721][       context.c:  178 try_load_conf()] context 0x560039ac6190: can't load config /usr/share/pipewire//etc/pipewire/pipewire.conf: No such file or directory
2021-07-06 07:14:21 +00:00
Peter Hutterer b1ac776ff0 test: remove duplicate test invocation 2021-07-06 07:14:21 +00:00
Barnabás Pőcze f5d51162c4 treewide: mark things static and const
Mark some structures, arrays static/const at various places.
In some cases this prevents unnecessary initialization
when a function is entered.

All in all, the text segments across all shared
libraries are reduced by about 2 KiB. However,
the total size increases by about 2 KiB as well.
2021-06-30 14:44:08 +02:00
Niklāvs Koļesņikovs e062c4d8de meson.build: adds summary() to optional programs 2021-06-29 17:23:37 +00:00