mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-30 20:00:09 +01:00
test: collect test case failures and print them on each fd
When running the test suite in full fork mode, the error messages are in the quite verbose output and searching for them is annoying. Work around this by opening a pipe to each subprocess and writing the failed test cases to that pipe. When all tests have finished, print the messages to stdout. This way the failures are always the last thing printed by the test suite. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
43de03a08c
commit
613ecda1cb
1 changed files with 43 additions and 3 deletions
|
|
@ -787,7 +787,7 @@ litest_free_test_list(struct list *tests)
|
|||
}
|
||||
|
||||
static int
|
||||
litest_run_suite(struct list *tests, int which, int max)
|
||||
litest_run_suite(struct list *tests, int which, int max, int error_fd)
|
||||
{
|
||||
int failed = 0;
|
||||
SRunner *sr = NULL;
|
||||
|
|
@ -865,6 +865,19 @@ litest_run_suite(struct list *tests, int which, int max)
|
|||
|
||||
srunner_run_all(sr, CK_ENV);
|
||||
failed = srunner_ntests_failed(sr);
|
||||
if (failed) {
|
||||
TestResult **trs;
|
||||
|
||||
trs = srunner_failures(sr);
|
||||
for (int i = 0; i < failed; i++) {
|
||||
dprintf(error_fd,
|
||||
":: Failure: %s:%d:%s\n",
|
||||
tr_lfile(trs[i]),
|
||||
tr_lno(trs[i]),
|
||||
tr_tcname(trs[i]));
|
||||
}
|
||||
free(trs);
|
||||
}
|
||||
srunner_free(sr);
|
||||
out:
|
||||
list_for_each_safe(n, tmp, &testnames, node) {
|
||||
|
|
@ -882,14 +895,29 @@ litest_fork_subtests(struct list *tests, int max_forks)
|
|||
int status;
|
||||
pid_t pid;
|
||||
int f;
|
||||
int pipes[max_forks];
|
||||
|
||||
for (f = 0; f < max_forks; f++) {
|
||||
int rc;
|
||||
int pipefd[2];
|
||||
|
||||
rc = pipe2(pipefd, O_NONBLOCK|O_NONBLOCK);
|
||||
assert(rc != -1);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
failed = litest_run_suite(tests, f, max_forks);
|
||||
close(pipefd[0]);
|
||||
failed = litest_run_suite(tests,
|
||||
f,
|
||||
max_forks,
|
||||
pipefd[1]);
|
||||
|
||||
litest_free_test_list(&all_tests);
|
||||
exit(failed);
|
||||
/* child always exits here */
|
||||
} else {
|
||||
pipes[f] = pipefd[0];
|
||||
close(pipefd[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -899,6 +927,18 @@ litest_fork_subtests(struct list *tests, int max_forks)
|
|||
failed = 1;
|
||||
}
|
||||
|
||||
for (f = 0; f < max_forks; f++) {
|
||||
char buf[1024] = {0};
|
||||
int rc;
|
||||
|
||||
while ((rc = read(pipes[f], buf, sizeof(buf) - 1)) > 0) {
|
||||
buf[rc] = '\0';
|
||||
fprintf(stderr, "%s", buf);
|
||||
}
|
||||
|
||||
close(pipes[f]);
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
|
|
@ -923,7 +963,7 @@ litest_run(int argc, char **argv)
|
|||
litest_setup_sighandler(SIGINT);
|
||||
|
||||
if (jobs == 1)
|
||||
failed = litest_run_suite(&all_tests, 1, 1);
|
||||
failed = litest_run_suite(&all_tests, 1, 1, STDERR_FILENO);
|
||||
else
|
||||
failed = litest_fork_subtests(&all_tests, jobs);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue