Commit Graph

283 Commits

Author SHA1 Message Date
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
U. Artie Eoff
fcf5f06b7d array-test: assert wl_array_add result is not NULL
Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2014-01-15 10:46:08 -08:00
Marek Ch
b99edb8b7e tests: add wl_resource tests 2013-09-21 11:38:32 -07:00
Marek Ch
6f1569bd38 tests: add unit tests for wl_signal
Test wl_signal initialization, adding and getting listeners and emitting
2013-09-21 11:37:38 -07:00
Marek Ch
ec08c5c3e9 tests: extended message when leak in test is detected
When memory or fd leak is detected, print how many blocks of memory were
allocated and not freed, respectively how many files were opened/unclosed.
2013-09-21 11:36:33 -07:00
Kristian Høgsberg
7100a5e0bb Replace two remaining wl_display_add_gloavl() occurences 2013-07-09 19:18:10 -04:00
Kristian Høgsberg
d94a8722cb server: Make wl_object and wl_resource opaque structs
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>
2013-07-02 15:52:47 -04:00
Jason Ekstrand
57f74af278 Update tests for wl_map changes and add a map_flags test 2013-06-05 17:55:14 -04:00
Jason Ekstrand
ca5b1946cb Change wl_closure_invoke to take an opcode instead of an actual function pointer
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
2013-03-18 23:04:32 -04:00
Jonas Ådahl
cb73bffed5 client: Invoke new_id closure arguments as pointers instead of integers
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>
2013-03-17 16:39:48 -04:00
Kristian Høgsberg
13d5271b47 tests: Add a help message for the test runner
In case we forget the name of the test case or typo it, the test runner
will now list the test cases in the test binary.
2013-02-11 13:58:39 -05:00
Kristian Høgsberg
adcb2d73b3 queue-test: WEXITSTATUS() is undefined if WIFEXITED() is false
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.
2013-02-08 11:38:59 -05:00
David Herrmann
66d55ab3c3 gitignore: add test-suite files
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>
2013-01-24 16:14:52 -05:00
Jason Ekstrand
2423497b99 Add a destroy signal to the wl_event_loop object 2013-01-15 14:05:27 -05:00
Jason Ekstrand
31511d0ea0 Added a destroy signal to the wl_display object.
Added a destroy signal to the wl_display object.
2013-01-11 15:52:39 -05:00
Quentin Glidic
0d2c233e15 test/event-loop: Check readable state on a pipe
When redirecting stdout to a non-readable file makes the test fail as a
false negative
2013-01-11 15:12:45 -05:00
Pekka Paalanen
bfdf44ec48 tests: rename temporary files
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>
2012-12-03 10:10:22 -05:00
Sven Joachim
7415e8eb05 tests: Don't leave temporary files behind
Signed-off-by: Sven Joachim <svenjoac@gmx.de>
2012-12-03 09:55:58 -05:00
Jonas Ådahl
2a8da76fb1 tests: Add out of order delete_id queue tests
Verify that when receiving the first of two synchronization callback
events, destroying the second one doesn't cause any errors even if the
delete_id event is handled out of order.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2012-11-07 18:37:55 -05:00
Jonas Ådahl
3d651dc2ee tests: Use a pipe for synchronization to avoid potential deadlock
Using signals in the previous way could potentially lead to dead locks
if the SIGCONT was signalled before a listener was registered.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2012-11-07 18:37:46 -05:00
Jonas Ådahl
1801cdc41a tests: Add queue test case
Check that after a callback removes a proxy that most likely will have
several events queued up with the same target proxy, no more callbacks
are invoked.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
2012-11-05 15:48:12 -05:00
Kristian Høgsberg
c450b6e23b tests: Include wayland-private.h for container_of 2012-10-21 10:04:17 -04:00
Kristian Høgsberg
53d24713a3 Change filedescriptor API to be thread safe
The update callback for the file descriptors was always a bit awkward and
un-intuitive.  The idea was that whenever the protocol code needed to
write data to the fd it would call the 'update' function.  This function
would adjust the mainloop so that it polls for POLLOUT on the fd so we
can eventually flush the data to the socket.

