From 78244d2e21146b88faffe2653397f0fa176794f1 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Wed, 3 Nov 2021 23:41:53 -0700 Subject: perf test: Add test case struct. Add a test case struct mirroring the 'struct kunit_case'. Use the struct with the DEFINE_SUITE macro, where the single test is turned into a test case. Update the helpers in builtin-test to handle test cases. Signed-off-by: Ian Rogers Tested-by: Sohaib Mohamed Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Brendan Higgins Cc: Daniel Latypov Cc: David Gow Cc: Ingo Molnar Cc: Jin Yao Cc: John Garry Cc: Mark Rutland Cc: Namhyung Kim Cc: Paul Clarke Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lore.kernel.org/r/20211104064208.3156807-8-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/tests/builtin-test.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'tools/perf/tests/builtin-test.c') diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c index 96eb486ffbc9..a6d84feba483 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -117,10 +117,19 @@ static struct test_suite **tests[] = { static int num_subtests(const struct test_suite *t) { + int num; + if (t->subtest.get_nr) return t->subtest.get_nr(); - return 0; + if (!t->test_cases) + return 0; + + num = 0; + while (t->test_cases[num].name) + num++; + + return num; } static bool has_subtests(const struct test_suite *t) @@ -138,10 +147,13 @@ static const char *skip_reason(const struct test_suite *t, int subtest) static const char *test_description(const struct test_suite *t, int subtest) { - if (subtest < 0 || !t->subtest.get_desc) - return t->desc; + if (t->test_cases && subtest >= 0) + return t->test_cases[subtest].desc; - return t->subtest.get_desc(subtest); + if (t->subtest.get_desc && subtest >= 0) + return t->subtest.get_desc(subtest); + + return t->desc; } static bool is_supported(const struct test_suite *t) @@ -149,9 +161,15 @@ static bool is_supported(const struct test_suite *t) return !t->is_supported || t->is_supported(); } -static test_fnptr test_function(const struct test_suite *t, int subtest __maybe_unused) +static test_fnptr test_function(const struct test_suite *t, int subtest) { - return t->func; + if (t->func) + return t->func; + + if (subtest <= 0) + return t->test_cases[0].run_case; + + return t->test_cases[subtest].run_case; } static bool perf_test__matches(const char *desc, int curr, int argc, const char *argv[]) -- cgit v1.2.3