perf test: Support dynamic test suites with setup callback and private data

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>
This commit is contained in:
Ian Rogers 2026-06-02 10:41:16 -07:00 committed by Arnaldo Carvalho de Melo
parent 744af59871
commit 8c8d61c38d
2 changed files with 18 additions and 1 deletions

View 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;

View 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) \