-
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: add CO-RE relocs enum/ptr/func_proto tests
Test CO-RE relocation handling of ints, enums, pointers, func protos, etc. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
- Loading branch information
Andrii Nakryiko
authored and
Alexei Starovoitov
committed
Aug 7, 2019
1 parent
20a9ad2
commit d9db355
Showing
10 changed files
with
167 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
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_primitives.c
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,3 @@ | ||
#include "core_reloc_types.h" | ||
|
||
void f(struct core_reloc_primitives x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_primitives___diff_enum_def.c
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,3 @@ | ||
#include "core_reloc_types.h" | ||
|
||
void f(struct core_reloc_primitives___diff_enum_def x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_primitives___diff_func_proto.c
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,3 @@ | ||
#include "core_reloc_types.h" | ||
|
||
void f(struct core_reloc_primitives___diff_func_proto x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_primitives___diff_ptr_type.c
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,3 @@ | ||
#include "core_reloc_types.h" | ||
|
||
void f(struct core_reloc_primitives___diff_ptr_type x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_primitives___err_non_enum.c
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,3 @@ | ||
#include "core_reloc_types.h" | ||
|
||
void f(struct core_reloc_primitives___err_non_enum x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_primitives___err_non_int.c
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,3 @@ | ||
#include "core_reloc_types.h" | ||
|
||
void f(struct core_reloc_primitives___err_non_int x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_primitives___err_non_ptr.c
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,3 @@ | ||
#include "core_reloc_types.h" | ||
|
||
void f(struct core_reloc_primitives___err_non_ptr x) {} |
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
43 changes: 43 additions & 0 deletions
43
tools/testing/selftests/bpf/progs/test_core_reloc_primitives.c
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,43 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2019 Facebook | ||
|
||
#include <linux/bpf.h> | ||
#include <stdint.h> | ||
#include "bpf_helpers.h" | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
static volatile struct data { | ||
char in[256]; | ||
char out[256]; | ||
} data; | ||
|
||
enum core_reloc_primitives_enum { | ||
A = 0, | ||
B = 1, | ||
}; | ||
|
||
struct core_reloc_primitives { | ||
char a; | ||
int b; | ||
enum core_reloc_primitives_enum c; | ||
void *d; | ||
int (*f)(const char *); | ||
}; | ||
|
||
SEC("raw_tracepoint/sys_enter") | ||
int test_core_primitives(void *ctx) | ||
{ | ||
struct core_reloc_primitives *in = (void *)&data.in; | ||
struct core_reloc_primitives *out = (void *)&data.out; | ||
|
||
if (BPF_CORE_READ(&out->a, &in->a) || | ||
BPF_CORE_READ(&out->b, &in->b) || | ||
BPF_CORE_READ(&out->c, &in->c) || | ||
BPF_CORE_READ(&out->d, &in->d) || | ||
BPF_CORE_READ(&out->f, &in->f)) | ||
return 1; | ||
|
||
return 0; | ||
} | ||
|