You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aya/test/integration-test/src/tests/smoke.rs

37 lines
1.3 KiB
Rust

use aya::{
programs::{Extension, Xdp, XdpFlags},
util::KernelVersion,
Bpf, BpfLoader,
};
#[test]
fn xdp() {
let kernel_version = KernelVersion::current().unwrap();
if kernel_version < KernelVersion::new(5, 18, 0) {
eprintln!("skipping test on kernel {kernel_version:?}, support for BPF_F_XDP_HAS_FRAGS was added in 5.18.0; see https://github.com/torvalds/linux/commit/c2f2cdb");
return;
}
integration-test: build one binary instead of N "integration tests" as defined by Cargo produce a binary per file in the tests directory. This is really not what we want and has a number of downsides, but the main one is binary size. Before: tamird@pc:~/src/aya$ cargo xtask build-integration-test | xargs ls -lah Finished dev [unoptimized + debuginfo] target(s) in 0.05s Running `target/debug/xtask build-integration-test` Compiling integration-test v0.1.0 (/home/tamird/src/aya/test/integration-test) Finished dev [unoptimized + debuginfo] target(s) in 0.68s -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/bpf_probe_read-e03eb905a5e6209c -rwxrwxr-x 1 tamird tamird 35M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/btf_relocations-57a4fbb38bf06064 -rwxrwxr-x 1 tamird tamird 31M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/elf-98b7a32d6d04effb -rwxrwxr-x 1 tamird tamird 6.9M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/integration_test-0dd55ce96bfdad77 -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/load-0718562e85b86d03 -rwxrwxr-x 1 tamird tamird 40M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/log-dbf355f9ea34068a -rwxrwxr-x 1 tamird tamird 36M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/rbpf-89a1bb848fa5cc3c -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/relocations-cfe655c3bb413d8b -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/smoke-ccd3974180a3fd29 After: tamird@pc:~/src/aya$ cargo xtask build-integration-test | xargs ls -lah Finished dev [unoptimized + debuginfo] target(s) in 0.05s Running `target/debug/xtask build-integration-test` Compiling integration-test v0.1.0 (/home/tamird/src/aya/test/integration-test) Finished dev [unoptimized + debuginfo] target(s) in 0.90s -rwxrwxr-x 1 tamird tamird 47M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/integration_test-0dd55ce96bfdad77 Since we plan to run these tests in a VM, copying 10x fewer bytes seems like a win.
1 year ago
let mut bpf = Bpf::load(crate::PASS).unwrap();
let dispatcher: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
dispatcher.load().unwrap();
dispatcher.attach("lo", XdpFlags::default()).unwrap();
}
#[test]
fn extension() {
let kernel_version = KernelVersion::current().unwrap();
if kernel_version < KernelVersion::new(5, 9, 0) {
eprintln!("skipping test on kernel {kernel_version:?}, XDP uses netlink");
return;
}
integration-test: build one binary instead of N "integration tests" as defined by Cargo produce a binary per file in the tests directory. This is really not what we want and has a number of downsides, but the main one is binary size. Before: tamird@pc:~/src/aya$ cargo xtask build-integration-test | xargs ls -lah Finished dev [unoptimized + debuginfo] target(s) in 0.05s Running `target/debug/xtask build-integration-test` Compiling integration-test v0.1.0 (/home/tamird/src/aya/test/integration-test) Finished dev [unoptimized + debuginfo] target(s) in 0.68s -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/bpf_probe_read-e03eb905a5e6209c -rwxrwxr-x 1 tamird tamird 35M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/btf_relocations-57a4fbb38bf06064 -rwxrwxr-x 1 tamird tamird 31M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/elf-98b7a32d6d04effb -rwxrwxr-x 1 tamird tamird 6.9M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/integration_test-0dd55ce96bfdad77 -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/load-0718562e85b86d03 -rwxrwxr-x 1 tamird tamird 40M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/log-dbf355f9ea34068a -rwxrwxr-x 1 tamird tamird 36M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/rbpf-89a1bb848fa5cc3c -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/relocations-cfe655c3bb413d8b -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/smoke-ccd3974180a3fd29 After: tamird@pc:~/src/aya$ cargo xtask build-integration-test | xargs ls -lah Finished dev [unoptimized + debuginfo] target(s) in 0.05s Running `target/debug/xtask build-integration-test` Compiling integration-test v0.1.0 (/home/tamird/src/aya/test/integration-test) Finished dev [unoptimized + debuginfo] target(s) in 0.90s -rwxrwxr-x 1 tamird tamird 47M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/integration_test-0dd55ce96bfdad77 Since we plan to run these tests in a VM, copying 10x fewer bytes seems like a win.
1 year ago
let mut bpf = Bpf::load(crate::MAIN).unwrap();
let pass: &mut Xdp = bpf.program_mut("pass").unwrap().try_into().unwrap();
pass.load().unwrap();
pass.attach("lo", XdpFlags::default()).unwrap();
integration-test: build one binary instead of N "integration tests" as defined by Cargo produce a binary per file in the tests directory. This is really not what we want and has a number of downsides, but the main one is binary size. Before: tamird@pc:~/src/aya$ cargo xtask build-integration-test | xargs ls -lah Finished dev [unoptimized + debuginfo] target(s) in 0.05s Running `target/debug/xtask build-integration-test` Compiling integration-test v0.1.0 (/home/tamird/src/aya/test/integration-test) Finished dev [unoptimized + debuginfo] target(s) in 0.68s -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/bpf_probe_read-e03eb905a5e6209c -rwxrwxr-x 1 tamird tamird 35M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/btf_relocations-57a4fbb38bf06064 -rwxrwxr-x 1 tamird tamird 31M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/elf-98b7a32d6d04effb -rwxrwxr-x 1 tamird tamird 6.9M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/integration_test-0dd55ce96bfdad77 -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/load-0718562e85b86d03 -rwxrwxr-x 1 tamird tamird 40M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/log-dbf355f9ea34068a -rwxrwxr-x 1 tamird tamird 36M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/rbpf-89a1bb848fa5cc3c -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/relocations-cfe655c3bb413d8b -rwxrwxr-x 1 tamird tamird 34M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/smoke-ccd3974180a3fd29 After: tamird@pc:~/src/aya$ cargo xtask build-integration-test | xargs ls -lah Finished dev [unoptimized + debuginfo] target(s) in 0.05s Running `target/debug/xtask build-integration-test` Compiling integration-test v0.1.0 (/home/tamird/src/aya/test/integration-test) Finished dev [unoptimized + debuginfo] target(s) in 0.90s -rwxrwxr-x 1 tamird tamird 47M Jul 12 15:21 /home/tamird/src/aya/target/debug/deps/integration_test-0dd55ce96bfdad77 Since we plan to run these tests in a VM, copying 10x fewer bytes seems like a win.
1 year ago
let mut bpf = BpfLoader::new().extension("drop").load(crate::EXT).unwrap();
let drop_: &mut Extension = bpf.program_mut("drop").unwrap().try_into().unwrap();
drop_.load(pass.fd().unwrap(), "xdp_pass").unwrap();
}