-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
selftests/bpf: Test kernel module ksym externs
Add per-CPU variable to bpf_testmod.ko and use those from new selftest to validate it works end-to-end. Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Yonghong Song <yhs@fb.com> Acked-by: Hao Luo <haoluo@google.com> Link: https://lore.kernel.org/bpf/20210112075520.4103414-8-andrii@kernel.org
- Loading branch information
Andrii Nakryiko
authored and
Alexei Starovoitov
committed
Jan 13, 2021
1 parent
284d258
commit 430d97a
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2021 Facebook */ | ||
|
||
#include <test_progs.h> | ||
#include <bpf/libbpf.h> | ||
#include <bpf/btf.h> | ||
#include "test_ksyms_module.skel.h" | ||
|
||
static int duration; | ||
|
||
void test_ksyms_module(void) | ||
{ | ||
struct test_ksyms_module* skel; | ||
int err; | ||
|
||
skel = test_ksyms_module__open_and_load(); | ||
if (CHECK(!skel, "skel_open", "failed to open skeleton\n")) | ||
return; | ||
|
||
err = test_ksyms_module__attach(skel); | ||
if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err)) | ||
goto cleanup; | ||
|
||
usleep(1); | ||
|
||
ASSERT_EQ(skel->bss->triggered, true, "triggered"); | ||
ASSERT_EQ(skel->bss->out_mod_ksym_global, 123, "global_ksym_val"); | ||
|
||
cleanup: | ||
test_ksyms_module__destroy(skel); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
/* Copyright (c) 2021 Facebook */ | ||
|
||
#include "vmlinux.h" | ||
|
||
#include <bpf/bpf_helpers.h> | ||
|
||
extern const int bpf_testmod_ksym_percpu __ksym; | ||
|
||
int out_mod_ksym_global = 0; | ||
bool triggered = false; | ||
|
||
SEC("raw_tp/sys_enter") | ||
int handler(const void *ctx) | ||
{ | ||
int *val; | ||
__u32 cpu; | ||
|
||
val = (int *)bpf_this_cpu_ptr(&bpf_testmod_ksym_percpu); | ||
out_mod_ksym_global = *val; | ||
triggered = true; | ||
|
||
return 0; | ||
} | ||
|
||
char LICENSE[] SEC("license") = "GPL"; |