Commit Graph

34 Commits

Author SHA1 Message Date
Antonio Borneo
294ed97e64 log: remove "%m" from format strings by using strerror(errno)
The printf() format specifier "%m" is a glibc extension to print
the string returned by strerror(errno). While supported by other
libraries (e.g. uClibc and musl), it is not widely portable.

In Wayland code the format string is often passed to a logging
function that calls other syscalls before the conversion of "%m"
takes place. If one of such syscall modifies the value in errno,
the conversion of "%m" will incorrectly report the error string
corresponding to the new value of errno.

Remove all the occurrences of the specifier "%m" in Wayland code
by using directly the string returned by strerror(errno).

Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
2019-05-02 22:14:53 +02:00
Daniel Stone
01095a9ce4 tests: Remove memory leak checking infrastructure
There are far better ways to detect memory leaks, such as either
valgrind or ASan. Having Meson makes it really easy to use these tools
in our tests, and we can do that in CI as well.

Having these local wrappers actually completely broke ASan usage, so
remove them in favour of using the more powerful options.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-29 09:59:04 +01:00
Daniel Stone
23d3c67c9a tests: Use unique XDG_RUNTIME_DIR
Rather than using a hardcoded 'wayland-tests' directory under
the existing XDG_RUNTIME_DIR to use as the new runtime dir, use mkdtemp
to guarantee uniqueness. This fixes make -jN check, as well as just
happening to run 'make check' twice from the same session.

Signed-off-by: Daniel Stone <daniels@collabora.com>
Reported-by: Pekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Tested-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2016-11-10 13:30:28 +02:00
Eric Engestrom
ee4e21c8a3 tests: fix typo
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Reviewed-by: Armin Krezović <krezovic.armin@gmail.com>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
2016-05-02 17:46:35 -07:00
Bryce Harrington
773babedfc tests: Update boilerplate from MIT X11 license to MIT Expat license
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2015-06-12 15:31:24 -07:00
Bryce Harrington
76fe89ed53 tests: Fix FAIL in sanity-test (*timeout*) when Yama LSM enabled
This fixes a regression in the testsuite since c3653f7f, where four of
the timeout tests fail with "Timeouts suppressed" messages.

The timeouts are being suppressed because the testsuite is erroneously
detecting that a debugger is attached.  This detection mechanism
(adopted from libinput) uses ptrace to test if there is a debugger
parent process that can be attached.  Unfortunately, this is an
unreliable test: Kernel security policies exist to restrict the scope of
ptrace to prevent processes from snooping on one another.[1] This
security policy is set as the default on Ubuntu, and potentially other
Linux distributions.[2]

The Yama documentation suggests, "For software that has defined
application-specific relationships between a debugging process and its
inferior (crash handlers, etc), prctl(PR_SET_PTRACER, pid, ...) can be
used.  An inferior can declare which other process (and its descendents)
are allowed to call PTRACE_ATTACH against it."  This prctl call has no
effect if Yama LSM is not loaded.

The child needs to be synchronized to the client to prevent a race
condition where the child might try to operate before the parent has
finished its prctl call.  This synchronization is done via pipes.

This patch can be tested by running sanity-test with
/proc/sys/kernel/yama/ptrace_scope set to 0 or 1; the test must pass for
either value.

1: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=2d514487faf188938a4ee4fb3464eeecfbdcf8eb
2: https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace_Protection

Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Reviewed-by: Derek Foreman <derekf@osg.samsung.com>

v4: Allow parent to communicate error state to child to prevent leaving
child in zombie state if parent hits an error.

v5: Check errno instead of rc for error.  Don't waitpid on ppid.
Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
2015-02-06 14:39:36 -08:00
Marek Chalupa
8094426a41 test-runner: wait for concrete pid
After running a test in fork, we were waiting for any child to terminate.
It is OK unless the child forks again. If the child calls fork, the waitid can
catch the child's child termination, stop block and run another test
while the former test is still running. This is racy i. e. when adding socket.
Since we have test compositor which uses fork, this situation can occur
pretty frequently.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-02-04 19:43:08 -08:00
Marek Chalupa
68c11c48c0 tests: add possibility to disable leak check for single test
In tests that are using external libraries (i. e. pthread) we
can get failure because of leaks in the external library.
Until we have some better solution (if ever), let these (and only these)
tests to disable leak checks.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-01-28 17:17:22 +00:00
Marek Chalupa
d8e72f98f2 test-runner: move leak checking into function
1) now we can use it in the test-compositor
2) it looks better

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Daniel Stone <daniels@collabora.com>
2015-01-28 17:15:57 +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
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
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
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
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
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
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
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
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
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
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
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
46df9232fa test-runner.c: Consolidate test running code 2012-03-05 22:29:53 -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