From: Namhyung Kim <namhyung@kernel.org>
To: Andi Kleen <ak@linux.intel.com>
Cc: linux-perf-users@vger.kernel.org
Subject: Re: [PATCH v7 2/4] perf test: Support external tests for separate objdir
Date: Thu, 25 Jul 2024 17:07:06 -0700 [thread overview]
Message-ID: <ZqLoqqV92Ol5dlF4@google.com> (raw)
In-Reply-To: <20240724190137.3810429-2-ak@linux.intel.com>
Hi Andi,
On Wed, Jul 24, 2024 at 12:01:35PM -0700, Andi Kleen wrote:
> Extend the searching for the test files so that it works
> when running perf from a separate objdir, and also when
> the perf executable is symlinked.
>
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
> tools/perf/tests/tests-scripts.c | 31 ++++++++++++++++++++++++++++---
> 1 file changed, 28 insertions(+), 3 deletions(-)
>
> diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scripts.c
> index e2042b368269..63be17289ac3 100644
> --- a/tools/perf/tests/tests-scripts.c
> +++ b/tools/perf/tests/tests-scripts.c
> @@ -29,16 +29,41 @@
>
> static int shell_tests__dir_fd(void)
> {
> - char path[PATH_MAX], *exec_path;
> - static const char * const devel_dirs[] = { "./tools/perf/tests/shell", "./tests/shell", };
> + struct stat st;
> + char path[PATH_MAX], path2[PATH_MAX], *exec_path;
> + static const char * const devel_dirs[] = {
> + "./tools/perf/tests/shell",
> + "./tests/shell",
> + "./source/tests/shell"
> + };
> + int fd;
> + char *p;
>
> for (size_t i = 0; i < ARRAY_SIZE(devel_dirs); ++i) {
> - int fd = open(devel_dirs[i], O_PATH);
> + fd = open(devel_dirs[i], O_PATH);
>
> if (fd >= 0)
> return fd;
> }
>
> + /* Use directory of executable */
> + if (readlink("/proc/self/exe", path2, sizeof path2) < 0)
> + return -1;
> + /* Follow another level of symlink if there */
> + if (lstat(path2, &st) == 0 && (st.st_mode & S_IFMT) == S_IFLNK) {
> + scnprintf(path, sizeof(path), path2);
> + if (readlink(path, path2, sizeof path2) < 0)
> + return -1;
> + }
> + /* Get directory */
> + p = strrchr(path2, '/');
> + if (*p)
Wouldn't it be 'if (p)' ?
Thanks,
Namhyung
> + p[1] = 0;
> + scnprintf(path, sizeof(path), "%s/tests/shell", path2);
> + fd = open(path, O_PATH);
> + if (fd >= 0)
> + return fd;
> +
> /* Then installed path. */
> exec_path = get_argv_exec_path();
> scnprintf(path, sizeof(path), "%s/tests/shell", exec_path);
> --
> 2.45.2
>
next prev parent reply other threads:[~2024-07-26 0:07 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-24 19:01 [PATCH v7 1/4] Create source symlink in perf object dir Andi Kleen
2024-07-24 19:01 ` [PATCH v7 2/4] perf test: Support external tests for separate objdir Andi Kleen
2024-07-26 0:07 ` Namhyung Kim [this message]
2024-07-24 19:01 ` [PATCH v7 3/4] perf script: Fix perf script -F +metric Andi Kleen
2024-07-26 0:31 ` Namhyung Kim
2024-07-26 3:13 ` Ian Rogers
2024-07-31 19:32 ` Andi Kleen
2024-08-02 18:26 ` Namhyung Kim
2024-08-02 20:58 ` Andi Kleen
2024-08-05 18:58 ` Namhyung Kim
2024-07-24 19:01 ` [PATCH v7 4/4] Add a test case for " Andi Kleen
2024-07-26 0:32 ` Namhyung Kim
2024-07-24 20:29 ` [PATCH v7 1/4] Create source symlink in perf object dir Ian Rogers
2024-07-24 21:48 ` Andi Kleen
2024-07-24 22:31 ` Ian Rogers
2024-07-25 7:28 ` Andi Kleen
2024-07-25 9:18 ` Ian Rogers
2024-07-25 22:50 ` Andi Kleen
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=ZqLoqqV92Ol5dlF4@google.com \
--to=namhyung@kernel.org \
--cc=ak@linux.intel.com \
--cc=linux-perf-users@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).