^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include "tests.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include "c++/clang-c.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) int (*func)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) const char *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) } clang_testcase_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifdef HAVE_LIBCLANGLLVM_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) .func = test__clang_to_IR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) .desc = "builtin clang compile C source to IR",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) .func = test__clang_to_obj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) .desc = "builtin clang compile C source to ELF object",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int test__clang_subtest_get_nr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) return (int)ARRAY_SIZE(clang_testcase_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) const char *test__clang_subtest_get_desc(int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (i < 0 || i >= (int)ARRAY_SIZE(clang_testcase_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) return clang_testcase_table[i].desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #ifndef HAVE_LIBCLANGLLVM_SUPPORT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int test__clang(struct test *test __maybe_unused, int i __maybe_unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) return TEST_SKIP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int test__clang(struct test *test __maybe_unused, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) if (i < 0 || i >= (int)ARRAY_SIZE(clang_testcase_table))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) return TEST_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return clang_testcase_table[i].func();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #endif