87 Commits

Author SHA1 Message Date
Joonas Lahtinen
a95033fdbc tests: install test programs to libexec
Install the test programs by default so that they can be packaged.

Tested with the testdisplay test so that it still runs after the
modifications as it depends on a data file to be present. Need to
pass -r option to enable QR code display on success (PNG data file).

Packaging is useful when building a complete software stack for a
DUT from scratch. This should bring us closer to achieving a
built-from-scratch testing workflow.

Package maintainers can always decide to ignore the installed files.

v2:
- Install more tests including scripts and their data

v3:
- Add clarification to commit message about why we do this.
  (Chris Wilson & Thomas Wood)
- Change libexec into pkglibexec to comply to standard
  (Thomas Wood)
- Do not install $(common_files). (Thomas Wood)
- Make it really obvious the installed files are tests by using
  tests directory name to avoid any confusion with packagers.

v4:
- Fixed commit message.

v5:
- Add file locator helper to retain backwards compatibility.
  (Thomas Wood)
- Test with testdisplay -r option that draws the .png file.

Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Thomas Wood <thomas.wood@intel.com>
Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-04-02 16:32:47 +01:00
Thomas Wood
47f6b1305c igt.cocci: check the return values of various functions
Add rules to fix unused-result warnings when compiling with
_FORTIFY_SOURCE defined and apply them to the library and tests.

Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-03-26 15:50:59 +00:00
Thomas Wood
277ca2b992 lib: print a stack trace when a test assertion fails
Add an optional dependency on libunwind to print stack traces when a
test assertion fails.

Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-03-26 15:50:05 +00:00
Chris Wilson
7763349a9a igt/gem_concurrent_blit: Separate out the combinatorial explosion
Apparently nobody else likes testing and debugging GEM coherency issues.
However, this also means that QA is skipping these vital tests. Split
out a set of canaries into igt/gem_concurrent_blit and keep the rest in
igt/gem_concurrent_all.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=89497
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2015-03-26 08:15:19 +00:00
Chris Wilson
2fa35c7316 lib/core: Silence internally used signals
We use SIGTERM to kill off child processes. We use it a lot. Reporting
everytime we use it is just spam. Treat the similar user signals
(SIGINT, SIGQUIT and the should-never-have-been SIGPIPE) similarly to
reduce noise.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Thomas Wood <thomas.wood@intel.com>
2015-03-26 08:15:18 +00:00
Daniel Vetter
4fec18e5e0 lib/core: add interactive debug point to igt_fail
Useful for inspecting the screen state in kms tests when they fail.

Also move the screen clearing in kms_cursor_crc to the bottom.

Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
2015-03-23 11:02:28 +01:00
Thomas Wood
a6c40c7665 lib: move igt_interactive_debug into igt_core.c
igt_interactive_debug should be defined in igt_core.c, rather than the
header, to avoid it being defined more than once.

Reported-by: Damien Lespiau <damien.lespiau@intel.com>
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-03-12 15:11:11 +00:00
Chris Wilson
b8db5d60e0 lib/core: Make the start of the debug output more clear
I missed the quiet "Log start" between the test failure and the debug
output (and so was very confused by the repetition). You have to shout
at me!

v2: Thomas suggested I make the end of the logging clear as well. Since
I completely missed that there was a end marker, he must be right!

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Thomas Wood <thomas.wood@intel.com>
2015-03-06 15:43:03 +00:00
Daniel Vetter
f45698df8b lib/igt_core: don't add newlines in logging functions
igt_kms extensively uses line continuation when dumping state updates
at the debug level. They got badly mangled with the recent changes to
for the log handling functions. Two separate fixes:
- Don't prepend domain and other metainformation when it's just a
  continuation line.
- Dont add newlines when dumping the log recorder.

If someone interleaves different log level messages this will go awry,
but really just don't do that.

Cc: Thomas Wood <thomas.wood@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
2015-02-27 19:34:38 +01:00
Thomas Wood
4ff4ea601a lib: print the signal name to stderr when handling a signal
Print the received signal name to stderr when handling a signal. This
uses an array of handled signal names since strsignal() only provides
descriptions.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-25 16:50:13 +00:00
Thomas Wood
8fb19782f8 lib: remove handled option arguments from argv
Remove options from argv that have been handled by getopt to allow
additional non-option parameters to be processed in the test application.

