[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241105142616.761042-2-acme@kernel.org>
Date: Tue, 5 Nov 2024 11:26:13 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Namhyung Kim <namhyung@...nel.org>
Cc: Ingo Molnar <mingo@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>,
Kan Liang <kan.liang@...ux.intel.com>,
Clark Williams <williams@...hat.com>,
linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org,
Arnaldo Carvalho de Melo <acme@...hat.com>,
Athira Rajeev <atrajeev@...ux.vnet.ibm.com>,
Howard Chu <howardchu95@...il.com>,
James Clark <james.clark@...aro.org>,
Leo Yan <leo.yan@...ux.dev>,
Thomas Richter <tmricht@...ux.ibm.com>,
Veronika Molnarova <vmolnaro@...hat.com>
Subject: [PATCH v2 1/4] perf test python: Robustify the 'perf test python' test case
From: Arnaldo Carvalho de Melo <acme@...hat.com>
Even without any python binding or support for loading it present in
perf, the 'import perf' 'perf test' says that testing that feature
somehow "passes":
$ strace -s1024 -f -e execve perf test 17
execve("/home/acme/bin/perf", ["perf", "test", "17"], 0x7ffe99ae5d50 /* 38 vars */) = 0
strace: Process 519319 attached
17: 'import perf' in python : Running (1 active)
strace: Process 519320 attached
[pid 519320] execve("/bin/sh", ["sh", "-c", "--", "echo \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" | 2> /dev/null"], 0x377ba9a0 /* 40 vars */) = 0
strace: Process 519321 attached
strace: Process 519322 attached
<SNIP>
17: 'import perf' in python : Ok
+++ exited with 0 +++
$
It doesn't matter if we fork a new perf process to run just that test
entry or if we don't (using -F).
The system() call (that execve) will return zero even with that echo
being piped into nothing:
# sh -c -- echo \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" | 2> /dev/null
-bash: syntax error near unexpected token `0,'
# echo $?
2
#
If we instead avoid the echo and use 'python -c' to pass that simple
python script just trying to load the non-existent perf binding we get
less processes and a more consistent result even in this pathological
case where PYTHON="":
$ perf test 17
17: 'import perf' in python : FAILED!
$ perf test -F 17
17: 'import perf' in python : FAILED!
$
$ perf test -vv 17
Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
17: 'import perf' in python:
--- start ---
test child forked, pid 522859
python usage test: " -c "import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf" "
sh: line 1: -c: command not found
---- end(-1) ----
17: 'import perf' in python : FAILED!
$
The next patch will sidestep all this by plain not building the python
binding test when the binding isn't built, i.e. with NO_LIBPYTHON=1.
Cc: Adrian Hunter <adrian.hunter@...el.com>
Cc: Athira Rajeev <atrajeev@...ux.vnet.ibm.com>
Cc: Howard Chu <howardchu95@...il.com>
Cc: Ian Rogers <irogers@...gle.com>
Cc: James Clark <james.clark@...aro.org>
Cc: Jiri Olsa <jolsa@...nel.org>
Cc: Kan Liang <kan.liang@...ux.intel.com>
Cc: Leo Yan <leo.yan@...ux.dev>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Thomas Richter <tmricht@...ux.ibm.com>
Cc: Veronika Molnarova <vmolnaro@...hat.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
---
tools/perf/tests/python-use.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c
index 0ebc22ac8d5b47ed..b7325caad22bab10 100644
--- a/tools/perf/tests/python-use.c
+++ b/tools/perf/tests/python-use.c
@@ -14,8 +14,8 @@ static int test__python_use(struct test_suite *test __maybe_unused, int subtest
char *cmd;
int ret;
- if (asprintf(&cmd, "echo \"import sys ; sys.path.insert(0, '%s'); import perf\" | %s %s",
- PYTHONPATH, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0)
+ if (asprintf(&cmd, "%s -c \"import sys ; sys.path.insert(0, '%s'); import perf\" %s",
+ PYTHON, PYTHONPATH, verbose > 0 ? "" : "2> /dev/null") < 0)
return -1;
pr_debug("python usage test: \"%s\"\n", cmd);
--
2.47.0
Powered by blists - more mailing lists