mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-02-03 20:30:27 +01:00
test: if we're in a debugger, use single-fork mode only
Don't fork by default if we're in gdb. Note that is_debugger_attached() is now inside #ifndef LITEST_NO_MAIN, gdb for the litest selftest will now require a manual CK_FORK=no. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
681f967c8f
commit
6cde53fc1d
2 changed files with 38 additions and 36 deletions
|
|
@ -11,7 +11,8 @@ The test suite has a make-like job control enabled by the `-j` or `--jobs`
|
|||
flag and will fork off as many parallel processes as given by this flag. The
|
||||
default if unspecified is 8. When debugging a specific test case failure it
|
||||
is recommended to employ test filtures (see @ref test-filtering) and disable
|
||||
parallel tests.
|
||||
parallel tests. The test suite automatically disables parallel make when run
|
||||
in gdb.
|
||||
|
||||
@section test-config X.Org config to avoid interference
|
||||
|
||||
|
|
|
|||
|
|
@ -751,35 +751,6 @@ _litest_add_ranged_for_device(const char *name,
|
|||
litest_abort_msg("Invalid test device type");
|
||||
}
|
||||
|
||||
static int
|
||||
is_debugger_attached(void)
|
||||
{
|
||||
int status;
|
||||
int rc;
|
||||
int pid = fork();
|
||||
|
||||
if (pid == -1)
|
||||
return 0;
|
||||
|
||||
if (pid == 0) {
|
||||
int ppid = getppid();
|
||||
if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0) {
|
||||
waitpid(ppid, NULL, 0);
|
||||
ptrace(PTRACE_CONT, NULL, NULL);
|
||||
ptrace(PTRACE_DETACH, ppid, NULL, NULL);
|
||||
rc = 0;
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
_exit(rc);
|
||||
} else {
|
||||
waitpid(pid, &status, 0);
|
||||
rc = WEXITSTATUS(status);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
litest_log_handler(struct libinput *libinput,
|
||||
enum libinput_log_priority pri,
|
||||
|
|
@ -988,12 +959,6 @@ litest_run(int argc, char **argv)
|
|||
return 1;
|
||||
}
|
||||
|
||||
if (in_debugger == -1) {
|
||||
in_debugger = is_debugger_attached();
|
||||
if (in_debugger)
|
||||
setenv("CK_FORK", "no", 0);
|
||||
}
|
||||
|
||||
if (getenv("LITEST_VERBOSE"))
|
||||
verbose = 1;
|
||||
|
||||
|
|
@ -3105,6 +3070,9 @@ litest_parse_argv(int argc, char **argv)
|
|||
JOBS_CUSTOM
|
||||
} want_jobs = JOBS_DEFAULT;
|
||||
|
||||
if (in_debugger)
|
||||
want_jobs = JOBS_SINGLE;
|
||||
|
||||
while(1) {
|
||||
int c;
|
||||
int option_index = 0;
|
||||
|
|
@ -3151,6 +3119,35 @@ litest_parse_argv(int argc, char **argv)
|
|||
}
|
||||
|
||||
#ifndef LITEST_NO_MAIN
|
||||
static int
|
||||
is_debugger_attached(void)
|
||||
{
|
||||
int status;
|
||||
int rc;
|
||||
int pid = fork();
|
||||
|
||||
if (pid == -1)
|
||||
return 0;
|
||||
|
||||
if (pid == 0) {
|
||||
int ppid = getppid();
|
||||
if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0) {
|
||||
waitpid(ppid, NULL, 0);
|
||||
ptrace(PTRACE_CONT, NULL, NULL);
|
||||
ptrace(PTRACE_DETACH, ppid, NULL, NULL);
|
||||
rc = 0;
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
_exit(rc);
|
||||
} else {
|
||||
waitpid(pid, &status, 0);
|
||||
rc = WEXITSTATUS(status);
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static void
|
||||
litest_list_tests(struct list *tests)
|
||||
{
|
||||
|
|
@ -3175,6 +3172,10 @@ main(int argc, char **argv)
|
|||
setenv("CK_DEFAULT_TIMEOUT", "30", 0);
|
||||
setenv("LIBINPUT_RUNNING_TEST_SUITE", "1", 1);
|
||||
|
||||
in_debugger = is_debugger_attached();
|
||||
if (in_debugger)
|
||||
setenv("CK_FORK", "no", 0);
|
||||
|
||||
mode = litest_parse_argv(argc, argv);
|
||||
if (mode == LITEST_MODE_ERROR)
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue