Commit Graph

283 Commits

Author SHA1 Message Date
David Edmundson
edb943dc64 client: Add method to get display for a given proxy
This can be useful for additional validation purposes when handling
proxies. This is similar to existing server side API
wl_global_get_display.

Signed-off-by: David Edmundson <david@davidedmundson.co.uk>
2023-08-07 13:38:01 +00:00
Alex Yang
6d33346571 debug: Replace "@<id>" with "#<id>" in logs
Wayland debug logs resemble email addresses. This is a problem when
anonymizing logs from users. For example:

[2512874.343] xdg_surface@700.configure(333)

In the above log line, the substring "surface@700.config" can be
mistaken for an email address and redacted during anonymization.

Signed-off-by: Alex Yang <aycyang@google.com>
2023-06-27 14:08:25 -07:00
Simon Ser
4ec379ebcc tests: manually wrap libc functions
The way we're wrapping libc functions via dlsym() is pretty fragile
and breaks on FreeBSD. The failures happen in our CI and are pretty
random, see e.g. [1].

Use a more manual way to wrap via a function pointer.

[1]: https://gitlab.freedesktop.org/wayland/wayland/-/jobs/44204010

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-06-27 13:31:50 +02:00
Simon Ser
f181de1bcf tests: add missing proxy-test
This was probably lost during a rebase.

Signed-off-by: Simon Ser <contact@emersion.fr>
2023-06-20 09:20:49 +02:00
Manuel Stoeckl
b1b97e8d34 tests: drop misleading fixed-benchmark
Because this benchmark performed wl_fixed_to_double conversions
on a long sequence of consecutive integers, the compiler could
optimize away the addition performed in wl_fixed_to_double, merging
it with the loop iteration code. This made tests/fixed-benchmark.c
significantly underestimate the actual cost of the current
wl_fixed_to_double implementation.

Signed-off-by: Manuel Stoeckl <code@mstoeckl.com>
2023-05-03 19:15:12 +00:00
Alexandros Frantzis
b01a85dfd5 client: Do not warn about attached proxies on default queue destruction.
If the default queue is being destroyed, the client is disconnecting
from the wl_display, so there is no possibility of subsequent events
being queued to the destroyed default queue, which is what this warning
is about.

Note that interacting with (e.g., destroying) a wl_proxy after its
wl_display is destroyed is a certain memory error, and this warning will
indirectly warn about this issue. However, this memory error should be
detected and warned about through a more deliberate mechanism.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2023-03-01 15:50:02 +02:00
Alexandros Frantzis
d72f9007c3 client: Abort when trying to add an event to a destroyed queue
Detect when we are trying to add an event to a destroyed queue,
and abort instead of causing a use-after-free memory error.

This situation can occur when an wl_event_queue is destroyed before
its attached wl_proxy objects.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2023-02-28 11:22:04 +00:00
Alexandros Frantzis
e09010f470 tests: Support tests that check for client failure
Add the display_destroy_expect_signal() function to check that test
clients exit due to a particular signal. This is useful for checking
that clients fail in an expected way.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2023-02-28 11:22:04 +00:00
Alexandros Frantzis
0ba650202e client: Warn when a queue is destroyed with attached proxies
Log a warning if the queue is destroyed while proxies are still
attached, to help developers debug and fix potential memory errors.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2023-02-28 11:22:04 +00:00
Alexandros Frantzis
d4d3228853 tests: Capture the test client log
Capture the test client log to a temporary fd, so that is accessible by both
the test server process and the test client process.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2023-02-28 11:22:04 +00:00
Daniel Stone
86d73b2da2 tests: Ensure resource vs. client destroy handler order
Make sure that the client destroy handler runs strictly before the
resource destroy handler, which runs strictly before the client
late-destroy handler.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-10-20 11:26:22 +00:00
Daniel Stone
51d788de5b wayland-server: Add wl_client_add_destroy_late_listener
A late-destroy listener for a client is called after all the client's
resources have been destroyed and the destroy callbacks emitted. This
lives in parallel to the existing client destroy listener, called
immediately before the client's objects get destroyed.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Fixes: wayland/wayland#207
2022-10-20 11:26:22 +00:00
Daniel Stone
e886b456ab tests: Use bool for client test
A 0/1-only int is a bool.

Signed-off-by: Daniel Stone <daniels@collabora.com>
2022-10-20 11:26:22 +00:00
Ian Douglas Scott
971f8e4ace Do not allow nullable new_id
The usefulness of this is limited, and `libwayland-client` doesn't
provide a way to pass a null `new_id` since the id is generated by the
library and given to the caller as the return value.

