Skip to contentSkip to conversation

'perf test python' fixes/improvements

PATCH Superseded Arnaldo Carvalho de Melo 3 participants 6 messages Nov 4, 2024 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Arnaldo Carvalho de Melo

author maintainer
#0 lore raw

cover 'perf test python' fixes/improvements

From: Arnaldo Carvalho de Melo <[email protected]>

Hi,

While evaluating what is needed for having shell tests that test
python functionality conditionally, i.e. so that we don't try to test the python binding if NO_LIBPYTHON=1 is used, I stumbled into these problems.

The first patch its more for documenting that strange system()
behaviour and to check if this was something that would have implications in other 'perf test' cases besides this python one, maybe somebody will spot the problem, but at least it seems more compact now using 'python -c inline-python-source'.

- Arnaldo

Arnaldo Carvalho de Melo (2):
perf test python: Robustify the 'perf test python' test case
perf test: Don't build the python binding builtin test case with NO_LIBPYTHON=1

 tools/perf/tests/Build          | 2 +-
 tools/perf/tests/builtin-test.c | 2 ++
 tools/perf/tests/python-use.c   | 4 ++--
 tools/perf/tests/tests.h        | 2 ++
 4 files changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.0
author maintainer
#1 lore raw

PATCH 1/2 perf test python: Robustify the 'perf test python' test case

From: Arnaldo Carvalho de Melo <[email protected]>

While working on a patch to not build the 'perf test' entry that tests the python binding when NO_LIBPYTHON=1 is used when building perf, meaning that the python binding will not be built, thus no need to test it, I noticed this inconsistency:

  $ perf test 17
   17: 'import perf' in python                                         : Ok
  $ perf test -F 17
   17: 'import perf' in python                                         : Ok
  $
  $ perf check feature libpython
               libpython: [ OFF ]  # HAVE_LIBPYTHON_SUPPORT
  $ ldd ~/bin/perf | grep python
  $

Even without any python binding or support for loading it present in perf, it 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
  [pid 519321] +++ exited with 0 +++
  [pid 519322] +++ exited with 0 +++
  [pid 519320] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=519321, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 519320] +++ exited with 0 +++
  [pid 519319] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=519320, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 519319] +++ exited with 0 +++
   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:

  $ perf test -h -F

Usage: perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]

-F, --dont-fork Do not fork for testcase
$

  $ strace -s1024 -f -e execve perf test -F 17
  execve("/home/acme/bin/perf", ["perf", "test", "-F", "17"], 0x7ffda8fafed8 /* 38 vars */) = 0
  strace: Process 519336 attached
  [pid 519336] execve("/bin/sh", ["sh", "-c", "--", "echo \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" |  2> /dev/null"], 0x159d99a0 /* 40 vars */) = 0
  strace: Process 519337 attached
  strace: Process 519338 attached
  [pid 519337] +++ exited with 0 +++
  [pid 519338] +++ exited with 0 +++
  [pid 519336] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=519337, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 519336] +++ exited with 0 +++
  --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=519336, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
   17: 'import perf' in python                                         : Ok
  +++ exited with 0 +++
  $

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
  # sh -c -- echo \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" |
  -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 <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Howard Chu <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Leo Yan <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Thomas Richter <[email protected]>
Cc Veronika Molnarova <[email protected]>
---
 tools/perf/tests/python-use.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/python-use.c +2 -2
index 0ebc22ac8d5b47ed..b7325caad22bab10 100644
@@ -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);
Signature · 1 line
2.47.0
reviewer Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] perf test python: Robustify the 'perf test python' test case

Quoted 101 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

While working on a patch to not build the 'perf test' entry that tests the python binding when NO_LIBPYTHON=1 is used when building perf, meaning that the python binding will not be built, thus no need to test it, I noticed this inconsistency:

  $ perf test 17
   17: 'import perf' in python                                         : Ok
  $ perf test -F 17
   17: 'import perf' in python                                         : Ok
  $
  $ perf check feature libpython
               libpython: [ OFF ]  # HAVE_LIBPYTHON_SUPPORT
  $ ldd ~/bin/perf | grep python
  $

