]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf test: Support dynamic test suites with setup callback and private data
authorIan Rogers <irogers@google.com>
Tue, 2 Jun 2026 17:41:16 +0000 (10:41 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 4 Jun 2026 14:36:21 +0000 (11:36 -0300)
Add void *priv to struct test_case to allow passing per-test context.
Add int (*setup)(struct test_suite *) to struct test_suite to allow
dynamic generation of test cases. Update build_suites() to invoke the
setup callback for each suite if present, ensuring dynamic cases are
available before listing or running.

Assisted-by: Gemini-CLI:Google Gemini 3
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/builtin-test.c
tools/perf/tests/tests.h

index 7946878195b7d7868d533700e5db287181b251ba..485ff75ab880a6061e5c81d55e5d57a8a0320c4c 100644 (file)
@@ -765,10 +765,21 @@ static struct test_suite **build_suites(void)
        for (size_t i = 0, j = 0; i < ARRAY_SIZE(suites); i++, j = 0)   \
                while ((suite = suites[i][j++]) != NULL)
 
-       for_each_suite(t)
+       for_each_suite(t) {
+               if (t->setup) {
+                       int ret = t->setup(t);
+
+                       if (ret < 0) {
+                               errno = -ret;
+                               return NULL;
+                       }
+               }
                num_suites++;
+       }
 
        result = calloc(num_suites + 1, sizeof(struct test_suite *));
+       if (!result)
+               return NULL;
 
        for (int pass = 1; pass <= 2; pass++) {
                for_each_suite(t) {
@@ -831,6 +842,8 @@ int cmd_test(int argc, const char **argv)
        argc = parse_options_subcommand(argc, argv, test_options, test_subcommands, test_usage, 0);
        if (argc >= 1 && !strcmp(argv[0], "list")) {
                suites = build_suites();
+               if (!suites)
+                       return errno ? -errno : -ENOMEM;
                ret = perf_test__list(stdout, suites, argc - 1, argv + 1);
                free(suites);
                return ret;
@@ -863,6 +876,8 @@ int cmd_test(int argc, const char **argv)
        rlimit__bump_memlock();
 
        suites = build_suites();
+       if (!suites)
+               return errno ? -errno : -ENOMEM;
        ret = __cmd_test(suites, argc, argv, skiplist);
        free(suites);
        return ret;
index ee00518bf36f24e4d44bfaad0b49938620f1dc93..9bcf1dbb06639c4c2c548e911677e0069b53924e 100644 (file)
@@ -38,12 +38,14 @@ struct test_case {
        const char *skip_reason;
        test_fnptr run_case;
        bool exclusive;
+       void *priv;
 };
 
 struct test_suite {
        const char *desc;
        struct test_case *test_cases;
        void *priv;
+       int (*setup)(struct test_suite *suite);
 };
 
 #define DECLARE_SUITE(name) \