This fixes issues when using options such as --debug with tests that accept
additional non-option parameters.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-25 16:48:25 +00:00
Thomas Wood
55cc132b32 lib: use defines for igt_simple_init and igt_subtest_init
Using defines removes an extra function call and prepares for changes
to the command line argument handling.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-25 16:48:25 +00:00
Thomas Wood
f8fd4c977a lib: print recent log messages to stderr when a test or subtest fails
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-17 11:24:04 +00:00
Thomas Wood
a5f21726cd lib: add a ring buffer for log entries
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-17 11:24:04 +00:00
Thomas Wood
16cfa37a50 lib: add exit status message to simple tests
Add an exit status message to simple tests, similar to the one printed
for subtests. This includes the test outcome and the time taken to run
the test.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-09 14:39:41 +00:00
Thomas Wood
9942a40437 lib: add subtest start and exit status code messages to debug output
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-09 14:39:41 +00:00
Thomas Wood
2b05ecfb06 lib: validate subtest names
Subtest names should only contain '-', '_' and alphanumeric characters.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-09 14:39:41 +00:00
Thomas Wood
61737903ad lib: print warning and critical messages when listing subtests
These messages are sent to stderr and could indicate an issue when
enumerating subtests.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-09 14:39:41 +00:00
Thomas Wood
a228223ffa lib: warning messages should be sent to stderr
This is a regression from commit df11a0f (lib: add a critical warning
level).

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-02-09 14:39:41 +00:00
Rodrigo Vivi
3d65ff780d lib: s/IGT_DEBUG_INTERACTIVE/--interactive-debug=var
Use cmdline variable for interactive debug instead of env var.

v2: Make interactive-debug domain optional and use "all" when not set.

Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-01-20 11:36:10 +01:00
Thomas Wood
0167619bbc lib: use critical log level for assertion failure messages
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-01-16 11:11:10 +00:00
Thomas Wood
df11a0f4a8 lib: add a critical warning level
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2015-01-16 11:11:10 +00:00
Alan Coopersmith
843beb152b Don't try to use CLOCK_MONOTONIC_COARSE on OS'es that don't support it
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-01-06 09:29:45 +01:00
Alan Coopersmith
95ea5d5c0b Provide sighandler_t fallback for non-GNU-libc platforms
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-01-06 09:29:45 +01:00
Alan Coopersmith
f04b9dfba0 Need to #include <libgen.h> for basename() on Solaris
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-01-06 09:29:45 +01:00
Alan Coopersmith
99e6defbe7 Use pthread calls instead of raw syscalls on non-Linux systems
Raw system calls aren't portable to other kernels.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2015-01-06 09:29:45 +01:00
Chris Wilson
c49a7e9163 lib/core: Fix compile error from rebasing
s/KMSG_INFO/KERN_INFO/

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2015-01-05 14:34:58 +00:00
Chris Wilson
d8bf7e17cb lib/core: Show the exitcode in kmsg as well
This provides symmetry with logging the start of the test via kmsg.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2015-01-05 14:12:02 +00:00
Thomas Wood
f59bbf7e8f lib: fix a few documentation warnings
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-12-12 14:18:12 +00:00
Thomas Wood
5fe9c88bda lib: add optional log domain filtering
v2: add an "application" filter for the default domain (used by
    applications)

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-12-11 17:57:03 +00:00
Thomas Wood
8161a21762 lib: introduce log domains
Log domains can be used to identify the source of log messages, such as
the test being run or the helper library.

v2: Add separate domains for different parts of the helper library and
    use an empty default domain for applications.
    Expand the log output to include the process name and the log level
    of the message in addition to the domain and pid.
    Print the expanded message only for warning and debug messages.

v3: check for glibc before using program_invocation_short_name

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-12-11 17:55:15 +00:00
Thomas Wood
a5425a101c docs: add a glossary of test name terms
Add a glossary of test name terms based on the details in
tests/NAMING-CONVENTION.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-12-04 16:07:55 +00:00
Thomas Wood
dbac905600 lib: ensure subtests are not added to simple tests
Simple tests do not support subtests, so fail if igt_subtest is used in
one.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-11-25 15:18:48 +00:00
Thomas Wood
ebab9f080b lib: only skip subsequent tests if a timeout occurs outside of a subtest
Make timeout behaviour more consistent with igt_fail, where subsequent
subtests are only skipped if the failure occurs outside of a subtest.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=85718
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-11-13 14:27:57 +00:00
Thomas Wood
f8b3c704af lib: add the ability to include a description with a test
The IGT_TEST_DESCRIPTION macro can be used to define a description for a
test.

v2: Remove semicolon from end of macro (Damien Lespiau)
    Add API documentation for the macro.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-11-06 13:24:29 +00:00
Tim Gore
5782eca1e1 lib/igt_core.c: disable lowmemorykiller during tests
Several IGT tests cycle through a lot of GEM memory and
when running these tests on Android they tend to get
killed by the lowmemorykiller. The lowmemorykiller really
is not usefull in this context and is just preventing the
test from doing its job. This commit adds a function to
disable the lowmemorykiller by writing "9999" to its
oom adj parameter, which means it will never "select"
any process to kill. The normal linux oom killer is still
there to protect the kernel.
The low memory killer is disabled during the common
init function and then re-enabled by the exit handler.
To make this work for single tests the exit handler is now
installed in the common init function also so that it is
invoked for all tests.
This is just a hack to get round the fact that the i915
driver uses the concept of purgeable memory which is not
understood by the lowmemorykiller. If this ever gets
fixed then this patch can be removed.