Signed-off-by: Ian Douglas Scott <idscott@system76.com>
2022-07-14 08:38:49 -07:00
Ian Douglas Scott
13b05c9ed1 Do not allow nullable arrays, which were not correctly implemented
Nullable arrays, which are not used anywhere, were marshalled the same
way as an empty non-null array. The demarshalling logic did not
recognize anything as a null array. Given this, it seems better to just
explicitly not support it.

Fixes https://gitlab.freedesktop.org/wayland/wayland/-/issues/306.

Signed-off-by: Ian Douglas Scott <idscott@system76.com>
2022-07-14 08:10:38 -07:00
Simon Ser
2fb4cdebbe tests: add a test for dynamic filtered globals
Ensure dynamically created and destroyed globals which are filtered
don't trigger any global/global_remove event.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-06-15 07:53:19 +00:00
Antonin Décimo
9434e8d69f Check that XDG base directories paths are absolute
The [spec][1] reads:

> All paths set in these environment variables must be absolute. If an
> implementation encounters a relative path in any of these variables it should
> consider the path invalid and ignore it.

and

> If $XDG_DATA_HOME is either not set or empty, a default equal to
> $HOME/.local/share should be used.

Testing that the path is absolute also entails that is is non-empty.

[1]: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Signed-off-by: Antonin Décimo <antonin.decimo@gmail.com>
2022-06-09 18:34:17 +00:00
Simon Ser
9402afc353 build: sanity check options
Fail when tests/documentation is enabled without libraries. Fail
when neither scanner nor libraries is enabled, because we don't
build anything in that case.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-05-10 14:02:51 +00:00
Simon Ser
962aefda42 server: introduce wl_signal_emit_mutable
wl_signal_emit doesn't handle well situations where a listener removes
another listener. This can happen in practice: wlroots and Weston [1]
both have private helpers to workaround this defect.

wl_signal_emit can't be fixed without breaking the API. Instead,
introduce a new function. Callers need to make sure to always remove
listeners when they are free'd.

[1]: https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/457

Signed-off-by: Simon Ser <contact@emersion.fr>
Signed-off-by: Alexandros Frantzis <alexandros.frantzis@collabora.com>
2022-03-28 19:06:16 +00:00
Simon Ser
24e0a7b622 build: specify native arg in add_languages()
Fixes the following warning:

    WARNING: add_languages is missing native:, assuming languages are wanted for
    both host and build.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-03-25 09:14:08 +00:00
Simon Ser
02661fde24 build: use full_path() instead of path()
Fixes the following warning:

    WARNING: Project targeting '>= 0.56.0' but tried to use feature deprecated
    since '0.55.0': ExternalProgram.path. use ExternalProgram.full_path() instead

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-03-25 09:14:08 +00:00
Fergus Dall
e949b3bfbb display-test: Fix a race condition in test suite
Several tests in this suite use setting and checking client.display_stopped (in
test-compositor.h) to synchronise between threads. This is a data race because
display_stopped is a non-atomic int. Fix this by making it an atomic_bool
instead. We don't need to change the access code because reads and writes are
sequentially consistent by default.

This can be reproduced (with both clang and gcc) by running
```
meson -Db_sanitize=thread build
cd build
ninja
meson test
```

Signed-off-by: Fergus Dall <sidereal@google.com>
2022-02-05 14:29:39 +00:00
Simon Ser
0d314c4a04 build: don't rely on implicit GNU extensions
Currently libwayland assumes GNU extensions will be available, but
doesn't define the C standard to use. Instead, let's unconditionally
enable POSIX extensions, and enable GNU extensions on a case-by-case
basis as needed.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-01-10 15:08:46 +01:00
Simon Ser
65616e946b tests: use __typeof__ instead of typeof
typeof is a GNU extension. Compiler extensions should be prefixed
with __ per the C standard.

Signed-off-by: Simon Ser <contact@emersion.fr>
2022-01-10 14:51:09 +01:00
shierote
aa6a07c2fe doc: fix typo in wl_data_device.data_offer
Signed-off-by: Taishi Eguchi <taishi2060@gmail.com>
2022-01-10 10:07:22 +00:00
Derek Foreman
ea237db7f6 tests: Fix tc_client_fd_leaks_exec test
tc_client_fd_leaks and tc_client_fd_leaks_exec are currently the exact
same test. It seems clear from the name that the latter was intended to
spawn sanity_fd_leak_exec instead of sanity_fd_leak.

