diff --git a/.github/workflows/build-aya.yml b/.github/workflows/build-aya.yml index baf666de..991298fa 100644 --- a/.github/workflows/build-aya.yml +++ b/.github/workflows/build-aya.yml @@ -66,8 +66,12 @@ jobs: - name: Install Pre-requisites run: | + wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - + echo "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-15 main" | sudo tee -a /etc/apt/sources.list sudo apt-get update - sudo apt-get -qy install linux-tools-common qemu-system-x86 cloud-image-utils openssh-client libelf-dev gcc-multilib + sudo apt-get -qy install linux-tools-common qemu-system-x86 cloud-image-utils openssh-client libelf-dev gcc-multilib llvm-15 clang-15 + sudo update-alternatives --install /usr/bin/llvm-objcopy llvm-objcopy /usr/bin/llvm-objcopy-15 200 + sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-15 200 cargo install bpf-linker - name: Lint integration tests diff --git a/test/integration-test/Cargo.toml b/test/integration-test/Cargo.toml index 5851e414..9282f8cc 100644 --- a/test/integration-test/Cargo.toml +++ b/test/integration-test/Cargo.toml @@ -19,3 +19,4 @@ object = { version = "0.30", default-features = false, features = ["std", "read_ rbpf = "0.1.0" regex = "1" tempfile = "3.3.0" +libtest-mimic = "0.6.0" diff --git a/test/integration-test/src/main.rs b/test/integration-test/src/main.rs index 1fd32ea4..b081e645 100644 --- a/test/integration-test/src/main.rs +++ b/test/integration-test/src/main.rs @@ -1,74 +1,21 @@ -use log::info; +use libtest_mimic::{Arguments, Trial}; mod tests; use tests::IntegrationTest; -use clap::Parser; - -#[derive(Debug, Parser)] -#[clap(author, version, about, long_about = None)] -#[clap(propagate_version = true)] -pub struct RunOptions { - #[clap(short, long, value_parser)] - tests: Option>, -} - -#[derive(Debug, Parser)] -struct Cli { - #[clap(subcommand)] - command: Option, -} - -#[derive(Debug, Parser)] -enum Command { - /// Run one or more tests: ... -- run -t test1 -t test2 - Run(RunOptions), - /// List all the tests: ... -- list - List, -} - -macro_rules! exec_test { - ($test:expr) => {{ - info!("Running {}", $test.name); - ($test.test_fn)(); - }}; -} - -macro_rules! exec_all_tests { - () => {{ - for t in inventory::iter:: { - exec_test!(t) - } - }}; -} - -fn main() -> anyhow::Result<()> { +fn main() { env_logger::init(); - - let cli = Cli::parse(); - - match &cli.command { - Some(Command::Run(opts)) => match &opts.tests { - Some(tests) => { - for t in inventory::iter:: { - if tests.contains(&t.name.into()) { - exec_test!(t) - } - } - } - None => { - exec_all_tests!() - } - }, - Some(Command::List) => { - for t in inventory::iter:: { - info!("{}", t.name); - } - } - None => { - exec_all_tests!() - } - } - - Ok(()) + let mut args = Arguments::from_args(); + // Force to run single-threaded + args.test_threads = Some(1); + let tests = inventory::iter:: + .into_iter() + .map(|test| { + Trial::test(test.name, move || { + (test.test_fn)(); + Ok(()) + }) + }) + .collect(); + libtest_mimic::run(&args, tests).exit(); } diff --git a/test/integration-test/src/tests/relocations.rs b/test/integration-test/src/tests/relocations.rs index abeb51a3..23bc7a18 100644 --- a/test/integration-test/src/tests/relocations.rs +++ b/test/integration-test/src/tests/relocations.rs @@ -145,7 +145,7 @@ impl RelocationTest { /// - Generate the target BTF source with a mock main() /// - Compile it with clang - /// - Extract the BTF with pahole + /// - Extract the BTF with llvm-objcopy fn build_btf(&self) -> Result { let target_btf = self.target_btf; let relocation_code = self.relocation_code; @@ -171,12 +171,12 @@ impl RelocationTest { "# )) .context("Failed to compile BTF")?; - Command::new("pahole") + Command::new("llvm-objcopy") .current_dir(tmp_dir.path()) - .arg("--btf_encode_detached=target.btf") + .args(["--dump-section", ".BTF=target.btf"]) .arg(compiled_file) .status() - .context("Failed to run pahole")? + .context("Failed to run llvm-objcopy")? .success() .then_some(()) .context("Failed to extract BTF")?; diff --git a/test/run.sh b/test/run.sh index b195d7a9..3be2b862 100755 --- a/test/run.sh +++ b/test/run.sh @@ -185,4 +185,10 @@ trap stop_vm EXIT cargo xtask build-integration-test --musl --libbpf-dir "$1" scp_vm ../target/x86_64-unknown-linux-musl/debug/integration-test -exec_vm sudo ./integration-test +exec_vm sudo ./integration-test --skip relocations + +# Relocation tests build the eBPF programs and require libbpf. We run them outside VM. +export LIBBPF_INCLUDE="${AYA_TMPDIR}/libbpf/" +mkdir -p "$LIBBPF_INCLUDE" +(cd "$1/src" && make INCLUDEDIR="$LIBBPF_INCLUDE" install_headers) +sudo -E ../target/x86_64-unknown-linux-musl/debug/integration-test relocations