aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/prog_tests/core_extern.c
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-12-18 16:28:35 -0800
committerAlexei Starovoitov <ast@kernel.org>2019-12-18 17:33:36 -0800
commit8601fd422148a8f7ff5f7eaf75b6703d5166332c (patch)
treeb490138fcfb50121dbef61121adccbe6d546172b /tools/testing/selftests/bpf/prog_tests/core_extern.c
parentlibbpf: Put Kconfig externs into .kconfig section (diff)
downloadlinux-dev-8601fd422148a8f7ff5f7eaf75b6703d5166332c.tar.xz
linux-dev-8601fd422148a8f7ff5f7eaf75b6703d5166332c.zip
libbpf: Allow to augment system Kconfig through extra optional config
Instead of all or nothing approach of overriding Kconfig file location, allow to extend it with extra values and override chosen subset of values though optional user-provided extra config, passed as a string through open options' .kconfig option. If same config key is present in both user-supplied config and Kconfig, user-supplied one wins. This allows applications to more easily test various conditions despite host kernel's real configuration. If all of BPF object's __kconfig externs are satisfied from user-supplied config, system Kconfig won't be read at all. Simplify selftests by not needing to create temporary Kconfig files. Suggested-by: Alexei Starovoitov <ast@fb.com> Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20191219002837.3074619-3-andriin@fb.com
Diffstat (limited to '')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/core_extern.c32
1 files changed, 4 insertions, 28 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/core_extern.c b/tools/testing/selftests/bpf/prog_tests/core_extern.c
index 5f03dc1de29e..b093787e9448 100644
--- a/tools/testing/selftests/bpf/prog_tests/core_extern.c
+++ b/tools/testing/selftests/bpf/prog_tests/core_extern.c
@@ -23,19 +23,13 @@ static uint32_t get_kernel_version(void)
static struct test_case {
const char *name;
const char *cfg;
- const char *cfg_path;
bool fails;
struct test_core_extern__data data;
} test_cases[] = {
- { .name = "default search path", .cfg_path = NULL,
- .data = { .bpf_syscall = true } },
- { .name = "/proc/config.gz", .cfg_path = "/proc/config.gz",
- .data = { .bpf_syscall = true } },
- { .name = "missing config", .fails = true,
- .cfg_path = "/proc/invalid-config.gz" },
+ { .name = "default search path", .data = { .bpf_syscall = true } },
{
.name = "custom values",
- .cfg = "CONFIG_BPF_SYSCALL=y\n"
+ .cfg = "CONFIG_BPF_SYSCALL=n\n"
"CONFIG_TRISTATE=m\n"
"CONFIG_BOOL=y\n"
"CONFIG_CHAR=100\n"
@@ -45,7 +39,7 @@ static struct test_case {
"CONFIG_STR=\"abracad\"\n"
"CONFIG_MISSING=0",
.data = {
- .bpf_syscall = true,
+ .bpf_syscall = false,
.tristate_val = TRI_MODULE,
.bool_val = true,
.char_val = 100,
@@ -133,30 +127,14 @@ void test_core_extern(void)
int n = sizeof(*skel->data) / sizeof(uint64_t);
for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
- char tmp_cfg_path[] = "/tmp/test_core_extern_cfg.XXXXXX";
struct test_case *t = &test_cases[i];
DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts,
- .kconfig_path = t->cfg_path,
+ .kconfig = t->cfg,
);
if (!test__start_subtest(t->name))
continue;
- if (t->cfg) {
- size_t n = strlen(t->cfg) + 1;
- int fd = mkstemp(tmp_cfg_path);
- int written;
-
- if (CHECK(fd < 0, "mkstemp", "errno: %d\n", errno))
- continue;
- printf("using '%s' as config file\n", tmp_cfg_path);
- written = write(fd, t->cfg, n);
- close(fd);
- if (CHECK_FAIL(written != n))
- goto cleanup;
- opts.kconfig_path = tmp_cfg_path;
- }
-
skel = test_core_extern__open_opts(&opts);
if (CHECK(!skel, "skel_open", "skeleton open failed\n"))
goto cleanup;
@@ -185,8 +163,6 @@ void test_core_extern(void)
j, exp[j], got[j]);
}
cleanup:
- if (t->cfg)
- unlink(tmp_cfg_path);
test_core_extern__destroy(skel);
skel = NULL;
}