Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1434856

Re: [PATCH 1/5] perf test: Add -F/--dont-fork option

From Arnaldo Carvalho de Melo <acme@kernel.org>
Newsgroups linux.kernel
Subject Re: [PATCH 1/5] perf test: Add -F/--dont-fork option
Date 2016-06-30 23:20 +0200
Message-ID <rPRxo-6a8-1@gated-at.bofh.it> (permalink)
References <rOZnk-6lK-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Em Tue, Jun 28, 2016 at 01:29:01PM +0200, Jiri Olsa escreveu:
> Adding -F/--dont-fork option to bypass forking
> for each test. It's useful for debugging test.

Applied, but moved 1/5 to after the csets fixing things that breaks with
it, I tested those without this one and they work, then with -F and they
continue working, no bisect breakage that way.

- Arnaldo
 
> Link: http://lkml.kernel.org/n/tip-yq9gy0fcr8nl70986gwnl3dh@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/Documentation/perf-test.txt |  4 +++
>  tools/perf/tests/builtin-test.c        | 55 ++++++++++++++++++++--------------
>  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
>  -v::
>  --verbose::
>  	Be more verbose.
> +
> +-F::
> +--dont-fork::
> +	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 @@
>  #include <subcmd/parse-options.h>
>  #include "symbol.h"
>  
> +static bool dont_fork;
> +
>  struct test __weak arch_tests[] = {
>  	{
>  		.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)
>  {
> -	int status, err = -1, child = fork();
> +	int status, err = -1, child = dont_fork ? 0 : fork();
>  	char sbuf[STRERR_BUFSIZE];
>  
>  	if (child < 0) {
> @@ -257,34 +259,41 @@ static int run_test(struct test *test, int subtest)
>  	}
>  
>  	if (!child) {
> -		pr_debug("test child forked, pid %d\n", getpid());
> -		if (!verbose) {
> -			int nullfd = open("/dev/null", O_WRONLY);
> -			if (nullfd >= 0) {
> -				close(STDERR_FILENO);
> -				close(STDOUT_FILENO);
> -
> -				dup2(nullfd, STDOUT_FILENO);
> -				dup2(STDOUT_FILENO, STDERR_FILENO);
> -				close(nullfd);
> +		if (!dont_fork) {
> +			pr_debug("test child forked, pid %d\n", getpid());
> +
> +			if (!verbose) {
> +				int nullfd = open("/dev/null", O_WRONLY);
> +
> +				if (nullfd >= 0) {
> +					close(STDERR_FILENO);
> +					close(STDOUT_FILENO);
> +
> +					dup2(nullfd, STDOUT_FILENO);
> +					dup2(STDOUT_FILENO, STDERR_FILENO);
> +					close(nullfd);
> +				}
> +			} else {
> +				signal(SIGSEGV, sighandler_dump_stack);
> +				signal(SIGFPE, sighandler_dump_stack);
>  			}
> -		} else {
> -			signal(SIGSEGV, sighandler_dump_stack);
> -			signal(SIGFPE, sighandler_dump_stack);
>  		}
>  
>  		err = test->func(subtest);
> -		exit(err);
> +		if (!dont_fork)
> +			exit(err);
>  	}
>  
> -	wait(&status);
> +	if (!dont_fork) {
> +		wait(&status);
>  
> -	if (WIFEXITED(status)) {
> -		err = (signed char)WEXITSTATUS(status);
> -		pr_debug("test child finished with %d\n", err);
> -	} else if (WIFSIGNALED(status)) {
> -		err = -1;
> -		pr_debug("test child interrupted\n");
> +		if (WIFEXITED(status)) {
> +			err = (signed char)WEXITSTATUS(status);
> +			pr_debug("test child finished with %d\n", err);
> +		} else if (WIFSIGNALED(status)) {
> +			err = -1;
> +			pr_debug("test child interrupted\n");
> +		}
>  	}
>  
>  	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_INCR('v', "verbose", &verbose,
>  		    "be more verbose (show symbol address, etc)"),
> +	OPT_BOOLEAN('F', "dont-fork", &dont_fork,
> +		    "Do not fork for testcase"),
>  	OPT_END()
>  	};
>  	const char * const test_subcommands[] = { "list", NULL };
> -- 
> 2.4.11

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 1/5] perf test: Add -F/--dont-fork option Jiri Olsa <jolsa@kernel.org> - 2016-06-28 13:40 +0200
  [PATCH 4/5] perf tools: Change cpu_map__fprintf output Jiri Olsa <jolsa@kernel.org> - 2016-06-28 13:40 +0200
    [tip:perf/core] perf tools: Change cpu_map__fprintf output tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-07-01 09:00 +0200
  [PATCH 2/5] perf tools: Allow to reset open files counter Jiri Olsa <jolsa@kernel.org> - 2016-06-28 13:40 +0200
    Re: [PATCH 2/5] perf tools: Allow to reset open files counter Nilay Vaish <nilayvaish@gmail.com> - 2016-06-29 18:10 +0200
      Re: [PATCH 2/5] perf tools: Allow to reset open files counter Nilay Vaish <nilayvaish@gmail.com> - 2016-06-30 15:30 +0200
    [tip:perf/core] perf tools: Allow to reset open files counter tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-07-01 08:50 +0200
  [PATCH 5/5] perf tools: Transform nodes string info to struct Jiri Olsa <jolsa@kernel.org> - 2016-06-28 13:40 +0200
    Re: [PATCH 5/5] perf tools: Transform nodes string info to struct Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-30 23:30 +0200
      Re: [PATCH 5/5] perf tools: Transform nodes string info to struct Jiri Olsa <jolsa@redhat.com> - 2016-07-01 08:30 +0200
  Re: [PATCH 1/5] perf test: Add -F/--dont-fork option Nilay Vaish <nilayvaish@gmail.com> - 2016-06-29 18:10 +0200
    Re: [PATCH 1/5] perf test: Add -F/--dont-fork option Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-29 18:10 +0200
      Re: [PATCH 1/5] perf test: Add -F/--dont-fork option Nilay Vaish <nilayvaish@gmail.com> - 2016-06-30 15:30 +0200
  Re: [PATCH 1/5] perf test: Add -F/--dont-fork option Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-30 23:20 +0200
  [tip:perf/core] perf test: Add -F/--dont-fork option tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-07-01 08:50 +0200

csiph-web