|
@@ -1,31 +1,51 @@
|
|
|
use aya::{Btf, EbpfLoader, Endianness, maps::Array, programs::UProbe, util::KernelVersion};
|
|
|
use test_case::test_case;
|
|
|
|
|
|
-#[test_case("enum_signed_32", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7AAAAAAAi32 as u64)]
|
|
|
-#[test_case("enum_signed_32", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7BBBBBBBi32 as u64)]
|
|
|
-#[test_case("enum_signed_32_checked_variants", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7AAAAAAAi32 as u64)]
|
|
|
-#[test_case("enum_signed_32_checked_variants", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7BBBBBBBi32 as u64)]
|
|
|
-#[test_case("enum_signed_64", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0xAAAAAAABBBBBBBBi64 as u64)]
|
|
|
-#[test_case("enum_signed_64", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0xCCCCCCCDDDDDDDDi64 as u64)]
|
|
|
-#[test_case("enum_signed_64_checked_variants", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0xAAAAAAABBBBBBBi64 as u64)]
|
|
|
-#[test_case("enum_signed_64_checked_variants", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0xCCCCCCCDDDDDDDi64 as u64)]
|
|
|
-#[test_case("enum_unsigned_32", false, None, 0xAAAAAAAA)]
|
|
|
-#[test_case("enum_unsigned_32", true, None, 0xBBBBBBBB)]
|
|
|
-#[test_case("enum_unsigned_32_checked_variants", false, None, 0xAAAAAAAA)]
|
|
|
-#[test_case("enum_unsigned_32_checked_variants", true, None, 0xBBBBBBBB)]
|
|
|
-#[test_case("enum_unsigned_64", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xAAAAAAAABBBBBBBB)]
|
|
|
-#[test_case("enum_unsigned_64", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xCCCCCCCCDDDDDDDD)]
|
|
|
-#[test_case("enum_unsigned_64_checked_variants", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xAAAAAAAABBBBBBBB)]
|
|
|
-#[test_case("enum_unsigned_64_checked_variants", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xCCCCCCCCDDDDDDDD)]
|
|
|
-#[test_case("field", false, None, 2)]
|
|
|
-#[test_case("field", true, None, 1)]
|
|
|
-#[test_case("pointer", false, None, 42)]
|
|
|
-#[test_case("pointer", true, None, 21)]
|
|
|
-#[test_case("struct_flavors", false, None, 1)]
|
|
|
-#[test_case("struct_flavors", true, None, 2)]
|
|
|
+#[test_case(crate::ENUM_SIGNED_32_RELOC_BPF, None, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7AAAAAAAi32 as u64)]
|
|
|
+#[test_case(crate::ENUM_SIGNED_32_RELOC_BPF, Some(crate::ENUM_SIGNED_32_RELOC_BTF), Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7BBBBBBBi32 as u64)]
|
|
|
+#[test_case(crate::ENUM_SIGNED_32_CHECKED_VARIANTS_RELOC_BPF, None, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7AAAAAAAi32 as u64)]
|
|
|
+#[test_case(crate::ENUM_SIGNED_32_CHECKED_VARIANTS_RELOC_BPF, Some(crate::ENUM_SIGNED_32_CHECKED_VARIANTS_RELOC_BTF), Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0x7BBBBBBBi32 as u64)]
|
|
|
+#[test_case(crate::ENUM_SIGNED_64_RELOC_BPF, None, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0xAAAAAAABBBBBBBBi64 as u64)]
|
|
|
+#[test_case(crate::ENUM_SIGNED_64_RELOC_BPF, Some(crate::ENUM_SIGNED_64_RELOC_BTF), Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0xCCCCCCCDDDDDDDDi64 as u64)]
|
|
|
+#[test_case(crate::ENUM_SIGNED_64_CHECKED_VARIANTS_RELOC_BPF, None, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0xAAAAAAABBBBBBBi64 as u64)]
|
|
|
+#[test_case(crate::ENUM_SIGNED_64_CHECKED_VARIANTS_RELOC_BPF, Some(crate::ENUM_SIGNED_64_CHECKED_VARIANTS_RELOC_BTF), Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), -0xCCCCCCCDDDDDDDi64 as u64)]
|
|
|
+#[test_case(crate::ENUM_UNSIGNED_32_RELOC_BPF, None, None, 0xAAAAAAAA)]
|
|
|
+#[test_case(
|
|
|
+ crate::ENUM_UNSIGNED_32_RELOC_BPF,
|
|
|
+ Some(crate::ENUM_UNSIGNED_32_RELOC_BTF),
|
|
|
+ None,
|
|
|
+ 0xBBBBBBBB
|
|
|
+)]
|
|
|
+#[test_case(
|
|
|
+ crate::ENUM_UNSIGNED_32_CHECKED_VARIANTS_RELOC_BPF,
|
|
|
+ None,
|
|
|
+ None,
|
|
|
+ 0xAAAAAAAA
|
|
|
+)]
|
|
|
+#[test_case(
|
|
|
+ crate::ENUM_UNSIGNED_32_CHECKED_VARIANTS_RELOC_BPF,
|
|
|
+ Some(crate::ENUM_UNSIGNED_32_CHECKED_VARIANTS_RELOC_BTF),
|
|
|
+ None,
|
|
|
+ 0xBBBBBBBB
|
|
|
+)]
|
|
|
+#[test_case(crate::ENUM_UNSIGNED_64_RELOC_BPF, None, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xAAAAAAAABBBBBBBB)]
|
|
|
+#[test_case(crate::ENUM_UNSIGNED_64_RELOC_BPF, Some(crate::ENUM_UNSIGNED_64_RELOC_BTF), Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xCCCCCCCCDDDDDDDD)]
|
|
|
+#[test_case(crate::ENUM_UNSIGNED_64_CHECKED_VARIANTS_RELOC_BPF, None, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xAAAAAAAABBBBBBBB)]
|
|
|
+#[test_case(crate::ENUM_UNSIGNED_64_CHECKED_VARIANTS_RELOC_BPF, Some(crate::ENUM_UNSIGNED_64_CHECKED_VARIANTS_RELOC_BTF), Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xCCCCCCCCDDDDDDDD)]
|
|
|
+#[test_case(crate::FIELD_RELOC_BPF, None, None, 2)]
|
|
|
+#[test_case(crate::FIELD_RELOC_BPF, Some(crate::FIELD_RELOC_BTF), None, 1)]
|
|
|
+#[test_case(crate::POINTER_RELOC_BPF, None, None, 42)]
|
|
|
+#[test_case(crate::POINTER_RELOC_BPF, Some(crate::POINTER_RELOC_BTF), None, 21)]
|
|
|
+#[test_case(crate::STRUCT_FLAVORS_RELOC_BPF, None, None, 1)]
|
|
|
+#[test_case(
|
|
|
+ crate::STRUCT_FLAVORS_RELOC_BPF,
|
|
|
+ Some(crate::STRUCT_FLAVORS_RELOC_BTF),
|
|
|
+ None,
|
|
|
+ 2
|
|
|
+)]
|
|
|
fn relocation_tests(
|
|
|
- program: &str,
|
|
|
- with_relocations: bool,
|
|
|
+ bpf: &[u8],
|
|
|
+ btf: Option<&[u8]>,
|
|
|
required_kernel_version: Option<(KernelVersion, &str)>,
|
|
|
expected: u64,
|
|
|
) {
|
|
@@ -33,20 +53,19 @@ fn relocation_tests(
|
|
|
let current_kernel_version = KernelVersion::current().unwrap();
|
|
|
if current_kernel_version < required_kernel_version {
|
|
|
eprintln!(
|
|
|
- "skipping test on kernel {current_kernel_version:?}, support for {program} was added in {required_kernel_version:?}; see {commit}"
|
|
|
+ "skipping test on kernel {current_kernel_version:?}, support was added in {required_kernel_version:?}; see {commit}"
|
|
|
);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
let mut bpf = EbpfLoader::new()
|
|
|
.btf(
|
|
|
- with_relocations
|
|
|
- .then(|| Btf::parse(crate::RELOC_BTF, Endianness::default()).unwrap())
|
|
|
+ btf.map(|btf| Btf::parse(btf, Endianness::default()).unwrap())
|
|
|
.as_ref(),
|
|
|
)
|
|
|
- .load(crate::RELOC_BPF)
|
|
|
+ .load(bpf)
|
|
|
.unwrap();
|
|
|
- let program: &mut UProbe = bpf.program_mut(program).unwrap().try_into().unwrap();
|
|
|
+ let program: &mut UProbe = bpf.program_mut("program").unwrap().try_into().unwrap();
|
|
|
program.load().unwrap();
|
|
|
program
|
|
|
.attach(
|