The problem is that in multi-threaded applications, any thread can issue
a request, which writes data to the output buffer and thus triggers the
update callback.  Thus, we'll be calling out with the display mutex
held and may call from any thread.

The solution is to eliminate the udpate callback and just require that
the application or server flushes all connection buffers before blocking.
This turns out to be a simpler API, although we now require clients to
deal with EAGAIN and non-blocking writes.  It also saves a few syscalls,
since the socket will be writable most of the time and most writes will
complete, so we avoid changing epoll to poll for POLLOUT, then write and
then change it back for each write.
2012-10-10 20:59:00 -04:00
Kristian Høgsberg
2be6e0ed14 tests: Quiet warning 2012-08-29 14:12:11 -04:00
U. Artie Eoff
91931bcabb tests: ensure sanity leak check tests pass when leak checks are disabled.
This finalizes Robert Bradfords patch to allow NO_ASSERT_LEAK_CHECK
environment variable to disable leak checks in unit tests.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2012-08-29 14:10:24 -04:00
Rob Bradford
c95c2dffb0 tests: Allow disabling leak checking assertions by env
Some code coverage tools trigger these assertions when run against the test
suite since they don't free all their memory.
2012-08-29 14:10:20 -04:00
Philipp Brüschweiler
0a633704e6 socket-test: don't try to be clever, fail if no XDG_RUNTIME_DIR is set
Not only setenv(), also putenv() allocates memory on my system
(glibc 2.16.0). Just fail with a clear message if XDG_RUNTIME_DIR is
not set.

https://bugs.freedesktop.org/show_bug.cgi?id=52618
2012-08-14 10:10:47 -04:00
Daniel Stone
3ec40512c7 More consistent ID printing
Use unsigned rather than signed for IDs, so they match up with what we
see in other prints.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23 20:17:10 -04:00
Kristian Høgsberg
a2c79b14a1 tests: Wrap calloc by just returning NULL if we're called too early
Since glibc dlsym() calls calloc, we get a call to our calloc wrapper as
we try to look up the real calloc implementation.  dlsym() will fall back
to a static buffer in case calloc returns NULL, so that's what we'll do.

This is all highly glibc dependent, of course, but the entire malloc
weak symbol wrapper mechanism is, so there's no loss of generality here.
2012-07-23 20:14:33 -04:00
Daniel Stone
61e9196f56 test-runner: Wrap realloc() too
So all our tests don't start failing just because we had the temerity to
use realloc() rather than malloc().

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-07-23 16:40:58 -04:00
Christopher James Halse Rogers
161c690b55 protocol: Add explicit nullable types
Most of the time it does not make sense to pass a NULL object, string, or array
to a protocol request. This commit adds an explicit “allow-null” attribute
to mark the request arguments where NULL makes sense.

Passing a NULL object, string, or array to a protocol request which is not
marked as allow-null is now an error. An implementation will never receive
a NULL value for these arguments from a client.

Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers@canonical.com>
2012-07-02 13:53:02 -04:00
Dylan Noblesmith
d2bcffc470 tests: test that path names longer than 108 bytes are rejected
These would either overflow the struct sockaddr_un, or
be truncated and leave a non-null-terminated string.
2012-06-30 20:01:20 +00:00
Dylan Noblesmith
b486e3aba5 tests: fix make check for out-of-tree builds
It was failing with missing include files.

While here, destroy the ugly "../src/..." include
paths used in the tests that was just hacking around
this problem in the Makefile:

sed -i s/..\\/src\\/// tests/*.c
2012-06-30 19:58:37 +00:00
Dylan Noblesmith
c394b75958 tests: sort list of tests 2012-06-30 19:58:37 +00:00
Kristian Høgsberg
b576443a0e tests: Update test cases to new closure allocate convention 2012-06-15 16:09:39 -04:00
Pekka Paalanen
b858a1b87b tests: update gitignore
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-05-29 10:10:07 -04:00
Pekka Paalanen
32ec041333 tests: add noop to fixed-benchmark
I was just curious of how much the looping takes time without
conversion, so I added this.

