summaryrefslogtreecommitdiff
path: root/tools/perf/tests/clang.c
blob: 5052be1b5b2081a00a855df5b61d939c21b0dca0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: GPL-2.0
#include "tests.h"
#include "c++/clang-c.h"
#include <linux/kernel.h>

static struct {
	int (*func)(void);
	const char *desc;
} clang_testcase_table[] = {
#ifdef HAVE_LIBCLANGLLVM_SUPPORT
	{
		.func = test__clang_to_IR,
		.desc = "builtin clang compile C source to IR",
	},
	{
		.func = test__clang_to_obj,
		.desc = "builtin clang compile C source to ELF object",
	},
#endif
};

static int test__clang_subtest_get_nr(void)
{
	return (int)ARRAY_SIZE(clang_testcase_table);
}

static const char *test__clang_subtest_get_desc(int i)
{
	if (i < 0 || i >= (int)ARRAY_SIZE(clang_testcase_table))
		return NULL;
	return clang_testcase_table[i].desc;
}

#ifndef HAVE_LIBCLANGLLVM_SUPPORT
static int test__clang(struct test *test __maybe_unused, int i __maybe_unused)
{
	return TEST_SKIP;
}
#else
static int test__clang(struct test *test __maybe_unused, int i)
{
	if (i < 0 || i >= (int)ARRAY_SIZE(clang_testcase_table))
		return TEST_FAIL;
	return clang_testcase_table[i].func();
}
#endif

struct test suite__clang = {
	.desc = "builtin clang support",
	.func = test__clang,
	.subtest = {
		.skip_if_fail	= true,
		.get_nr		= test__clang_subtest_get_nr,
		.get_desc	= test__clang_subtest_get_desc,
	}
};