From: Jiri Olsa <jolsa@redhat.com>
To: Denys Zagorui <dzagorui@cisco.com>
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, namhyung@kernel.org
Subject: Re: [PATCH v7 2/3] perf tests: avoid storing an absolute path in perf binary
Date: Sun, 23 May 2021 18:30:44 +0200 [thread overview]
Message-ID: <YKqDNJbKOR5NqloD@krava> (raw)
In-Reply-To: <20210522062016.84677-2-dzagorui@cisco.com>
On Fri, May 21, 2021 at 11:20:15PM -0700, Denys Zagorui wrote:
> python binding test uses PYTHONPATH definition to find python/perf.so
> library. This definition is an absolute path that makes perf binary
> unreproducible. This path can be found during runtime execution.
>
> Signed-off-by: Denys Zagorui <dzagorui@cisco.com>
> ---
> tools/perf/tests/Build | 2 +-
> tools/perf/tests/python-use.c | 32 ++++++++++++++++++++++++++++++--
> 2 files changed, 31 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> index 650aec19d490..a20098dcdbc4 100644
> --- a/tools/perf/tests/Build
> +++ b/tools/perf/tests/Build
> @@ -98,5 +98,5 @@ perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o
> endif
>
> CFLAGS_attr.o += -DBINDIR="BUILD_STR($(bindir_SQ))" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
> -CFLAGS_python-use.o += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))"
> +CFLAGS_python-use.o += -DPYTHON="BUILD_STR($(PYTHON_WORD))"
> CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls
> diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c
> index 98c6d474aa6f..e196faf1140d 100644
> --- a/tools/perf/tests/python-use.c
> +++ b/tools/perf/tests/python-use.c
> @@ -8,18 +8,46 @@
> #include <linux/compiler.h>
> #include "tests.h"
> #include "util/debug.h"
> +#include "util/util.h"
> +#include <sys/stat.h>
> +#include <limits.h>
> +#include <libgen.h>
sry, did not notice there was new version.. looks good, 2 nits below
thanks,
jirka
>
> int test__python_use(struct test *test __maybe_unused, int subtest __maybe_unused)
> {
> char *cmd;
> int ret;
> + char *exec_path;
> + char *buf;
> + char *pythonpath = NULL;
> + struct stat sb;
>
> - if (asprintf(&cmd, "echo \"import sys ; sys.path.append('%s'); import perf\" | %s %s",
> - PYTHONPATH, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0)
> + buf = malloc(PATH_MAX);
why bother with dynamic allocation here, we normaly do that on stack
> + if (buf == NULL)
> return -1;
>
> + perf_exe(buf, PATH_MAX);
> + exec_path = dirname(buf);
> +
> + if (asprintf(&pythonpath, "%s/python", exec_path) < 0) {
> + ret = -1;
you could initialize ret with -1
> + goto out;
> + }
> +
> + if (stat(pythonpath, &sb) || !S_ISDIR(sb.st_mode))
> + pythonpath[0] = 0;
> +
> + if (asprintf(&cmd, "echo \"import sys ; sys.path.append('%s'); import perf\" | %s %s",
> + pythonpath, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0) {
> + ret = -1;
> + goto out;
> + }
> +
> pr_debug("python usage test: \"%s\"\n", cmd);
> ret = system(cmd) ? -1 : 0;
> free(cmd);
> +out:
> + free(buf);
> + free(pythonpath);
> return ret;
> }
> --
> 2.26.2.Cisco
>
next prev parent reply other threads:[~2021-05-23 16:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-22 6:20 [PATCH v7 1/3] perf report: compile tips.txt in perf binary Denys Zagorui
2021-05-22 6:20 ` [PATCH v7 2/3] perf tests: avoid storing an absolute path " Denys Zagorui
2021-05-23 16:30 ` Jiri Olsa [this message]
2021-05-22 6:20 ` [PATCH v7 3/3] perf parse-events: add bison --file-prefix-map option Denys Zagorui
2021-05-26 14:07 ` [PATCH v7 1/3] perf report: compile tips.txt in perf binary Arnaldo Carvalho de Melo
2021-05-26 14:50 ` Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco)
2021-05-26 15:44 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YKqDNJbKOR5NqloD@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=dzagorui@cisco.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox