Skip to content

Commit

Permalink
perf tests: Spawn child for each test
Browse files Browse the repository at this point in the history
In upcoming tests we will setup process limits, which
might affect other tests. Spawning child for each test
to prevent this.

Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jean Pihet <jean.pihet@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Reviewed-by: David Ahern <dsahern@gmail.com>
Link: http://lkml.kernel.org/r/1401892622-30848-11-git-send-email-jolsa@kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
  • Loading branch information
Jiri Olsa committed Jun 12, 2014
1 parent c1f9aa0 commit 0d8a5fa
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tools/perf/tests/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* Builtin regression testing command: ever growing number of sanity tests
*/
#include <unistd.h>
#include <string.h>
#include "builtin.h"
#include "intlist.h"
#include "tests.h"
Expand Down Expand Up @@ -172,6 +174,34 @@ static bool perf_test__matches(int curr, int argc, const char *argv[])
return false;
}

static int run_test(struct test *test)
{
int status, err = -1, child = fork();

if (child < 0) {
pr_err("failed to fork test: %s\n", strerror(errno));
return -1;
}

if (!child) {
pr_debug("test child forked, pid %d\n", getpid());
err = test->func();
exit(err);
}

wait(&status);

if (WIFEXITED(status)) {
err = 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;
}

static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
{
int i = 0;
Expand Down Expand Up @@ -200,7 +230,7 @@ static int __cmd_test(int argc, const char *argv[], struct intlist *skiplist)
}

pr_debug("\n--- start ---\n");
err = tests[curr].func();
err = run_test(&tests[curr]);
pr_debug("---- end ----\n%s:", tests[curr].desc);

switch (err) {
Expand Down

0 comments on commit 0d8a5fa

Please sign in to comment.