My results on Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz:

benchmarked noop:	1.876349827s
benchmarked magic:	2.245844470s
benchmarked div:	12.709085309s
benchmarked mul:	7.504838141s

Mul seems to take 15x the time magic does, cool!

Btw. the simple default cast of int32_t to double is slower than magic
for me, hence the use of union.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-05-15 11:00:19 -04:00
Kristian Høgsberg
f5df38959b Optimize wl_fixed_t to/from double conversion functions 2012-05-14 09:36:38 -04:00
Daniel Stone
c5aba11acc Add support for signed 24.8 decimal numbers
'fixed' is a signed decimal type which offers a sign bit, 23 bits of
integer precision, and 8 bits of decimal precision.  This is exposed as
an opaque struct with conversion helpers to and from double and int on
the C API side.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-05-08 14:40:39 -04:00
Kristian Høgsberg
f42d763cd0 tests: prefix event loop tests with event_loop_ 2012-05-08 09:58:01 -04:00
Kristian Høgsberg
d8dda50d27 tests: assert that mask is zero is post_dispatch callback 2012-05-08 09:57:17 -04:00
Kristian Høgsberg
550e8f3861 tests: Add timerfd test 2012-05-08 09:55:55 -04:00
Kristian Høgsberg
d56af2787e tests: Add signal test case
Doesn't necessarily catch the signalfd bug just fixed, since that only
triggers when an uninitialized int is negative.
2012-05-08 09:41:37 -04:00
Daniel Stone
0a828e098c tests: Fix out-of-tree builds
Make sure we include any generated headers from src/ as well, like
wayland-version.h.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
2012-05-02 16:01:04 -04:00
Kristian Høgsberg
bf1c2f3257 tests: Just list tests under the TESTS variable 2012-04-26 08:06:43 -04:00
Pekka Paalanen
ff50f6bfc4 os: wrap accept4(SOCK_CLOEXEC)
Some system C libraries do not have SOCK_CLOEXEC, and completely miss
accept4(), too. Provide a fallback for this case.

This changes the behaviour: no error messages are printed now for
failing to set CLOEXEC but the file descriptor is closed.

The unit test for this wrapper is NOT included.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-25 09:37:42 +03:00
Pekka Paalanen
b2eaf870cf os: wrap epoll_create
Some system C libraries do not have epoll_create1() nor EPOLL_CLOEXEC,
provide a fallback.

Add tests for the wrapper.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-25 09:37:42 +03:00
Pekka Paalanen
35d5053c62 os: wrap recvmsg(MSG_CMSG_CLOEXEC)
Some system C libraries do not have MSG_CMSG_CLOEXEC. This flag would
automatically set O_CLOEXEC flag on any received file descriptors.

Provide a fallback that does it manually. If setting CLOEXEC fails, the
file descriptor is closed immediately, which will lead to failures but
avoid leaks. However, setting CLOEXEC is not really expected to fail
occasionally.

Add tests for the wrapper. The setup is copied from connection-test.c.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-25 09:37:42 +03:00
Pekka Paalanen
2ccaf918ab tests: silence warnings from pipe()
warning: ignoring return value of ‘pipe’, declared with attribute
warn_unused_result

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-25 09:32:58 +03:00
Pekka Paalanen
1463a41f89 os: wrap F_DUPFD_CLOEXEC
Some system C libraries do not have F_DUPFD_CLOEXEC. Provide a fallback.

Add tests for the new wl_os_dupfd_cloexec() wrapper.

