Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf test: Add an 'import perf' test shell script

The 'import perf' test needs to set up a path to the python module as
well as to know the python command to invoke.

These are hard coded at build time to be build a directory and the
python used in the build, which is less than desirable.

Avoid the hard coded values by reusing the existing shell script python
setup and determine a potential built python module via the path of the
perf executable.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Collin Funk <collin.funk1@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
33706fb0 9f0fa213

+36
+36
tools/perf/tests/shell/python-use.sh
··· 1 + #!/bin/bash 2 + # 'import perf' in python 3 + # SPDX-License-Identifier: GPL-2.0 4 + # Just test if we can load the python binding. 5 + set -e 6 + 7 + shelldir=$(dirname "$0") 8 + # shellcheck source=lib/setup_python.sh 9 + . "${shelldir}"/lib/setup_python.sh 10 + 11 + MODULE_DIR=$(dirname "$(which perf)")/python 12 + 13 + if [ -d "$MODULE_DIR" ] 14 + then 15 + CMD=$(cat <<EOF 16 + import sys 17 + sys.path.insert(0, '$MODULE_DIR') 18 + import perf 19 + print('success!') 20 + EOF 21 + ) 22 + else 23 + CMD=$(cat <<EOF 24 + import perf 25 + print('success!') 26 + EOF 27 + ) 28 + fi 29 + 30 + echo -e "Testing 'import perf' with:\n$CMD" 31 + 32 + if ! echo "$CMD" | $PYTHON | grep -q "success!" 33 + then 34 + exit 1 35 + fi 36 + exit 0