[PATCH v7 5/7] perf test: Format log directories for shell tests

Jakub Brnak
2026-04-16T11:14:39Z

The name of the log directory can be taken from the test suite
description, which possibly could contain whitespace characters. This
can cause further issues if the name is not quoted correctly.

Replace the whitespace characters with an underscore to prevent the
possible issues caused by the name splitting.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Co-developed-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
Signed-off-by: Jakub Brnak <jbrnak@redhat.com>
---
tools/perf/tests/builtin-test.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 306ecfe5e22f..6cdff3687a82 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -342,16 +342,28 @@ static bool create_logs(struct test_suite *t, int pass)
return false;
}

+static const char PERF_LOG_PREFIX[] = "/tmp/perf_test_";
+static const char PERF_LOG_SUFFIX[] = ".XXXXXX";
+
static char *setup_shell_logs(const char *name)
{
char template[PATH_MAX];
char *temp_dir;
+ size_t i, len;

- if (snprintf(template, PATH_MAX, "/tmp/perf_test_%s.XXXXXX", name) >= PATH_MAX) {
+ if (snprintf(template, PATH_MAX, "%s%s%s", PERF_LOG_PREFIX, name,
+ PERF_LOG_SUFFIX) >= PATH_MAX) {
pr_err("Failed to create log dir template");
return NULL; /* Skip the testsuite */
}

+ /* Replace non-alphanumeric characters with _ in the name part */
+ len = strlen(template);
+ for (i = sizeof(PERF_LOG_PREFIX) - 1; i < len - (sizeof(PERF_LOG_SUFFIX) - 1); i++) {
+ if (!isalnum((unsigned char)template[i]))
+ template[i] = '_';
+ }
+
temp_dir = mkdtemp(template);
if (temp_dir) {
setenv("PERFSUITE_RUN_DIR", temp_dir, 1);
--
2.52.0