#include <tests/llvm.h>
const char test_llvm__bpf_base_prog[] =
"// SPDX-License-Identifier: GPL-2.0\n"
"/*\n"
" * bpf-script-example.c\n"
" * Test basic LLVM building\n"
" */\n"
"#ifndef LINUX_VERSION_CODE\n"
"# error Need LINUX_VERSION_CODE\n"
"# error Example: for 4.2 kernel, put 'clang-opt=\"-DLINUX_VERSION_CODE=0x40200\" into llvm section of ~/.perfconfig'\n"
"#endif\n"
"#define BPF_ANY 0\n"
"#define BPF_MAP_TYPE_ARRAY 2\n"
"#define BPF_FUNC_map_lookup_elem 1\n"
"#define BPF_FUNC_map_update_elem 2\n"
"\n"
"static void *(*bpf_map_lookup_elem)(void *map, void *key) =\n"
"	(void *) BPF_FUNC_map_lookup_elem;\n"
"static void *(*bpf_map_update_elem)(void *map, void *key, void *value, int flags) =\n"
"	(void *) BPF_FUNC_map_update_elem;\n"
"\n"
"/*\n"
" * Following macros are taken from tools/lib/bpf/bpf_helpers.h,\n"
" * and are used to create BTF defined maps. It is easier to take\n"
" * 2 simple macros, than being able to include above header in\n"
" * runtime.\n"
" *\n"
" * __uint - defines integer attribute of BTF map definition,\n"
" * Such attributes are represented using a pointer to an array,\n"
" * in which dimensionality of array encodes specified integer\n"
" * value.\n"
" *\n"
" * __type - defines pointer variable with typeof(val) type for\n"
" * attributes like key or value, which will be defined by the\n"
" * size of the type.\n"
" */\n"
"#define __uint(name, val) int (*name)[val]\n"
"#define __type(name, val) typeof(val) *name\n"
"\n"
"#define SEC(NAME) __attribute__((section(NAME), used))\n"
"struct {\n"
"	__uint(type, BPF_MAP_TYPE_ARRAY);\n"
"	__uint(max_entries, 1);\n"
"	__type(key, int);\n"
"	__type(value, int);\n"
"} flip_table SEC(\".maps\");\n"
"\n"
"SEC(\"func=do_epoll_wait\")\n"
"int bpf_func__SyS_epoll_pwait(void *ctx)\n"
"{\n"
"	int ind =0;\n"
"	int *flag = bpf_map_lookup_elem(&flip_table, &ind);\n"
"	int new_flag;\n"
"	if (!flag)\n"
"		return 0;\n"
"	/* flip flag and store back */\n"
"	new_flag = !*flag;\n"
"	bpf_map_update_elem(&flip_table, &ind, &new_flag, BPF_ANY);\n"
"	return new_flag;\n"
"}\n"
"char _license[] SEC(\"license\") = \"GPL\";\n"
"int _version SEC(\"version\") = LINUX_VERSION_CODE;\n"
;