Even without any python binding or support for loading it present in perf, it 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
  [pid 519321] +++ exited with 0 +++
  [pid 519322] +++ exited with 0 +++
  [pid 519320] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=519321, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 519320] +++ exited with 0 +++
  [pid 519319] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=519320, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 519319] +++ exited with 0 +++
   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:

  $ perf test -h -F

Usage: perf test [<options>] [{list <test-name-fragment>|[<test-name-fragments>|<test-numbers>]}]

-F, --dont-fork Do not fork for testcase
$

  $ strace -s1024 -f -e execve perf test -F 17
  execve("/home/acme/bin/perf", ["perf", "test", "-F", "17"], 0x7ffda8fafed8 /* 38 vars */) = 0
  strace: Process 519336 attached
  [pid 519336] execve("/bin/sh", ["sh", "-c", "--", "echo \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" |  2> /dev/null"], 0x159d99a0 /* 40 vars */) = 0
  strace: Process 519337 attached
  strace: Process 519338 attached
  [pid 519337] +++ exited with 0 +++
  [pid 519338] +++ exited with 0 +++
  [pid 519336] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=519337, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 519336] +++ exited with 0 +++
  --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=519336, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
   17: 'import perf' in python                                         : Ok
  +++ exited with 0 +++
  $

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
  # sh -c -- echo \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" |
  -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.

Quoted 12 lines
Cc Adrian Hunter <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Howard Chu <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Leo Yan <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Thomas Richter <[email protected]>
Cc Veronika Molnarova <[email protected]>

Fwiw, I found the commit message overly long.

Thanks,
Ian

Quoted 22 lines
---
 tools/perf/tests/python-use.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/tests/python-use.c +2 -3
index 0ebc22ac8d5b47ed..b7325caad22bab10 100644
@@ -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

author maintainer
#3 lore raw

PATCH 2/2 perf test: Don't build the python binding builtin test case with NO_LIBPYTHON=1

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

The python_use test suite was being built even when the python binding that it is designed to test is not being built, fix it.

Testing this patch:

When building with NO_LIBPYTHON=1, i.e. explicitely disabling linking against libpython and thus not building the python binding:

  $ perf check feature libpython
             libpython: [ OFF ]  # HAVE_LIBPYTHON_SUPPORT
  $ perf test "import perf"
  $

Not disabling linking with libpython, the default, that results in the python binding being built:

  $ perf check feature libpython
               libpython: [ on  ]  # HAVE_LIBPYTHON_SUPPORT
  $ perf test "import perf"
   17: 'import perf' in python                                         : Ok
  $ perf test -vv "import perf"
  Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
   17: 'import perf' in python:
  --- start ---
  test child forked, pid 533419
  python usage test: "'/usr/bin/python3' -c "import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf" "
  ---- end(0) ----
   17: 'import perf' in python                                         : Ok
  $ strace -s1024 -f -e execve perf test 17
  execve("/home/acme/bin/perf", ["perf", "test", "17"], 0x7ffe04832040 /* 38 vars */) = 0
  strace: Process 533458 attached
   17: 'import perf' in python                                         : Running (1 active)
  strace: Process 533459 attached
  [pid 533459] execve("/bin/sh", ["sh", "-c", "--", "'/usr/bin/python3' -c \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" 2> /dev/null"], 0x133179a0 /* 40 vars */) = 0
  strace: Process 533460 attached
  [pid 533460] execve("/usr/bin/python3", ["/usr/bin/python3", "-c", "import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf"], 0x5566715c7280 /* 40 vars */) = 0
  [pid 533460] +++ exited with 0 +++
  [pid 533459] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=533460, si_uid=1000, si_status=0, si_utime=4 /* 0.04 s */, si_stime=2 /* 0.02 s */} ---
  [pid 533459] +++ exited with 0 +++
  [pid 533458] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=533459, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 533458] +++ exited with 0 +++
   17: 'import perf' in python                                         : Ok
  +++ exited with 0 +++
  $
Cc Adrian Hunter <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Howard Chu <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Leo Yan <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Thomas Richter <[email protected]>
Cc Veronika Molnarova <[email protected]>
---
 tools/perf/tests/Build          | 2 +-
 tools/perf/tests/builtin-test.c | 2 ++
 tools/perf/tests/tests.h        | 2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)