Fixes #121

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2022-01-10 09:52:00 +00:00
Damian Hobson-Garcia
d564823cfd server: stop wl_display event loop from any context
Calling wl_display_terminate() will exit the wl_display event loop
at the start of the next loop iteration.  This works fine when
wl_display_terminate() is called after the event loop wakes up
from polling on the added event sources.  If, however, it is
called before polling starts, the event loop will not exit until
one or more event sources trigger.  Depending on the types of event
sources, they may never trigger (or may not trigger for a long time),
so the event loop may never exit.

Add an extra event source to the wl_display event loop that will trigger
whenever wl_display_terminate() is called, so that the event loop will
always exit.

Fixes #201

Signed-off-by: Damian Hobson-Garcia <dhobsong@igel.co.jp>
2021-10-09 13:09:04 +00:00
Alex Richardson
ed423b8ac6 Allow event-loop signal tests to pass on FreeBSD
On Linux the signal will be immediately visible in the epoll_wait() call.
However, on FreeBSD we may need a small delay between kill() call and the
signal being visible to the kevent() call. This sometimes happens when the
signal processing and kevent processing runs on different CPUs in the
kernel, so becomes more likely when the system is under load (e.g. running
all tests in parallel).

See https://github.com/jiixyj/epoll-shim/pull/32

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-09-10 11:35:54 +00:00
Alex Richardson
382f368a27 Detect FreeBSD versions with broken MSG_CMSG_CLOEXEC
If we are compiling against a version of FreeBSD where MSG_CMSG_CLOEXEC
does not work, use the fallback directly. This was only fixed recently
(in https://cgit.freebsd.org/src/commit/?id=6ceacebdf52211).

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-09-10 11:35:54 +00:00
Alex Richardson
42bf011f65 test-helpers: use sysctl() to count open fds on FreeBSD
This allows running the tests on FreeBSD without mounting fdescfs.
Previously you had to run `mount -t fdescfs -o linrdlnk null /dev/fd` to
get file descriptors >=3 listed in /dev/fd.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-09-10 11:35:54 +00:00
Alex Richardson
bb92828807 test-runner: Implement is_debugger_attached() for FreeBSD
FreeBSD provides a PROC_TRACE_STATUS procctl(2) to detect this directly.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-09-10 11:35:54 +00:00
Alex Richardson
644efe9517 Use /dev/fd instead of /proc/self/fd
/dev/fd exists on all operating systems I can test (Linux, FreeBSD, macOS),
whereas /proc/self/fd only appears to exist on Linux.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-09-10 11:35:54 +00:00
Alex Richardson
c65f852fc8 Use epoll-shim to emulate epoll(7) on FreeBSD
FreeBSD does not provide epoll(7) and instead requires an external library,
epoll-shim, that implements epoll() using kqueue(2)

Co-authored-by: Jan Beich <jbeich@FreeBSD.org>
Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-09-10 11:35:54 +00:00
Alex Richardson
8ec25be6db os-wrappers-test: Handle fcntl() being declared as a macro
On some systems (e.g. FreeBSD with the latest epoll-shim), fcntl is
declared as a macro instead of a function. Wrap the definition here in
parantheses to avoid function-macro expansion.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-09-10 11:35:54 +00:00
Derek Foreman
bf98c1a8f2 tests: Destroy custom global object
Destroy our custom global object at end of run so we no longer "leak"
it.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2021-08-27 09:56:17 -05:00
Derek Foreman
0e0274af0c scanner: Use the new atomic marshal/destroy function
Use the new flagged marshal+destroy function in generated code.

It's intended as a replacement for all existing wl_proxy_marshal_*
functions, so I've used it to replace them all. This results in a large
update to the scanner test files as well.

We now pass the new WL_MARSHAL_FLAG_DESTROY flag when appropriate, so
the race condition in #86 caused by releasing the display mutex between
marshalling the proxy and destroying the proxy is now gone.

Fixes #86

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
2021-08-07 11:53:23 +00:00
Fergus Dall
91d98b622f os-wrappers-test: Make syscall intercepts work with sanitizers
Sanitizers need to intercept syscalls in the compiler run-time library, as
do these tests. We try to make this work by using dlsym(RTLD_NEXT) to find
the next definition in the chain, but here this approach won't work because
the compiler run-time library is linked into the same elf object as the test
interceptors are.

The sanitizer library supports this by giving the intercept functions a
prefix and making them only weakly alias the real names, so our interceptors
can call the sanitizers interceptors explicitly, which will then use dlsym
to call the real function.

By making our declarations of the sanitizer interceptor function weak we can
handle any combination of intercepts (including none, if there is no
sanitizer). If our declaration is resolves to a NULL pointer, we just use
dlsym.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-07-22 22:27:45 +00:00
Fergus Dall
e5c3ac9bcd connection-test: Pad out strings with null bytes
The connection_demarshal test writes a 10 byte string into a wayland message,
but doesn't pad it out to a four byte boundary. This leads to the last 32-bit
word of the message being partially uninitialized, which triggers an msan
violation when the message is written to the socket.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-07-22 22:27:45 +00:00
Fergus Dall
80164ef300 util: Avoid undefined behaviour in for_each_helper
for_each_helper tries to calculate a one-past-the-end pointer for its
wl_array input. This is fine when the array has one or more entries, but we
initialize arrays by setting wl_array.data to NULL. Pointer arithmetic is
only defined when both the pointer operand and the result point to the same
allocation, or one-past-the-end of that allocation. As NULL points to no
allocation, no pointer arithmetic can be performed on it, not even adding 0,
even if the result is never dereferenced.

This is caught by clang's ubsan from version 10.

Many tests already hit this case, but I added an explicit test for iterating
over an empty wl_map.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-07-21 11:42:42 +00:00
James Legg
b7153f2273 tests: Test wayland-scanner with a description in an entry
This previously would have caused a memory leak and incorrect
comments.

Signed-off-by: James Legg <lankyleggy@gmail.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
2021-07-07 12:11:42 +00:00
Fergus Dall
ccc9612e82 connection: Handle non-nullable strings in wl_connection_demarshal
Currently a null string passed into a non-nullable argument of a message
will decode succesfully, probably resulting in the handler function
crashing. Instead treat it the same way we do non-nullable objects and ids.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-06-22 20:15:39 +10:00
Fergus Dall
4f53613e70 connection-test: Encode size in message headers correctly
In these tests, message sizes are inconsistently encoded in either the upper
or lower 16 bits of the second word of the message. Resolve this in favour
of using the upper 16 bits, as this is how messages are supposed to be
encoded, even though that aspect of message decoding isn't being tested
here.

Signed-off-by: Fergus Dall <sidereal@google.com>
2021-06-22 20:15:32 +10:00
James Hilliard
4c21053123 meson: only require cpp for tests
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
2021-04-16 03:04:56 -06:00
Alex Richardson
e881934927 os-wrappers-test.c: Correctly forward arguments to fcntl
We can't just unconditionally read the optional arguments (and also read
it as a void* despite actually being an int).
While this happens to work on most architectures because the first few
variadic arguments are passed in registers, this is non-portable and
causes a crash on architectures that set bounds on variadic function
arguments (for example CHERI-enabled architectures). It could also cause
problems on big-endian architectures that pass variadic arguments on the
stack rather than in registers.