Add per-wrapper call counters in os_wrappers-test.c. Makes it easier to
determine the minimum required number of wrapped calls.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-25 09:32:58 +03:00
Pekka Paalanen
3b29783dc8 os: define SOCK_CLOEXEC on Linux
If it's not already defined, and we are on Linux, #define it. This gets
rid of a load of #ifdefs. This should also allow to use it when the
kernel supports it, but the libc does not define it.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-25 09:32:57 +03:00
Kristian Høgsberg
e7dd32710f tests: Test invoking closures built with wl_closure_vmarshal() 2012-04-22 14:17:27 -04:00
Kristian Høgsberg
1901d66ffc connection: Move closure object out of wl_connection 2012-04-22 13:49:35 -04:00
Pekka Paalanen
f52a901f88 tests: add .gitignore
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-20 16:28:15 +03:00
Pekka Paalanen
7134a439c1 os: wrap socket(SOCK_CLOEXEC) calls
Some system C libraries do not offer SOCK_CLOEXEC flag.

Add a new header for OS compatibility wrappers. Wrap socket() calls into
wl_os_socket_cloexec() which makes sure the O_CLOEXEC flag gets set on
the file descriptor.

On systems having SOCK_CLOEXEC this uses the old socket() call, and
falls back if it fails due to the flag (kernel not supporting it).

wayland-os.h is private and not exported.

Add close-on-exec tests for both normal and forced fallback paths.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-20 16:26:37 +03:00
Pekka Paalanen
da6b1a8e47 tests: support testing fd inheritance over exec
Add facility for testing how (many) file descriptors survive an exec.
This allows implementing O_CLOEXEC tests.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-20 15:06:27 +03:00
Pekka Paalanen
7c0aa1a4a3 tests: plug fd leaks in free_source_with_data
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-20 14:58:31 +03:00
Pekka Paalanen
e0561ac68d tests: detect fd leaks
Detect file descriptor leaks in tests.

Add a sanity test to verify that we catch the leaks.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-20 14:58:31 +03:00
Kristian Høgsberg
d44074900d tests: Add more sanity test to make sure we catch different failure modes 2012-04-19 12:37:40 -04:00
Kristian Høgsberg
41570a5ed9 tests: Make sure unused malloc() doesn't get optimized away 2012-04-19 12:07:20 -04:00
Pekka Paalanen
55489883c4 tests: add sanity-test
Test the testing framework itself, so that it catches the errors we
expect it to.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-19 14:46:52 +03:00
Pekka Paalanen
bb74adbc4d tests: add support for tests expected to fail
Add a new macro FAIL_TEST that can be used to define tests that are
supposed to fail. To distinguish the supposed outcome of a test, add a
field to 'struct test'.

However, simply adding a field to 'struct test' will make all tests past
the first one in an executable to be garbage. Apparently, the variables
of type 'struct test' have different alignment when put into a special
section than otherwise, and the compiler will get the skip from one
'struct test' to the next wrong.