Signed-off-by: Tim Gore <tim.gore@intel.com>
[danvet: A bit of polish (coding style, static and rename
check_igt_exit to common_exit_handler, drop the is_disabled check
since we only call this once now).]
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-10-01 14:44:30 +02:00
Thomas Wood
756764a4e7 lib: ensure any buffers are flushed before fork
Flush any buffers before forking to prevent duplicated output.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-09-30 17:54:02 +01:00
Thomas Wood
519f377ddd doc: various spelling and typo fixes
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-09-30 17:54:02 +01:00
Tim Gore
f33fa71481 lib/igt_core: make single/simple tests use igt_exit
Currently tests that use igt_simple_main will simply call
"exit()" if they pass, making it difficult to ensure that
any required cleanup is done. At present this is not an
issue, but it will be when I submit a patch to turn off the
lowmemorykiller for all tests.

Signed-off-by: Tim Gore <tim.gore@intel.com>
[danvet: Also update api docs.]
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
2014-09-29 16:57:49 +02:00
Chris Wilson
91a432721c core: Display subtest walltime
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2014-09-06 12:11:08 +01:00
Paulo Zanoni
a16ebccaee igt_core: zero exit_handler_count before forking
If we don't reset exit_handler_count before forking, we may have a
case where the forked process is killed before it even does
"exit_handler_count = 0": in that case, it is still finishing forking.
When that happens, we may end up calling our exit handlers. On the
specific bug I'm investigating, we call igt_reset_connnectors(), which
ends up in a deadlock inside malloc_atfork. If we attach gdb to the
forked process and get a backtrace, we have:

(gdb) bt
0  __lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
1  0x00007f15634d36bf in _L_lock_10524 () from /lib/x86_64-linux-gnu/libc.so.6
2  0x00007f15634d12ef in malloc_atfork (sz=139729840351352, caller=<optimized out>) at arena.c:181
3  0x00007f15640466a1 in drmMalloc () from /usr/lib/x86_64-linux-gnu/libdrm.so.2
4  0x00007f1564049ad7 in drmModeGetResources () from /usr/lib/x86_64-linux-gnu/libdrm.so.2
5  0x0000000000408f84 in igt_reset_connectors () at igt_kms.c:1656
6  0x00000000004092dc in call_exit_handlers (sig=15) at igt_core.c:1130
7  fatal_sig_handler (sig=15) at igt_core.c:1154
8  <signal handler called>
9  0x00007f15634cce60 in ptmalloc_unlock_all2 () at arena.c:298
10 0x00007f156350ca3f in __libc_fork () at ../nptl/sysdeps/unix/sysv/linux/x86_64/../fork.c:188
11 0x000000000040a029 in __igt_fork_helper (proc=proc@entry=0x610fc4 <signal_helper>) at igt_core.c:910
12 0x000000000040459d in igt_fork_signal_helper () at igt_aux.c:110
13 0x0000000000402ab7 in __real_main63 () at bug.c:76
14 0x000000000040296e in main (argc=<optimized out>, argv=<optimized out>) at bug.c:63

After doing some searches for "stuck at malloc_atfork", it seems to me
we probably shouldn't be doing any malloc calls at this point of the
code, so the best way to do that is to make sure we can't really run
the exit handlers.

So on this patch, instead of resetting the exit handlers after
forking, we reset them before forking, and then restore the original
value on the parent process.

I can reproduce this problem by running "./kms_flip --run-subtest
2x-flip-vs-modeset" under an infinite loop. Usually after a few
hundred calls, we end up stuck on the deadlock mentioned above. QA
says this problem happens every time, but I'm not sure what is the
difference between our environments that makes the race condition so
much easier for them.

The kms_flip.c problem can be considered a regression introduced by:
commit eef768f283466b6d7cb3f08381f72ccf3951dc99
Author: Thomas Wood <thomas.wood@intel.com>
Date:   Wed Jun 18 14:28:43 2014 +0100
    tests: enable extra connectors in kms_flip and kms_pipe_crc_basic

even though this commit is not the one that introduced the real
problem.

It is also possible to reproduce this problem with a few modifications
to template.c:
  - Add a call to igt_enable_connectors() inside the first fixture.
  - Add igt_fork_signal_helper() and igt_stop_signal_helper() calls
    around subtest B.

Note that the crucial piece is that the parent actively kills helper
children, and if we skip tests this can happen _really_ fast. See e.g.