tools/perf/tests/Build +1 -1
index 01ed9335db4dba4e..8596616907adf244 100644
@@ -20,7 +20,7 @@ perf-test-y += hists_link.o
 perf-test-y += hists_filter.o
 perf-test-y += hists_output.o
 perf-test-y += hists_cumulate.o
-perf-test-y += python-use.o
+perf-test-$(CONFIG_LIBPYTHON) += python-use.o
 perf-test-y += bp_signal.o
 perf-test-y += bp_signal_overflow.o
 perf-test-y += bp_account.o
tools/perf/tests/builtin-test.c +2 -0
index d2cabaa8ad922d68..13f7b24694d1d0b0 100644
@@ -79,7 +79,9 @@ static struct test_suite *generic_tests[] = {
 	&suite__syscall_openat_tp_fields,
 #endif
 	&suite__hists_link,
+#ifdef HAVE_LIBPYTHON_SUPPORT
 	&suite__python_use,
+#endif
 	&suite__bp_signal,
 	&suite__bp_signal_overflow,
 	&suite__bp_accounting,
tools/perf/tests/tests.h +2 -0
index af284dd47e5c7855..3144c7916532825c 100644
@@ -99,7 +99,9 @@ DECLARE_SUITE(dso_data_cache);
 DECLARE_SUITE(dso_data_reopen);
 DECLARE_SUITE(parse_events);
 DECLARE_SUITE(hists_link);
+#ifdef HAVE_LIBPYTHON_SUPPORT
 DECLARE_SUITE(python_use);
+#endif
 DECLARE_SUITE(bp_signal);
 DECLARE_SUITE(bp_signal_overflow);
 DECLARE_SUITE(bp_accounting);
Signature · 1 line
2.47.0
reviewer Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] perf test: Don't build the python binding builtin test case with NO_LIBPYTHON=1

Quoted 5 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

The python_use test suite was being built even when the python binding that it is designed to test is not being built, fix it.

The python module that the test is testing isn't strictly using libpython.so, that's perf script. Perhaps there needs to be more than 1 overloaded #define.

Thanks,
Ian

Quoted 104 lines

Testing this patch:

When building with NO_LIBPYTHON=1, i.e. explicitely disabling linking against libpython and thus not building the python binding:

  $ perf check feature libpython
             libpython: [ OFF ]  # HAVE_LIBPYTHON_SUPPORT
  $ perf test "import perf"
  $

Not disabling linking with libpython, the default, that results in the python binding being built:

  $ perf check feature libpython
               libpython: [ on  ]  # HAVE_LIBPYTHON_SUPPORT
  $ perf test "import perf"
   17: 'import perf' in python                                         : Ok
  $ perf test -vv "import perf"
  Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
   17: 'import perf' in python:
  --- start ---
  test child forked, pid 533419
  python usage test: "'/usr/bin/python3' -c "import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf" "
  ---- end(0) ----
   17: 'import perf' in python                                         : Ok
  $ strace -s1024 -f -e execve perf test 17
  execve("/home/acme/bin/perf", ["perf", "test", "17"], 0x7ffe04832040 /* 38 vars */) = 0
  strace: Process 533458 attached
   17: 'import perf' in python                                         : Running (1 active)
  strace: Process 533459 attached
  [pid 533459] execve("/bin/sh", ["sh", "-c", "--", "'/usr/bin/python3' -c \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" 2> /dev/null"], 0x133179a0 /* 40 vars */) = 0
  strace: Process 533460 attached
  [pid 533460] execve("/usr/bin/python3", ["/usr/bin/python3", "-c", "import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf"], 0x5566715c7280 /* 40 vars */) = 0
  [pid 533460] +++ exited with 0 +++
  [pid 533459] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=533460, si_uid=1000, si_status=0, si_utime=4 /* 0.04 s */, si_stime=2 /* 0.02 s */} ---
  [pid 533459] +++ exited with 0 +++
  [pid 533458] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=533459, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 533458] +++ exited with 0 +++
   17: 'import perf' in python                                         : Ok
  +++ exited with 0 +++
  $
