From b72abcc7ded3ba83bae6da1f3895cf73c8fb0602 Mon Sep 17 00:00:00 2001 From: Matteo Nardi Date: Mon, 19 Dec 2022 14:21:18 +0100 Subject: [PATCH] tests: add pointer relocation test --- .../integration-test/src/tests/relocations.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/integration-test/src/tests/relocations.rs b/test/integration-test/src/tests/relocations.rs index 4778f14f..2654dff6 100644 --- a/test/integration-test/src/tests/relocations.rs +++ b/test/integration-test/src/tests/relocations.rs @@ -54,6 +54,25 @@ fn relocate_enum() { assert_eq!(test.run_no_btf().unwrap(), 0); } +#[integration_test] +fn relocate_pointer() { + let test = RelocationTest { + local_definition: r#" + struct foo {}; + struct bar { struct foo *f; }; + "#, + target_btf: r#""#, + relocation_code: r#" + __u8 memory[] = {0, 0, 0, 0, 0, 0, 0, 42}; + struct foo *f = BPF_CORE_READ((struct bar *)&memory, f); + __u32 value = (f == (struct foo *) 42); + "#, + } + .build() + .unwrap(); + assert_eq!(test.run().unwrap(), 1); +} + /// Utility code for running relocation tests: /// - Generates the eBPF program using probided local definition and relocation code /// - Generates the BTF from the target btf code