commit a031a1bf93b828585e7147f06145fc5030814547
Author: Daniel Vetter <daniel.vetter@ffwll.ch>
Date:   Fri Sep 13 16:43:22 2013 +0200

    lib/drmtest: ducttape over fork race

for past hilarity in this area.

Cc: Thomas Wood <thomas.wood@intel.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=81367
Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
2014-09-04 10:35:21 +02:00
Chris Wilson
de1e877be5 core: Add all kernel log levels
And notice that INFO is 6 not 5. This is because I had intended to use
KERN_NOTICE anyway...

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2014-07-30 12:04:46 +01:00
Thomas Wood
c3ba7740c1 lib: check test options for conflicts
Check any test specific options for conflicts with the standard set of
options.

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-07-30 11:13:13 +01:00
Thomas Wood
fc5e25750f lib: avoid getopt value conflicts with tests
Most tests use a printable character as the value for getopt to return,
so avoid conflicts by using non-printing values for the standard options.

v2: fix "-h" short option

Signed-off-by: Thomas Wood <thomas.wood@intel.com>
2014-07-30 11:13:13 +01:00
Chris Wilson
b9e7637542 core: Inject program name into dmesg
Write the program name if !list_only so that we associate oops with
simple tests.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2014-07-25 14:39:18 +01:00
Chris Wilson
e0dffbdeda core: Improve phrasing for test requirements
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2014-07-25 14:39:18 +01:00
Chris Wilson
52915fc88a core: Inject subtest message into dmesg
One of the side-effects we test for are kernel oops and knowing the
guilty subtest can help speed up debugging. We can write to /dev/kmsg to
inject messages into dmesg, so let's do so before the start of every
test.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2014-07-24 14:54:30 +01:00
Chris Wilson
66e46630f8 igt_core: Read manpages more carefully for WNOHANG
/me hides

I thought it said it would not return for a signal and stopped thinking.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2014-07-24 12:02:36 +01:00
Chris Wilson
745945546f igt_core: Refactor igt_stop_helper() to use igt_wait_helper()
Reduce code duplication as the igt_stop_helper can reuse
igt_wait_helper() to replace its own waiting routine.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2014-07-24 11:52:37 +01:00
Chris Wilson
bd3cf81e98 core: Only use signalsafe functions inside signal handlers
The atexit() and signal() callbacks both need to only use signalsafe
functions - that excludes the use of assert. So simplify
fork_helper_exit_handler() and children_exit_handler().

__lll_lock_wait_private () at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
0x00007fd630883d2b in _L_lock_13840 () from /lib/x86_64-linux-gnu/libc.so.6
0x00007fd630881df8 in __GI___libc_realloc (oldmem=0xfcb010, bytes=88) at malloc.c:3025
0x00007fd63087111b in _IO_vasprintf (result_ptr=0x7fff35dc4780, format=<optimised out>, args=args@entry=0x7fff35dc4658) at vasprintf.c:84
0x00007fd630852907 in ___asprintf (string_ptr=string_ptr@entry=0x7fff35dc4780, format=format@entry=0x7fd63097f718 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n") at asprintf.c:35
0x00007fd63082dd92 in __assert_fail_base (fmt=0x7fd63097f718 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x40cff5 "ret == 0", file=file@entry=0x4108d1 "igt_core.c", line=line@entry=872, function=function@entry=0x410ea0 <__PRETTY_FUNCTION__.8052> "children_exit_handler") at assert.c:57
0x00007fd63082dee2 in __GI___assert_fail (assertion=assertion@entry=0x40cff5 "ret == 0", file=file@entry=0x4108d1 "igt_core.c", line=line@entry=872, function=function@entry=0x410ea0 <__PRETTY_FUNCTION__.8052> "children_exit_handler") at assert.c:101
0x000000000040b03f in children_exit_handler (sig=<optimised out>) at igt_core.c:872
0x000000000040b089 in call_exit_handlers (sig=2) at igt_core.c:1029 fatal_sig_handler (sig=2) at igt_core.c:1053 <signal handler called>
0x00007fd6308bfe63 in __libc_fork () at ../nptl/sysdeps/unix/sysv/linux/x86_64/../fork.c:130
0x00007fd630bd6045 in __fork () at ../nptl/sysdeps/unix/sysv/linux/pt-fork.c:25
0x000000000040c51a in __igt_fork () at igt_core.c:900
0x00000000004036c2 in forking_evictions (ops=0x614360 <fault_ops>, surface_size=1048576, flags=5, trash_surfaces=<optimised out>, working_surfaces=338, fd=4) at eviction_common.c:203
test_forking_evictions (size=1048576, flags=5, count=338, fd=4) at gem_userptr_blits.c:1086
main (argc=1, argv=0x7fff35dc5328) at gem_userptr_blits.c:1478

Reported-by: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2014-07-24 11:50:00 +01:00