summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/test_core_reloc_nesting.c
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-08-07 14:39:55 -0700
committerAlexei Starovoitov <ast@kernel.org>2019-08-07 14:43:49 -0700
commitec6438a988a43dcb03f0a04f3f51a48aba54764a (patch)
tree376e2801ac2e543aabf2fecc6ff6f0995e647324 /tools/testing/selftests/bpf/progs/test_core_reloc_nesting.c
parent002d3afce65518dc5dfc398a37c2be2a6bf559c4 (diff)
selftests/bpf: add CO-RE relocs nesting tests
Add a bunch of test validating correct handling of nested structs/unions. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Song Liu <songliubraving@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/testing/selftests/bpf/progs/test_core_reloc_nesting.c')
-rw-r--r--tools/testing/selftests/bpf/progs/test_core_reloc_nesting.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/progs/test_core_reloc_nesting.c b/tools/testing/selftests/bpf/progs/test_core_reloc_nesting.c
new file mode 100644
index 000000000000..3ca30cec2b39
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/test_core_reloc_nesting.c
@@ -0,0 +1,46 @@
+// 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_nesting_substruct {
+ int a;
+};
+
+union core_reloc_nesting_subunion {
+ int b;
+};
+
+/* int a.a.a and b.b.b accesses */
+struct core_reloc_nesting {
+ union {
+ struct core_reloc_nesting_substruct a;
+ } a;
+ struct {
+ union core_reloc_nesting_subunion b;
+ } b;
+};
+
+SEC("raw_tracepoint/sys_enter")
+int test_core_nesting(void *ctx)
+{
+ struct core_reloc_nesting *in = (void *)&data.in;
+ struct core_reloc_nesting *out = (void *)&data.out;
+
+ if (BPF_CORE_READ(&out->a.a.a, &in->a.a.a))
+ return 1;
+ if (BPF_CORE_READ(&out->b.b.b, &in->b.b.b))
+ return 1;
+
+ return 0;
+}
+