Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7fa9b8fb authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo
Browse files

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: default avatarJiri Olsa <jolsa@kernel.org>
Tested-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: default avatarNilay 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 8fbc38aa
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -30,3 +30,7 @@ OPTIONS
-v::
-v::
--verbose::
--verbose::
	Be more verbose.
	Be more verbose.

-F::
--dont-fork::
	Do not fork child for each test, run all tests within single process.
+33 −22
Original line number Original line Diff line number Diff line
@@ -14,6 +14,8 @@
#include <subcmd/parse-options.h>
#include <subcmd/parse-options.h>
#include "symbol.h"
#include "symbol.h"


static bool dont_fork;

struct test __weak arch_tests[] = {
struct test __weak arch_tests[] = {
	{
	{
		.func = NULL,
		.func = NULL,
@@ -247,7 +249,7 @@ static bool perf_test__matches(struct test *test, int curr, int argc, const char


static int run_test(struct test *test, int subtest)
static int run_test(struct test *test, int subtest)
{
{
	int status, err = -1, child = fork();
	int status, err = -1, child = dont_fork ? 0 : fork();
	char sbuf[STRERR_BUFSIZE];
	char sbuf[STRERR_BUFSIZE];


	if (child < 0) {
	if (child < 0) {
@@ -257,9 +259,12 @@ static int run_test(struct test *test, int subtest)
	}
	}


	if (!child) {
	if (!child) {
		if (!dont_fork) {
			pr_debug("test child forked, pid %d\n", getpid());
			pr_debug("test child forked, pid %d\n", getpid());

			if (!verbose) {
			if (!verbose) {
				int nullfd = open("/dev/null", O_WRONLY);
				int nullfd = open("/dev/null", O_WRONLY);

				if (nullfd >= 0) {
				if (nullfd >= 0) {
					close(STDERR_FILENO);
					close(STDERR_FILENO);
					close(STDOUT_FILENO);
					close(STDOUT_FILENO);
@@ -272,11 +277,14 @@ static int run_test(struct test *test, int subtest)
				signal(SIGSEGV, sighandler_dump_stack);
				signal(SIGSEGV, sighandler_dump_stack);
				signal(SIGFPE, sighandler_dump_stack);
				signal(SIGFPE, sighandler_dump_stack);
			}
			}
		}


		err = test->func(subtest);
		err = test->func(subtest);
		if (!dont_fork)
			exit(err);
			exit(err);
	}
	}


	if (!dont_fork) {
		wait(&status);
		wait(&status);


		if (WIFEXITED(status)) {
		if (WIFEXITED(status)) {
@@ -286,6 +294,7 @@ static int run_test(struct test *test, int subtest)
			err = -1;
			err = -1;
			pr_debug("test child interrupted\n");
			pr_debug("test child interrupted\n");
		}
		}
	}


	return err;
	return err;
}
}
@@ -425,6 +434,8 @@ int cmd_test(int argc, const char **argv, const char *prefix __maybe_unused)
	OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
	OPT_STRING('s', "skip", &skip, "tests", "tests to skip"),
	OPT_INCR('v', "verbose", &verbose,
	OPT_INCR('v', "verbose", &verbose,
		    "be more verbose (show symbol address, etc)"),
		    "be more verbose (show symbol address, etc)"),
	OPT_BOOLEAN('F', "dont-fork", &dont_fork,
		    "Do not fork for testcase"),
	OPT_END()
	OPT_END()
	};
	};
	const char * const test_subcommands[] = { "list", NULL };
	const char * const test_subcommands[] = { "list", NULL };