From: vmolnaro@redhat.com
To: linux-perf-users@vger.kernel.org, acme@kernel.org,
acme@redhat.com, namhyung@kernel.org, mpetlan@redhat.com
Cc: irogers@google.com
Subject: [PATCH 08/10] perf test: Introduce storing logs for shell tests
Date: Fri, 20 Dec 2024 23:03:32 +0100 [thread overview]
Message-ID: <20241220220334.69198-9-vmolnaro@redhat.com> (raw)
In-Reply-To: <20241220220334.69198-1-vmolnaro@redhat.com>
From: Veronika Molnarova <vmolnaro@redhat.com>
Create temporary directories for storing log files for shell tests
that could help while debugging. The log files are necessary for
perftool testsuite test cases also. If the variable KEEP_TEST_LOGS
is set keep the logs, else delete them.
Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
---
tools/perf/tests/builtin-test.c | 110 ++++++++++++++++++++++++++++---
tools/perf/tests/tests-scripts.c | 3 +
tools/perf/tests/tests-scripts.h | 1 +
3 files changed, 105 insertions(+), 9 deletions(-)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 585613446d8a3c8d..3458db9c41e370a5 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -5,6 +5,7 @@
* Builtin regression testing command: ever growing number of sanity tests
*/
#include <fcntl.h>
+#include <ftw.h>
#include <errno.h>
#include <poll.h>
#include <unistd.h>
@@ -217,6 +218,86 @@ static bool test_exclusive(const struct test_suite *t, int subtest)
return t->test_cases[subtest].exclusive;
}
+static int delete_file(const char *fpath, const struct stat *sb __maybe_unused,
+ int typeflag, struct FTW *ftwbuf)
+{
+ int rv = -1;
+
+ /* Stop traversal if going too deep */
+ if (ftwbuf->level > 5) {
+ pr_err("Tree traversal reached level %d, stopping.", ftwbuf->level);
+ return rv;
+ }
+
+ /* Remove only expected directories */
+ if (typeflag == FTW_D || typeflag == FTW_DP){
+ const char *dirname = fpath + ftwbuf->base;
+
+ if (strcmp(dirname, "logs") && strcmp(dirname, "examples") &&
+ strcmp(dirname, "header_tar") && strncmp(dirname, "perf_", 5)) {
+ pr_err("Unknown directory %s", dirname);
+ return rv;
+ }
+ }
+
+ /* Attempt to remove the file */
+ rv = remove(fpath);
+ if (rv)
+ pr_err("Failed to remove file: %s", fpath);
+
+ return rv;
+}
+
+static bool create_logs(struct test_suite *t, int pass){
+ bool store_logs = t->priv && ((struct shell_info*)(t->priv))->store_logs;
+ if (pass == 1 && (!test_exclusive(t, 0) || sequential || dont_fork)) {
+ /* Sequential and non-exclusive tests run on the first pass. */
+ return store_logs;
+ }
+ else if (pass != 1 && test_exclusive(t, 0) && !sequential && !dont_fork) {
+ /* Exclusive tests without sequential run on the second pass. */
+ return store_logs;
+ }
+ return false;
+}
+
+static char *setup_shell_logs(const char *name)
+{
+ char template[PATH_MAX];
+ char *temp_dir;
+
+ if (snprintf(template, PATH_MAX, "/tmp/perf_test_%s.XXXXXX", name) < 0) {
+ pr_err("Failed to create log dir template");
+ return NULL; /* Skip the testsuite */
+ }
+
+ temp_dir = mkdtemp(template);
+ if (temp_dir) {
+ setenv("PERFSUITE_RUN_DIR", temp_dir, 1);
+ return strdup(temp_dir);
+ }
+ else {
+ pr_err("Failed to create the temporary directory");
+ }
+
+ return NULL; /* Skip the testsuite */
+}
+
+static void cleanup_shell_logs(char *dirname)
+{
+ char *keep_logs = getenv("PERFTEST_KEEP_LOGS");
+
+ /* Check if logs should be kept or do cleanup */
+ if (dirname) {
+ if (!keep_logs || strcmp(keep_logs, "y") != 0) {
+ nftw(dirname, delete_file, 8, FTW_DEPTH | FTW_PHYS);
+ }
+ free(dirname);
+ }
+
+ unsetenv("PERFSUITE_RUN_DIR");
+}
+
static bool perf_test__matches(const char *desc, int curr, int argc, const char *argv[])
{
int i;
@@ -548,6 +629,7 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
for (struct test_suite **t = suites; *t; t++) {
int curr = i++;
+ char *tmpdir = NULL;
if (!perf_test__matches(test_description(*t, -1), curr, argc, argv)) {
/*
@@ -572,23 +654,33 @@ static int __cmd_test(struct test_suite **suites, int argc, const char *argv[],
continue;
}
+ /* Setup temporary log directories for shell test suites */
+ if (create_logs(*t, pass)) {
+ tmpdir = setup_shell_logs((*t)->desc);
+
+ if (tmpdir == NULL) /* Couldn't create log dir, skip test suite */
+ ((struct shell_info*)((*t)->priv))->has_setup = FAILED_SETUP;
+ }
+
if (!has_subtests(*t)) {
err = start_test(*t, curr, -1, &child_tests[child_test_num++],
width, pass);
if (err)
goto err_out;
- continue;
}
- for (int subi = 0, subn = num_subtests(*t); subi < subn; subi++) {
- if (!perf_test__matches(test_description(*t, subi),
- curr, argc, argv))
- continue;
+ else {
+ for (int subi = 0, subn = num_subtests(*t); subi < subn; subi++) {
+ if (!perf_test__matches(test_description(*t, subi),
+ curr, argc, argv))
+ continue;
- err = start_test(*t, curr, subi, &child_tests[child_test_num++],
- width, pass);
- if (err)
- goto err_out;
+ err = start_test(*t, curr, subi, &child_tests[child_test_num++],
+ width, pass);
+ if (err)
+ goto err_out;
+ }
}
+ cleanup_shell_logs(tmpdir);
}
if (!sequential) {
/* Parallel mode starts tests but doesn't finish them. Do that now. */
diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scripts.c
index 77a6b8d2213e6e74..2dab7324ed05e7e9 100644
--- a/tools/perf/tests/tests-scripts.c
+++ b/tools/perf/tests/tests-scripts.c
@@ -251,6 +251,7 @@ static struct test_suite* prepare_test_suite(int dir_fd)
test_info->base_path = strdup_check(dirpath); /* Absolute path to dir */
test_info->has_setup = NO_SETUP;
+ test_info->store_logs = false;
test_suite->priv = test_info;
test_suite->desc = NULL;
@@ -427,6 +428,8 @@ static void append_suits_in_dir(int dir_fd,
continue;
}
+ /* Store logs for testsuite is sub-directories */
+ ((struct shell_info*)(test_suite->priv))->store_logs = true;
if (is_test_script(fd, SHELL_SETUP)) { /* Check for setup existance */
char *desc = shell_test__description(fd, SHELL_SETUP);
test_suite->desc = desc; /* Set the suite name by the setup description */
diff --git a/tools/perf/tests/tests-scripts.h b/tools/perf/tests/tests-scripts.h
index da4dcd26140cdfd2..41da0a175e4e7033 100644
--- a/tools/perf/tests/tests-scripts.h
+++ b/tools/perf/tests/tests-scripts.h
@@ -16,6 +16,7 @@ enum shell_setup {
struct shell_info {
const char *base_path;
enum shell_setup has_setup;
+ bool store_logs;
};
struct test_suite **create_script_test_suites(void);
--
2.43.0
next prev parent reply other threads:[~2024-12-20 22:04 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 22:03 [PATCH 00/10] Introduce structure for shell tests vmolnaro
2024-12-20 22:03 ` [PATCH 01/10] perf test perftool_testsuite: Add missing description vmolnaro
2024-12-20 22:03 ` [PATCH 02/10] perf test perftool_testsuite: Return correct value for skipping vmolnaro
2024-12-20 22:03 ` [PATCH 03/10] perf test perftool_testsuite: Use absolute paths vmolnaro
2024-12-20 22:03 ` [PATCH 04/10] perf tests: Create a structure for shell tests vmolnaro
2024-12-20 22:03 ` [PATCH 05/10] perf testsuite: Fix perf-report tests installation vmolnaro
2024-12-20 22:03 ` [PATCH 06/10] perf test: Provide setup for the shell test suite vmolnaro
2024-12-20 22:03 ` [PATCH 07/10] perftool-testsuite: Add empty setup for base_probe vmolnaro
2024-12-20 22:03 ` vmolnaro [this message]
2024-12-20 22:03 ` [PATCH 09/10] perf test: Format log directories for shell tests vmolnaro
2024-12-20 22:03 ` [PATCH 10/10] perf test: Remove perftool drivers vmolnaro
2025-01-13 15:24 ` [PATCH 00/10] Introduce structure for shell tests Arnaldo Carvalho de Melo
2025-01-13 18:25 ` [PATCH v2 " vmolnaro
2025-07-21 13:26 ` [PATCH v3 0/7] " Jakub Brnak
2025-07-21 13:26 ` [PATCH v3 1/7] perf test perftool_testsuite: Use absolute paths Jakub Brnak
2025-07-26 6:00 ` Namhyung Kim
2025-08-21 11:01 ` Jakub Brnak
2025-07-21 13:26 ` [PATCH v3 2/7] perf tests: Create a structure for shell tests Jakub Brnak
2025-07-21 19:39 ` Ian Rogers
2025-07-26 6:03 ` Namhyung Kim
2025-08-21 11:15 ` Jakub Brnak
2025-07-21 13:26 ` [PATCH v3 3/7] perf test: Provide setup for the shell test suite Jakub Brnak
2025-07-26 6:07 ` Namhyung Kim
2025-08-04 14:39 ` Michael Petlan
2025-07-21 13:26 ` [PATCH v3 4/7] perftool-testsuite: Add empty setup for base_probe Jakub Brnak
2025-07-21 13:26 ` [PATCH v3 5/7] perf test: Introduce storing logs for shell tests Jakub Brnak
2025-07-21 19:43 ` Ian Rogers
2025-07-26 6:17 ` Namhyung Kim
2025-07-21 13:26 ` [PATCH v3 6/7] perf test: Format log directories " Jakub Brnak
2025-07-26 6:21 ` Namhyung Kim
2025-07-21 13:26 ` [PATCH v3 7/7] perf test: Remove perftool drivers Jakub Brnak
2025-07-21 19:46 ` Ian Rogers
2025-07-31 12:54 ` [PATCH v3 0/7] Introduce structure for shell tests tejas05
2025-01-13 18:25 ` [PATCH v2 01/10] perf test perftool_testsuite: Add missing description vmolnaro
2025-01-13 18:25 ` [PATCH v2 02/10] perf test perftool_testsuite: Return correct value for skipping vmolnaro
2025-01-13 18:25 ` [PATCH v2 03/10] perf test perftool_testsuite: Use absolute paths vmolnaro
2025-01-13 18:25 ` [PATCH v2 04/10] perf tests: Create a structure for shell tests vmolnaro
2025-01-13 18:26 ` [PATCH v2 05/10] perf testsuite: Fix perf-report tests installation vmolnaro
2025-01-13 18:26 ` [PATCH v2 06/10] perf test: Provide setup for the shell test suite vmolnaro
2025-01-13 18:26 ` [PATCH v2 07/10] perftool-testsuite: Add empty setup for base_probe vmolnaro
2025-01-13 18:26 ` [PATCH v2 08/10] perf test: Introduce storing logs for shell tests vmolnaro
2025-01-13 18:26 ` [PATCH v2 09/10] perf test: Format log directories " vmolnaro
2025-01-13 18:26 ` [PATCH v2 10/10] perf test: Remove perftool drivers vmolnaro
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=20241220220334.69198-9-vmolnaro@redhat.com \
--to=vmolnaro@redhat.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=irogers@google.com \
--cc=linux-perf-users@vger.kernel.org \
--cc=mpetlan@redhat.com \
--cc=namhyung@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.