blob: adc525a1e08b7f759487413c5f945837685a3538 [file] [log] [blame]
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +01001/*
2 * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdio.h>
19#include <stdarg.h>
20#include <unistd.h>
21#include <string.h>
22#include <stdlib.h>
23#include <errno.h>
Sandeep Patilc9a7def2017-09-19 12:49:58 -070024#include <sys/mount.h>
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010025#include <sys/types.h>
26#include <sys/wait.h>
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010027
28#define TST_NO_DEFAULT_MAIN
29#include "tst_test.h"
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010030#include "tst_device.h"
31#include "lapi/futex.h"
Steve Mucklec20831d2017-09-20 13:23:06 -070032#include "lapi/syscalls.h"
Petr Vorel3a0ef862017-03-01 15:31:08 +010033#include "tst_ansi_color.h"
Jan Stancekb95b1992017-10-10 15:47:58 +020034#include "tst_safe_stdio.h"
Cyril Hrubisc4596542017-06-20 15:42:18 +020035#include "tst_timer_test.h"
Cyril Hrubis2f7c8e92018-01-22 15:19:31 +010036#include "tst_clocks.h"
37#include "tst_timer.h"
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010038
39#include "old_resource.h"
40#include "old_device.h"
41#include "old_tmpdir.h"
42
43struct tst_test *tst_test;
44
Li Wangb5d620a2017-11-01 13:15:23 +080045static const char *tid;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010046static int iterations = 1;
47static float duration = -1;
Jan Stanceke0bfa7d2016-06-08 15:27:55 +020048static pid_t main_pid, lib_pid;
Sandeep Patilc9a7def2017-09-19 12:49:58 -070049static int mntpoint_mounted;
Jan Stancek1893e012018-08-28 16:17:52 +020050static struct timespec tst_start_time; /* valid only for test pid */
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010051
52struct results {
Jan Stancekc54ca052016-04-13 12:31:13 +020053 int passed;
54 int skipped;
55 int failed;
56 int warnings;
Cyril Hrubis2ad59b72016-08-03 15:53:55 +020057 unsigned int timeout;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010058};
59
60static struct results *results;
61
62static int ipc_fd;
63
64extern void *tst_futexes;
65extern unsigned int tst_max_futexes;
66
67#define IPC_ENV_VAR "LTP_IPC_PATH"
68
69static char ipc_path[1024];
70const char *tst_ipc_path = ipc_path;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010071
72static char shm_path[1024];
73
Christian Lanig18b780d2018-07-23 15:24:50 +020074int TST_ERR;
75long TST_RET;
76
Jan Stancek332540e2016-06-08 16:48:22 +020077static void do_cleanup(void);
Cyril Hrubisfa495172016-06-08 16:06:35 +020078static void do_exit(int ret) __attribute__ ((noreturn));
Jan Stanceke0bfa7d2016-06-08 15:27:55 +020079
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010080static void setup_ipc(void)
81{
82 size_t size = getpagesize();
83
Steven Jackson9f41dcf2016-12-21 20:09:01 +000084 if (access("/dev/shm", F_OK) == 0) {
85 snprintf(shm_path, sizeof(shm_path), "/dev/shm/ltp_%s_%d",
Li Wangb5d620a2017-11-01 13:15:23 +080086 tid, getpid());
Steven Jackson9f41dcf2016-12-21 20:09:01 +000087 } else {
88 char *tmpdir;
89
90 if (!tst_tmpdir_created())
91 tst_tmpdir();
92
93 tmpdir = tst_get_tmpdir();
94 snprintf(shm_path, sizeof(shm_path), "%s/ltp_%s_%d",
Li Wangb5d620a2017-11-01 13:15:23 +080095 tmpdir, tid, getpid());
Steven Jackson9f41dcf2016-12-21 20:09:01 +000096 free(tmpdir);
97 }
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +010098
99 ipc_fd = open(shm_path, O_CREAT | O_EXCL | O_RDWR, 0600);
100 if (ipc_fd < 0)
101 tst_brk(TBROK | TERRNO, "open(%s)", shm_path);
Jan Stancek2113eef2017-10-04 12:25:42 +0200102 SAFE_CHMOD(shm_path, 0666);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100103
104 SAFE_FTRUNCATE(ipc_fd, size);
105
106 results = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, ipc_fd, 0);
107
108 /* Checkpoints needs to be accessible from processes started by exec() */
Cyril Hrubis9e5a0762018-07-31 15:03:21 +0200109 if (tst_test->needs_checkpoints || tst_test->child_needs_reinit) {
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100110 sprintf(ipc_path, IPC_ENV_VAR "=%s", shm_path);
Jan Stancek03fc5372017-10-10 13:36:59 +0200111 putenv(ipc_path);
112 } else {
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100113 SAFE_UNLINK(shm_path);
Jan Stancek03fc5372017-10-10 13:36:59 +0200114 }
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100115
116 SAFE_CLOSE(ipc_fd);
117
118 if (tst_test->needs_checkpoints) {
119 tst_futexes = (char*)results + sizeof(struct results);
120 tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
121 }
122}
123
124static void cleanup_ipc(void)
125{
126 size_t size = getpagesize();
127
128 if (ipc_fd > 0 && close(ipc_fd))
129 tst_res(TWARN | TERRNO, "close(ipc_fd) failed");
130
Cyril Hrubis9726b902017-07-27 11:28:50 +0200131 if (shm_path[0] && !access(shm_path, F_OK) && unlink(shm_path))
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100132 tst_res(TWARN | TERRNO, "unlink(%s) failed", shm_path);
133
Cyril Hrubis9726b902017-07-27 11:28:50 +0200134 if (results) {
135 msync((void*)results, size, MS_SYNC);
136 munmap((void*)results, size);
137 }
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100138}
139
140void tst_reinit(void)
141{
Jan Stancek03fc5372017-10-10 13:36:59 +0200142 const char *path = getenv(IPC_ENV_VAR);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100143 size_t size = getpagesize();
144 int fd;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100145
146 if (!path)
Jan Stancek03fc5372017-10-10 13:36:59 +0200147 tst_brk(TBROK, IPC_ENV_VAR" is not defined");
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100148
149 if (access(path, F_OK))
150 tst_brk(TBROK, "File %s does not exist!", path);
151
152 fd = SAFE_OPEN(path, O_RDWR);
153
Cyril Hrubis9e5a0762018-07-31 15:03:21 +0200154 results = SAFE_MMAP(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
155 tst_futexes = (char*)results + sizeof(struct results);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100156 tst_max_futexes = (size - sizeof(struct results))/sizeof(futex_t);
157
158 SAFE_CLOSE(fd);
159}
160
Cyril Hrubis160ffcc2017-02-14 10:21:08 +0100161static void update_results(int ttype)
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100162{
Cyril Hrubisd97debf2017-02-13 12:37:39 +0100163 if (!results)
164 return;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100165
166 switch (ttype) {
167 case TCONF:
168 tst_atomic_inc(&results->skipped);
169 break;
170 case TPASS:
171 tst_atomic_inc(&results->passed);
172 break;
173 case TWARN:
174 tst_atomic_inc(&results->warnings);
175 break;
176 case TFAIL:
177 tst_atomic_inc(&results->failed);
178 break;
179 }
180}
181
182static void print_result(const char *file, const int lineno, int ttype,
183 const char *fmt, va_list va)
184{
185 char buf[1024];
186 char *str = buf;
Veronika Kabatovacecbd0c2017-11-07 17:10:42 +0100187 int ret, size = sizeof(buf), ssize;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100188 const char *str_errno = NULL;
189 const char *res;
190
191 switch (TTYPE_RESULT(ttype)) {
192 case TPASS:
193 res = "PASS";
194 break;
195 case TFAIL:
196 res = "FAIL";
197 break;
198 case TBROK:
199 res = "BROK";
200 break;
201 case TCONF:
202 res = "CONF";
203 break;
204 case TWARN:
205 res = "WARN";
206 break;
207 case TINFO:
208 res = "INFO";
209 break;
210 default:
211 tst_brk(TBROK, "Invalid ttype value %i", ttype);
Cyril Hrubis6440c5d2017-02-09 15:41:24 +0100212 abort();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100213 }
214
215 if (ttype & TERRNO)
216 str_errno = tst_strerrno(errno);
217
218 if (ttype & TTERRNO)
Christian Lanig18b780d2018-07-23 15:24:50 +0200219 str_errno = tst_strerrno(TST_ERR);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100220
Richard Palethorpefb32e892018-03-13 16:24:47 +0100221 if (ttype & TRERRNO) {
Christian Lanig18b780d2018-07-23 15:24:50 +0200222 ret = TST_RET < 0 ? -(int)TST_RET : (int)TST_RET;
Richard Palethorpefb32e892018-03-13 16:24:47 +0100223 str_errno = tst_strerrno(ret);
224 }
225
Petr Vorela7f61332017-01-24 20:47:30 +0100226 ret = snprintf(str, size, "%s:%i: ", file, lineno);
227 str += ret;
228 size -= ret;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100229
Cyril Hrubis047c7272017-02-13 16:23:36 +0100230 if (tst_color_enabled(STDERR_FILENO))
Petr Vorela7f61332017-01-24 20:47:30 +0100231 ret = snprintf(str, size, "%s%s: %s", tst_ttype2color(ttype),
232 res, ANSI_COLOR_RESET);
233 else
234 ret = snprintf(str, size, "%s: ", res);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100235 str += ret;
236 size -= ret;
237
Veronika Kabatovacecbd0c2017-11-07 17:10:42 +0100238 ssize = size - 2;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100239 ret = vsnprintf(str, size, fmt, va);
Veronika Kabatovacecbd0c2017-11-07 17:10:42 +0100240 str += MIN(ret, ssize);
241 size -= MIN(ret, ssize);
242 if (ret >= ssize) {
243 tst_res_(file, lineno, TWARN,
244 "Next message is too long and truncated:");
245 } else if (str_errno) {
246 ssize = size - 2;
Petr Vorela7f61332017-01-24 20:47:30 +0100247 ret = snprintf(str, size, ": %s", str_errno);
Veronika Kabatovacecbd0c2017-11-07 17:10:42 +0100248 str += MIN(ret, ssize);
249 size -= MIN(ret, ssize);
250 if (ret >= ssize)
251 tst_res_(file, lineno, TWARN,
252 "Next message is too long and truncated:");
Petr Vorela7f61332017-01-24 20:47:30 +0100253 }
254
255 snprintf(str, size, "\n");
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100256
257 fputs(buf, stderr);
258}
259
260void tst_vres_(const char *file, const int lineno, int ttype,
261 const char *fmt, va_list va)
262{
263 print_result(file, lineno, ttype, fmt, va);
264
Cyril Hrubis160ffcc2017-02-14 10:21:08 +0100265 update_results(TTYPE_RESULT(ttype));
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100266}
267
268void tst_vbrk_(const char *file, const int lineno, int ttype,
Cyril Hrubis6440c5d2017-02-09 15:41:24 +0100269 const char *fmt, va_list va);
270
271static void (*tst_brk_handler)(const char *file, const int lineno, int ttype,
272 const char *fmt, va_list va) = tst_vbrk_;
273
274static void tst_cvres(const char *file, const int lineno, int ttype,
275 const char *fmt, va_list va)
276{
277 if (TTYPE_RESULT(ttype) == TBROK) {
278 ttype &= ~TTYPE_MASK;
279 ttype |= TWARN;
280 }
281
282 print_result(file, lineno, ttype, fmt, va);
283 update_results(TTYPE_RESULT(ttype));
284}
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100285
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200286static void do_test_cleanup(void)
287{
Cyril Hrubis6440c5d2017-02-09 15:41:24 +0100288 tst_brk_handler = tst_cvres;
289
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200290 if (tst_test->cleanup)
291 tst_test->cleanup();
Cyril Hrubis6440c5d2017-02-09 15:41:24 +0100292
293 tst_brk_handler = tst_vbrk_;
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200294}
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100295
296void tst_vbrk_(const char *file, const int lineno, int ttype,
297 const char *fmt, va_list va)
298{
299 print_result(file, lineno, ttype, fmt, va);
300
Steve Mucklec20831d2017-09-20 13:23:06 -0700301 /*
302 * The getpid implementation in some C library versions may cause cloned
303 * test threads to show the same pid as their parent when CLONE_VM is
304 * specified but CLONE_THREAD is not. Use direct syscall to avoid
305 * cleanup running in the child.
306 */
307 if (syscall(SYS_getpid) == main_pid)
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200308 do_test_cleanup();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100309
Jan Stanceke0bfa7d2016-06-08 15:27:55 +0200310 if (getpid() == lib_pid)
Cyril Hrubisfa495172016-06-08 16:06:35 +0200311 do_exit(TTYPE_RESULT(ttype));
Jan Stanceke0bfa7d2016-06-08 15:27:55 +0200312
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100313 exit(TTYPE_RESULT(ttype));
314}
315
316void tst_res_(const char *file, const int lineno, int ttype,
317 const char *fmt, ...)
318{
319 va_list va;
320
321 va_start(va, fmt);
322 tst_vres_(file, lineno, ttype, fmt, va);
323 va_end(va);
324}
325
326void tst_brk_(const char *file, const int lineno, int ttype,
327 const char *fmt, ...)
328{
329 va_list va;
330
331 va_start(va, fmt);
Cyril Hrubis6440c5d2017-02-09 15:41:24 +0100332 tst_brk_handler(file, lineno, ttype, fmt, va);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100333 va_end(va);
334}
335
336static void check_child_status(pid_t pid, int status)
337{
338 int ret;
339
340 if (WIFSIGNALED(status)) {
341 tst_brk(TBROK, "Child (%i) killed by signal %s",
342 pid, tst_strsig(WTERMSIG(status)));
343 }
344
345 if (!(WIFEXITED(status)))
Petr Vorelf8853482017-10-31 09:40:38 +0100346 tst_brk(TBROK, "Child (%i) exited abnormaly", pid);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100347
348 ret = WEXITSTATUS(status);
349 switch (ret) {
350 case TPASS:
351 break;
352 case TBROK:
353 case TCONF:
354 tst_brk(ret, "Reported by child (%i)", pid);
Cyril Hrubis45cd37f2018-08-31 14:25:28 +0200355 break;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100356 default:
357 tst_brk(TBROK, "Invalid child (%i) exit value %i", pid, ret);
358 }
359}
360
Stanislav Kholmanskikh6b56aa72016-08-04 17:16:31 +0300361void tst_reap_children(void)
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100362{
363 int status;
364 pid_t pid;
365
366 for (;;) {
367 pid = wait(&status);
368
369 if (pid > 0) {
370 check_child_status(pid, status);
371 continue;
372 }
373
374 if (errno == ECHILD)
375 break;
376
377 if (errno == EINTR)
378 continue;
379
380 tst_brk(TBROK | TERRNO, "wait() failed");
381 }
382}
383
384
385pid_t safe_fork(const char *filename, unsigned int lineno)
386{
387 pid_t pid;
388
389 if (!tst_test->forks_child)
390 tst_brk(TBROK, "test.forks_child must be set!");
391
Michael Moese9da42372018-03-09 15:16:09 +0100392 tst_flush();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100393
394 pid = fork();
395 if (pid < 0)
396 tst_brk_(filename, lineno, TBROK | TERRNO, "fork() failed");
397
398 return pid;
399}
400
401static struct option {
402 char *optstr;
403 char *help;
404} options[] = {
Cyril Hrubisb819c222016-08-03 14:36:07 +0200405 {"h", "-h Prints this help"},
406 {"i:", "-i n Execute test n times"},
407 {"I:", "-I x Execute test for n seconds"},
408 {"C:", "-C ARG Run child process with ARG arguments (used internally)"},
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100409};
410
411static void print_help(void)
412{
413 unsigned int i;
414
415 for (i = 0; i < ARRAY_SIZE(options); i++)
416 fprintf(stderr, "%s\n", options[i].help);
417
418 if (!tst_test->options)
419 return;
420
421 for (i = 0; tst_test->options[i].optstr; i++)
Cyril Hrubisb819c222016-08-03 14:36:07 +0200422 fprintf(stderr, "%s\n", tst_test->options[i].help);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100423}
424
425static void check_option_collision(void)
426{
427 unsigned int i, j;
428 struct tst_option *toptions = tst_test->options;
429
430 if (!toptions)
431 return;
432
433 for (i = 0; toptions[i].optstr; i++) {
434 for (j = 0; j < ARRAY_SIZE(options); j++) {
435 if (toptions[i].optstr[0] == options[j].optstr[0]) {
436 tst_brk(TBROK, "Option collision '%s'",
437 options[j].help);
438 }
439 }
440 }
441}
442
443static unsigned int count_options(void)
444{
445 unsigned int i;
446
447 if (!tst_test->options)
448 return 0;
449
450 for (i = 0; tst_test->options[i].optstr; i++);
451
452 return i;
453}
454
455static void parse_topt(unsigned int topts_len, int opt, char *optarg)
456{
457 unsigned int i;
458 struct tst_option *toptions = tst_test->options;
459
460 for (i = 0; i < topts_len; i++) {
461 if (toptions[i].optstr[0] == opt)
462 break;
463 }
464
465 if (i >= topts_len)
466 tst_brk(TBROK, "Invalid option '%c' (should not happen)", opt);
467
Jan Stancekc07d36c2016-08-01 11:44:55 +0200468 *(toptions[i].arg) = optarg ? optarg : "";
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100469}
470
471/* see self_exec.c */
472#ifdef UCLINUX
473extern char *child_args;
474#endif
475
476static void parse_opts(int argc, char *argv[])
477{
478 unsigned int i, topts_len = count_options();
479 char optstr[2 * ARRAY_SIZE(options) + 2 * topts_len];
480 int opt;
481
482 check_option_collision();
483
484 optstr[0] = 0;
485
486 for (i = 0; i < ARRAY_SIZE(options); i++)
487 strcat(optstr, options[i].optstr);
488
489 for (i = 0; i < topts_len; i++)
490 strcat(optstr, tst_test->options[i].optstr);
491
492 while ((opt = getopt(argc, argv, optstr)) > 0) {
493 switch (opt) {
494 case '?':
495 print_help();
496 tst_brk(TBROK, "Invalid option");
Cyril Hrubis45cd37f2018-08-31 14:25:28 +0200497 break;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100498 case 'h':
499 print_help();
500 exit(0);
501 case 'i':
502 iterations = atoi(optarg);
503 break;
504 case 'I':
505 duration = atof(optarg);
506 break;
507 case 'C':
508#ifdef UCLINUX
509 child_args = optarg;
510#endif
511 break;
512 default:
513 parse_topt(topts_len, opt, optarg);
514 }
515 }
Cyril Hrubis9dc07e02017-10-02 11:11:04 +0200516
517 if (optind < argc)
518 tst_brk(TBROK, "Unexpected argument(s) '%s'...", argv[optind]);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100519}
520
Cyril Hrubis1e92d8a2016-08-03 16:31:46 +0200521int tst_parse_int(const char *str, int *val, int min, int max)
522{
523 long rval;
Alexey Kodanevdd90c002016-12-18 00:36:00 +0300524
525 if (!str)
526 return 0;
527
528 int ret = tst_parse_long(str, &rval, min, max);
529
530 if (ret)
531 return ret;
532
533 *val = (int)rval;
534 return 0;
535}
536
537int tst_parse_long(const char *str, long *val, long min, long max)
538{
539 long rval;
Cyril Hrubis1e92d8a2016-08-03 16:31:46 +0200540 char *end;
541
542 if (!str)
543 return 0;
544
545 errno = 0;
546 rval = strtol(str, &end, 10);
547
548 if (str == end || *end != '\0')
549 return EINVAL;
550
551 if (errno)
552 return errno;
553
Alexey Kodanevdd90c002016-12-18 00:36:00 +0300554 if (rval > max || rval < min)
Cyril Hrubis1e92d8a2016-08-03 16:31:46 +0200555 return ERANGE;
556
Alexey Kodanevdd90c002016-12-18 00:36:00 +0300557 *val = rval;
Cyril Hrubis1e92d8a2016-08-03 16:31:46 +0200558 return 0;
559}
560
561int tst_parse_float(const char *str, float *val, float min, float max)
562{
563 double rval;
564 char *end;
565
566 if (!str)
567 return 0;
568
569 errno = 0;
570 rval = strtod(str, &end);
571
572 if (str == end || *end != '\0')
573 return EINVAL;
574
575 if (errno)
576 return errno;
577
578 if (rval > (double)max || rval < (double)min)
579 return ERANGE;
580
581 *val = (float)rval;
582 return 0;
583}
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100584
Cyril Hrubisfa495172016-06-08 16:06:35 +0200585static void do_exit(int ret)
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100586{
Xiao Yang11dfc322016-06-16 15:52:04 +0800587 if (results) {
588 printf("\nSummary:\n");
589 printf("passed %d\n", results->passed);
590 printf("failed %d\n", results->failed);
591 printf("skipped %d\n", results->skipped);
592 printf("warnings %d\n", results->warnings);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100593
Cyril Hrubisfecdd882018-01-17 14:51:30 +0100594 if (results->passed && ret == TCONF)
595 ret = 0;
596
Xiao Yang11dfc322016-06-16 15:52:04 +0800597 if (results->failed)
598 ret |= TFAIL;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100599
Cyril Hrubis5390d6e2017-09-07 15:47:22 +0200600 if (results->skipped && !results->passed)
Xiao Yang11dfc322016-06-16 15:52:04 +0800601 ret |= TCONF;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100602
Xiao Yang11dfc322016-06-16 15:52:04 +0800603 if (results->warnings)
604 ret |= TWARN;
605 }
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100606
Jan Stancek332540e2016-06-08 16:48:22 +0200607 do_cleanup();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100608
609 exit(ret);
610}
611
612void check_kver(void)
613{
614 int v1, v2, v3;
615
Cyril Hrubis4dcfd282016-11-01 15:07:12 +0100616 if (tst_parse_kver(tst_test->min_kver, &v1, &v2, &v3)) {
617 tst_res(TWARN,
618 "Invalid kernel version %s, expected %%d.%%d.%%d",
619 tst_test->min_kver);
620 }
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100621
622 if (tst_kvercmp(v1, v2, v3) < 0) {
623 tst_brk(TCONF, "The test requires kernel %s or newer",
624 tst_test->min_kver);
625 }
626}
627
628static int results_equal(struct results *a, struct results *b)
629{
630 if (a->passed != b->passed)
631 return 0;
632
633 if (a->failed != b->failed)
634 return 0;
635
636 if (a->skipped != b->skipped)
637 return 0;
638
639 return 1;
640}
641
642static int needs_tmpdir(void)
643{
644 return tst_test->needs_tmpdir ||
645 tst_test->needs_device ||
Cyril Hrubis16352e42018-04-05 16:01:47 +0200646 tst_test->mntpoint ||
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100647 tst_test->resource_files ||
648 tst_test->needs_checkpoints;
649}
650
651static void copy_resources(void)
652{
653 unsigned int i;
654
655 for (i = 0; tst_test->resource_files[i]; i++)
656 TST_RESOURCE_COPY(NULL, tst_test->resource_files[i], NULL);
657}
658
Cyril Hrubisa5bf5252017-03-14 15:25:29 +0800659static const char *get_tid(char *argv[])
660{
661 char *p;
662
663 if (!argv[0] || !argv[0][0]) {
664 tst_res(TINFO, "argv[0] is empty!");
665 return "ltp_empty_argv";
666 }
667
668 p = strrchr(argv[0], '/');
669 if (p)
670 return p+1;
671
672 return argv[0];
673}
674
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100675static struct tst_device tdev;
676struct tst_device *tst_device;
677
Cyril Hrubisc4596542017-06-20 15:42:18 +0200678static void assert_test_fn(void)
679{
680 int cnt = 0;
681
682 if (tst_test->test)
683 cnt++;
684
685 if (tst_test->test_all)
686 cnt++;
687
688 if (tst_test->sample)
689 cnt++;
690
691 if (!cnt)
692 tst_brk(TBROK, "No test function speficied");
693
694 if (cnt != 1)
695 tst_brk(TBROK, "You can define only one test function");
696
697 if (tst_test->test && !tst_test->tcnt)
698 tst_brk(TBROK, "Number of tests (tcnt) must not be > 0");
699
700 if (!tst_test->test && tst_test->tcnt)
701 tst_brk(TBROK, "You can define tcnt only for test()");
702}
703
Cyril Hrubise6da8672018-04-05 16:01:48 +0200704static int prepare_and_mount_ro_fs(const char *dev,
705 const char *mntpoint,
706 const char *fs_type)
707{
708 char buf[PATH_MAX];
709
710 if (mount(dev, mntpoint, fs_type, 0, NULL)) {
711 tst_res(TINFO | TERRNO, "Can't mount %s at %s (%s)",
712 dev, mntpoint, fs_type);
713 return 1;
714 }
715
716 mntpoint_mounted = 1;
717
718 snprintf(buf, sizeof(buf), "%s/dir/", mntpoint);
719 SAFE_MKDIR(buf, 0777);
720
721 snprintf(buf, sizeof(buf), "%s/file", mntpoint);
722 SAFE_FILE_PRINTF(buf, "file content");
723 SAFE_CHMOD(buf, 0777);
724
725 SAFE_MOUNT(dev, mntpoint, fs_type, MS_REMOUNT | MS_RDONLY, NULL);
726
727 return 0;
728}
729
Cyril Hrubis35b8a132017-09-01 10:45:26 +0200730static void prepare_device(void)
731{
732 if (tst_test->format_device) {
733 SAFE_MKFS(tdev.dev, tdev.fs_type, tst_test->dev_fs_opts,
734 tst_test->dev_extra_opt);
735 }
736
Cyril Hrubise6da8672018-04-05 16:01:48 +0200737 if (tst_test->needs_rofs) {
738 prepare_and_mount_ro_fs(tdev.dev, tst_test->mntpoint,
739 tdev.fs_type);
740 return;
741 }
742
Cyril Hrubis35b8a132017-09-01 10:45:26 +0200743 if (tst_test->mount_device) {
744 SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
745 tst_test->mnt_flags, tst_test->mnt_data);
746 mntpoint_mounted = 1;
747 }
748}
749
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100750static void do_setup(int argc, char *argv[])
751{
752 if (!tst_test)
753 tst_brk(TBROK, "No tests to run");
754
Cyril Hrubisf706a2f2017-08-01 17:31:30 +0200755 if (tst_test->tconf_msg)
756 tst_brk(TCONF, "%s", tst_test->tconf_msg);
757
Cyril Hrubisc4596542017-06-20 15:42:18 +0200758 assert_test_fn();
759
Li Wangb5d620a2017-11-01 13:15:23 +0800760 tid = get_tid(argv);
761
Cyril Hrubisc4596542017-06-20 15:42:18 +0200762 if (tst_test->sample)
763 tst_test = tst_timer_test_setup(tst_test);
764
Cyril Hrubis88c220d2017-07-27 11:16:39 +0200765 parse_opts(argc, argv);
766
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100767 if (tst_test->needs_root && geteuid() != 0)
768 tst_brk(TCONF, "Test needs to be run as root");
769
770 if (tst_test->min_kver)
771 check_kver();
772
Cyril Hrubis874326d2017-02-14 15:59:40 +0100773 if (tst_test->format_device)
774 tst_test->needs_device = 1;
775
776 if (tst_test->mount_device) {
777 tst_test->needs_device = 1;
778 tst_test->format_device = 1;
779 }
780
Cyril Hrubis35b8a132017-09-01 10:45:26 +0200781 if (tst_test->all_filesystems)
782 tst_test->needs_device = 1;
783
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100784 setup_ipc();
785
Steven Jackson9f41dcf2016-12-21 20:09:01 +0000786 if (needs_tmpdir() && !tst_tmpdir_created())
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100787 tst_tmpdir();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100788
Sandeep Patilc9a7def2017-09-19 12:49:58 -0700789 if (tst_test->mntpoint)
790 SAFE_MKDIR(tst_test->mntpoint, 0777);
791
Cyril Hrubis35b8a132017-09-01 10:45:26 +0200792 if ((tst_test->needs_rofs || tst_test->mount_device ||
793 tst_test->all_filesystems) && !tst_test->mntpoint) {
Sandeep Patilc9a7def2017-09-19 12:49:58 -0700794 tst_brk(TBROK, "tst_test->mntpoint must be set!");
795 }
796
797 if (tst_test->needs_rofs) {
798 /* If we failed to mount read-only tmpfs. Fallback to
Cyril Hrubise6da8672018-04-05 16:01:48 +0200799 * using a device with read-only filesystem.
Sandeep Patilc9a7def2017-09-19 12:49:58 -0700800 */
Cyril Hrubise6da8672018-04-05 16:01:48 +0200801 if (prepare_and_mount_ro_fs(NULL, tst_test->mntpoint, "tmpfs")) {
802 tst_res(TINFO, "Can't mount tmpfs read-only, "
803 "falling back to block device...");
Sandeep Patilc9a7def2017-09-19 12:49:58 -0700804 tst_test->needs_device = 1;
805 tst_test->format_device = 1;
Sandeep Patilc9a7def2017-09-19 12:49:58 -0700806 }
807 }
808
809 if (tst_test->needs_device && !mntpoint_mounted) {
Cyril Hrubis874326d2017-02-14 15:59:40 +0100810 tdev.dev = tst_acquire_device_(NULL, tst_test->dev_min_size);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100811
812 if (!tdev.dev)
813 tst_brk(TCONF, "Failed to acquire device");
814
815 tst_device = &tdev;
Cyril Hrubis874326d2017-02-14 15:59:40 +0100816
817 if (tst_test->dev_fs_type)
818 tdev.fs_type = tst_test->dev_fs_type;
819 else
820 tdev.fs_type = tst_dev_fs_type();
821
Cyril Hrubis35b8a132017-09-01 10:45:26 +0200822 if (!tst_test->all_filesystems)
823 prepare_device();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100824 }
825
826 if (tst_test->resource_files)
827 copy_resources();
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200828}
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100829
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200830static void do_test_setup(void)
831{
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100832 main_pid = getpid();
833
834 if (tst_test->setup)
835 tst_test->setup();
836
837 if (main_pid != getpid())
838 tst_brk(TBROK, "Runaway child in setup()!");
839}
840
841static void do_cleanup(void)
842{
Sandeep Patilc9a7def2017-09-19 12:49:58 -0700843 if (mntpoint_mounted)
Cyril Hrubis874326d2017-02-14 15:59:40 +0100844 tst_umount(tst_test->mntpoint);
845
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100846 if (tst_test->needs_device && tdev.dev)
847 tst_release_device(tdev.dev);
848
Steven Jackson9f41dcf2016-12-21 20:09:01 +0000849 if (tst_tmpdir_created()) {
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100850 /* avoid munmap() on wrong pointer in tst_rmdir() */
851 tst_futexes = NULL;
852 tst_rmdir();
853 }
Jan Stancek332540e2016-06-08 16:48:22 +0200854
855 cleanup_ipc();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100856}
857
858static void run_tests(void)
859{
860 unsigned int i;
861 struct results saved_results;
862
863 if (!tst_test->test) {
864 saved_results = *results;
865 tst_test->test_all();
866
867 if (getpid() != main_pid) {
868 exit(0);
869 }
870
Stanislav Kholmanskikh6b56aa72016-08-04 17:16:31 +0300871 tst_reap_children();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100872
873 if (results_equal(&saved_results, results))
874 tst_brk(TBROK, "Test haven't reported results!");
875 return;
876 }
877
878 for (i = 0; i < tst_test->tcnt; i++) {
879 saved_results = *results;
880 tst_test->test(i);
881
882 if (getpid() != main_pid) {
883 exit(0);
884 }
885
Stanislav Kholmanskikh6b56aa72016-08-04 17:16:31 +0300886 tst_reap_children();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100887
888 if (results_equal(&saved_results, results))
889 tst_brk(TBROK, "Test %i haven't reported results!", i);
890 }
891}
892
893static unsigned long long get_time_ms(void)
894{
Cyril Hrubis2f7c8e92018-01-22 15:19:31 +0100895 struct timespec ts;
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100896
Cyril Hrubis2f7c8e92018-01-22 15:19:31 +0100897 if (tst_clock_gettime(CLOCK_MONOTONIC, &ts))
898 tst_brk(TBROK | TERRNO, "tst_clock_gettime()");
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100899
Cyril Hrubis2f7c8e92018-01-22 15:19:31 +0100900 return tst_timespec_to_ms(ts);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100901}
902
Jan Stancekb95b1992017-10-10 15:47:58 +0200903static void add_paths(void)
904{
905 char *old_path = getenv("PATH");
906 const char *start_dir;
907 char *new_path;
908
909 start_dir = tst_get_startwd();
910
911 if (old_path)
912 SAFE_ASPRINTF(&new_path, "%s::%s", old_path, start_dir);
913 else
914 SAFE_ASPRINTF(&new_path, "::%s", start_dir);
915
916 SAFE_SETENV("PATH", new_path, 1);
917 free(new_path);
918}
919
Cyril Hrubis35b8a132017-09-01 10:45:26 +0200920static void heartbeat(void)
921{
Jan Stancek1893e012018-08-28 16:17:52 +0200922 if (tst_clock_gettime(CLOCK_MONOTONIC, &tst_start_time))
923 tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
924
Cyril Hrubis35b8a132017-09-01 10:45:26 +0200925 kill(getppid(), SIGUSR1);
926}
927
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200928static void testrun(void)
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100929{
930 unsigned int i = 0;
931 unsigned long long stop_time = 0;
932 int cont = 1;
933
Jan Stancek1893e012018-08-28 16:17:52 +0200934 heartbeat();
Jan Stancekb95b1992017-10-10 15:47:58 +0200935 add_paths();
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200936 do_test_setup();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100937
938 if (duration > 0)
939 stop_time = get_time_ms() + (unsigned long long)(duration * 1000);
940
941 for (;;) {
942 cont = 0;
943
944 if (i < (unsigned int)iterations) {
945 i++;
946 cont = 1;
947 }
948
949 if (stop_time && get_time_ms() < stop_time)
950 cont = 1;
951
952 if (!cont)
953 break;
954
955 run_tests();
Cyril Hrubis35b8a132017-09-01 10:45:26 +0200956 heartbeat();
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +0100957 }
958
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200959 do_test_cleanup();
960 exit(0);
961}
962
963static pid_t test_pid;
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200964
Cyril Hrubis79163172017-05-18 10:57:07 +0200965
966static volatile sig_atomic_t sigkill_retries;
967
968#define WRITE_MSG(msg) do { \
969 if (write(2, msg, sizeof(msg) - 1)) { \
970 /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 */ \
971 } \
972} while (0)
973
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200974static void alarm_handler(int sig LTP_ATTRIBUTE_UNUSED)
975{
Cyril Hrubis79163172017-05-18 10:57:07 +0200976 WRITE_MSG("Test timeouted, sending SIGKILL!\n");
Cyril Hrubis0f053c82016-06-07 14:29:39 +0200977 kill(-test_pid, SIGKILL);
Cyril Hrubis79163172017-05-18 10:57:07 +0200978 alarm(5);
979
980 if (++sigkill_retries > 10) {
981 WRITE_MSG("Cannot kill test processes!\n");
982 WRITE_MSG("Congratulation, likely test hit a kernel bug.\n");
983 WRITE_MSG("Exitting uncleanly...\n");
984 _exit(TFAIL);
985 }
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +0200986}
987
988static void heartbeat_handler(int sig LTP_ATTRIBUTE_UNUSED)
989{
Cyril Hrubis2ad59b72016-08-03 15:53:55 +0200990 alarm(results->timeout);
Cyril Hrubis79163172017-05-18 10:57:07 +0200991 sigkill_retries = 0;
Cyril Hrubis2ad59b72016-08-03 15:53:55 +0200992}
993
Cyril Hrubisa41e9942016-08-04 16:31:06 +0200994static void sigint_handler(int sig LTP_ATTRIBUTE_UNUSED)
995{
996 if (test_pid > 0) {
Cyril Hrubis79163172017-05-18 10:57:07 +0200997 WRITE_MSG("Sending SIGKILL to test process...\n");
Cyril Hrubisa41e9942016-08-04 16:31:06 +0200998 kill(-test_pid, SIGKILL);
999 }
1000}
1001
Jan Stancek1893e012018-08-28 16:17:52 +02001002unsigned int tst_timeout_remaining(void)
1003{
1004 static struct timespec now;
1005 unsigned int elapsed;
1006
1007 if (tst_clock_gettime(CLOCK_MONOTONIC, &now))
1008 tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
1009
1010 elapsed = (tst_timespec_diff_ms(now, tst_start_time) + 500) / 1000;
1011 if (results->timeout > elapsed)
1012 return results->timeout - elapsed;
1013
1014 return 0;
1015}
1016
Li Wang94823cf2017-07-18 16:23:00 +08001017void tst_set_timeout(int timeout)
Cyril Hrubis2ad59b72016-08-03 15:53:55 +02001018{
1019 char *mul = getenv("LTP_TIMEOUT_MUL");
1020
Li Wang94823cf2017-07-18 16:23:00 +08001021 if (timeout == -1) {
1022 tst_res(TINFO, "Timeout per run is disabled");
1023 return;
1024 }
1025
Cyril Hrubis2ad59b72016-08-03 15:53:55 +02001026 results->timeout = timeout;
1027
1028 if (mul) {
1029 float m = atof(mul);
1030
1031 if (m < 1)
1032 tst_brk(TBROK, "Invalid timeout multiplier '%s'", mul);
1033
1034 results->timeout = results->timeout * m + 0.5;
1035 }
1036
1037 tst_res(TINFO, "Timeout per run is %uh %02um %02us",
1038 results->timeout/3600, (results->timeout%3600)/60,
1039 results->timeout % 60);
1040
1041 if (getpid() == lib_pid)
1042 alarm(results->timeout);
1043 else
Cyril Hrubis35b8a132017-09-01 10:45:26 +02001044 heartbeat();
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001045}
1046
Cyril Hrubis35b8a132017-09-01 10:45:26 +02001047static int fork_testrun(void)
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001048{
1049 int status;
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001050
Cyril Hrubis2ad59b72016-08-03 15:53:55 +02001051 if (tst_test->timeout)
1052 tst_set_timeout(tst_test->timeout);
1053 else
1054 tst_set_timeout(300);
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001055
Cyril Hrubisa41e9942016-08-04 16:31:06 +02001056 SAFE_SIGNAL(SIGINT, sigint_handler);
1057
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001058 test_pid = fork();
1059 if (test_pid < 0)
1060 tst_brk(TBROK | TERRNO, "fork()");
1061
Cyril Hrubis0f053c82016-06-07 14:29:39 +02001062 if (!test_pid) {
Cyril Hrubisa41e9942016-08-04 16:31:06 +02001063 SAFE_SIGNAL(SIGALRM, SIG_DFL);
1064 SAFE_SIGNAL(SIGUSR1, SIG_DFL);
1065 SAFE_SIGNAL(SIGINT, SIG_DFL);
Cyril Hrubis0f053c82016-06-07 14:29:39 +02001066 SAFE_SETPGID(0, 0);
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001067 testrun();
Cyril Hrubis0f053c82016-06-07 14:29:39 +02001068 }
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001069
1070 SAFE_WAITPID(test_pid, &status, 0);
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001071 alarm(0);
Cyril Hrubisa41e9942016-08-04 16:31:06 +02001072 SAFE_SIGNAL(SIGINT, SIG_DFL);
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001073
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001074 if (WIFEXITED(status) && WEXITSTATUS(status))
Cyril Hrubis35b8a132017-09-01 10:45:26 +02001075 return WEXITSTATUS(status);
Cyril Hrubis4aebb6c2016-06-07 13:40:41 +02001076
1077 if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
1078 tst_res(TINFO, "If you are running on slow machine, "
1079 "try exporting LTP_TIMEOUT_MUL > 1");
1080 tst_brk(TBROK, "Test killed! (timeout?)");
1081 }
1082
1083 if (WIFSIGNALED(status))
1084 tst_brk(TBROK, "Test killed by %s!", tst_strsig(WTERMSIG(status)));
1085
Cyril Hrubis35b8a132017-09-01 10:45:26 +02001086 return 0;
1087}
1088
1089static int run_tcases_per_fs(void)
1090{
1091 int ret = 0;
1092 unsigned int i;
1093 const char *const *filesystems = tst_get_supported_fs_types();
1094
1095 if (!filesystems[0])
1096 tst_brk(TCONF, "There are no supported filesystems");
1097
1098 for (i = 0; filesystems[i]; i++) {
Xiong Zhoua0d8c2e2018-03-24 08:47:51 +08001099
1100 tst_res(TINFO, "Testing on %s", filesystems[i]);
Cyril Hrubis35b8a132017-09-01 10:45:26 +02001101 tdev.fs_type = filesystems[i];
1102
1103 prepare_device();
1104
1105 ret = fork_testrun();
1106
1107 if (mntpoint_mounted) {
1108 tst_umount(tst_test->mntpoint);
1109 mntpoint_mounted = 0;
1110 }
1111
1112 if (ret == TCONF) {
1113 update_results(ret);
1114 continue;
1115 }
1116
1117 if (ret == 0)
1118 continue;
1119
1120 do_exit(ret);
1121 }
1122
1123 return ret;
1124}
1125
1126void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
1127{
1128 int ret;
1129
1130 lib_pid = getpid();
1131 tst_test = self;
1132
1133 do_setup(argc, argv);
1134
1135 TCID = tid;
1136
1137 SAFE_SIGNAL(SIGALRM, alarm_handler);
1138 SAFE_SIGNAL(SIGUSR1, heartbeat_handler);
1139
1140 if (tst_test->all_filesystems)
1141 ret = run_tcases_per_fs();
1142 else
1143 ret = fork_testrun();
1144
1145 do_exit(ret);
Cyril Hrubisbbdb9f72016-03-16 15:53:57 +01001146}
Michael Moese1ab33ce2018-03-09 15:16:08 +01001147
1148
1149void tst_flush(void)
1150{
1151 int rval;
1152
1153 rval = fflush(stderr);
1154 if (rval != 0)
1155 tst_brk(TBROK | TERRNO, "fflush(stderr) failed");
1156
1157 rval = fflush(stderr);
1158 if (rval != 0)
1159 tst_brk(TBROK | TERRNO, "fflush(stdout) failed");
1160
1161}