Cc Adrian Hunter <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Howard Chu <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Leo Yan <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Thomas Richter <[email protected]>
Cc Veronika Molnarova <[email protected]>
---
 tools/perf/tests/Build          | 2 +-
 tools/perf/tests/builtin-test.c | 2 ++
 tools/perf/tests/tests.h        | 2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)
tools/perf/tests/Build +1 -1
index 01ed9335db4dba4e..8596616907adf244 100644
@@ -20,7 +20,7 @@ perf-test-y += hists_link.o
 perf-test-y += hists_filter.o
 perf-test-y += hists_output.o
 perf-test-y += hists_cumulate.o
-perf-test-y += python-use.o
+perf-test-$(CONFIG_LIBPYTHON) += python-use.o
 perf-test-y += bp_signal.o
 perf-test-y += bp_signal_overflow.o
 perf-test-y += bp_account.o
tools/perf/tests/builtin-test.c +2 -0
index d2cabaa8ad922d68..13f7b24694d1d0b0 100644
@@ -79,7 +79,9 @@ static struct test_suite *generic_tests[] = {
        &suite__syscall_openat_tp_fields,
 #endif
        &suite__hists_link,
+#ifdef HAVE_LIBPYTHON_SUPPORT
        &suite__python_use,
+#endif
        &suite__bp_signal,
        &suite__bp_signal_overflow,
        &suite__bp_accounting,
tools/perf/tests/tests.h +2 -1
index af284dd47e5c7855..3144c7916532825c 100644
@@ -99,7 +99,9 @@ DECLARE_SUITE(dso_data_cache);
 DECLARE_SUITE(dso_data_reopen);
 DECLARE_SUITE(parse_events);
 DECLARE_SUITE(hists_link);
+#ifdef HAVE_LIBPYTHON_SUPPORT
 DECLARE_SUITE(python_use);
+#endif
 DECLARE_SUITE(bp_signal);
 DECLARE_SUITE(bp_signal_overflow);
 DECLARE_SUITE(bp_accounting);
--

2.47.0

maintainer
#5 lore raw

Re: [PATCH 2/2] perf test: Don't build the python binding builtin test case with NO_LIBPYTHON=1

In reply to Arnaldo Carvalho de Melo
Quoted 4 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

The python_use test suite was being built even when the python binding that it is designed to test is not being built, fix it.

Can we keep the test and skip it instead? It'd be helpful to maintain the test number consistent and to give a clear message why it skipped.

Thanks,
Namhyung

Quoted 105 lines

Testing this patch:

When building with NO_LIBPYTHON=1, i.e. explicitely disabling linking against libpython and thus not building the python binding:

  $ perf check feature libpython
             libpython: [ OFF ]  # HAVE_LIBPYTHON_SUPPORT
  $ perf test "import perf"
  $

Not disabling linking with libpython, the default, that results in the python binding being built:

  $ perf check feature libpython
               libpython: [ on  ]  # HAVE_LIBPYTHON_SUPPORT
  $ perf test "import perf"
   17: 'import perf' in python                                         : Ok
  $ perf test -vv "import perf"
  Couldn't bump rlimit(MEMLOCK), failures may take place when creating BPF maps, etc
   17: 'import perf' in python:
  --- start ---
  test child forked, pid 533419
  python usage test: "'/usr/bin/python3' -c "import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf" "
  ---- end(0) ----
   17: 'import perf' in python                                         : Ok
  $ strace -s1024 -f -e execve perf test 17
  execve("/home/acme/bin/perf", ["perf", "test", "17"], 0x7ffe04832040 /* 38 vars */) = 0
  strace: Process 533458 attached
   17: 'import perf' in python                                         : Running (1 active)
  strace: Process 533459 attached
  [pid 533459] execve("/bin/sh", ["sh", "-c", "--", "'/usr/bin/python3' -c \"import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf\" 2> /dev/null"], 0x133179a0 /* 40 vars */) = 0
  strace: Process 533460 attached
  [pid 533460] execve("/usr/bin/python3", ["/usr/bin/python3", "-c", "import sys ; sys.path.insert(0, '/tmp/build/perf-tools-next/python'); import perf"], 0x5566715c7280 /* 40 vars */) = 0
  [pid 533460] +++ exited with 0 +++
  [pid 533459] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=533460, si_uid=1000, si_status=0, si_utime=4 /* 0.04 s */, si_stime=2 /* 0.02 s */} ---
  [pid 533459] +++ exited with 0 +++
  [pid 533458] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=533459, si_uid=1000, si_status=0, si_utime=0, si_stime=0} ---
  [pid 533458] +++ exited with 0 +++
   17: 'import perf' in python                                         : Ok
  +++ exited with 0 +++
  $
