aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2016-06-28 07:29:01 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-06-30 17:27:45 -0400
commit7fa9b8fba0b55edd1ff5b8ea696ec75fc5f6194c (patch)
treee4f3236715e90375bfd268d1d34af713896bb12b /tools
parent8fbc38aaaf542433ef195e5fae704c56d1c071e6 (diff)
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>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Documentation/perf-test.txt4
-rw-r--r--tools/perf/tests/builtin-test.c55
2 files changed, 37 insertions, 22 deletions
diff --git a/tools/perf/Documentation/perf-test.txt b/tools/perf/Documentation/perf-test.txt
index 31a5c3ea7f74..b329c65d7f40 100644
--- a/tools/perf/Documentation/perf-test.txt
+++ b/tools/perf/Documentation/perf-test.txt
@@ -30,3 +30,7 @@ OPTIONS
30-v:: 30-v::
31--verbose:: 31--verbose::
32 Be more verbose. 32 Be more verbose.
33
34-F::
35--dont-fork::
36 Do not fork child for each test, run all tests within single process.
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 0e95c20ecf6e..5781c1640eae 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -14,6 +14,8 @@
14#include <subcmd/parse-options.h> 14#include <subcmd/parse-options.h>
15#include "symbol.h" 15#include "symbol.h"
16 16
17static bool dont_fork;
18
17struct test __weak arch_tests[] = { 19struct test __weak arch_tests[] = {
18 { 20 {
19 .func = NULL, 21 .func = NULL,
@@ -247,7 +249,7 @@ static bool perf_test__matches(struct test *test, int curr, int argc, const char
247 249
248static int run_test(struct test *test, int subtest) 250static int run_test(struct test *test, int subtest)
249{ 251{
250 int status, err = -1, child = fork(); 252 int status, err = -1, child = dont_fork ? 0 : fork();
251 char sbuf[STRERR_BUFSIZE]; 253 char sbuf[STRERR_BUFSIZE];
252 254
253 if (child < 0) { 255 if (child < 0) {
@@ -257,34 +259,41 @@ static int run_test(struct test *test, int subtest)
257 } 259 }
258 260
259 if (!child) { 261 if (!child) {
260 pr_debug("test child forked, pid %d\n", getpid()); 262 if (!dont_fork) {
261 if (!verbose) { 263 pr_debug("test child forked, pid %d\n", getpid());
262 int nullfd = open("/dev/null", O_WRONLY); 264
263 if (nullfd >= 0) { 265 if (!verbose) {
264 close(STDERR_FILENO); 266 int nullfd = open("/dev/null", O_WRONLY);
265 close(STDOUT_FILENO); 267
266 268 if (nullfd >= 0) {
267 dup2(nullfd, STDOUT_FILENO); 269 close(STDERR_FILENO);
268 dup2(STDOUT_FILENO, STDERR_FILENO); 270 close(STDOUT_FILENO);
269 close(nullfd); 271
272 dup2(nullfd, STDOUT_FILENO);
273 dup2(STDOUT_FILENO, STDERR_FILENO);
274 close(nullfd);
275 }
276 } else {
277 signal(SIGSEGV, sighandler_dump_stack);
278 signal(SIGFPE, sighandler_dump_stack);
270 } 279 }
271 } else {
272 signal(SIGSEGV, sighandler_dump_stack);
273 signal(SIGFPE, sighandler_dump_stack);
274 } 280 }
275 281
276 err = test->func(subtest); 282 err = test->func(subtest);
277 exit(err); 283 if (!dont_fork)
284 exit(err);
278 } 285 }
279 286
280 wait(&status); 287 if (!dont_fork) {
288 wait(&status);
281 289
282 if (WIFEXITED(status)) { 290 if (WIFEXITED(status)) {
283 err = (signed char)WEXITSTATUS(status); 291 err = (signed char)WEXITSTATUS(status);
284 pr_debug("test child finished with %d\n", err); 292 pr_debug("test child finished with %d\n", err);
285 } else if (WIFSIGNALED(status)) { 293 } else if (WIFSIGNALED(status)) {
286 err = -1; 294 err = -1;
287 pr_debug("test child interrupted\n"); 295 pr_debug("test child interrupted\n");
296 }
288 } 297 }
289 298
290 return err; 299 return err;
@@ -425,6 +434,8 @@ int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
425 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"), 434 OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
426 OPT_INCR('v', "verbose", &verbose, 435 OPT_INCR('v', "verbose", &verbose,
427 "be more verbose (show symbol address, etc)"), 436 "be more verbose (show symbol address, etc)"),
437 OPT_BOOLEAN('F', "dont-fork", &dont_fork,
438 "Do not fork for testcase"),
428 OPT_END() 439 OPT_END()
429 }; 440 };
430 const char * const test_subcommands[] = { "list", NULL }; 441 const char * const test_subcommands[] = { "list", NULL };