Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Add -F/--dont-fork option

Adding -F/--dont-fork option to bypass forking for each test. It's
useful for debugging test.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: Nilay Vaish <nilayvaish@gmail.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1467113345-12669-1-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
7fa9b8fb 8fbc38aa

+36 -21
+4
tools/perf/Documentation/perf-test.txt
··· 30 30 -v:: 31 31 --verbose:: 32 32 Be more verbose. 33 + 34 + -F:: 35 + --dont-fork:: 36 + Do not fork child for each test, run all tests within single process.
+32 -21
tools/perf/tests/builtin-test.c
··· 14 14 #include <subcmd/parse-options.h> 15 15 #include "symbol.h" 16 16 17 + static bool dont_fork; 18 + 17 19 struct test __weak arch_tests[] = { 18 20 { 19 21 .func = NULL, ··· 249 247 250 248 static int run_test(struct test *test, int subtest) 251 249 { 252 - int status, err = -1, child = fork(); 250 + int status, err = -1, child = dont_fork ? 0 : fork(); 253 251 char sbuf[STRERR_BUFSIZE]; 254 252 255 253 if (child < 0) { ··· 259 257 } 260 258 261 259 if (!child) { 262 - pr_debug("test child forked, pid %d\n", getpid()); 263 - if (!verbose) { 264 - int nullfd = open("/dev/null", O_WRONLY); 265 - if (nullfd >= 0) { 266 - close(STDERR_FILENO); 267 - close(STDOUT_FILENO); 260 + if (!dont_fork) { 261 + pr_debug("test child forked, pid %d\n", getpid()); 268 262 269 - dup2(nullfd, STDOUT_FILENO); 270 - dup2(STDOUT_FILENO, STDERR_FILENO); 271 - close(nullfd); 263 + if (!verbose) { 264 + int nullfd = open("/dev/null", O_WRONLY); 265 + 266 + if (nullfd >= 0) { 267 + close(STDERR_FILENO); 268 + close(STDOUT_FILENO); 269 + 270 + dup2(nullfd, STDOUT_FILENO); 271 + dup2(STDOUT_FILENO, STDERR_FILENO); 272 + close(nullfd); 273 + } 274 + } else { 275 + signal(SIGSEGV, sighandler_dump_stack); 276 + signal(SIGFPE, sighandler_dump_stack); 272 277 } 273 - } else { 274 - signal(SIGSEGV, sighandler_dump_stack); 275 - signal(SIGFPE, sighandler_dump_stack); 276 278 } 277 279 278 280 err = test->func(subtest); 279 - exit(err); 281 + if (!dont_fork) 282 + exit(err); 280 283 } 281 284 282 - wait(&status); 285 + if (!dont_fork) { 286 + wait(&status); 283 287 284 - if (WIFEXITED(status)) { 285 - err = (signed char)WEXITSTATUS(status); 286 - pr_debug("test child finished with %d\n", err); 287 - } else if (WIFSIGNALED(status)) { 288 - err = -1; 289 - pr_debug("test child interrupted\n"); 288 + if (WIFEXITED(status)) { 289 + err = (signed char)WEXITSTATUS(status); 290 + pr_debug("test child finished with %d\n", err); 291 + } else if (WIFSIGNALED(status)) { 292 + err = -1; 293 + pr_debug("test child interrupted\n"); 294 + } 290 295 } 291 296 292 297 return err; ··· 434 425 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"), 435 426 OPT_INCR('v', "verbose", &verbose, 436 427 "be more verbose (show symbol address, etc)"), 428 + OPT_BOOLEAN('F', "dont-fork", &dont_fork, 429 + "Do not fork for testcase"), 437 430 OPT_END() 438 431 }; 439 432 const char * const test_subcommands[] = { "list", NULL };