| 1 |
/* |
| 2 |
* Copyright © 2024 Red Hat, Inc. |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice (including the next |
| 12 |
* paragraph) shall be included in all copies or substantial portions of the |
| 13 |
* Software. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 |
* DEALINGS IN THE SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#include "config.h" |
| 25 |
|
| 26 |
#include <errno.h> |
| 27 |
#include <inttypes.h> |
| 28 |
#include <sys/epoll.h> |
| 29 |
#include <sys/sysinfo.h> |
| 30 |
#include <sys/timerfd.h> |
| 31 |
#include <sys/wait.h> |
| 32 |
#ifdef HAVE_PIDFD_OPEN |
| 33 |
#include <sys/syscall.h> |
| 34 |
#endif |
| 35 |
#include <fcntl.h> |
| 36 |
#include <setjmp.h> |
| 37 |
#include <signal.h> |
| 38 |
#include <stdlib.h> |
| 39 |
#include <valgrind/valgrind.h> |
| 40 |
|
| 41 |
#include "util-files.h" |
| 42 |
#include "util-list.h" |
| 43 |
#include "util-multivalue.h" |
| 44 |
#include "util-stringbuf.h" |
| 45 |
|
| 46 |
#include "litest-runner.h" |
| 47 |
|
| 48 |
static bool use_jmpbuf; /* only used for max_forks = 0 */ |
| 49 |
static jmp_buf jmpbuf; |
| 50 |
|
| 51 |
/* musl doesn't have this one but it's not that important */ |
| 52 |
#ifndef HAVE_SIGABBREV_NP |
| 53 |
#define sigabbrev_np(...) "???" |
| 54 |
#endif |
| 55 |
|
| 56 |
static struct litest_runner *global_runner = NULL; |
| 57 |
|
| 58 |
enum litest_runner_logfds { |
| 59 |
FD_STDOUT, |
| 60 |
FD_STDERR, |
| 61 |
FD_LOG, |
| 62 |
FD_VALGRIND, |
| 63 |
_FD_LAST, |
| 64 |
}; |
| 65 |
|
| 66 |
struct litest_runner_test { |
| 67 |
struct litest_runner_test_description desc; |
| 68 |
struct list node; |
| 69 |
|
| 70 |
enum litest_runner_result result; |
| 71 |
int sig_or_errno; |
| 72 |
|
| 73 |
struct stringbuf logs[_FD_LAST]; |
| 74 |
pid_t pid; /* the test's PID, if any */ |
| 75 |
int read_fds[_FD_LAST]; /* logging fds while the test is running */ |
| 76 |
|
| 77 |
int epollfd; |
| 78 |
int pidfd; |
| 79 |
int timerfd; |
| 80 |
|
| 81 |
struct { |
| 82 |
usec_t start_usec; |
| 83 |
usec_t end_usec; |
| 84 |
} times; |
| 85 |
}; |
| 86 |
|
| 87 |
struct litest_runner { |
| 88 |
size_t max_forks; |
| 89 |
unsigned int timeout; |
| 90 |
bool verbose; |
| 91 |
bool use_colors; |
| 92 |
bool exit_on_fail; |
| 93 |
FILE *fp; |
| 94 |
|
| 95 |
int terminating; |
| 96 |
|
| 97 |
struct list tests; /* struct litest_runner_test */ |
| 98 |
struct list tests_running; /* struct litest_runner_test */ |
| 99 |
struct list tests_complete; /* struct litest_runner_test */ |
| 100 |
|
| 101 |
struct { |
| 102 |
time_t start; |
| 103 |
time_t end; |
| 104 |
usec_t start_usec; |
| 105 |
} times; |
| 106 |
|
| 107 |
struct { |
| 108 |
litest_runner_global_setup_func_t setup; |
| 109 |
litest_runner_global_teardown_func_t teardown; |
| 110 |
void *userdata; |
| 111 |
} global; |
| 112 |
}; |
| 113 |
|
| 114 |
/** |
| 115 |
* A global variable that the tests can use |
| 116 |
* to write log data to. Defaults to stdout |
| 117 |
* but if used by the tests it shows up as separate |
| 118 |
* from stdout in the logs. |
| 119 |
*/ |
| 120 |
int testlog_fd = STDOUT_FILENO; |
| 121 |
|
| 122 |
static void |
| 123 |
close_pipes(int fds[_FD_LAST]) |
| 124 |
{ |
| 125 |
for (int i = 0; i < _FD_LAST; i++) { |
| 126 |
if (fds[i] != -1) |
| 127 |
fsync(fds[i]); |
| 128 |
xclose(&fds[i]); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
static int |
| 133 |
init_pipes(int read_fds[_FD_LAST], int write_fds[_FD_LAST]) |
| 134 |
{ |
| 135 |
int r; |
| 136 |
int i; |
| 137 |
int pipe_max_size = 4194304; |
| 138 |
|
| 139 |
for (i = 0; i < _FD_LAST; i++) { |
| 140 |
read_fds[i] = -1; |
| 141 |
write_fds[i] = -1; |
| 142 |
} |
| 143 |
|
| 144 |
#ifdef __linux__ |
| 145 |
{ |
| 146 |
FILE *f; |
| 147 |
f = fopen("/proc/sys/fs/pipe-max-size", "re"); |
| 148 |
if (f) { |
| 149 |
if (fscanf(f, "%d", &r) == 1) |
| 150 |
pipe_max_size = min(r, pipe_max_size); |
| 151 |
fclose(f); |
| 152 |
} |
| 153 |
} |
| 154 |
#endif |
| 155 |
|
| 156 |
for (i = 0; i < _FD_LAST; i++) { |
| 157 |
int pipe[2]; |
| 158 |
|
| 159 |
r = pipe2(pipe, O_CLOEXEC | O_NONBLOCK); |
| 160 |
if (r < 0) |
| 161 |
goto error; |
| 162 |
read_fds[i] = pipe[0]; |
| 163 |
write_fds[i] = pipe[1]; |
| 164 |
#ifdef __linux__ |
| 165 |
/* Max pipe buffers, to avoid scrambling if reading lags. |
| 166 |
* Can't use blocking write fds, since reading too slow |
| 167 |
* then affects execution. |
| 168 |
*/ |
| 169 |
fcntl(write_fds[i], F_SETPIPE_SZ, pipe_max_size); |
| 170 |
#endif |
| 171 |
} |
| 172 |
|
| 173 |
return 0; |
| 174 |
error: |
| 175 |
r = -errno; |
| 176 |
close_pipes(read_fds); |
| 177 |
close_pipes(write_fds); |
| 178 |
return r; |
| 179 |
} |
| 180 |
|
| 181 |
static const char * |
| 182 |
litest_runner_result_as_str(enum litest_runner_result result) |
| 183 |
{ |
| 184 |
switch (result) { |
| 185 |
CASE_RETURN_STRING(LITEST_PASS); |
| 186 |
CASE_RETURN_STRING(LITEST_NOT_APPLICABLE); |
| 187 |
CASE_RETURN_STRING(LITEST_FAIL); |
| 188 |
CASE_RETURN_STRING(LITEST_SYSTEM_ERROR); |
| 189 |
CASE_RETURN_STRING(LITEST_TIMEOUT); |
| 190 |
CASE_RETURN_STRING(LITEST_SKIP); |
| 191 |
} |
| 192 |
|
| 193 |
litest_abort_msg("Unknown result %d", result); |
| 194 |
return NULL; |
| 195 |
} |
| 196 |
|
| 197 |
static void |
| 198 |
litest_runner_test_close(struct litest_runner_test *t) |
| 199 |
{ |
| 200 |
for (size_t i = 0; i < ARRAY_LENGTH(t->read_fds); i++) { |
| 201 |
xclose(&t->read_fds[i]); |
| 202 |
} |
| 203 |
xclose(&t->epollfd); |
| 204 |
xclose(&t->pidfd); |
| 205 |
xclose(&t->timerfd); |
| 206 |
} |
| 207 |
|
| 208 |
static void |
| 209 |
litest_runner_test_destroy(struct litest_runner_test *t) |
| 210 |
{ |
| 211 |
list_remove(&t->node); |
| 212 |
close_pipes(t->read_fds); |
| 213 |
if (t->pid != 0) { |
| 214 |
kill(t->pid, SIGTERM); |
| 215 |
t->pid = 0; |
| 216 |
} |
| 217 |
litest_runner_test_close(t); |
| 218 |
for (int i = 0; i < _FD_LAST; i++) { |
| 219 |
stringbuf_reset(&t->logs[i]); |
| 220 |
} |
| 221 |
free(t); |
| 222 |
} |
| 223 |
|
| 224 |
static void |
| 225 |
litest_runner_detach_tests(struct litest_runner *runner) |
| 226 |
{ |
| 227 |
struct litest_runner_test *t; |
| 228 |
|
| 229 |
list_for_each_safe(t, &runner->tests, node) { |
| 230 |
t->pid = 0; |
| 231 |
} |
| 232 |
list_for_each_safe(t, &runner->tests_complete, node) { |
| 233 |
t->pid = 0; |
| 234 |
} |
| 235 |
list_for_each_safe(t, &runner->tests_running, node) { |
| 236 |
t->pid = 0; |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
void |
| 241 |
litest_runner_destroy(struct litest_runner *runner) |
| 242 |
{ |
| 243 |
struct litest_runner_test *t; |
| 244 |
list_for_each_safe(t, &runner->tests, node) { |
| 245 |
litest_runner_test_destroy(t); |
| 246 |
} |
| 247 |
list_for_each_safe(t, &runner->tests_complete, node) { |
| 248 |
litest_runner_test_destroy(t); |
| 249 |
} |
| 250 |
list_for_each_safe(t, &runner->tests_running, node) { |
| 251 |
litest_runner_test_destroy(t); |
| 252 |
} |
| 253 |
free(runner); |
| 254 |
} |
| 255 |
|
| 256 |
static enum litest_runner_result |
| 257 |
litest_runner_test_run(const struct litest_runner_test_description *desc) |
| 258 |
{ |
| 259 |
const struct litest_runner_test_env env = { |
| 260 |
.rangeval = desc->rangeval, |
| 261 |
.params = desc->params, |
| 262 |
}; |
| 263 |
|
| 264 |
if (desc->setup) |
| 265 |
desc->setup(desc); |
| 266 |
|
| 267 |
enum litest_runner_result result = desc->func(&env); |
| 268 |
|
| 269 |
if (desc->teardown) |
| 270 |
desc->teardown(desc); |
| 271 |
|
| 272 |
return result; |
| 273 |
} |
| 274 |
|
| 275 |
static void |
| 276 |
sighandler_forked_child(int signal) |
| 277 |
{ |
| 278 |
struct sigaction act; |
| 279 |
sigemptyset(&act.sa_mask); |
| 280 |
act.sa_flags = 0; |
| 281 |
act.sa_handler = SIG_DFL; |
| 282 |
sigaction(signal, &act, NULL); |
| 283 |
|
| 284 |
/* abort() was probably called by litest_assert... which inserts |
| 285 |
* the backtrace anyway - we only need to backtrace the other signals |
| 286 |
*/ |
| 287 |
if (signal != SIGABRT) |
| 288 |
litest_backtrace(NULL); |
| 289 |
|
| 290 |
raise(signal); |
| 291 |
} |
| 292 |
|
| 293 |
static int |
| 294 |
litest_runner_fork_test(struct litest_runner *runner, struct litest_runner_test *t) |
| 295 |
{ |
| 296 |
pid_t pid; |
| 297 |
struct sigaction act; |
| 298 |
int write_fds[_FD_LAST]; |
| 299 |
int r; |
| 300 |
|
| 301 |
r = init_pipes(t->read_fds, write_fds); |
| 302 |
if (r < 0) { |
| 303 |
return -1; |
| 304 |
} |
| 305 |
|
| 306 |
pid = fork(); |
| 307 |
if (pid < 0) { |
| 308 |
int r = -errno; |
| 309 |
close_pipes(t->read_fds); |
| 310 |
close_pipes(write_fds); |
| 311 |
return r; |
| 312 |
} |
| 313 |
|
| 314 |
if (pid > 0) { /* parent */ |
| 315 |
close_pipes(write_fds); |
| 316 |
t->pid = pid; |
| 317 |
return pid; |
| 318 |
} |
| 319 |
|
| 320 |
/* child */ |
| 321 |
close_pipes(t->read_fds); |
| 322 |
|
| 323 |
/* Catch any crashers so we can insert a backtrace */ |
| 324 |
sigemptyset(&act.sa_mask); |
| 325 |
act.sa_flags = 0; |
| 326 |
act.sa_handler = sighandler_forked_child; |
| 327 |
sigaction(SIGSEGV, &act, NULL); |
| 328 |
sigaction(SIGBUS, &act, NULL); |
| 329 |
sigaction(SIGSEGV, &act, NULL); |
| 330 |
sigaction(SIGABRT, &act, NULL); |
| 331 |
/* SIGALARM is used for our timeout */ |
| 332 |
sigaction(SIGALRM, &act, NULL); |
| 333 |
|
| 334 |
r = dup2(write_fds[FD_STDERR], STDERR_FILENO); |
| 335 |
litest_assert_errno_success(r); |
| 336 |
setlinebuf(stderr); |
| 337 |
r = dup2(write_fds[FD_STDOUT], STDOUT_FILENO); |
| 338 |
litest_assert_errno_success(r); |
| 339 |
setlinebuf(stdout); |
| 340 |
|
| 341 |
/* For convenience in the tests, let this be a global variable. */ |
| 342 |
testlog_fd = write_fds[FD_LOG]; |
| 343 |
|
| 344 |
/* We're forked so we have a full copy of everything - but all we want |
| 345 |
* to do is avoid valgrind complaining about memleaks in the child |
| 346 |
* process. So let's cleanup everything, copy the one thing we |
| 347 |
* care about and proceed to the exit */ |
| 348 |
struct litest_runner_test_description desc = t->desc; |
| 349 |
litest_runner_detach_tests(runner); |
| 350 |
litest_runner_destroy(runner); |
| 351 |
|
| 352 |
/* Now run the actual test */ |
| 353 |
enum litest_runner_result result = litest_runner_test_run(&desc); |
| 354 |
|
| 355 |
close_pipes(write_fds); |
| 356 |
|
| 357 |
exit(result); |
| 358 |
} |
| 359 |
|
| 360 |
static char * |
| 361 |
valgrind_logfile(pid_t pid) |
| 362 |
{ |
| 363 |
const char *prefix = getenv("LITEST_VALGRIND_LOGDIR"); |
| 364 |
if (!prefix) |
| 365 |
prefix = "."; |
| 366 |
|
| 367 |
char *filename = strdup_printf("%s/valgrind.%d.log", prefix, pid); |
| 368 |
litest_assert_ptr_notnull(filename); |
| 369 |
|
| 370 |
return filename; |
| 371 |
} |
| 372 |
|
| 373 |
static void |
| 374 |
collect_file(const char *filename, struct stringbuf *b) |
| 375 |
{ |
| 376 |
int fd = open(filename, O_RDONLY); |
| 377 |
if (fd == -1) { |
| 378 |
_autofree_ char *msg = |
| 379 |
strdup_printf("Failed to find '%s': %m", filename); |
| 380 |
stringbuf_append_string(b, msg); |
| 381 |
} else { |
| 382 |
stringbuf_append_from_fd(b, fd, 0); |
| 383 |
close(fd); |
| 384 |
} |
| 385 |
} |
| 386 |
|
| 387 |
static bool |
| 388 |
litest_runner_test_collect_child(struct litest_runner_test *t) |
| 389 |
{ |
| 390 |
int r; |
| 391 |
int status; |
| 392 |
|
| 393 |
r = waitpid(t->pid, &status, WNOHANG); |
| 394 |
if (r <= 0) |
| 395 |
return false; |
| 396 |
|
| 397 |
if (WIFEXITED(status)) { |
| 398 |
t->result = WEXITSTATUS(status); |
| 399 |
if (RUNNING_ON_VALGRIND && t->result == 3) { |
| 400 |
char msg[64]; |
| 401 |
snprintf(msg, |
| 402 |
sizeof(msg), |
| 403 |
"valgrind exited with an error code, see logs\n"); |
| 404 |
stringbuf_append_string(&t->logs[FD_LOG], msg); |
| 405 |
t->result = LITEST_SYSTEM_ERROR; |
| 406 |
} |
| 407 |
switch (t->result) { |
| 408 |
case LITEST_PASS: |
| 409 |
case LITEST_SKIP: |
| 410 |
case LITEST_NOT_APPLICABLE: |
| 411 |
case LITEST_FAIL: |
| 412 |
case LITEST_TIMEOUT: |
| 413 |
case LITEST_SYSTEM_ERROR: |
| 414 |
break; |
| 415 |
#pragma GCC diagnostic push |
| 416 |
#pragma GCC diagnostic ignored "-Wswitch" |
| 417 |
case 0: |
| 418 |
/* if a test execve's itself allow for the normal |
| 419 |
* exit codes to map to the results */ |
| 420 |
t->result = LITEST_PASS; |
| 421 |
break; |
| 422 |
#pragma GCC diagnostic pop |
| 423 |
default: { |
| 424 |
char msg[64]; |
| 425 |
snprintf(msg, |
| 426 |
sizeof(msg), |
| 427 |
"Invalid test exit status %d", |
| 428 |
t->result); |
| 429 |
stringbuf_append_string(&t->logs[FD_LOG], msg); |
| 430 |
t->result = LITEST_FAIL; |
| 431 |
break; |
| 432 |
} |
| 433 |
} |
| 434 |
} else { |
| 435 |
if (WIFSIGNALED(status)) { |
| 436 |
t->sig_or_errno = WTERMSIG(status); |
| 437 |
t->result = (t->sig_or_errno == t->desc.args.signal) |
| 438 |
? LITEST_PASS |
| 439 |
: LITEST_FAIL; |
| 440 |
} else { |
| 441 |
t->result = LITEST_FAIL; |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
usec_t now = usec_from_uint64_t(0); |
| 446 |
now_in_us(&now); |
| 447 |
t->times.end_usec = now; |
| 448 |
|
| 449 |
if (RUNNING_ON_VALGRIND) { |
| 450 |
_autofree_ char *filename = valgrind_logfile(t->pid); |
| 451 |
collect_file(filename, &t->logs[FD_VALGRIND]); |
| 452 |
} |
| 453 |
|
| 454 |
t->pid = 0; |
| 455 |
|
| 456 |
return true; |
| 457 |
} |
| 458 |
|
| 459 |
static int |
| 460 |
litest_runner_test_setup_monitoring(struct litest_runner *runner, |
| 461 |
struct litest_runner_test *t) |
| 462 |
{ |
| 463 |
int pidfd = -1, timerfd = -1, epollfd = -1; |
| 464 |
struct epoll_event ev[10]; |
| 465 |
size_t nevents = 0; |
| 466 |
int r = 0; |
| 467 |
|
| 468 |
#ifdef HAVE_PIDFD_OPEN |
| 469 |
pidfd = syscall(SYS_pidfd_open, t->pid, 0); |
| 470 |
#else |
| 471 |
errno = ENOSYS; |
| 472 |
#endif |
| 473 |
/* If we don't have pidfd, we use a timerfd to ping us every 200ms */ |
| 474 |
if (pidfd < 0 && errno == ENOSYS) { |
| 475 |
pidfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); |
| 476 |
if (pidfd == -1) { |
| 477 |
r = -errno; |
| 478 |
goto error; |
| 479 |
} |
| 480 |
r = timerfd_settime(pidfd, |
| 481 |
0, |
| 482 |
&((struct itimerspec){ |
| 483 |
.it_interval.tv_nsec = 200 * 1000 * 1000, |
| 484 |
.it_value.tv_nsec = 200 * 1000 * 1000, |
| 485 |
}), |
| 486 |
NULL); |
| 487 |
if (r < 0) { |
| 488 |
r = -errno; |
| 489 |
goto error; |
| 490 |
} |
| 491 |
} |
| 492 |
|
| 493 |
/* Each test has an epollfd with: |
| 494 |
* - a timerfd so we can kill() it if it hangs |
| 495 |
* - a pidfd so we get notified when the test exits |
| 496 |
* - a pipe for stdout and a pipe for stderr |
| 497 |
* - a pipe for logging (the various pwtest functions) |
| 498 |
* - a pipe for the daemon's stdout |
| 499 |
*/ |
| 500 |
timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK); |
| 501 |
if (timerfd < 0) { |
| 502 |
r = -errno; |
| 503 |
goto error; |
| 504 |
} |
| 505 |
timerfd_settime(timerfd, |
| 506 |
0, |
| 507 |
&((struct itimerspec){ .it_value.tv_sec = runner->timeout }), |
| 508 |
NULL); |
| 509 |
|
| 510 |
epollfd = epoll_create(1); |
| 511 |
if (epollfd < 0) |
| 512 |
goto error; |
| 513 |
ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, .data.fd = pidfd }; |
| 514 |
ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, |
| 515 |
.data.fd = t->read_fds[FD_STDOUT] }; |
| 516 |
ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, |
| 517 |
.data.fd = t->read_fds[FD_STDERR] }; |
| 518 |
ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, |
| 519 |
.data.fd = t->read_fds[FD_LOG] }; |
| 520 |
ev[nevents++] = (struct epoll_event){ .events = EPOLLIN, .data.fd = timerfd }; |
| 521 |
|
| 522 |
for (size_t i = 0; i < nevents; i++) { |
| 523 |
r = epoll_ctl(epollfd, EPOLL_CTL_ADD, ev[i].data.fd, &ev[i]); |
| 524 |
if (r < 0) { |
| 525 |
r = -errno; |
| 526 |
goto error; |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
t->epollfd = epollfd; |
| 531 |
t->pidfd = pidfd; |
| 532 |
t->timerfd = timerfd; |
| 533 |
|
| 534 |
r = 0; |
| 535 |
|
| 536 |
error: |
| 537 |
if (r) { |
| 538 |
xclose(&pidfd); |
| 539 |
xclose(&timerfd); |
| 540 |
xclose(&epollfd); |
| 541 |
} |
| 542 |
|
| 543 |
return -r; |
| 544 |
} |
| 545 |
|
| 546 |
static int |
| 547 |
litest_runner_test_check_status(struct litest_runner_test *t) |
| 548 |
{ |
| 549 |
struct epoll_event e; |
| 550 |
|
| 551 |
if (t->pid == 0) /* nofork case */ |
| 552 |
return 0; |
| 553 |
|
| 554 |
while (true) { |
| 555 |
/* FIXME: this is a busy wait ... */ |
| 556 |
int r = epoll_wait(t->epollfd, &e, 1, 50); |
| 557 |
if (r == 0) |
| 558 |
return -EAGAIN; |
| 559 |
|
| 560 |
if (r == -1) { |
| 561 |
goto error; |
| 562 |
} |
| 563 |
|
| 564 |
if (e.data.fd == t->pidfd) { |
| 565 |
uint64_t buf; |
| 566 |
int ignore = read(t->pidfd, |
| 567 |
&buf, |
| 568 |
sizeof(buf)); /* for timerfd fallback */ |
| 569 |
(void)ignore; |
| 570 |
if (litest_runner_test_collect_child(t)) { |
| 571 |
break; |
| 572 |
} |
| 573 |
} else if (e.data.fd == t->timerfd) { |
| 574 |
/* SIGALARM so we get the backtrace */ |
| 575 |
kill(t->pid, SIGALRM); |
| 576 |
t->result = LITEST_TIMEOUT; |
| 577 |
waitpid(t->pid, NULL, 0); |
| 578 |
t->pid = 0; |
| 579 |
break; |
| 580 |
} else { |
| 581 |
for (int i = 0; i < _FD_LAST; i++) { |
| 582 |
if (e.data.fd == t->read_fds[i]) { |
| 583 |
stringbuf_append_from_fd(&t->logs[i], |
| 584 |
e.data.fd, |
| 585 |
1024); |
| 586 |
} |
| 587 |
} |
| 588 |
} |
| 589 |
}; |
| 590 |
|
| 591 |
errno = 0; |
| 592 |
error: |
| 593 |
return -errno; |
| 594 |
} |
| 595 |
|
| 596 |
static void |
| 597 |
litest_runner_test_update_errno(struct litest_runner_test *t, int error) |
| 598 |
{ |
| 599 |
if (error) |
| 600 |
t->sig_or_errno = -error; |
| 601 |
|
| 602 |
if (error == SIGTERM) { |
| 603 |
char msg[64]; |
| 604 |
snprintf(msg, sizeof(msg), "litest: tests terminated by signal\n"); |
| 605 |
stringbuf_append_string(&t->logs[FD_LOG], msg); |
| 606 |
t->result = LITEST_SYSTEM_ERROR; |
| 607 |
} |
| 608 |
|
| 609 |
for (size_t i = 0; i < ARRAY_LENGTH(t->read_fds); i++) { |
| 610 |
stringbuf_append_from_fd(&t->logs[i], t->read_fds[i], 1024); |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
__attribute__((noreturn)) void |
| 615 |
litest_runner_abort(void) |
| 616 |
{ |
| 617 |
if (use_jmpbuf) { |
| 618 |
longjmp(jmpbuf, SIGABRT); |
| 619 |
} else { |
| 620 |
abort(); |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
static int |
| 625 |
litest_runner_run_test(struct litest_runner *runner, struct litest_runner_test *t) |
| 626 |
{ |
| 627 |
int r; |
| 628 |
|
| 629 |
t->result = LITEST_SYSTEM_ERROR; |
| 630 |
|
| 631 |
usec_t now = usec_from_uint64_t(0); |
| 632 |
now_in_us(&now); |
| 633 |
t->times.start_usec = now; |
| 634 |
|
| 635 |
if (runner->max_forks == 0) { |
| 636 |
if (use_jmpbuf && setjmp(jmpbuf) == 0) { |
| 637 |
t->result = litest_runner_test_run(&t->desc); |
| 638 |
} else { |
| 639 |
t->result = LITEST_FAIL; |
| 640 |
} |
| 641 |
r = 0; /* -Wclobbered */ |
| 642 |
} else { |
| 643 |
r = litest_runner_fork_test(runner, t); |
| 644 |
if (r >= 0) |
| 645 |
r = litest_runner_test_setup_monitoring(runner, t); |
| 646 |
litest_runner_test_update_errno(t, -r); |
| 647 |
} |
| 648 |
|
| 649 |
if (r >= 0) { |
| 650 |
list_remove(&t->node); |
| 651 |
list_append(&runner->tests_running, &t->node); |
| 652 |
} |
| 653 |
|
| 654 |
return r; |
| 655 |
} |
| 656 |
|
| 657 |
static void |
| 658 |
print_lines(FILE *fp, const char *log, const char *prefix) |
| 659 |
{ |
| 660 |
size_t nlines = 0; |
| 661 |
_autostrvfree_ char **lines = strv_from_string(log, "\n", &nlines); |
| 662 |
|
| 663 |
for (size_t i = 0; i < nlines; i++) { |
| 664 |
fprintf(fp, "%s%s\n", prefix, lines[i]); |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
void |
| 669 |
_litest_test_param_fetch(const struct litest_test_parameters *params, ...) |
| 670 |
{ |
| 671 |
struct litest_test_param *p; |
| 672 |
|
| 673 |
const char *name; |
| 674 |
|
| 675 |
va_list args; |
| 676 |
va_start(args, params); |
| 677 |
|
| 678 |
while ((name = va_arg(args, const char *))) { |
| 679 |
bool found = false; |
| 680 |
char type = (char)va_arg(args, int); |
| 681 |
void **ptr = va_arg(args, void *); |
| 682 |
list_for_each(p, ¶ms->test_params, link) { |
| 683 |
if (streq(p->name, name)) { |
| 684 |
if (tolower(p->value.type) != tolower(type)) |
| 685 |
litest_abort_msg( |
| 686 |
"Paramter type mismatch: parameter '%s' is of type %c", |
| 687 |
p->name, |
| 688 |
p->value.type); |
| 689 |
found = true; |
| 690 |
multivalue_extract(&p->value, ptr); |
| 691 |
break; |
| 692 |
} |
| 693 |
} |
| 694 |
if (!found) |
| 695 |
litest_abort_msg("Unknown test parameter name '%s'", name); |
| 696 |
} |
| 697 |
|
| 698 |
va_end(args); |
| 699 |
} |
| 700 |
|
| 701 |
struct litest_test_parameters * |
| 702 |
litest_test_parameters_new(void) |
| 703 |
{ |
| 704 |
struct litest_test_parameters *params = zalloc(sizeof *params); |
| 705 |
params->refcnt = 1; |
| 706 |
list_init(¶ms->test_params); |
| 707 |
return params; |
| 708 |
} |
| 709 |
|
| 710 |
struct litest_test_parameters * |
| 711 |
litest_test_parameters_unref(struct litest_test_parameters *params) |
| 712 |
{ |
| 713 |
if (params) { |
| 714 |
assert(params->refcnt > 0); |
| 715 |
if (--params->refcnt == 0) { |
| 716 |
struct litest_test_param *p; |
| 717 |
list_for_each_safe(p, ¶ms->test_params, link) { |
| 718 |
free(p); |
| 719 |
} |
| 720 |
free(params); |
| 721 |
} |
| 722 |
} |
| 723 |
return NULL; |
| 724 |
} |
| 725 |
|
| 726 |
static void |
| 727 |
litest_runner_log_test_result(struct litest_runner *runner, |
| 728 |
struct litest_runner_test *t) |
| 729 |
{ |
| 730 |
const char *color = NULL; |
| 731 |
const char *status = NULL; |
| 732 |
|
| 733 |
litest_assert_int_ge(t->result, (enum litest_runner_result)LITEST_PASS); |
| 734 |
litest_assert_int_le(t->result, (enum litest_runner_result)LITEST_SYSTEM_ERROR); |
| 735 |
|
| 736 |
switch (t->result) { |
| 737 |
case LITEST_PASS: |
| 738 |
color = ANSI_BOLD_GREEN; |
| 739 |
break; |
| 740 |
case LITEST_FAIL: |
| 741 |
color = ANSI_BOLD_RED; |
| 742 |
break; |
| 743 |
case LITEST_SKIP: |
| 744 |
color = ANSI_BOLD_YELLOW; |
| 745 |
break; |
| 746 |
case LITEST_NOT_APPLICABLE: |
| 747 |
color = ANSI_BLUE; |
| 748 |
break; |
| 749 |
case LITEST_TIMEOUT: |
| 750 |
color = ANSI_BOLD_CYAN; |
| 751 |
break; |
| 752 |
case LITEST_SYSTEM_ERROR: |
| 753 |
color = ANSI_BOLD_MAGENTA; |
| 754 |
break; |
| 755 |
} |
| 756 |
|
| 757 |
fprintf(runner->fp, " - name: \"%s\"\n", t->desc.name); |
| 758 |
int min = t->desc.args.range.lower, max = t->desc.args.range.upper; |
| 759 |
if (range_is_valid(&t->desc.args.range)) |
| 760 |
fprintf(runner->fp, |
| 761 |
" rangeval: %d # %d..%d\n", |
| 762 |
t->desc.rangeval, |
| 763 |
min, |
| 764 |
max); |
| 765 |
|
| 766 |
if (t->desc.params) { |
| 767 |
fprintf(runner->fp, " params:\n"); |
| 768 |
struct litest_test_param *p; |
| 769 |
list_for_each(p, &t->desc.params->test_params, link) { |
| 770 |
_autofree_ char *val = multivalue_as_str(&p->value); |
| 771 |
fprintf(runner->fp, " %s: %s\n", p->name, val); |
| 772 |
} |
| 773 |
} |
| 774 |
|
| 775 |
usec_t delta = usec_delta(t->times.end_usec, t->times.start_usec); |
| 776 |
usec_t total_delta = usec_delta(t->times.end_usec, runner->times.start_usec); |
| 777 |
fprintf(runner->fp, |
| 778 |
" duration: %d # (ms), total test run time: %02" PRIu32 |
| 779 |
":%02" PRIu32 "\n", |
| 780 |
usec_to_millis(delta), |
| 781 |
usec_to_minutes(total_delta), |
| 782 |
usec_to_seconds(total_delta) % 60); |
| 783 |
|
| 784 |
status = litest_runner_result_as_str(t->result); |
| 785 |
fprintf(runner->fp, |
| 786 |
" status: %s%s%s\n", |
| 787 |
runner->use_colors ? color : "", |
| 788 |
&status[7], /* skip LITEST_ prefix */ |
| 789 |
runner->use_colors ? ANSI_NORMAL : ""); |
| 790 |
|
| 791 |
switch (t->result) { |
| 792 |
case LITEST_PASS: |
| 793 |
case LITEST_SKIP: |
| 794 |
case LITEST_NOT_APPLICABLE: |
| 795 |
if (!runner->verbose) |
| 796 |
return; |
| 797 |
break; |
| 798 |
default: |
| 799 |
break; |
| 800 |
} |
| 801 |
|
| 802 |
if (t->sig_or_errno > 0) |
| 803 |
fprintf(runner->fp, |
| 804 |
" signal: %d # SIG%s \n", |
| 805 |
t->sig_or_errno, |
| 806 |
sigabbrev_np(t->sig_or_errno)); |
| 807 |
else if (t->sig_or_errno < 0) |
| 808 |
fprintf(runner->fp, |
| 809 |
" errno: %d # %s\n", |
| 810 |
-t->sig_or_errno, |
| 811 |
strerror(-t->sig_or_errno)); |
| 812 |
if (!stringbuf_is_empty(&t->logs[FD_LOG])) { |
| 813 |
fprintf(runner->fp, " log: |\n"); |
| 814 |
print_lines(runner->fp, t->logs[FD_LOG].data, " "); |
| 815 |
} |
| 816 |
if (!stringbuf_is_empty(&t->logs[FD_STDOUT])) { |
| 817 |
fprintf(runner->fp, " stdout: |\n"); |
| 818 |
print_lines(runner->fp, t->logs[FD_STDOUT].data, " "); |
| 819 |
} |
| 820 |
if (!stringbuf_is_empty(&t->logs[FD_STDERR])) { |
| 821 |
fprintf(runner->fp, " stderr: |\n"); |
| 822 |
print_lines(runner->fp, t->logs[FD_STDERR].data, " "); |
| 823 |
} |
| 824 |
if (!stringbuf_is_empty(&t->logs[FD_VALGRIND])) { |
| 825 |
fprintf(runner->fp, " valgrind: |\n"); |
| 826 |
print_lines(runner->fp, t->logs[FD_VALGRIND].data, " "); |
| 827 |
} |
| 828 |
} |
| 829 |
|
| 830 |
struct litest_runner * |
| 831 |
litest_runner_new(void) |
| 832 |
{ |
| 833 |
struct litest_runner *runner = zalloc(sizeof *runner); |
| 834 |
|
| 835 |
list_init(&runner->tests); |
| 836 |
list_init(&runner->tests_complete); |
| 837 |
list_init(&runner->tests_running); |
| 838 |
runner->timeout = LITEST_RUNNER_DEFAULT_TIMEOUT; |
| 839 |
runner->max_forks = get_nprocs() * 2; |
| 840 |
runner->fp = stderr; |
| 841 |
|
| 842 |
return runner; |
| 843 |
} |
| 844 |
|
| 845 |
void |
| 846 |
litest_runner_set_timeout(struct litest_runner *runner, unsigned int timeout) |
| 847 |
{ |
| 848 |
runner->timeout = timeout; |
| 849 |
} |
| 850 |
|
| 851 |
void |
| 852 |
litest_runner_set_output_file(struct litest_runner *runner, FILE *fp) |
| 853 |
{ |
| 854 |
setlinebuf(fp); |
| 855 |
runner->fp = fp; |
| 856 |
} |
| 857 |
|
| 858 |
void |
| 859 |
litest_runner_set_num_parallel(struct litest_runner *runner, size_t num_jobs) |
| 860 |
{ |
| 861 |
runner->max_forks = num_jobs; |
| 862 |
} |
| 863 |
|
| 864 |
void |
| 865 |
litest_runner_set_verbose(struct litest_runner *runner, bool verbose) |
| 866 |
{ |
| 867 |
runner->verbose = verbose; |
| 868 |
} |
| 869 |
|
| 870 |
void |
| 871 |
litest_runner_set_use_colors(struct litest_runner *runner, bool use_colors) |
| 872 |
{ |
| 873 |
runner->use_colors = use_colors; |
| 874 |
} |
| 875 |
|
| 876 |
void |
| 877 |
litest_runner_set_exit_on_fail(struct litest_runner *runner, bool do_exit) |
| 878 |
{ |
| 879 |
runner->exit_on_fail = do_exit; |
| 880 |
} |
| 881 |
|
| 882 |
void |
| 883 |
litest_runner_set_setup_funcs(struct litest_runner *runner, |
| 884 |
litest_runner_global_setup_func_t setup, |
| 885 |
litest_runner_global_teardown_func_t teardown, |
| 886 |
void *userdata) |
| 887 |
{ |
| 888 |
runner->global.setup = setup; |
| 889 |
runner->global.teardown = teardown; |
| 890 |
runner->global.userdata = userdata; |
| 891 |
} |
| 892 |
|
| 893 |
void |
| 894 |
litest_runner_add_test(struct litest_runner *runner, |
| 895 |
const struct litest_runner_test_description *desc) |
| 896 |
{ |
| 897 |
struct litest_runner_test *t = zalloc(sizeof(*t)); |
| 898 |
|
| 899 |
t->desc = *desc; |
| 900 |
t->epollfd = -1; |
| 901 |
t->pidfd = -1; |
| 902 |
t->timerfd = -1; |
| 903 |
|
| 904 |
for (int i = 0; i < _FD_LAST; i++) { |
| 905 |
stringbuf_init(&t->logs[i]); |
| 906 |
} |
| 907 |
|
| 908 |
for (size_t i = 0; i < ARRAY_LENGTH(t->read_fds); i++) { |
| 909 |
t->read_fds[i] = -1; |
| 910 |
} |
| 911 |
|
| 912 |
list_append(&runner->tests, &t->node); |
| 913 |
} |
| 914 |
|
| 915 |
static int |
| 916 |
litest_runner_check_finished_tests(struct litest_runner *runner) |
| 917 |
{ |
| 918 |
struct litest_runner_test *running; |
| 919 |
size_t count = 0; |
| 920 |
|
| 921 |
list_for_each_safe(running, &runner->tests_running, node) { |
| 922 |
int r = litest_runner_test_check_status(running); |
| 923 |
if (r == -EAGAIN) |
| 924 |
continue; |
| 925 |
|
| 926 |
usec_t now = usec_from_uint64_t(0); |
| 927 |
now_in_us(&now); |
| 928 |
running->times.end_usec = now; |
| 929 |
|
| 930 |
if (r < 0) |
| 931 |
litest_runner_test_update_errno(running, -r); |
| 932 |
|
| 933 |
litest_runner_log_test_result(runner, running); |
| 934 |
litest_runner_test_close(running); |
| 935 |
list_remove(&running->node); |
| 936 |
list_append(&runner->tests_complete, &running->node); |
| 937 |
count++; |
| 938 |
} |
| 939 |
|
| 940 |
return count; |
| 941 |
} |
| 942 |
|
| 943 |
static void |
| 944 |
runner_sighandler(int sig) |
| 945 |
{ |
| 946 |
struct litest_runner_test *t; |
| 947 |
struct litest_runner *runner = global_runner; |
| 948 |
|
| 949 |
list_for_each(t, &runner->tests_running, node) { |
| 950 |
if (t->pid != 0) { |
| 951 |
kill(t->pid, SIGTERM); |
| 952 |
t->pid = 0; |
| 953 |
} |
| 954 |
} |
| 955 |
|
| 956 |
global_runner->terminating = true; |
| 957 |
} |
| 958 |
|
| 959 |
static inline void |
| 960 |
setup_sighandler(int sig) |
| 961 |
{ |
| 962 |
struct sigaction act, oact; |
| 963 |
int rc; |
| 964 |
|
| 965 |
sigemptyset(&act.sa_mask); |
| 966 |
sigaddset(&act.sa_mask, sig); |
| 967 |
act.sa_flags = 0; |
| 968 |
act.sa_handler = runner_sighandler; |
| 969 |
rc = sigaction(sig, &act, &oact); |
| 970 |
litest_assert_int_ne(rc, -1); |
| 971 |
} |
| 972 |
|
| 973 |
enum litest_runner_result |
| 974 |
litest_runner_run_tests(struct litest_runner *runner) |
| 975 |
{ |
| 976 |
struct litest_runner_test *t; |
| 977 |
size_t available_jobs = max(runner->max_forks, 1); |
| 978 |
char timestamp[64]; |
| 979 |
struct tm *ltime; |
| 980 |
|
| 981 |
global_runner = runner; /* sigh, need this for signal handling */ |
| 982 |
|
| 983 |
if (runner->global.setup) |
| 984 |
runner->global.setup(runner->global.userdata); |
| 985 |
|
| 986 |
use_jmpbuf = runner->max_forks == 0; |
| 987 |
|
| 988 |
setup_sighandler(SIGINT); |
| 989 |
|
| 990 |
usec_t now = usec_from_uint64_t(0); |
| 991 |
now_in_us(&now); |
| 992 |
|
| 993 |
runner->times.start_usec = now; |
| 994 |
runner->times.start = time(NULL); |
| 995 |
ltime = localtime(&runner->times.start); |
| 996 |
strftime(timestamp, sizeof(timestamp), "%FT%H:%M", ltime); |
| 997 |
fprintf(runner->fp, |
| 998 |
"start: %lld # \"%s\"\n", |
| 999 |
(long long)runner->times.start, |
| 1000 |
timestamp); |
| 1001 |
fprintf(runner->fp, "jobs: %zd\n", runner->max_forks); |
| 1002 |
fprintf(runner->fp, "tests:\n"); |
| 1003 |
list_for_each_safe(t, &runner->tests, node) { |
| 1004 |
int r = litest_runner_run_test(runner, t); |
| 1005 |
if (r >= 0) { |
| 1006 |
available_jobs--; |
| 1007 |
} |
| 1008 |
|
| 1009 |
/* Wait for something to become available */ |
| 1010 |
while (available_jobs == 0 && !runner->terminating) { |
| 1011 |
int complete = litest_runner_check_finished_tests(runner); |
| 1012 |
available_jobs += complete; |
| 1013 |
} |
| 1014 |
|
| 1015 |
if (runner->terminating) { |
| 1016 |
break; |
| 1017 |
} |
| 1018 |
|
| 1019 |
if (runner->exit_on_fail) { |
| 1020 |
bool do_exit = false; |
| 1021 |
struct litest_runner_test *complete; |
| 1022 |
list_for_each(complete, &runner->tests_complete, node) { |
| 1023 |
switch (complete->result) { |
| 1024 |
case LITEST_FAIL: |
| 1025 |
case LITEST_SYSTEM_ERROR: |
| 1026 |
case LITEST_TIMEOUT: |
| 1027 |
do_exit = true; |
| 1028 |
break; |
| 1029 |
default: |
| 1030 |
break; |
| 1031 |
} |
| 1032 |
if (do_exit) |
| 1033 |
break; |
| 1034 |
} |
| 1035 |
if (do_exit) |
| 1036 |
break; |
| 1037 |
} |
| 1038 |
} |
| 1039 |
|
| 1040 |
while (!runner->terminating && !list_empty(&runner->tests_running)) { |
| 1041 |
litest_runner_check_finished_tests(runner); |
| 1042 |
} |
| 1043 |
|
| 1044 |
if (runner->global.teardown) |
| 1045 |
runner->global.teardown(runner->global.userdata); |
| 1046 |
|
| 1047 |
size_t npass = 0, nfail = 0, nskip = 0, nna = 0; |
| 1048 |
size_t ncomplete = 0; |
| 1049 |
|
| 1050 |
list_for_each(t, &runner->tests_complete, node) { |
| 1051 |
ncomplete++; |
| 1052 |
switch (t->result) { |
| 1053 |
case LITEST_PASS: |
| 1054 |
npass++; |
| 1055 |
break; |
| 1056 |
case LITEST_NOT_APPLICABLE: |
| 1057 |
nna++; |
| 1058 |
break; |
| 1059 |
case LITEST_FAIL: |
| 1060 |
case LITEST_SYSTEM_ERROR: |
| 1061 |
case LITEST_TIMEOUT: |
| 1062 |
nfail++; |
| 1063 |
break; |
| 1064 |
case LITEST_SKIP: |
| 1065 |
nskip++; |
| 1066 |
break; |
| 1067 |
} |
| 1068 |
} |
| 1069 |
|
| 1070 |
runner->times.end = time(NULL); |
| 1071 |
ltime = localtime(&runner->times.end); |
| 1072 |
strftime(timestamp, sizeof(timestamp), "%FT%H:%M", ltime); |
| 1073 |
fprintf(runner->fp, |
| 1074 |
"end: %lld # \"%s\"\n", |
| 1075 |
(long long)runner->times.end, |
| 1076 |
timestamp); |
| 1077 |
fprintf(runner->fp, |
| 1078 |
"duration: %lld # (s) %02lld:%02lld\n", |
| 1079 |
(long long)(runner->times.end - runner->times.start), |
| 1080 |
(long long)((runner->times.end - runner->times.start) / 60), |
| 1081 |
(long long)((runner->times.end - runner->times.start) % 60)); |
| 1082 |
fprintf(runner->fp, "summary:\n"); |
| 1083 |
fprintf(runner->fp, " completed: %zd\n", ncomplete); |
| 1084 |
fprintf(runner->fp, " pass: %zd\n", npass); |
| 1085 |
fprintf(runner->fp, " na: %zd\n", nna); |
| 1086 |
fprintf(runner->fp, " fail: %zd\n", nfail); |
| 1087 |
fprintf(runner->fp, " skip: %zd\n", nskip); |
| 1088 |
if (nfail > 0) { |
| 1089 |
fprintf(runner->fp, " failed:\n"); |
| 1090 |
list_for_each(t, &runner->tests_complete, node) { |
| 1091 |
switch (t->result) { |
| 1092 |
case LITEST_FAIL: |
| 1093 |
case LITEST_SYSTEM_ERROR: |
| 1094 |
case LITEST_TIMEOUT: |
| 1095 |
litest_runner_log_test_result(runner, t); |
| 1096 |
break; |
| 1097 |
default: |
| 1098 |
break; |
| 1099 |
} |
| 1100 |
} |
| 1101 |
} |
| 1102 |
|
| 1103 |
if (RUNNING_ON_VALGRIND) { |
| 1104 |
_autofree_ char *filename = valgrind_logfile(getpid()); |
| 1105 |
_destroy_(stringbuf) *b = stringbuf_new(); |
| 1106 |
|
| 1107 |
collect_file(filename, b); |
| 1108 |
fprintf(runner->fp, "valgrind:\n"); |
| 1109 |
print_lines(runner->fp, b->data, " "); |
| 1110 |
fprintf(runner->fp, |
| 1111 |
"# Valgrind log is incomplete, see %s for full log\n", |
| 1112 |
filename); |
| 1113 |
} |
| 1114 |
|
| 1115 |
enum litest_runner_result result = LITEST_PASS; |
| 1116 |
|
| 1117 |
/* Didn't finish */ |
| 1118 |
if (!list_empty(&runner->tests) || !list_empty(&runner->tests_running)) { |
| 1119 |
result = LITEST_SYSTEM_ERROR; |
| 1120 |
} else { |
| 1121 |
list_for_each(t, &runner->tests_complete, node) { |
| 1122 |
switch (t->result) { |
| 1123 |
case LITEST_PASS: |
| 1124 |
case LITEST_SKIP: |
| 1125 |
case LITEST_NOT_APPLICABLE: |
| 1126 |
break; |
| 1127 |
default: |
| 1128 |
result = LITEST_FAIL; |
| 1129 |
break; |
| 1130 |
} |
| 1131 |
} |
| 1132 |
} |
| 1133 |
/* Status is always prefixed with LITEST_ */ |
| 1134 |
fprintf(runner->fp, " status: %s\n", &litest_runner_result_as_str(result)[7]); |
| 1135 |
|
| 1136 |
return result; |
| 1137 |
} |