For CHERI-MIPS, reading sizeof(void*) causes a read of 16 bytes from the
bounded varargs capability. This always crashes since even calls with the
optional argument only have 4 bytes available.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
Reviewed-by: Simon Ser <contact@emersion.fr>
2021-04-15 07:34:53 +00:00
Loïc Yhuel
74182eb605 meson: link with -lrt if needed for clock_gettime
This is already done in autotools, and fixes the build with glibc < 2.17.

Signed-off-by: Loïc Yhuel <loic.yhuel@softathome.com>
2020-12-23 15:37:58 +01:00
Maxime Roussin-Bélanger
efa5e3c8c6 tests: fix typos 2020-12-17 16:03:14 -05:00
Peter Hutterer
df969706f4 Replace initial 8 spaces with a tab for all xml files
This is the style used in wayland.xml which is the only file we really
care about for git blame information. So let's adjust all others to that
style for consistency and fix editorconfig to avoid messing this up in
the future.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-04-29 12:21:33 +00:00
Guido Günther
cc8b6aa3d9 scanner: Guard interface declarations
This allows to include client and server headers in the same file
fixing warnings like

In file included from ../subprojects/wlroots/include/wlr/types/wlr_layer_shell_v1.h:16,
                 from ../src/desktop.h:16,
                 from ../src/server.h:13,
                 from ../tests/testlib.c:8:
