Commit Graph

142 Commits

Author SHA1 Message Date
Mariusz Ceier
e3dc9a7af6 tests: C++ compilation test
This test includes one of wayland headers, which produced
error with C++ compiler. C compiler can't be used for this test,
because it issues only a warning[1] and only when wayland headers
are not installed in system headers path (/usr/include).

[1] wayland-server-protocol.h:201:2: warning: implicit declaration of function ‘wl_resource_post_event’

[daniels: Merged in Marek's follow-up to check for a C++ compiler.]

Signed-off-by: Mariusz Ceier <mceier+wayland@gmail.com>
Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-01-27 11:17:42 +00:00
Bryce Harrington
9386e2be27 tests: Correct return code handling
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
2015-01-26 18:11:40 -08:00
Bryce Harrington
2eeb2cbc52 tests: Fix typo "evnironment"
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
2015-01-26 18:11:11 -08:00
Marek Chalupa
e118c11178 tests: fix memory leak
We didn't free the struct client that we got from client_connect()

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-12-01 12:34:23 +02:00
Marek Chalupa
fdb519be08 tests: split queue-test testcases
All the test-cases are in one test atm. It doesn't matter for the
outcome, but when it is split to more tests, the debugging and reading
the output is simpler.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-12-01 12:04:18 +02:00
Marek Chalupa
c3653f7f61 tests: detect if debugger is attached
Copy function from libinput/test/litest.c is_debugger_detached()
and use it in our test-runner. If debugger is attached, turn off
leak checks and timeouts automatically.

Revision of libinput: 028513a0a723e97941c39c4aeb17433198723913

v2. rebased to master

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-12-01 11:49:45 +02:00
Marek Chalupa
0e1cc7aba7 tests: use color when printing on terminal
Colorize output of the tests when prinitng on terminal.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Tested-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-28 15:50:51 +02:00
Marek Chalupa
57050589b6 test-runner: print separator line after each test-case
Who can read the output when it is a single piece of text?

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
2014-11-28 14:04:13 +02:00
Marek Chalupa
bef2948348 tests: rename env vars for tests
Rename WAYLAND_TESTS_NO_TIMEOUTS to WAYLAND_TEST_NO_TIMEOUTS.
Further rename NO_ASSERT_LEAK_CHECK to WAYLAND_TEST_NO_LEAK_CHECK.
Now the naming is consistent not only here, in Wayland, but even with
naming of weston env varibles related to testing.

This is version 2 of the patch. The first version just renamed
NO_ASSERT_LEAK_CHECK to WAYLAND_TEST_NO_LEAK_CHECK.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Acked-by: Bryce Harrington <b.harrington@samsung.com>
2014-11-28 13:27:34 +02:00
Marek Chalupa
59f255d66e client: read_events should return -1 after an error
When a thread is sleeping, waiting until another thread read
from the display, it always returns 0. Even when an error
occured. In documentation stands:

  "return 0 on success or -1 on error.  In case of error errno will
   be set accordingly"

So this is a fix for this.

Along with the read_events, fix a test so that it now complies
with this behaviour (and we have this tested)

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-21 13:59:42 +02:00
Marek Chalupa
4d617b83a7 tests: don't print '\0' character
print "" (which results in no output) instead of
printing '\0' (which is not visible, but is there)

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
2014-11-19 13:51:44 +02:00
Marek Chalupa
cf11e9dfbe queue-test: put back timeout
In 93e654061b we removed call to alarm() that served as timeout in this test.
Now when we have test_set_timeout() func, return the timeout back.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
2014-11-17 16:59:50 +02:00
Marek Chalupa
bbbdff88b1 tests: use test_set_timeout in display-test
replace call to alarm() with test_set_timeout()

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Acked-by: Giulio Camuffo <giuliocamuffo@gmail.com>
2014-11-17 16:58:31 +02:00
Marek Chalupa
1d2ef9ee08 tests: add timeout tests
sanity tests for timeouts.

v2:
  use test_sleep instead of sleep
  add few more test-cases

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-17 16:51:51 +02:00
Marek Chalupa
6ebe55060e tests: add test_usleep and test_sleep functions
The former one was already used in tests, but was private.
These functions can be shared across the tests, so make them
public.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-17 16:48:14 +02:00
Marek Chalupa
7bf8049c48 tests: add timeout
Add test_set_timeout() function that allows the test to
set timeout for its completition. Any other call to the function
re-sets the timeout to the new value. The timeouts can be turned off
(usefull when debugging) by setting evironment variable
WAYLAND_TESTS_NO_TIMEOUTS.

v2:
  rename NO_TIMEOUTS to WAYLAND_TESTS_NO_TIMEOUTS
  use unsigned int as argument of test_set_timeout()
  improve printing of the message about timeout

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-17 16:45:49 +02:00
Marek Chalupa
ba6b79c577 tests: use our own XDG_RUNTIME_DIR for tests
Use $XDG_RUNTIME_DIR/wayland-tests for tests. This way we won't be
messing XDG_RUNTIME_DIR and it also fixes a bug, when socket-test
failed when another compositor was running.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Giulio Camuffo <giuliocamuffo@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-10 14:00:56 +02:00
Philip Withnall
2097414a7c queue-test: Add another assertion
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>
2014-11-05 14:26:53 +02:00
Benjamin Herr
391820b0d6 connection: Leave fd open in wl_connection_destroy
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>
2014-11-04 11:26:22 +02:00
Marek Chalupa
65d02b7a83 display-test: test if threads are woken up on EAGAIN
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>
2014-09-11 10:21:08 +03:00
Marek Chalupa
d837741166 tests: use nanosleep instead of usleep
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>
2014-09-09 12:43:38 +03:00
Marek Chalupa
aa49a79d7a display-test: make use of create_thread function
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>
2014-09-04 15:47:04 +03:00
Marek Chalupa
71141288f0 tests: add test for reading after an error occurred
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>
2014-08-22 12:58:25 +03:00
Marek Chalupa
213366e698 tests: add tests for wl_display_cancel_read
Test if wl_display_cancel_read wakes up other threads.

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-22 12:55:37 +03:00
Marek Chalupa
171e0bdace tests: test if thread can block on error
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>
2014-08-22 12:53:49 +03:00
Marek Chalupa
47208d2ab1 tests: test posting errors
Test posting errors to one and more clients.

Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-22 12:43:38 +03:00
Marek Chalupa
93e654061b tests: use test compositor in queue-test
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>
2014-08-22 12:39:52 +03:00
Marek Chalupa
85d08e8bd6 tests: add test-compositor
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>
2014-08-22 12:34:33 +03:00
Marek Chalupa
c6d98e15ca tests: remove unnecessary lines from queue-test
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:

385fe30e8b
78cfa96768
3c7e8bfbb4

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Acked-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-21 14:44:51 +03:00
Marek Chalupa
8cf7a23e57 tests: remove leaks from queue-test
Destroy all objects that we have created

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-08-21 14:44:39 +03:00
Giulio Camuffo
a52357f6fb tests: test the wl_display_roundtrip_queue() function
[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>
2014-08-21 10:30:26 +03:00
Marek Chalupa
b24fa4c821 tests: fix event_loop_timer_updates
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>
2014-08-19 14:34:50 +03:00
Marek Chalupa
12ec657014 tests: event_loop_timer_updates - add asserts and fix indentation
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>
2014-08-19 14:34:34 +03:00
Marek Chalupa
5bed9e46e7 tests: add one more test for event-loop signal source
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>
2014-08-18 13:36:22 +03:00
Marek Chalupa
5504c9338b tests: make event-loop-test more explicit
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>
2014-08-18 12:55:35 +03:00
Marek Chalupa
4c7d1af70b tests: add tests for bug in adding socket
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>
2014-08-07 16:04:17 +03:00
Jonas Ådahl
e2b1218422 tests: Add message version sanity test
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-05-09 14:32:04 -07:00
Jonas Ådahl
591f5ee3b1 event-loop-test: Remove unused variable
Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2014-05-09 14:29:27 -07:00
U. Artie Eoff
b41ded812d connection-test: check malloc result
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-05-06 14:59:33 -07:00
Andrew Wedgbury
74df22befe test: Add test showing blocking problem when updating timers
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.
2014-04-25 14:08:31 -07:00
Ander Conselvan de Oliveira
bfc93649cb connection: Don't write past the end of the connection buffer
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
2014-04-21 14:51:42 -07:00
Pekka Paalanen
9cfffffe07 update .gitignore
Makes 'git status' clean again after a successful 'make distcheck'.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-03-10 13:11:09 -07:00
Kristian Høgsberg
7ecb102409 build: Move tests/Makefile.am into toplevel Makefile.am 2014-03-07 12:00:06 -08:00
Kristian Høgsberg
4c163b9b00 build: Move src/Makefile.am into toplevel Makefile.am 2014-03-07 11:50:59 -08:00
Kristian Høgsberg
3b8a1c7fed resources-test: Don't send invalid event
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.
2014-01-20 15:07:55 -08:00
U. Artie Eoff
c0218227fe resources-test: assert non-NULL return values
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-01-15 10:46:09 -08:00
U. Artie Eoff
22a4a95873 queue-test: assert non-NULL return values
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-01-15 10:46:08 -08:00
U. Artie Eoff
e0c58cea4e os-wrappers-test: assert closure is not NULL before invoking it
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-01-15 10:46:08 -08:00
U. Artie Eoff
5e096ccc94 event-loop-test: assert non-NULL results
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-01-15 10:46:08 -08:00
U. Artie Eoff
3a1be1e6fe connection-test: assert closure is not NULL before invoking it
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-01-15 10:46:08 -08:00