linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: vmolnaro@redhat.com
To: linux-perf-users@vger.kernel.org, acme@kernel.org,
	acme@redhat.com, mpetlan@redhat.com, namhyung@kernel.org
Cc: irogers@google.com
Subject: [PATCH v2 06/10] perf test: Provide setup for the shell test suite
Date: Mon, 13 Jan 2025 19:26:01 +0100	[thread overview]
Message-ID: <20250113182605.130719-7-vmolnaro@redhat.com> (raw)
In-Reply-To: <Z4UwHy-Kj9XDI9cf@x1>

From: Veronika Molnarova <vmolnaro@redhat.com>

Some of the perftool-testsuite test cases require a setup to be done
beforehand as may be recording data, setting up cache or restoring sample
rate. The setup file also provides the possibility to set the name of
the test suite, if the name of the directory is not good enough.

Check for the existence of the "setup.sh" script for the shell test
suites and run it before the any of the test cases. If the setup fails,
skip all of the test cases of the test suite as the setup may be
required for the result to be valid.

Signed-off-by: Michael Petlan <mpetlan@redhat.com>
Signed-off-by: Veronika Molnarova <vmolnaro@redhat.com>
---
 tools/perf/tests/builtin-test.c  | 23 ++++++++++++++++++---
 tools/perf/tests/tests-scripts.c | 34 ++++++++++++++++++++++++++++++--
 tools/perf/tests/tests-scripts.h | 10 ++++++++++
 tools/perf/tests/tests.h         |  8 +++++---
 4 files changed, 67 insertions(+), 8 deletions(-)

diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index a5b9ccd0033a8484..4a4dc86ebcf60d0d 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -192,6 +192,22 @@ static test_fnptr test_function(const struct test_suite *t, int subtest)
 	return t->test_cases[subtest].run_case;
 }
 
+/* If setup fails, skip all test cases */
+static void check_shell_setup(const struct test_suite *t, int ret)
+{
+	struct shell_info* test_info;
+
+	if (!t->priv)
+		return;
+
+	test_info = t->priv;
+
+	if (ret == TEST_SETUP_FAIL)
+		test_info->has_setup = FAILED_SETUP;
+	else if (test_info->has_setup == RUN_SETUP)
+		test_info->has_setup = PASSED_SETUP;
+}
+
 static bool test_exclusive(const struct test_suite *t, int subtest)
 {
 	if (subtest <= 0)
@@ -268,8 +284,6 @@ static int run_test_child(struct child_process *process)
 	return -err;
 }
 
