Ensure that the round trip succeeds.
Signed-off-by: Philip Withnall <philip at tecnocode.co.uk>
Signed-off-by: Karsten Otto <ottoka at posteo.de>
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Calling close() on the same file descriptor that a previous call to
close() already closed is wrong, and racy if another thread received
that same file descriptor as a eg. new socket or actual file.
There are two situations where wl_connection_destroy() would close its
file descriptor and then another function up in the call chain would
close the same file descriptor:
* When wl_client_create() fails after calling wl_connection_create(),
it will call wl_connection_destroy() before returning. However, its
caller will always close the file descriptor if wl_client_create()
fails.
* wl_display_disconnect() unconditionally closes the display file
descriptor and also calls wl_connection_destroy().
So these two seem to expect wl_connection_destroy() to leave the file
descriptor open. The other caller of wl_connection_destroy(),
wl_client_destroy(), does however expect wl_connection_destroy() to
close its file descriptor, alas.
This patch changes wl_connection_destroy() to indulge this majority of
two callers by simply not closing the file descriptor. For the benefit
of wl_client_destroy(), wl_connection_destroy() then returns the
unclosed file descriptor so that wl_client_destroy() can close it
itself.
Since wl_connection_destroy() is a private function called from few
places, changing its semantics seemed like the more expedient way to
address the double-close() problem than shuffling around the logic in
wl_client_create() to somehow enable it to always avoid calling
wl_connection_destroy().
Signed-off-by: Benjamin Herr <ben@0x539.de>
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
When wl_connection_read() in wl_display_read_events() returns with EAGAIN,
we want the sleeping threads to be woken up. Test it!
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
man usleep says that bahaviour of using usleep with SIGALRM signal
is unspecified. So create our own usleep that calls nanosleep instead.
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This function is used in one test only, but its functionality can be
used in another tests to (create thread and wait until it is sleeping).
We just need to pass the starting function for the thread as an argument.
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This test shows that it's possible to successfully call wl_display_prepare_read
and wl_display_read_events after an error occurred. That may lead to
deadlock.
When you call prepare read from two threads and then call read_events,
one thread gets sleeping. The call from the other thread will return -1 and invokes
display_fatal_error, but since
we have display->last_error already set, the broadcast is not called and
the sleeping thread sleeps indefinitely.
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
wl_display_read_events() can make a thread wait until some other thread
ends reading. Normally it wakes up all threads after the reading is
done. But there's a place when it does not get to waking up the threads
- when an error occurs. This test reveals bug that can block programs.
If a thread is waiting in wl_display_read_events() and another thread
calls wl_display_read_events and the reading fails,
then the sleeping thread is not woken up. This is because
display_handle_error is using old pthread_cond instead of new
display->reader_cond, that was added along with wl_display_read_events().
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Most of the code of the queue-test is covered by the test compositor,
so we can save few lines and use the test compositor instead.
I think it's also more readable.
This patch removes timeout from the test. We plan to add timeout
to all tests later, though.
v2.
rebased to master
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
This patch introduces a set of functions that can create a display
and clients for tests.
On server side the user can use functions:
display_create()
display_destroy()
create_client()
display_run()
display_resume()
and on client side the user can use:
client_connect()
client_disconnect()
stop_display()
The stop_display() and display_resume() are functions that serve as a barrier
and also allow the display to take some action after the display_run() was called,
because after the display is stopped, it can run arbitrary code until it calls
display_resume().
client_connect() function connects to wayland display and creates a proxy to
test_compositor global object, so it can ask for stopping the display later
using stop_display().
An example:
void
client_main()
{
/* or client can use wl_display_connect(NULL)
* and do all the stuff manually */
struct client *c = client_connect();
/* do some stuff, ... */
/* stop the display so that it can
* do some other stuff */
stop_display(c, 1);
/* ... */
client_disconnect(c);
}
TEST(dummy_tst)
{
struct display *d = display_create();
/* set up the display */
wl_global_create(d->wl_display, ...);
/* ... */
create_client(d, client_main);
display_run();
/* if we are here, the display has been stopped
* and we can do some code, i. e. create another global or so */
wl_global_create(d->wl_display, ...);
/* ... */
display_resume(d); /* resume display and clients */
display_destroy(d);
}
v2:
added/changed message in few asserts that were not clear
fixed codying style issues and typo
client_create_with_name: fixed a condition in an assert
get_socket_name: use also pid
check_error: fix errno -> err
[Pekka Paalanen: added test-compositor.h to SOURCES, added
WL_HIDE_DEPRECATED to get rid of deprecated defs and lots of warnings,
fixed one unchecked return value from write().]
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Earlier, the wl_display_dispatch_pending were setting number of thread
that can dispatch events. This behaviour was removed later,
so now these lines are redundant.
Related commits:
385fe30e8b78cfa967683c7e8bfbb4
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Destroy all objects that we have created
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
[Pekka Paalanen: moved variable declarations to before code. Added some
comments, and added the re-arm to additionally test the opposite case.]
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
It may happen that there's some time between the first and the other timer expire.
If epoll_wait is called after the first timer expired and
the other not, it returns only one source to dispatch and therefore
the test fails. To fix that, sleep a while before
wl_event_loop_dispatch() to make sure both timers expired.
To be 100% sure, we could use poll() before calling
wl_event_loop_dispatch(), but that would need modification in libwayland
(need to get the source's fd somehow)
https://bugs.freedesktop.org/show_bug.cgi?id=80594
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Make sure the wl_event_source_timer_update suceeded. Also, fix weird
indentation.
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Test if when we get a signal, all signal sources for that signal
get dispatched.
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Check value set in handler against an explicit value instead of:
assert(value);
also add one assert() for non-NULL value.
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Last set of commits introduced a bug. When adding of socket with
a particular name fails, then the socket and its lockfile are deleted
regardless who created the socket.
/* OK */
wl_display_add_socket(display, "wayland-0");
/* this call fails and will delete the original socket */
wl_display_add_socket(display, "wayland-0");
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
I've noticed a blocking problem in Wayland's event-loop code when updating
timer event sources. The problem occurs if you update the timer at a point
after is has expired, but before it has been dispatched, i.e. from an event
callback that happens during the same epoll wakeup.
When the timer is subsequently dispatched, wl_event_source_timer_dispatch
blocks for the duration of the new timeout in its call to read() from the
timer fd (which is the expected behaviour according to the man page for
timerfd_settime).
This isn't too uncommon a scenario - for example, a socket with an associated
timeout timer. You'd typically want to update the timer when reading from the
socket. This is how I noticed the issue, since I was setting a timeout of
1 minute, and saw my server blocking for this duration!
The following patch adds a (currently failing) test case to Wayland's
event-loop-test.c. It demonstrates the problem using two timers, which are
set to expire at the same time. The first timer to receive its expiry
callback updates the other timer with a much larger timeout, which then
causes the test to block for this timeout before calling the second timer's
callback.
As for a fix, I'm not so sure (which is why I thought I'd post the failing
test case first to show what I mean). I notice that it doesn't actually do
anything with the value read from the timerfd socket, which gives the number
of times the timer expired since the last read, or when the timer was last
updated (which blocks if the timer hasn't yet expired). I believe this value
should always read as 1 anyway, since we don't use periodic timers.
A simple fix would be to use the TFD_NONBLOCK option when creating the
timerfd, ensuring that the read call won't block. We'd then have to ignore
the case when the read returns EAGAIN.
If a message was too big to fit in the connection buffer, the code
in wl_buffer_put would just write past the end of it.
I haven't seen any real world use case that would trigger this bug, but
it was possible to trigger it by sending a long enough string to the
wl_data_source.offer request.
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=69267
Even if nothing receives the even, the arguments still need to be valid.
The test is sending out event 0 from the wl_display interface, which is
the error event. This requires arg 0 to be a valid object and arg 2 to
be a non-null string. The test just leaves that undefined, causing
intermittent test failures.
As it is, the resource destroy test doesn't need to send an event to
validate the various resource destroy hooks, so we can just remove the
call to wl_resource_post_event() alltogether.
Thanks to Matt Turner <mattst88@gmail.com> for pointing out the failure.
With the work to add wl_resource accessors and port weston to use them,
we're ready to make wl_resource and wl_object opaque structs. We keep
wl_buffer in the header for EGL stacks to use, but don't expose it by
default. In time we'll remove it completely, but for now it provides a
transition paths for code that still uses wl_buffer.
Reviewed-by: Jason Ekstrand<jason@jlekstrand.net>
This commit adds a flags parameter to wl_closure_invoke(). The so far
added flags are ment to specify if the invokation is client side or
server side. When on the server side, closure arguments of type 'new_id'
should be invoked as a integer id while on the client side they should
be invoked as a pointer to a proxy object.
This fixes a bug happening when the address of a client side 'new_id'
proxy object did not fit in a 32 bit integer.
krh: Squashed test suite compile fix from Jason Ekstrand.
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
If a child process dies from a signal, WIFEXITED() returns false and
WEXITSTATUS() isn't well-defined. In this case, if the client segfaults,
the status is 134 and WEXITSTATUS(134) is EXIT_SUCCESS, so we mask the error.
The *.log and *.trs files should be ignored by git as well as the GNU
autotools ./test-driver helper script.
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
This is libwayland, not weston, so call the temporary files
wayland-tests-*, not weston-tests-*.
This is a candidate for the stable branch.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>