Explicitly specify the alingment of 'struct test' to be 16 bytes, which
is what it seems to be in the special section on x86_64.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-19 14:26:51 +03:00
Pekka Paalanen
56426d8a4a tests: stylish test-runner.c
Fix a typo, add a comment, change the print format, and add a variable
that will ease implementing tests that are expected to fail.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-19 14:06:08 +03:00
Pekka Paalanen
b1d4eb24c6 tests: fail build if NDEBUG is defined
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-19 12:14:19 +03:00
Pekka Paalanen
84464a3e9b tests: put common test source files in a variable
Makes all test targets have the same common make dependencies.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2012-04-19 12:12:13 +03:00
Kristian Høgsberg
b68b5e9e0c tests: Make leak check work again by setting default visibility for malloc/free
We compile the test cases with -fvisibility=hidden which makes
our malloc/free wrappers fail to override system malloc/free.
2012-04-13 10:13:49 -04:00
Kristian Høgsberg
d8b66a00f4 tests: Fix warning in memory leak assert 2012-04-13 10:13:21 -04:00
Kristian Høgsberg
ac06144cc9 tests: Fix signedness warnings 2012-04-13 10:11:11 -04:00
Kristian Høgsberg
fa5f7b1191 server: Add client destroy signal 2012-04-13 09:53:15 -04:00
U. Artie Eoff
a0e590a0f3 Add simple memory leak check to all tests.
Wrap all tests with a memory balance check to detect potential
memory leaks.
Fixed a few tests that had memory leaks contained in the tests
themselves.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
2012-03-24 14:37:42 -04:00
Kristian Høgsberg
9086b60d81 connection-test: Add test case to stress connection buffers
This catches the bug fixed in cab70c9e5d.
2012-03-24 14:35:53 -04:00
Kristian Høgsberg
b01ae07727 connection-test: Test fd transport 2012-03-24 14:27:30 -04:00
Kristian Høgsberg
fa4769cadd connection-test: Add more test cases 2012-03-23 16:57:34 -04:00
Kristian Høgsberg
33ad8a3315 connection-test: Store expected result in struct marshal_data 2012-03-23 16:56:19 -04:00
Kristian Høgsberg
0ca52cce98 tests: Add marshal+demarshal connection test 2012-03-23 11:41:34 -04:00
Kristian Høgsberg
f67f6395b1 tests: Use different connections for read and write tests
The connection tests so far only use one connection at a time, but this
prepares for tests that use a connection on both sides of the socket.
2012-03-23 11:32:17 -04:00
Kristian Høgsberg
7746a80e2a tests: Remove debug printf 2012-03-21 10:32:06 -04:00
Kristian Høgsberg
f48bd0714a tests: Add test case for freeing source with pending data 2012-03-21 10:30:19 -04:00
Ander Conselvan de Oliveira
707623f0cb test: add a unit test for the event loop post dispatch check 2012-03-20 15:49:27 -04:00
Kristian Høgsberg
46df9232fa test-runner.c: Consolidate test running code 2012-03-05 22:29:53 -05:00
Kristian Høgsberg
4bc5a0ab2c tests: Add demarshal tests 2012-03-05 22:26:17 -05:00
Kristian Høgsberg
b2afde6f18 tests: Add more marshal tests 2012-03-05 21:53:38 -05:00
Kristian Høgsberg
d86718fc33 tests: Simplify connection tests a bit 2012-03-05 21:40:01 -05:00
Kristian Høgsberg
efab74e956 tests: Add wl_list tests 2012-03-05 21:38:25 -05:00
Kristian Høgsberg
b4351bc08e tests: More wl_map tests 2012-03-05 21:14:57 -05:00
Gaetan Nadon
c1804b5735 tests: makefile error: missing test-runner.h
Detected by running distcheck

Signed-off-by: Gaetan Nadon <memsize@videotron.ca>
2012-03-05 10:57:57 -05:00
Gaetan Nadon
bb4b05bc8d check: connection-test fails to link to ffi
This prevents distcheck from completing.
Moving the -lffi at the end of the command fixes the problem.

Signed-off-by: Gaetan Nadon <memsize@videotron.ca>
2012-03-04 15:03:03 -05:00
Kristian Høgsberg
8e2cac7ae4 Add wl_array_for_each 2012-03-04 13:40:49 -05:00
Kristian Høgsberg
87a1e59992 tests: Add connection marshalling tests 2012-03-03 00:29:21 -05:00
Kristian Høgsberg
22834deca7 tests: Add connection tests 2012-03-02 23:59:50 -05:00
Kristian Høgsberg
d2067508c1 test-runner: Fix warnings 2012-03-02 23:42:07 -05:00
Kristian Høgsberg
e655059256 tests: Print test status after running test
This way assert output will be a line by itself, which is easier to read
and lets editors such as emacs step through failed assertions.
2012-03-02 22:45:28 -05:00
Kristian Høgsberg
62d2569954 tests: Add Unit tests for wl_map and wl_array data structures
We use a simple test-runner helper that runs each test in a separate
process and reports the pass/fail rate at the end.
2012-03-02 18:05:33 -05:00