-#define TEST_RUNNING -3
-
 static int print_test_result(struct test_suite *t, int i, int subtest, int result, int width,
 			     int running)
 {
@@ -287,7 +301,8 @@ static int print_test_result(struct test_suite *t, int i, int subtest, int resul
 	case TEST_OK:
 		pr_info(" Ok\n");
 		break;
-	case TEST_SKIP: {
+	case TEST_SKIP:
+	case TEST_SETUP_FAIL:{
 		const char *reason = skip_reason(t, subtest);
 
 		if (reason)
@@ -400,6 +415,7 @@ static void finish_test(struct child_test **child_tests, int running_test, int c
 	}
 	/* Clean up child process. */
 	ret = finish_command(&child_test->process);
+	check_shell_setup(t, ret);
 	if (verbose > 1 || (verbose == 1 && ret == TEST_FAIL))
 		fprintf(stderr, "%s", err_output.buf);
 
@@ -422,6 +438,7 @@ static int start_test(struct test_suite *test, int i, int subi, struct child_tes
 			err = test_function(test, subi)(test, subi);
 			pr_debug("---- end ----\n");
 			print_test_result(test, i, subi, err, width, /*running=*/0);
+			check_shell_setup(test, err);
 		}
 		return 0;
 	}
diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scripts.c
index c742a3d0a6a26bb4..fa8f18cbcd2ae2bc 100644
--- a/tools/perf/tests/tests-scripts.c
+++ b/tools/perf/tests/tests-scripts.c
@@ -138,6 +138,11 @@ static bool is_test_script(int dir_fd, const char *name)
 	return is_shell_script(dir_fd, name);
 }
 
+/* Filter for scandir */
+static int setup_filter(const struct dirent *entry){
+	return strcmp(entry->d_name, SHELL_SETUP);
+}
+
 /* Duplicate a string and fall over and die if we run out of memory */
 static char *strdup_check(const char *str)
 {
@@ -175,6 +180,7 @@ static void free_suite(struct test_suite *suite) {
 
 static int shell_test__run(struct test_suite *test, int subtest)
 {
+	struct shell_info *test_info = test->priv;
 	const char *file;
 	int err;
 	char *cmd = NULL;
@@ -187,6 +193,22 @@ static int shell_test__run(struct test_suite *test, int subtest)
 		file = test->test_cases[0].name;
 	}
 
+	/* Run setup if needed */
+	if (test_info->has_setup == RUN_SETUP){
+		char *setup_script;
+		if (asprintf(&setup_script, "%s%s%s", test_info->base_path, SHELL_SETUP, verbose ? " -v" : "") < 0)
+			return TEST_SETUP_FAIL;
+
+		err = system(setup_script);
+		free(setup_script);
+
+		if (err)
+			return TEST_SETUP_FAIL;
+	}
+	else if (test_info->has_setup == FAILED_SETUP) {
+		return TEST_SKIP; /* Skip test suite if setup failed */
+	}
+
 	if (asprintf(&cmd, "%s%s", file, verbose ? " -v" : "") < 0)
 		return TEST_FAIL;
 
@@ -228,6 +250,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_suite->priv = test_info;
 	test_suite->desc = NULL;
@@ -309,7 +332,7 @@ static void append_scripts_in_subdir(int dir_fd,
 	int n_dirs, i;
 
 	/* List files, sorted by alpha */
-	n_dirs = scandirat(dir_fd, ".", &entlist, NULL, alphasort);
+	n_dirs = scandirat(dir_fd, ".", &entlist, setup_filter, alphasort);
 	if (n_dirs == -1)
 		return;
 	for (i = 0; i < n_dirs && (ent = entlist[i]); i++) {
@@ -404,7 +427,14 @@ static void append_suits_in_dir(int dir_fd,
 			continue;
 		}
 
-		test_suite->desc = strdup_check(ent->d_name);	/* If no setup, set name to the directory */
+		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 */
+			((struct shell_info*)(test_suite->priv))->has_setup = RUN_SETUP;
+		}
+		else {
+			test_suite->desc = strdup_check(ent->d_name);	/* If no setup, set name to the directory */
+		}
 
 		append_suite(result, result_sz, test_suite);
 	}
diff --git a/tools/perf/tests/tests-scripts.h b/tools/perf/tests/tests-scripts.h
index 60a1a19a45c999f4..da4dcd26140cdfd2 100644
--- a/tools/perf/tests/tests-scripts.h
+++ b/tools/perf/tests/tests-scripts.h
@@ -4,8 +4,18 @@
 
 #include "tests.h"
 
+#define SHELL_SETUP "setup.sh"
+
+enum shell_setup {
+	NO_SETUP     = 0,
+	RUN_SETUP    = 1,
+	FAILED_SETUP = 2,
+	PASSED_SETUP = 3,
+};
+
 struct shell_info {
 	const char *base_path;
+	enum shell_setup has_setup;
 };
 
 struct test_suite **create_script_test_suites(void);
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 8aea344536b8ab7d..2c5e665d1805b908 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -5,9 +5,11 @@
 #include <stdbool.h>
 
 enum {
-	TEST_OK   =  0,
-	TEST_FAIL = -1,
-	TEST_SKIP = -2,
+	TEST_OK         =  0,
+	TEST_FAIL      	= -1,
+	TEST_SKIP       = -2,
+	TEST_RUNNING	= -3,
+	TEST_SETUP_FAIL = -4,
 };
 
 #define TEST_ASSERT_VAL(text, cond)					 \
-- 
2.43.0


  parent reply	other threads:[~2025-01-13 18:26 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 ` [PATCH 08/10] perf test: Introduce storing logs for shell tests vmolnaro
2024-12-20 22:03 ` [PATCH 09/10] perf test: Format log directories " 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   ` vmolnaro [this message]
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=20250113182605.130719-7-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 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).