-
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 modifiers/typedef tests
Add tests validating correct handling of various combinations of typedefs and const/volatile/restrict modifiers. 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
d9db355
commit 9654e2a
Showing
6 changed files
with
170 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,3 @@ | ||
#include "core_reloc_types.h" | ||
|
||
void f(struct core_reloc_mods x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_mods___mod_swap.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_mods___mod_swap x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_mods___typedefs.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_mods___typedefs 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
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,62 @@ | ||
// 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; | ||
|
||
struct core_reloc_mods_output { | ||
int a, b, c, d, e, f, g, h; | ||
}; | ||
|
||
typedef const int int_t; | ||
typedef const char *char_ptr_t; | ||
typedef const int arr_t[7]; | ||
|
||
struct core_reloc_mods_substruct { | ||
int x; | ||
int y; | ||
}; | ||
|
||
typedef struct { | ||
int x; | ||
int y; | ||
} core_reloc_mods_substruct_t; | ||
|
||
struct core_reloc_mods { | ||
int a; | ||
int_t b; | ||
char *c; | ||
char_ptr_t d; | ||
int e[3]; | ||
arr_t f; | ||
struct core_reloc_mods_substruct g; | ||
core_reloc_mods_substruct_t h; | ||
}; | ||
|
||
SEC("raw_tracepoint/sys_enter") | ||
int test_core_mods(void *ctx) | ||
{ | ||
struct core_reloc_mods *in = (void *)&data.in; | ||
struct core_reloc_mods_output *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->e, &in->e[2]) || | ||
BPF_CORE_READ(&out->f, &in->f[1]) || | ||
BPF_CORE_READ(&out->g, &in->g.x) || | ||
BPF_CORE_READ(&out->h, &in->h.y)) | ||
return 1; | ||
|
||
return 0; | ||
} | ||
|