-
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 array tests
Add tests for various array handling/relocation scenarios. 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
ec6438a
commit 20a9ad2
Showing
11 changed files
with
201 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_arrays x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_arrays___diff_arr_dim.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_arrays___diff_arr_dim x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_arrays___diff_arr_val_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_arrays___diff_arr_val_sz x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_arrays___err_non_array.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_arrays___err_non_array x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_arrays___err_too_shallow.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_arrays___err_too_shallow x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_arrays___err_too_small.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_arrays___err_too_small x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_arrays___err_wrong_val_type1.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_arrays___err_wrong_val_type1 x) {} |
3 changes: 3 additions & 0 deletions
3
tools/testing/selftests/bpf/progs/btf__core_reloc_arrays___err_wrong_val_type2.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_arrays___err_wrong_val_type2 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
55 changes: 55 additions & 0 deletions
55
tools/testing/selftests/bpf/progs/test_core_reloc_arrays.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,55 @@ | ||
// 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_arrays_output { | ||
int a2; | ||
char b123; | ||
int c1c; | ||
int d00d; | ||
}; | ||
|
||
struct core_reloc_arrays_substruct { | ||
int c; | ||
int d; | ||
}; | ||
|
||
struct core_reloc_arrays { | ||
int a[5]; | ||
char b[2][3][4]; | ||
struct core_reloc_arrays_substruct c[3]; | ||
struct core_reloc_arrays_substruct d[1][2]; | ||
}; | ||
|
||
SEC("raw_tracepoint/sys_enter") | ||
int test_core_arrays(void *ctx) | ||
{ | ||
struct core_reloc_arrays *in = (void *)&data.in; | ||
struct core_reloc_arrays_output *out = (void *)&data.out; | ||
|
||
/* in->a[2] */ | ||
if (BPF_CORE_READ(&out->a2, &in->a[2])) | ||
return 1; | ||
/* in->b[1][2][3] */ | ||
if (BPF_CORE_READ(&out->b123, &in->b[1][2][3])) | ||
return 1; | ||
/* in->c[1].c */ | ||
if (BPF_CORE_READ(&out->c1c, &in->c[1].c)) | ||
return 1; | ||
/* in->d[0][0].d */ | ||
if (BPF_CORE_READ(&out->d00d, &in->d[0][0].d)) | ||
return 1; | ||
|
||
return 0; | ||
} | ||
|