diff --git a/Cargo.toml b/Cargo.toml index c7748639..c4abc669 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,29 +25,6 @@ members = [ 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] authors = ["Aya Contributors"] edition = "2024" diff --git a/test/integration-test/build.rs b/test/integration-test/build.rs index 2caea5a4..1a1767fc 100644 --- a/test/integration-test/build.rs +++ b/test/integration-test/build.rs @@ -25,6 +25,7 @@ use xtask::{AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR, exec}; /// runtime because the stubs are inadequate for actually running the tests. fn main() -> Result<()> { 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 // aya-build if we can determine that we're in a check build. diff --git a/test/integration-test/src/tests/bpf_probe_read.rs b/test/integration-test/src/tests/bpf_probe_read.rs index 7f2c5d39..db0c2b35 100644 --- a/test/integration-test/src/tests/bpf_probe_read.rs +++ b/test/integration-test/src/tests/bpf_probe_read.rs @@ -1,14 +1,15 @@ use aya::{Ebpf, maps::Array, programs::UProbe}; 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() { let bpf = set_user_buffer(b"foo\0", RESULT_BUF_LEN); 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() { let s = vec![b'a'; 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]); } -#[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() { let bpf = set_user_buffer(b"\0", RESULT_BUF_LEN); 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() { let bpf = set_user_buffer(b"foo\0", 0); 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() { let bpf = set_kernel_buffer(b"foo\0", RESULT_BUF_LEN); 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() { let s = vec![b'a'; 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]); } -#[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() { let bpf = set_kernel_buffer(b"\0", RESULT_BUF_LEN); 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() { let bpf = set_kernel_buffer(b"foo\0", 0); assert_eq!(result_bytes(&bpf), b""); diff --git a/test/integration-test/src/tests/btf_relocations.rs b/test/integration-test/src/tests/btf_relocations.rs index 4d3b6845..a77258a1 100644 --- a/test/integration-test/src/tests/btf_relocations.rs +++ b/test/integration-test/src/tests/btf_relocations.rs @@ -1,28 +1,46 @@ 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)] +#[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))] +#[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))] +#[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))] +#[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))] +#[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))] +#[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))] +#[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))] +#[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))] +#[cfg_attr( + aya_integration_test, + test_case::test_case("enum_unsigned_32", false, None, 0xAAAAAAAA) +)] +#[cfg_attr( + aya_integration_test, + test_case::test_case("enum_unsigned_32", true, None, 0xBBBBBBBB) +)] +#[cfg_attr( + aya_integration_test, + test_case::test_case("enum_unsigned_32_checked_variants", false, None, 0xAAAAAAAA) +)] +#[cfg_attr( + 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( program: &str, with_relocations: bool, diff --git a/test/integration-test/src/tests/elf.rs b/test/integration-test/src/tests/elf.rs index 83e5f6c0..eb6a1161 100644 --- a/test/integration-test/src/tests/elf.rs +++ b/test/integration-test/src/tests/elf.rs @@ -1,7 +1,7 @@ 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() { let obj_file = object::File::parse(crate::MAP_TEST).unwrap(); assert!(obj_file.section_by_name("maps").is_some()); diff --git a/test/integration-test/src/tests/info.rs b/test/integration-test/src/tests/info.rs index d4410b77..200973d4 100644 --- a/test/integration-test/src/tests/info.rs +++ b/test/integration-test/src/tests/info.rs @@ -18,7 +18,8 @@ use libc::EINVAL; 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() { // Load a program. // 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() { // 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"); @@ -108,7 +110,8 @@ fn test_program_info() { test_prog.fd().unwrap(); } -#[test] +#[cfg_attr(aya_integration_test, test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn test_loaded_at() { let mut bpf: Ebpf = Ebpf::load(crate::SIMPLE_PROG).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() { // Test depends on whether trace point 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)); } -#[test] +#[cfg_attr(aya_integration_test, test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn list_loaded_maps() { // Load a program with maps. 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() { let mut bpf: Ebpf = Ebpf::load(crate::MAP_TEST).unwrap(); let prog: &mut SocketFilter = bpf.program_mut("simple_prog").unwrap().try_into().unwrap(); diff --git a/test/integration-test/src/tests/iter.rs b/test/integration-test/src/tests/iter.rs index 174a79ee..a32f4781 100644 --- a/test/integration-test/src/tests/iter.rs +++ b/test/integration-test/src/tests/iter.rs @@ -1,9 +1,9 @@ use std::io::BufRead as _; 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() { let mut ebpf = Ebpf::load(crate::ITER_TASK).unwrap(); let btf = Btf::from_sys_fs().unwrap(); diff --git a/test/integration-test/src/tests/load.rs b/test/integration-test/src/tests/load.rs index a93e6f16..f0cdb215 100644 --- a/test/integration-test/src/tests/load.rs +++ b/test/integration-test/src/tests/load.rs @@ -11,12 +11,12 @@ use aya::{ util::KernelVersion, }; use aya_obj::programs::XdpAttachType; -use test_log::test; const MAX_RETRIES: usize = 100; 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() { let mut bpf = Ebpf::load(crate::NAME_TEST).unwrap(); 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. } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn multiple_btf_maps() { let mut bpf = Ebpf::load(crate::MULTIMAP_BTF).unwrap(); @@ -62,7 +63,8 @@ fn multiple_btf_maps() { 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() { 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() { let mut bpf = Ebpf::load(crate::TEST).unwrap(); let prog: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap(); @@ -216,7 +219,8 @@ fn unload_xdp() { assert_unloaded("pass"); } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn unload_kprobe() { let mut bpf = Ebpf::load(crate::TEST).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"); } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn memmove() { let mut bpf = Ebpf::load(crate::MEMMOVE_TEST).unwrap(); let prog: &mut Xdp = bpf.program_mut("do_dnat").unwrap().try_into().unwrap(); @@ -250,7 +255,8 @@ fn memmove() { 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() { let mut bpf = Ebpf::load(crate::TEST).unwrap(); let prog: &mut TracePoint = bpf @@ -281,7 +287,8 @@ fn basic_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() { let mut bpf = Ebpf::load(crate::TEST).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"); } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn basic_flow_dissector() { let mut bpf = Ebpf::load(crate::TEST).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"); } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn pin_link() { let kernel_version = KernelVersion::current().unwrap(); if kernel_version < KernelVersion::new(5, 9, 0) { @@ -370,7 +379,8 @@ fn pin_link() { assert_unloaded("pass"); } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn pin_lifecycle() { let kernel_version = KernelVersion::current().unwrap(); if kernel_version < KernelVersion::new(5, 18, 0) { @@ -433,7 +443,8 @@ fn pin_lifecycle() { 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() { // 1. Load Program and Pin { @@ -487,7 +498,8 @@ fn pin_lifecycle_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() { // 1. Load Program and Pin { @@ -551,7 +563,8 @@ extern "C" fn 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() { 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"; diff --git a/test/integration-test/src/tests/log.rs b/test/integration-test/src/tests/log.rs index 01820b63..0f958b00 100644 --- a/test/integration-test/src/tests/log.rs +++ b/test/integration-test/src/tests/log.rs @@ -6,7 +6,6 @@ use std::{ use aya::{Ebpf, programs::UProbe}; use aya_log::EbpfLogger; use log::{Level, Log, Record}; -use test_log::test; #[unsafe(no_mangle)] #[inline(never)] @@ -38,7 +37,8 @@ struct CapturedLog<'a> { 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() { let mut bpf = Ebpf::load(crate::LOG).unwrap(); diff --git a/test/integration-test/src/tests/raw_tracepoint.rs b/test/integration-test/src/tests/raw_tracepoint.rs index ab64abb9..01e137b4 100644 --- a/test/integration-test/src/tests/raw_tracepoint.rs +++ b/test/integration-test/src/tests/raw_tracepoint.rs @@ -6,7 +6,8 @@ fn get_event(bpf: &mut Ebpf) -> SysEnterEvent { map.get(&0, 0).unwrap() } -#[test] +#[cfg_attr(aya_integration_test, test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn raw_tracepoint() { let mut bpf = Ebpf::load(crate::RAW_TRACEPOINT).unwrap(); diff --git a/test/integration-test/src/tests/rbpf.rs b/test/integration-test/src/tests/rbpf.rs index ce62cb5c..6386ed25 100644 --- a/test/integration-test/src/tests/rbpf.rs +++ b/test/integration-test/src/tests/rbpf.rs @@ -3,9 +3,9 @@ use std::collections::HashMap; use assert_matches::assert_matches; 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() { let object = Object::parse(crate::PASS).unwrap(); @@ -37,7 +37,8 @@ fn run_with_rbpf() { static mut MULTIMAP_MAPS: [*mut Vec; 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() { let mut object = Object::parse(crate::MULTIMAP_BTF).unwrap(); diff --git a/test/integration-test/src/tests/relocations.rs b/test/integration-test/src/tests/relocations.rs index 592cbd50..bea2d47b 100644 --- a/test/integration-test/src/tests/relocations.rs +++ b/test/integration-test/src/tests/relocations.rs @@ -3,9 +3,9 @@ use aya::{ programs::{UProbe, Xdp}, 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() { 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); } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn text_64_64_reloc() { let kernel_version = KernelVersion::current().unwrap(); 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); } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn variables_reloc() { let mut bpf = Ebpf::load(crate::VARIABLES_RELOC).unwrap(); let prog: &mut Xdp = bpf diff --git a/test/integration-test/src/tests/ring_buf.rs b/test/integration-test/src/tests/ring_buf.rs index c7bf633f..e0442d6b 100644 --- a/test/integration-test/src/tests/ring_buf.rs +++ b/test/integration-test/src/tests/ring_buf.rs @@ -18,7 +18,6 @@ use aya::{ use aya_obj::generated::BPF_RINGBUF_HDR_SZ; use integration_common::ring_buf::Registers; use rand::Rng as _; -use test_log::test; use tokio::{ io::unix::AsyncFd, time::{Duration, sleep}, @@ -83,11 +82,12 @@ impl WithData { } } -#[test_case::test_case(0; "write zero items")] -#[test_case::test_case(1; "write one item")] -#[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")] -#[test_case::test_case(RING_BUF_MAX_ENTRIES * 8; "write more items than capacity")] +#[cfg_attr(aya_integration_test, test_case::test_case(0; "write zero items"))] +#[cfg_attr(aya_integration_test, test_case::test_case(1; "write one item"))] +#[cfg_attr(aya_integration_test, 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 - 1; "write one less than capacity items"))] +#[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) { let WithData( 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 // 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. -#[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() { let WithData( 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() { let WithData( 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 // state was not properly synchronized between the producer and consumer. This would result in the // 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() { let RingBufTest { 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. -#[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() { let RingBufTest { ring_buf, diff --git a/test/integration-test/src/tests/smoke.rs b/test/integration-test/src/tests/smoke.rs index 5465fb14..7dbe5aae 100644 --- a/test/integration-test/src/tests/smoke.rs +++ b/test/integration-test/src/tests/smoke.rs @@ -3,11 +3,11 @@ use aya::{ programs::{Extension, TracePoint, Xdp, XdpFlags, tc}, util::KernelVersion, }; -use test_log::test; use crate::utils::NetNsGuard; -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn modprobe() { // This very simple looking test is actually quite complex. // 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(); } -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn xdp() { let kernel_version = KernelVersion::current().unwrap(); if kernel_version < KernelVersion::new(5, 18, 0) { @@ -38,7 +39,8 @@ fn xdp() { 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() { let mut bpf = Ebpf::load(crate::TWO_PROGS).unwrap(); @@ -60,7 +62,8 @@ fn two_progs() { 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() { let kernel_version = KernelVersion::current().unwrap(); if kernel_version < KernelVersion::new(5, 9, 0) { diff --git a/test/integration-test/src/tests/strncmp.rs b/test/integration-test/src/tests/strncmp.rs index fe25b48b..ad6c5239 100644 --- a/test/integration-test/src/tests/strncmp.rs +++ b/test/integration-test/src/tests/strncmp.rs @@ -10,7 +10,8 @@ use aya::{ }; use integration_common::strncmp::TestResult; -#[test] +#[cfg_attr(aya_integration_test, test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn bpf_strncmp() { let mut bpf = Ebpf::load(crate::STRNCMP).unwrap(); diff --git a/test/integration-test/src/tests/tcx.rs b/test/integration-test/src/tests/tcx.rs index 215620c3..69659a15 100644 --- a/test/integration-test/src/tests/tcx.rs +++ b/test/integration-test/src/tests/tcx.rs @@ -3,11 +3,11 @@ use aya::{ programs::{LinkOrder, ProgramId, SchedClassifier, TcAttachType, tc::TcAttachOptions}, util::KernelVersion, }; -use test_log::test; use crate::utils::NetNsGuard; -#[test] +#[cfg_attr(aya_integration_test, test_log::test)] +#[cfg_attr(not(aya_integration_test), allow(dead_code))] fn tcx() { let kernel_version = KernelVersion::current().unwrap(); if kernel_version < KernelVersion::new(6, 6, 0) { diff --git a/test/integration-test/src/tests/uprobe_cookie.rs b/test/integration-test/src/tests/uprobe_cookie.rs index dd69762b..6b5510fc 100644 --- a/test/integration-test/src/tests/uprobe_cookie.rs +++ b/test/integration-test/src/tests/uprobe_cookie.rs @@ -1,7 +1,7 @@ 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() { const RING_BUF_BYTE_SIZE: u32 = 512; // arbitrary, but big enough diff --git a/test/integration-test/src/tests/xdp.rs b/test/integration-test/src/tests/xdp.rs index 67066e85..cf9efb37 100644 --- a/test/integration-test/src/tests/xdp.rs +++ b/test/integration-test/src/tests/xdp.rs @@ -6,12 +6,12 @@ use aya::{ programs::{Xdp, XdpFlags}, }; use object::{Object as _, ObjectSection as _, ObjectSymbol as _, SymbolSection}; -use test_log::test; use xdpilone::{BufIdx, IfInfo, Socket, SocketConfig, Umem, UmemConfig}; 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() { let _netns = NetNsGuard::new(); @@ -98,7 +98,8 @@ fn af_xdp() { 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() { 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() { let bpf = Ebpf::load(crate::XDP_SEC).unwrap(); @@ -144,7 +146,8 @@ fn map_load() { 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() { let _netns = NetNsGuard::new(); diff --git a/xtask/src/run.rs b/xtask/src/run.rs index d5a48ebe..c148fddc 100644 --- a/xtask/src/run.rs +++ b/xtask/src/run.rs @@ -155,13 +155,15 @@ pub fn run(opts: Options) -> Result<()> { .into_iter() .map(|profile| { let binaries = build(target, |cmd| { - cmd.env(AYA_BUILD_INTEGRATION_BPF, "true").args([ - "--package", - "integration-test", - "--tests", - "--profile", - profile, - ]) + cmd.env(AYA_BUILD_INTEGRATION_BPF, "true") + .env("RUSTFLAGS", "--cfg aya_integration_test") + .args([ + "--package", + "integration-test", + "--tests", + "--profile", + profile, + ]) })?; anyhow::Ok((profile, binaries)) })