Cc Adrian Hunter <[email protected]>
Cc Athira Rajeev <[email protected]>
Cc Howard Chu <[email protected]>
Cc Ian Rogers <[email protected]>
Cc James Clark <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Kan Liang <[email protected]>
Cc Leo Yan <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Thomas Richter <[email protected]>
Cc Veronika Molnarova <[email protected]>
---
 tools/perf/tests/Build          | 2 +-
 tools/perf/tests/builtin-test.c | 2 ++
 tools/perf/tests/tests.h        | 2 ++
 3 files changed, 5 insertions(+), 1 deletion(-)
tools/perf/tests/Build +1 -1
index 01ed9335db4dba4e..8596616907adf244 100644
@@ -20,7 +20,7 @@ perf-test-y += hists_link.o
 perf-test-y += hists_filter.o
 perf-test-y += hists_output.o
 perf-test-y += hists_cumulate.o
-perf-test-y += python-use.o
+perf-test-$(CONFIG_LIBPYTHON) += python-use.o
 perf-test-y += bp_signal.o
 perf-test-y += bp_signal_overflow.o
 perf-test-y += bp_account.o
tools/perf/tests/builtin-test.c +2 -0
index d2cabaa8ad922d68..13f7b24694d1d0b0 100644
@@ -79,7 +79,9 @@ static struct test_suite *generic_tests[] = {
 	&suite__syscall_openat_tp_fields,
 #endif
 	&suite__hists_link,
+#ifdef HAVE_LIBPYTHON_SUPPORT
 	&suite__python_use,
+#endif
 	&suite__bp_signal,
 	&suite__bp_signal_overflow,
 	&suite__bp_accounting,
tools/perf/tests/tests.h +2 -0
index af284dd47e5c7855..3144c7916532825c 100644
@@ -99,7 +99,9 @@ DECLARE_SUITE(dso_data_cache);
 DECLARE_SUITE(dso_data_reopen);
 DECLARE_SUITE(parse_events);
 DECLARE_SUITE(hists_link);
+#ifdef HAVE_LIBPYTHON_SUPPORT
 DECLARE_SUITE(python_use);
+#endif
 DECLARE_SUITE(bp_signal);
 DECLARE_SUITE(bp_signal_overflow);
 DECLARE_SUITE(bp_accounting);
Signature · 1 line
2.47.0