tests/59830eb@@footest@sta/wlr-layer-shell-unstable-v1-protocol.h:80:34: warning: redundant redeclaration of ‘zwlr_layer_shell_v1_interface’ [-Wredundant-decls]
   80 | extern const struct wl_interface zwlr_layer_shell_v1_interface;
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../tests/testlib.h:8,
                 from ../tests/testlib.c:7:
tests/59830eb@@footest@sta/wlr-layer-shell-unstable-v1-client-protocol.h:77:34: note: previous declaration of ‘zwlr_layer_shell_v1_interface’ was here
   77 | extern const struct wl_interface zwlr_layer_shell_v1_interface;
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../subprojects/wlroots/include/wlr/types/wlr_layer_shell_v1.h:16,
                 from ../src/desktop.h:16,
                 from ../src/server.h:13,
                 from ../tests/testlib.c:8:
tests/59830eb@@footest@sta/wlr-layer-shell-unstable-v1-protocol.h:106:34: warning: redundant redeclaration of ‘zwlr_layer_surface_v1_interface’ [-Wredundant-decls]
  106 | extern const struct wl_interface zwlr_layer_surface_v1_interface;
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../tests/testlib.h:8,
                 from ../tests/testlib.c:7:
tests/59830eb@@footest@sta/wlr-layer-shell-unstable-v1-client-protocol.h:103:34: note: previous declaration of ‘zwlr_layer_surface_v1_interface’ was here
  103 | extern const struct wl_interface zwlr_layer_surface_v1_interface;

Signed-off-by: Guido Günther <agx@sigxcpu.org>
Closes: #158
2020-04-23 10:17:18 +02:00
Matt Turner
618663c791 meson: Add option to control building wayland-scanner
Wayland requires a binary, wayland-scanner, to be run during the build
process. For any configuration other than native builds (including
cross compiling and even 32-bit x86 builds on an x86-64 build machine)
Wayland's build process builds and uses its own wayland-scanner.

For any builds using a cross file, wayland-scanner is built for the host
machine and therefore cannot be executed during the build of the Wayland
libraries. Instead builds using a cross file must execute the build
machine's wayland-scanner (typically /usr/bin/wayland-scanner).

As such, to build Wayland's libraries for a non-native ABI a package
manager must build and install /usr/bin/wayland-scanner first. But then
the build for the native ABI then rebuilds wayland-scanner itself and
doesn't use the system's, and worse, wants to install its own, which
conflicts with the /usr/bin/wayland-scanner already installed!

So, add the -Dscanner=... option to control whether to install
wayland-scanner.

Signed-off-by: Matt Turner <mattst88@gmail.com>
2020-03-13 10:25:24 -07:00
Jan Beich
0fc00fff30 meson/tests: add missing dependencies on protocol headers
In file included from ../tests/connection-test.c:43:
In file included from ../tests/test-compositor.h:30:
../src/wayland-client.h:40:10: fatal error: 'wayland-client-protocol.h' file not found
 #include "wayland-client-protocol.h"
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../tests/display-test.c:45:
In file included from ../src/wayland-server.h:104:
src/wayland-server-protocol.h:4454:2: error: unterminated /* comment
        /**
        ^
In file included from ../tests/cpp-compile-test.cpp:2:
In file included from src/wayland-server-protocol.h:8:
In file included from ../src/wayland-server.h:104:
src/wayland-server-protocol.h:3:2: error: unterminated conditional directive
 #ifndef WAYLAND_SERVER_PROTOCOL_H
  ^
../tests/headers-protocol-test.c:33:2: error: including wayland-server-protocol.h did not include wayland-server.h!
 #error including wayland-server-protocol.h did not include wayland-server.h!
  ^
In file included from ../tests/headers-protocol-test.c:26:
In file included from src/wayland-client-protocol.h:8:
In file included from ../src/wayland-client.h:40:
src/wayland-client-protocol.h:1358:2: error: unterminated conditional directive
 #ifndef WL_SHM_FORMAT_ENUM
  ^
In file included from ../tests/protocol-logger-test.c:34:
In file included from ../src/wayland-client.h:40:
src/wayland-client-protocol.h:2613:1: error: unterminated /* comment
/**
^
../tests/resources-test.c:49:36: error: use of undeclared identifier 'wl_seat_interface'
        res = wl_resource_create(client, &wl_seat_interface, 4, 0);
                                          ^
2020-02-15 02:55:00 +00:00