lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250522171044.1075583-1-namhyung@kernel.org>
Date: Thu, 22 May 2025 10:10:42 -0700
From: Namhyung Kim <namhyung@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...nel.org>,
	Ian Rogers <irogers@...gle.com>,
	Kan Liang <kan.liang@...ux.intel.com>
Cc: Jiri Olsa <jolsa@...nel.org>,
	Adrian Hunter <adrian.hunter@...el.com>,
	Peter Zijlstra <peterz@...radead.org>,
	Ingo Molnar <mingo@...nel.org>,
	LKML <linux-kernel@...r.kernel.org>,
	linux-perf-users@...r.kernel.org
Subject: [PATCH 1/3] perf test: Support arch-specific shell tests

This is a preparation for shell tests belong to an arch.

Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
 tools/perf/tests/builtin-test.c  |  3 ++
 tools/perf/tests/tests-scripts.c | 73 ++++++++++++++++++++++++++++++++
 tools/perf/tests/tests-scripts.h |  1 +
 3 files changed, 77 insertions(+)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 45d3d8b3317a7c0a..b9a86631b34cac90 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -650,6 +650,7 @@ static struct test_suite **build_suites(void)
 		generic_tests,
 		arch_tests,
 		NULL,
+		NULL,
 	};
 	struct test_suite **result;
 	struct test_suite *t;
@@ -657,6 +658,8 @@ static struct test_suite **build_suites(void)
 
 	if (suites[2] == NULL)
 		suites[2] = create_script_test_suites();
+	if (suites[3] == NULL)
+		suites[3] = create_script_test_suites_arch();
 
 #define for_each_suite(suite)						\
 	for (size_t i = 0, j = 0; i < ARRAY_SIZE(suites); i++, j = 0)	\
diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scripts.c
index 1d5759d08141749d..e6e6fab0c3c4bb8c 100644
--- a/tools/perf/tests/tests-scripts.c
+++ b/tools/perf/tests/tests-scripts.c
@@ -24,6 +24,7 @@
 #include "string2.h"
 #include "symbol.h"
 #include "tests.h"
+#include "util/env.h"
 #include "util/rlimit.h"
 #include "util/util.h"
 
@@ -75,6 +76,52 @@ static int shell_tests__dir_fd(void)
 	return open(path, O_PATH);
 }
 
+static int shell_tests__arch_dir_fd(void)
+{
+	struct stat st;
+	const char *arch;
+	char path[PATH_MAX], path2[PATH_MAX], *exec_path;
+	int fd;
+	char *p;
+
+	arch = perf_env__arch(NULL);
+	if (arch == NULL)
+		return -1;
+
+	scnprintf(path, sizeof(path), "./arch/%s/tests/shell", arch);
+	fd = open(path, 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)
+		*p = 0;
+	scnprintf(path, sizeof(path), "%s/arch/%s/tests/shell", path2, arch);
+	fd = open(path, O_PATH);
+	if (fd >= 0)
+		return fd;
+	scnprintf(path, sizeof(path), "%s/source/arch/%s/tests/shell", path2, arch);
+	fd = open(path, O_PATH);
+	if (fd >= 0)
+		return fd;
+
+	/* Then installed path. */
+	exec_path = get_argv_exec_path();
+	scnprintf(path, sizeof(path), "%s/arch/%s/tests/shell", exec_path, arch);
+	free(exec_path);
+	return open(path, O_PATH);
+}
+
 static char *shell_test__description(int dir_fd, const char *name)
 {
 	struct io io;
@@ -291,3 +338,29 @@ struct test_suite **create_script_test_suites(void)
 		close(dir_fd);
 	return result;
 }
+
+struct test_suite **create_script_test_suites_arch(void)
+{
+	struct test_suite **result = NULL, **result_tmp;
+	size_t result_sz = 0;
+	int dir_fd = shell_tests__arch_dir_fd(); /* Walk dir */
+
+	/*
+	 * Append scripts if fd is good, otherwise return a NULL terminated zero
+	 * length array.
+	 */
+	if (dir_fd >= 0)
+		append_scripts_in_dir(dir_fd, &result, &result_sz);
+
+	result_tmp = realloc(result, (result_sz + 1) * sizeof(*result_tmp));
+	if (result_tmp == NULL) {
+		pr_err("Out of memory while building script test suite list\n");
+		abort();
+	}
+	/* NULL terminate the test suite array. */
+	result = result_tmp;
+	result[result_sz] = NULL;
+	if (dir_fd >= 0)
+		close(dir_fd);
+	return result;
+}
diff --git a/tools/perf/tests/tests-scripts.h b/tools/perf/tests/tests-scripts.h
index b553ad26ea17642a..b03ee4a1ee63a25a 100644
--- a/tools/perf/tests/tests-scripts.h
+++ b/tools/perf/tests/tests-scripts.h
@@ -5,5 +5,6 @@
 #include "tests.h"
 
 struct test_suite **create_script_test_suites(void);
+struct test_suite **create_script_test_suites_arch(void);
 
 #endif /* TESTS_SCRIPTS_H */
-- 
2.49.0.1164.gab81da1b16-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