-
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 field existence CO-RE relocs tests
Add a bunch of tests validating CO-RE is handling field existence relocation. Relaxed CO-RE relocation mode is activated for these new tests to prevent libbpf from rejecting BPF object for no-match relocation, even though test BPF program is not going to use that relocation, if field is missing. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20191015182849.3922287-6-andriin@fb.com
- Loading branch information
Andrii Nakryiko
authored and
Alexei Starovoitov
committed
Oct 15, 2019
1 parent
01340e3
commit c7566a6
Showing
11 changed files
with
233 additions
and
2 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_existence.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_existence x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_kind.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_existence___err_wrong_arr_kind x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_arr_value_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_existence___err_wrong_arr_value_type x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_kind.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_existence___err_wrong_int_kind x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_sz.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_existence___err_wrong_int_sz x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_int_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_existence___err_wrong_int_type x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___err_wrong_struct_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_existence___err_wrong_struct_type x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_existence___minimal.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_existence___minimal 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
79 changes: 79 additions & 0 deletions
79
tools/testing/selftests/bpf/progs/test_core_reloc_existence.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,79 @@ | ||
// SPDX-License-Identifier: GPL-2.0 | ||
// Copyright (c) 2019 Facebook | ||
|
||
#include <linux/bpf.h> | ||
#include <stdint.h> | ||
#include "bpf_helpers.h" | ||
#include "bpf_core_read.h" | ||
|
||
char _license[] SEC("license") = "GPL"; | ||
|
||
static volatile struct data { | ||
char in[256]; | ||
char out[256]; | ||
} data; | ||
|
||
struct core_reloc_existence_output { | ||
int a_exists; | ||
int a_value; | ||
int b_exists; | ||
int b_value; | ||
int c_exists; | ||
int c_value; | ||
int arr_exists; | ||
int arr_value; | ||
int s_exists; | ||
int s_value; | ||
}; | ||
|
||
struct core_reloc_existence { | ||
struct { | ||
int x; | ||
} s; | ||
int arr[1]; | ||
int a; | ||
struct { | ||
int b; | ||
}; | ||
int c; | ||
}; | ||
|
||
SEC("raw_tracepoint/sys_enter") | ||
int test_core_existence(void *ctx) | ||
{ | ||
struct core_reloc_existence *in = (void *)&data.in; | ||
struct core_reloc_existence_output *out = (void *)&data.out; | ||
|
||
out->a_exists = bpf_core_field_exists(in->a); | ||
if (bpf_core_field_exists(in->a)) | ||
out->a_value = BPF_CORE_READ(in, a); | ||
else | ||
out->a_value = 0xff000001u; | ||
|
||
out->b_exists = bpf_core_field_exists(in->b); | ||
if (bpf_core_field_exists(in->b)) | ||
out->b_value = BPF_CORE_READ(in, b); | ||
else | ||
out->b_value = 0xff000002u; | ||
|
||
out->c_exists = bpf_core_field_exists(in->c); | ||
if (bpf_core_field_exists(in->c)) | ||
out->c_value = BPF_CORE_READ(in, c); | ||
else | ||
out->c_value = 0xff000003u; | ||
|
||
out->arr_exists = bpf_core_field_exists(in->arr); | ||
if (bpf_core_field_exists(in->arr)) | ||
out->arr_value = BPF_CORE_READ(in, arr[0]); | ||
else | ||
out->arr_value = 0xff000004u; | ||
|
||
out->s_exists = bpf_core_field_exists(in->s); | ||
if (bpf_core_field_exists(in->s)) | ||
out->s_value = BPF_CORE_READ(in, s.x); | ||
else | ||
out->s_value = 0xff000005u; | ||
|
||
return 0; | ||
} | ||
|