Exclude integration test from regular test run

Integration tests should only run when compiled via the xtask command.
To achieve this, we introduce a custom `cfg` that removes the `test`
attribute when the code is compiled via regular `cargo test`.
reviewable/pr1229/r7
Thomas Eizinger 3 weeks ago
parent da34fc2689
commit 3f9b604b17
No known key found for this signature in database
GPG Key ID: 05633CD77196CAF3

@ -25,29 +25,6 @@ members = [
resolver = "2" resolver = "2"
default-members = [
"aya",
"aya-build",
"aya-log",
"aya-log-common",
"aya-log-parser",
"aya-obj",
"aya-tool",
"test-distro",
"test/integration-common",
# test/integration-test is omitted; including it in this list causes `cargo test` to run its
# tests, and that doesn't work unless they've been built with `cargo xtask`.
"xtask",
"aya-ebpf-macros",
"aya-log-ebpf-macros",
"ebpf/aya-ebpf",
"ebpf/aya-ebpf-bindings",
"ebpf/aya-log-ebpf",
"test/integration-ebpf",
]
[workspace.package] [workspace.package]
authors = ["Aya Contributors"] authors = ["Aya Contributors"]
edition = "2024" edition = "2024"

@ -25,6 +25,7 @@ use xtask::{AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR, exec};
/// runtime because the stubs are inadequate for actually running the tests. /// runtime because the stubs are inadequate for actually running the tests.
fn main() -> Result<()> { fn main() -> Result<()> {
println!("cargo:rerun-if-env-changed={AYA_BUILD_INTEGRATION_BPF}"); println!("cargo:rerun-if-env-changed={AYA_BUILD_INTEGRATION_BPF}");
println!("cargo::rustc-check-cfg=cfg(aya_integration_test)");
// TODO(https://github.com/rust-lang/cargo/issues/4001): generalize this and move it to // TODO(https://github.com/rust-lang/cargo/issues/4001): generalize this and move it to
// aya-build if we can determine that we're in a check build. // aya-build if we can determine that we're in a check build.

@ -1,14 +1,15 @@
use aya::{Ebpf, maps::Array, programs::UProbe}; use aya::{Ebpf, maps::Array, programs::UProbe};
use integration_common::bpf_probe_read::{RESULT_BUF_LEN, TestResult}; use integration_common::bpf_probe_read::{RESULT_BUF_LEN, TestResult};
use test_log::test;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_probe_read_user_str_bytes() { fn bpf_probe_read_user_str_bytes() {
let bpf = set_user_buffer(b"foo\0", RESULT_BUF_LEN); let bpf = set_user_buffer(b"foo\0", RESULT_BUF_LEN);
assert_eq!(result_bytes(&bpf), b"foo"); assert_eq!(result_bytes(&bpf), b"foo");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_probe_read_user_str_bytes_truncate() { fn bpf_probe_read_user_str_bytes_truncate() {
let s = vec![b'a'; RESULT_BUF_LEN]; let s = vec![b'a'; RESULT_BUF_LEN];
let bpf = set_user_buffer(&s, RESULT_BUF_LEN); let bpf = set_user_buffer(&s, RESULT_BUF_LEN);
@ -16,25 +17,29 @@ fn bpf_probe_read_user_str_bytes_truncate() {
assert_eq!(result_bytes(&bpf), &s[..RESULT_BUF_LEN - 1]); assert_eq!(result_bytes(&bpf), &s[..RESULT_BUF_LEN - 1]);
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_probe_read_user_str_bytes_empty_string() { fn bpf_probe_read_user_str_bytes_empty_string() {
let bpf = set_user_buffer(b"\0", RESULT_BUF_LEN); let bpf = set_user_buffer(b"\0", RESULT_BUF_LEN);
assert_eq!(result_bytes(&bpf), b""); assert_eq!(result_bytes(&bpf), b"");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_probe_read_user_str_bytes_empty_dest() { fn bpf_probe_read_user_str_bytes_empty_dest() {
let bpf = set_user_buffer(b"foo\0", 0); let bpf = set_user_buffer(b"foo\0", 0);
assert_eq!(result_bytes(&bpf), b""); assert_eq!(result_bytes(&bpf), b"");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_probe_read_kernel_str_bytes() { fn bpf_probe_read_kernel_str_bytes() {
let bpf = set_kernel_buffer(b"foo\0", RESULT_BUF_LEN); let bpf = set_kernel_buffer(b"foo\0", RESULT_BUF_LEN);
assert_eq!(result_bytes(&bpf), b"foo"); assert_eq!(result_bytes(&bpf), b"foo");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_probe_read_kernel_str_bytes_truncate() { fn bpf_probe_read_kernel_str_bytes_truncate() {
let s = vec![b'a'; RESULT_BUF_LEN]; let s = vec![b'a'; RESULT_BUF_LEN];
let bpf = set_kernel_buffer(&s, RESULT_BUF_LEN); let bpf = set_kernel_buffer(&s, RESULT_BUF_LEN);
@ -42,13 +47,15 @@ fn bpf_probe_read_kernel_str_bytes_truncate() {
assert_eq!(result_bytes(&bpf), &s[..RESULT_BUF_LEN - 1]); assert_eq!(result_bytes(&bpf), &s[..RESULT_BUF_LEN - 1]);
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_probe_read_kernel_str_bytes_empty_string() { fn bpf_probe_read_kernel_str_bytes_empty_string() {
let bpf = set_kernel_buffer(b"\0", RESULT_BUF_LEN); let bpf = set_kernel_buffer(b"\0", RESULT_BUF_LEN);
assert_eq!(result_bytes(&bpf), b""); assert_eq!(result_bytes(&bpf), b"");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_probe_read_kernel_str_bytes_empty_dest() { fn bpf_probe_read_kernel_str_bytes_empty_dest() {
let bpf = set_kernel_buffer(b"foo\0", 0); let bpf = set_kernel_buffer(b"foo\0", 0);
assert_eq!(result_bytes(&bpf), b""); assert_eq!(result_bytes(&bpf), b"");

@ -1,28 +1,46 @@
use aya::{Btf, EbpfLoader, Endianness, maps::Array, programs::UProbe, util::KernelVersion}; 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)] #[cfg_attr(aya_integration_test, 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)] #[cfg_attr(aya_integration_test, test_case::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)] #[cfg_attr(aya_integration_test, test_case::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)] #[cfg_attr(aya_integration_test, test_case::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)] #[cfg_attr(aya_integration_test, test_case::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)] #[cfg_attr(aya_integration_test, test_case::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)] #[cfg_attr(aya_integration_test, test_case::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)] #[cfg_attr(aya_integration_test, test_case::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)] #[cfg_attr(
#[test_case("enum_unsigned_32", true, None, 0xBBBBBBBB)] aya_integration_test,
#[test_case("enum_unsigned_32_checked_variants", false, None, 0xAAAAAAAA)] test_case::test_case("enum_unsigned_32", 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)] #[cfg_attr(
#[test_case("enum_unsigned_64", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xCCCCCCCCDDDDDDDD)] aya_integration_test,
#[test_case("enum_unsigned_64_checked_variants", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xAAAAAAAABBBBBBBB)] test_case::test_case("enum_unsigned_32", true, None, 0xBBBBBBBB)
#[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)] #[cfg_attr(
#[test_case("field", true, None, 1)] aya_integration_test,
#[test_case("pointer", false, None, 42)] test_case::test_case("enum_unsigned_32_checked_variants", false, None, 0xAAAAAAAA)
#[test_case("pointer", true, None, 21)] )]
#[test_case("struct_flavors", false, None, 1)] #[cfg_attr(
#[test_case("struct_flavors", true, None, 2)] aya_integration_test,
test_case::test_case("enum_unsigned_32_checked_variants", true, None, 0xBBBBBBBB)
)]
#[cfg_attr(aya_integration_test, test_case::test_case("enum_unsigned_64", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xAAAAAAAABBBBBBBB))]
#[cfg_attr(aya_integration_test, test_case::test_case("enum_unsigned_64", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xCCCCCCCCDDDDDDDD))]
#[cfg_attr(aya_integration_test, test_case::test_case("enum_unsigned_64_checked_variants", false, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xAAAAAAAABBBBBBBB))]
#[cfg_attr(aya_integration_test, test_case::test_case("enum_unsigned_64_checked_variants", true, Some((KernelVersion::new(6, 0, 0), "https://github.com/torvalds/linux/commit/6089fb3")), 0xCCCCCCCCDDDDDDDD))]
#[cfg_attr(aya_integration_test, test_case::test_case("field", false, None, 2))]
#[cfg_attr(aya_integration_test, test_case::test_case("field", true, None, 1))]
#[cfg_attr(aya_integration_test, test_case::test_case("pointer", false, None, 42))]
#[cfg_attr(aya_integration_test, test_case::test_case("pointer", true, None, 21))]
#[cfg_attr(
aya_integration_test,
test_case::test_case("struct_flavors", false, None, 1)
)]
#[cfg_attr(
aya_integration_test,
test_case::test_case("struct_flavors", true, None, 2)
)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn relocation_tests( fn relocation_tests(
program: &str, program: &str,
with_relocations: bool, with_relocations: bool,

@ -1,7 +1,7 @@
use object::{Object as _, ObjectSymbol as _}; use object::{Object as _, ObjectSymbol as _};
use test_log::test;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn test_maps() { fn test_maps() {
let obj_file = object::File::parse(crate::MAP_TEST).unwrap(); let obj_file = object::File::parse(crate::MAP_TEST).unwrap();
assert!(obj_file.section_by_name("maps").is_some()); assert!(obj_file.section_by_name("maps").is_some());

@ -18,7 +18,8 @@ use libc::EINVAL;
use crate::utils::{kernel_assert, kernel_assert_eq}; use crate::utils::{kernel_assert, kernel_assert_eq};
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn test_loaded_programs() { fn test_loaded_programs() {
// Load a program. // Load a program.
// Since we are only testing the programs for their metadata, there is no need to "attach" them. // Since we are only testing the programs for their metadata, there is no need to "attach" them.
@ -50,7 +51,8 @@ fn test_loaded_programs() {
); );
} }
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn test_program_info() { fn test_program_info() {
// Kernels below v4.15 have been observed to have `bpf_jit_enable` disabled by default. // Kernels below v4.15 have been observed to have `bpf_jit_enable` disabled by default.
let _guard = ensure_sysctl_enabled("/proc/sys/net/core/bpf_jit_enable"); let _guard = ensure_sysctl_enabled("/proc/sys/net/core/bpf_jit_enable");
@ -108,7 +110,8 @@ fn test_program_info() {
test_prog.fd().unwrap(); test_prog.fd().unwrap();
} }
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn test_loaded_at() { fn test_loaded_at() {
let mut bpf: Ebpf = Ebpf::load(crate::SIMPLE_PROG).unwrap(); let mut bpf: Ebpf = Ebpf::load(crate::SIMPLE_PROG).unwrap();
let prog: &mut SocketFilter = bpf.program_mut("simple_prog").unwrap().try_into().unwrap(); let prog: &mut SocketFilter = bpf.program_mut("simple_prog").unwrap().try_into().unwrap();
@ -154,7 +157,8 @@ fn test_loaded_at() {
} }
} }
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn test_prog_stats() { fn test_prog_stats() {
// Test depends on whether trace point exists. // Test depends on whether trace point exists.
if !Path::new("/sys/kernel/debug/tracing/events/syscalls/sys_enter_bpf").exists() { if !Path::new("/sys/kernel/debug/tracing/events/syscalls/sys_enter_bpf").exists() {
@ -179,7 +183,8 @@ fn test_prog_stats() {
kernel_assert!(test_prog.run_count() > 0, KernelVersion::new(5, 1, 0)); kernel_assert!(test_prog.run_count() > 0, KernelVersion::new(5, 1, 0));
} }
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn list_loaded_maps() { fn list_loaded_maps() {
// Load a program with maps. // Load a program with maps.
let mut bpf: Ebpf = Ebpf::load(crate::MAP_TEST).unwrap(); let mut bpf: Ebpf = Ebpf::load(crate::MAP_TEST).unwrap();
@ -229,7 +234,8 @@ fn list_loaded_maps() {
); );
} }
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn test_map_info() { fn test_map_info() {
let mut bpf: Ebpf = Ebpf::load(crate::MAP_TEST).unwrap(); let mut bpf: Ebpf = Ebpf::load(crate::MAP_TEST).unwrap();
let prog: &mut SocketFilter = bpf.program_mut("simple_prog").unwrap().try_into().unwrap(); let prog: &mut SocketFilter = bpf.program_mut("simple_prog").unwrap().try_into().unwrap();

@ -1,9 +1,9 @@
use std::io::BufRead as _; use std::io::BufRead as _;
use aya::{Btf, Ebpf, programs::Iter}; use aya::{Btf, Ebpf, programs::Iter};
use test_log::test;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn iter_task() { fn iter_task() {
let mut ebpf = Ebpf::load(crate::ITER_TASK).unwrap(); let mut ebpf = Ebpf::load(crate::ITER_TASK).unwrap();
let btf = Btf::from_sys_fs().unwrap(); let btf = Btf::from_sys_fs().unwrap();

@ -11,12 +11,12 @@ use aya::{
util::KernelVersion, util::KernelVersion,
}; };
use aya_obj::programs::XdpAttachType; use aya_obj::programs::XdpAttachType;
use test_log::test;
const MAX_RETRIES: usize = 100; const MAX_RETRIES: usize = 100;
const RETRY_DURATION: Duration = Duration::from_millis(10); const RETRY_DURATION: Duration = Duration::from_millis(10);
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn long_name() { fn long_name() {
let mut bpf = Ebpf::load(crate::NAME_TEST).unwrap(); let mut bpf = Ebpf::load(crate::NAME_TEST).unwrap();
let name_prog: &mut Xdp = bpf let name_prog: &mut Xdp = bpf
@ -32,7 +32,8 @@ fn long_name() {
// Therefore, as long as we were able to load the program, this is good enough. // Therefore, as long as we were able to load the program, this is good enough.
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn multiple_btf_maps() { fn multiple_btf_maps() {
let mut bpf = Ebpf::load(crate::MULTIMAP_BTF).unwrap(); let mut bpf = Ebpf::load(crate::MULTIMAP_BTF).unwrap();
@ -62,7 +63,8 @@ fn multiple_btf_maps() {
remove_file(map_pin).unwrap(); remove_file(map_pin).unwrap();
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn pin_lifecycle_multiple_btf_maps() { fn pin_lifecycle_multiple_btf_maps() {
let mut bpf = Ebpf::load(crate::MULTIMAP_BTF).unwrap(); let mut bpf = Ebpf::load(crate::MULTIMAP_BTF).unwrap();
@ -191,7 +193,8 @@ fn assert_unloaded(name: &str) {
) )
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn unload_xdp() { fn unload_xdp() {
let mut bpf = Ebpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
@ -216,7 +219,8 @@ fn unload_xdp() {
assert_unloaded("pass"); assert_unloaded("pass");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn unload_kprobe() { fn unload_kprobe() {
let mut bpf = Ebpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut KProbe = bpf.program_mut("test_kprobe").unwrap().try_into().unwrap(); let prog: &mut KProbe = bpf.program_mut("test_kprobe").unwrap().try_into().unwrap();
@ -241,7 +245,8 @@ fn unload_kprobe() {
assert_unloaded("test_kprobe"); assert_unloaded("test_kprobe");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn memmove() { fn memmove() {
let mut bpf = Ebpf::load(crate::MEMMOVE_TEST).unwrap(); let mut bpf = Ebpf::load(crate::MEMMOVE_TEST).unwrap();
let prog: &mut Xdp = bpf.program_mut("do_dnat").unwrap().try_into().unwrap(); let prog: &mut Xdp = bpf.program_mut("do_dnat").unwrap().try_into().unwrap();
@ -250,7 +255,8 @@ fn memmove() {
assert_loaded("do_dnat"); assert_loaded("do_dnat");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn basic_tracepoint() { fn basic_tracepoint() {
let mut bpf = Ebpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut TracePoint = bpf let prog: &mut TracePoint = bpf
@ -281,7 +287,8 @@ fn basic_tracepoint() {
assert_unloaded("test_tracepoint"); assert_unloaded("test_tracepoint");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn basic_uprobe() { fn basic_uprobe() {
let mut bpf = Ebpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut UProbe = bpf.program_mut("test_uprobe").unwrap().try_into().unwrap(); let prog: &mut UProbe = bpf.program_mut("test_uprobe").unwrap().try_into().unwrap();
@ -311,7 +318,8 @@ fn basic_uprobe() {
assert_unloaded("test_uprobe"); assert_unloaded("test_uprobe");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn basic_flow_dissector() { fn basic_flow_dissector() {
let mut bpf = Ebpf::load(crate::TEST).unwrap(); let mut bpf = Ebpf::load(crate::TEST).unwrap();
let prog: &mut FlowDissector = bpf.program_mut("test_flow").unwrap().try_into().unwrap(); let prog: &mut FlowDissector = bpf.program_mut("test_flow").unwrap().try_into().unwrap();
@ -339,7 +347,8 @@ fn basic_flow_dissector() {
assert_unloaded("test_flow"); assert_unloaded("test_flow");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn pin_link() { fn pin_link() {
let kernel_version = KernelVersion::current().unwrap(); let kernel_version = KernelVersion::current().unwrap();
if kernel_version < KernelVersion::new(5, 9, 0) { if kernel_version < KernelVersion::new(5, 9, 0) {
@ -370,7 +379,8 @@ fn pin_link() {
assert_unloaded("pass"); assert_unloaded("pass");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn pin_lifecycle() { fn pin_lifecycle() {
let kernel_version = KernelVersion::current().unwrap(); let kernel_version = KernelVersion::current().unwrap();
if kernel_version < KernelVersion::new(5, 18, 0) { if kernel_version < KernelVersion::new(5, 18, 0) {
@ -433,7 +443,8 @@ fn pin_lifecycle() {
assert_unloaded("pass"); assert_unloaded("pass");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn pin_lifecycle_tracepoint() { fn pin_lifecycle_tracepoint() {
// 1. Load Program and Pin // 1. Load Program and Pin
{ {
@ -487,7 +498,8 @@ fn pin_lifecycle_tracepoint() {
assert_unloaded("test_tracepoint"); assert_unloaded("test_tracepoint");
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn pin_lifecycle_kprobe() { fn pin_lifecycle_kprobe() {
// 1. Load Program and Pin // 1. Load Program and Pin
{ {
@ -551,7 +563,8 @@ extern "C" fn uprobe_function() {
core::hint::black_box(uprobe_function); core::hint::black_box(uprobe_function);
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn pin_lifecycle_uprobe() { fn pin_lifecycle_uprobe() {
const FIRST_PIN_PATH: &str = "/sys/fs/bpf/aya-uprobe-test-prog-1"; const FIRST_PIN_PATH: &str = "/sys/fs/bpf/aya-uprobe-test-prog-1";
const SECOND_PIN_PATH: &str = "/sys/fs/bpf/aya-uprobe-test-prog-2"; const SECOND_PIN_PATH: &str = "/sys/fs/bpf/aya-uprobe-test-prog-2";

@ -6,7 +6,6 @@ use std::{
use aya::{Ebpf, programs::UProbe}; use aya::{Ebpf, programs::UProbe};
use aya_log::EbpfLogger; use aya_log::EbpfLogger;
use log::{Level, Log, Record}; use log::{Level, Log, Record};
use test_log::test;
#[unsafe(no_mangle)] #[unsafe(no_mangle)]
#[inline(never)] #[inline(never)]
@ -38,7 +37,8 @@ struct CapturedLog<'a> {
pub target: Cow<'a, str>, pub target: Cow<'a, str>,
} }
#[test(tokio::test)] #[cfg_attr(aya_integration_test, test_log::test(tokio::test))]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
async fn log() { async fn log() {
let mut bpf = Ebpf::load(crate::LOG).unwrap(); let mut bpf = Ebpf::load(crate::LOG).unwrap();

@ -6,7 +6,8 @@ fn get_event(bpf: &mut Ebpf) -> SysEnterEvent {
map.get(&0, 0).unwrap() map.get(&0, 0).unwrap()
} }
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn raw_tracepoint() { fn raw_tracepoint() {
let mut bpf = Ebpf::load(crate::RAW_TRACEPOINT).unwrap(); let mut bpf = Ebpf::load(crate::RAW_TRACEPOINT).unwrap();

@ -3,9 +3,9 @@ use std::collections::HashMap;
use assert_matches::assert_matches; use assert_matches::assert_matches;
use aya_obj::{Object, ProgramSection, generated::bpf_insn, programs::XdpAttachType}; use aya_obj::{Object, ProgramSection, generated::bpf_insn, programs::XdpAttachType};
use test_log::test;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn run_with_rbpf() { fn run_with_rbpf() {
let object = Object::parse(crate::PASS).unwrap(); let object = Object::parse(crate::PASS).unwrap();
@ -37,7 +37,8 @@ fn run_with_rbpf() {
static mut MULTIMAP_MAPS: [*mut Vec<u64>; 3] = [null_mut(); 3]; static mut MULTIMAP_MAPS: [*mut Vec<u64>; 3] = [null_mut(); 3];
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn use_map_with_rbpf() { fn use_map_with_rbpf() {
let mut object = Object::parse(crate::MULTIMAP_BTF).unwrap(); let mut object = Object::parse(crate::MULTIMAP_BTF).unwrap();

@ -3,9 +3,9 @@ use aya::{
programs::{UProbe, Xdp}, programs::{UProbe, Xdp},
util::KernelVersion, util::KernelVersion,
}; };
use test_log::test;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn relocations() { fn relocations() {
let bpf = load_and_attach("test_64_32_call_relocs", crate::RELOCATIONS); let bpf = load_and_attach("test_64_32_call_relocs", crate::RELOCATIONS);
@ -17,7 +17,8 @@ fn relocations() {
assert_eq!(m.get(&2, 0).unwrap(), 3); assert_eq!(m.get(&2, 0).unwrap(), 3);
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn text_64_64_reloc() { fn text_64_64_reloc() {
let kernel_version = KernelVersion::current().unwrap(); let kernel_version = KernelVersion::current().unwrap();
if kernel_version < KernelVersion::new(5, 13, 0) { if kernel_version < KernelVersion::new(5, 13, 0) {
@ -39,7 +40,8 @@ fn text_64_64_reloc() {
assert_eq!(m.get(&1, 0).unwrap(), 3); assert_eq!(m.get(&1, 0).unwrap(), 3);
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn variables_reloc() { fn variables_reloc() {
let mut bpf = Ebpf::load(crate::VARIABLES_RELOC).unwrap(); let mut bpf = Ebpf::load(crate::VARIABLES_RELOC).unwrap();
let prog: &mut Xdp = bpf let prog: &mut Xdp = bpf

@ -18,7 +18,6 @@ use aya::{
use aya_obj::generated::BPF_RINGBUF_HDR_SZ; use aya_obj::generated::BPF_RINGBUF_HDR_SZ;
use integration_common::ring_buf::Registers; use integration_common::ring_buf::Registers;
use rand::Rng as _; use rand::Rng as _;
use test_log::test;
use tokio::{ use tokio::{
io::unix::AsyncFd, io::unix::AsyncFd,
time::{Duration, sleep}, time::{Duration, sleep},
@ -83,11 +82,12 @@ impl WithData {
} }
} }
#[test_case::test_case(0; "write zero items")] #[cfg_attr(aya_integration_test, test_case::test_case(0; "write zero items"))]
#[test_case::test_case(1; "write one item")] #[cfg_attr(aya_integration_test, test_case::test_case(1; "write one item"))]
#[test_case::test_case(RING_BUF_MAX_ENTRIES / 2; "write half the capacity items")] #[cfg_attr(aya_integration_test, test_case::test_case(RING_BUF_MAX_ENTRIES / 2; "write half the capacity items"))]
#[test_case::test_case(RING_BUF_MAX_ENTRIES - 1; "write one less than capacity items")] #[cfg_attr(aya_integration_test, test_case::test_case(RING_BUF_MAX_ENTRIES - 1; "write one less than capacity items"))]
#[test_case::test_case(RING_BUF_MAX_ENTRIES * 8; "write more items than capacity")] #[cfg_attr(aya_integration_test, test_case::test_case(RING_BUF_MAX_ENTRIES * 8; "write more items than capacity"))]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn ring_buf(n: usize) { fn ring_buf(n: usize) {
let WithData( let WithData(
RingBufTest { RingBufTest {
@ -151,7 +151,11 @@ pub extern "C" fn ring_buf_trigger_ebpf_program(arg: u64) {
// to fill the ring_buf. We just ensure that the number of events we see is sane given // to fill the ring_buf. We just ensure that the number of events we see is sane given
// what the producer sees, and that the logic does not hang. This exercises interleaving // what the producer sees, and that the logic does not hang. This exercises interleaving
// discards, successful commits, and drops due to the ring_buf being full. // discards, successful commits, and drops due to the ring_buf being full.
#[test(tokio::test(flavor = "multi_thread"))] #[cfg_attr(
aya_integration_test,
test_log::test(tokio::test(flavor = "multi_thread"))
)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
async fn ring_buf_async_with_drops() { async fn ring_buf_async_with_drops() {
let WithData( let WithData(
RingBufTest { RingBufTest {
@ -258,7 +262,11 @@ async fn ring_buf_async_with_drops() {
); );
} }
#[test(tokio::test(flavor = "multi_thread"))] #[cfg_attr(
aya_integration_test,
test_log::test(tokio::test(flavor = "multi_thread"))
)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
async fn ring_buf_async_no_drop() { async fn ring_buf_async_no_drop() {
let WithData( let WithData(
RingBufTest { RingBufTest {
@ -326,7 +334,8 @@ async fn ring_buf_async_no_drop() {
// This test reproduces a bug where the ring buffer would not be notified of new entries if the // This test reproduces a bug where the ring buffer would not be notified of new entries if the
// state was not properly synchronized between the producer and consumer. This would result in the // state was not properly synchronized between the producer and consumer. This would result in the
// consumer never being woken up and the test hanging. // consumer never being woken up and the test hanging.
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn ring_buf_epoll_wakeup() { fn ring_buf_epoll_wakeup() {
let RingBufTest { let RingBufTest {
mut ring_buf, mut ring_buf,
@ -360,7 +369,8 @@ fn ring_buf_epoll_wakeup() {
} }
// This test is like the above test but uses tokio and AsyncFd instead of raw epoll. // This test is like the above test but uses tokio and AsyncFd instead of raw epoll.
#[test(tokio::test)] #[cfg_attr(aya_integration_test, test_log::test(tokio::test))]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
async fn ring_buf_asyncfd_events() { async fn ring_buf_asyncfd_events() {
let RingBufTest { let RingBufTest {
ring_buf, ring_buf,

@ -3,11 +3,11 @@ use aya::{
programs::{Extension, TracePoint, Xdp, XdpFlags, tc}, programs::{Extension, TracePoint, Xdp, XdpFlags, tc},
util::KernelVersion, util::KernelVersion,
}; };
use test_log::test;
use crate::utils::NetNsGuard; use crate::utils::NetNsGuard;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn modprobe() { fn modprobe() {
// This very simple looking test is actually quite complex. // This very simple looking test is actually quite complex.
// The call to tc::qdisc_add_clsact() causes the linux kernel to call into // The call to tc::qdisc_add_clsact() causes the linux kernel to call into
@ -20,7 +20,8 @@ fn modprobe() {
tc::qdisc_add_clsact("lo").unwrap(); tc::qdisc_add_clsact("lo").unwrap();
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn xdp() { fn xdp() {
let kernel_version = KernelVersion::current().unwrap(); let kernel_version = KernelVersion::current().unwrap();
if kernel_version < KernelVersion::new(5, 18, 0) { if kernel_version < KernelVersion::new(5, 18, 0) {
@ -38,7 +39,8 @@ fn xdp() {
dispatcher.attach("lo", XdpFlags::default()).unwrap(); dispatcher.attach("lo", XdpFlags::default()).unwrap();
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn two_progs() { fn two_progs() {
let mut bpf = Ebpf::load(crate::TWO_PROGS).unwrap(); let mut bpf = Ebpf::load(crate::TWO_PROGS).unwrap();
@ -60,7 +62,8 @@ fn two_progs() {
prog_two.attach("sched", "sched_switch").unwrap(); prog_two.attach("sched", "sched_switch").unwrap();
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn extension() { fn extension() {
let kernel_version = KernelVersion::current().unwrap(); let kernel_version = KernelVersion::current().unwrap();
if kernel_version < KernelVersion::new(5, 9, 0) { if kernel_version < KernelVersion::new(5, 9, 0) {

@ -10,7 +10,8 @@ use aya::{
}; };
use integration_common::strncmp::TestResult; use integration_common::strncmp::TestResult;
#[test] #[cfg_attr(aya_integration_test, test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn bpf_strncmp() { fn bpf_strncmp() {
let mut bpf = Ebpf::load(crate::STRNCMP).unwrap(); let mut bpf = Ebpf::load(crate::STRNCMP).unwrap();

@ -3,11 +3,11 @@ use aya::{
programs::{LinkOrder, ProgramId, SchedClassifier, TcAttachType, tc::TcAttachOptions}, programs::{LinkOrder, ProgramId, SchedClassifier, TcAttachType, tc::TcAttachOptions},
util::KernelVersion, util::KernelVersion,
}; };
use test_log::test;
use crate::utils::NetNsGuard; use crate::utils::NetNsGuard;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn tcx() { fn tcx() {
let kernel_version = KernelVersion::current().unwrap(); let kernel_version = KernelVersion::current().unwrap();
if kernel_version < KernelVersion::new(6, 6, 0) { if kernel_version < KernelVersion::new(6, 6, 0) {

@ -1,7 +1,7 @@
use aya::{EbpfLoader, maps::ring_buf::RingBuf, programs::UProbe}; use aya::{EbpfLoader, maps::ring_buf::RingBuf, programs::UProbe};
use test_log::test;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn test_uprobe_cookie() { fn test_uprobe_cookie() {
const RING_BUF_BYTE_SIZE: u32 = 512; // arbitrary, but big enough const RING_BUF_BYTE_SIZE: u32 = 512; // arbitrary, but big enough

@ -6,12 +6,12 @@ use aya::{
programs::{Xdp, XdpFlags}, programs::{Xdp, XdpFlags},
}; };
use object::{Object as _, ObjectSection as _, ObjectSymbol as _, SymbolSection}; use object::{Object as _, ObjectSection as _, ObjectSymbol as _, SymbolSection};
use test_log::test;
use xdpilone::{BufIdx, IfInfo, Socket, SocketConfig, Umem, UmemConfig}; use xdpilone::{BufIdx, IfInfo, Socket, SocketConfig, Umem, UmemConfig};
use crate::utils::NetNsGuard; use crate::utils::NetNsGuard;
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn af_xdp() { fn af_xdp() {
let _netns = NetNsGuard::new(); let _netns = NetNsGuard::new();
@ -98,7 +98,8 @@ fn af_xdp() {
assert_eq!(rx.available(), 2); assert_eq!(rx.available(), 2);
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn prog_sections() { fn prog_sections() {
let obj_file = object::File::parse(crate::XDP_SEC).unwrap(); let obj_file = object::File::parse(crate::XDP_SEC).unwrap();
@ -132,7 +133,8 @@ fn ensure_symbol(obj_file: &object::File, sec_name: &str, sym_name: &str) {
); );
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn map_load() { fn map_load() {
let bpf = Ebpf::load(crate::XDP_SEC).unwrap(); let bpf = Ebpf::load(crate::XDP_SEC).unwrap();
@ -144,7 +146,8 @@ fn map_load() {
bpf.program("xdp_frags_devmap").unwrap(); bpf.program("xdp_frags_devmap").unwrap();
} }
#[test] #[cfg_attr(aya_integration_test, test_log::test)]
#[cfg_attr(not(aya_integration_test), allow(dead_code))]
fn cpumap_chain() { fn cpumap_chain() {
let _netns = NetNsGuard::new(); let _netns = NetNsGuard::new();

@ -155,13 +155,15 @@ pub fn run(opts: Options) -> Result<()> {
.into_iter() .into_iter()
.map(|profile| { .map(|profile| {
let binaries = build(target, |cmd| { let binaries = build(target, |cmd| {
cmd.env(AYA_BUILD_INTEGRATION_BPF, "true").args([ cmd.env(AYA_BUILD_INTEGRATION_BPF, "true")
"--package", .env("RUSTFLAGS", "--cfg aya_integration_test")
"integration-test", .args([
"--tests", "--package",
"--profile", "integration-test",
profile, "--tests",
]) "--profile",
profile,
])
})?; })?;
anyhow::Ok((profile, binaries)) anyhow::Ok((profile, binaries))
}) })

Loading…
Cancel
Save