perf test: Convert llvm tests to test cases.
authorIan Rogers <irogers@google.com>
Thu, 4 Nov 2021 06:42:00 +0000 (23:42 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sat, 13 Nov 2021 21:11:49 +0000 (18:11 -0300)
Use null terminated array of test cases rather than the previous sub
test functions.

Signed-off-by: Ian Rogers <irogers@google.com>
Tested-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: Daniel Latypov <dlatypov@google.com>
Cc: David Gow <davidgow@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/r/20211104064208.3156807-15-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/llvm.c

index 057d6a5..f27ef00 100644 (file)
@@ -124,7 +124,7 @@ out:
        return ret;
 }
 
-static int test__llvm(struct test_suite *test __maybe_unused, int subtest)
+static int test__llvm(int subtest)
 {
        int ret;
        void *obj_buf = NULL;
@@ -148,42 +148,73 @@ static int test__llvm(struct test_suite *test __maybe_unused, int subtest)
 
        return ret;
 }
+#endif //HAVE_LIBBPF_SUPPORT
 
-static int test__llvm_subtest_get_nr(void)
+static int test__llvm__bpf_base_prog(struct test_suite *test __maybe_unused,
+                                    int subtest __maybe_unused)
 {
-       return __LLVM_TESTCASE_MAX;
+#ifdef HAVE_LIBBPF_SUPPORT
+       return test__llvm(LLVM_TESTCASE_BASE);
+#else
+       pr_debug("Skip LLVM test because BPF support is not compiled\n");
+       return TEST_SKIP;
+#endif
 }
 
-static const char *test__llvm_subtest_get_desc(int subtest)
-{
-       if ((subtest < 0) || (subtest >= __LLVM_TESTCASE_MAX))
-               return NULL;
-
-       return bpf_source_table[subtest].desc;
-}
-#else //HAVE_LIBBPF_SUPPORT
-static int test__llvm(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
+static int test__llvm__bpf_test_kbuild_prog(struct test_suite *test __maybe_unused,
+                                           int subtest __maybe_unused)
 {
+#ifdef HAVE_LIBBPF_SUPPORT
+       return test__llvm(LLVM_TESTCASE_KBUILD);
+#else
+       pr_debug("Skip LLVM test because BPF support is not compiled\n");
        return TEST_SKIP;
+#endif
 }
 
-static int test__llvm_subtest_get_nr(void)
+static int test__llvm__bpf_test_prologue_prog(struct test_suite *test __maybe_unused,
+                                             int subtest __maybe_unused)
 {
-       return 0;
+#ifdef HAVE_LIBBPF_SUPPORT
+       return test__llvm(LLVM_TESTCASE_BPF_PROLOGUE);
+#else
+       pr_debug("Skip LLVM test because BPF support is not compiled\n");
+       return TEST_SKIP;
+#endif
 }
 
-static const char *test__llvm_subtest_get_desc(int subtest __maybe_unused)
+static int test__llvm__bpf_test_relocation(struct test_suite *test __maybe_unused,
+                                          int subtest __maybe_unused)
 {
-       return NULL;
+#ifdef HAVE_LIBBPF_SUPPORT
+       return test__llvm(LLVM_TESTCASE_BPF_RELOCATION);
+#else
+       pr_debug("Skip LLVM test because BPF support is not compiled\n");
+       return TEST_SKIP;
+#endif
 }
-#endif // HAVE_LIBBPF_SUPPORT
+
+
+static struct test_case llvm_tests[] = {
+#ifdef HAVE_LIBBPF_SUPPORT
+       TEST_CASE("Basic BPF llvm compile", llvm__bpf_base_prog),
+       TEST_CASE("kbuild searching", llvm__bpf_test_kbuild_prog),
+       TEST_CASE("Compile source for BPF prologue generation",
+                 llvm__bpf_test_prologue_prog),
+       TEST_CASE("Compile source for BPF relocation", llvm__bpf_test_relocation),
+#else
+       TEST_CASE_REASON("Basic BPF llvm compile", llvm__bpf_base_prog, "not compiled in"),
+       TEST_CASE_REASON("kbuild searching", llvm__bpf_test_kbuild_prog, "not compiled in"),
+       TEST_CASE_REASON("Compile source for BPF prologue generation",
+                       llvm__bpf_test_prologue_prog, "not compiled in"),
+       TEST_CASE_REASON("Compile source for BPF relocation",
+                       llvm__bpf_test_relocation, "not compiled in"),
+#endif
+       { .name = NULL, }
+};
 
 struct test_suite suite__llvm = {
        .desc = "LLVM search and compile",
-       .func = test__llvm,
-       .subtest = {
-               .skip_if_fail   = true,
-               .get_nr         = test__llvm_subtest_get_nr,
-               .get_desc       = test__llvm_subtest_get_desc,
-       },
+       .test_cases = llvm_tests,
+       .subtest = { .skip_if_fail = true, },
 };