tests: use libtest-mimic and fix CI

pull/467/head
Matteo Nardi 2 years ago
parent 27f22f205d
commit 34e040b8e9

@ -66,8 +66,12 @@ jobs:
- name: Install Pre-requisites - name: Install Pre-requisites
run: | 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 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 cargo install bpf-linker
- name: Lint integration tests - name: Lint integration tests

@ -19,3 +19,4 @@ object = { version = "0.30", default-features = false, features = ["std", "read_
rbpf = "0.1.0" rbpf = "0.1.0"
regex = "1" regex = "1"
tempfile = "3.3.0" tempfile = "3.3.0"
libtest-mimic = "0.6.0"

@ -1,74 +1,21 @@
use log::info; use libtest_mimic::{Arguments, Trial};
mod tests; mod tests;
use tests::IntegrationTest; use tests::IntegrationTest;
use clap::Parser; fn main() {
#[derive(Debug, Parser)]
#[clap(author, version, about, long_about = None)]
#[clap(propagate_version = true)]
pub struct RunOptions {
#[clap(short, long, value_parser)]
tests: Option<Vec<String>>,
}
#[derive(Debug, Parser)]
struct Cli {
#[clap(subcommand)]
command: Option<Command>,
}
#[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::<IntegrationTest> {
exec_test!(t)
}
}};
}
fn main() -> anyhow::Result<()> {
env_logger::init(); env_logger::init();
let mut args = Arguments::from_args();
let cli = Cli::parse(); // Force to run single-threaded
args.test_threads = Some(1);
match &cli.command { let tests = inventory::iter::<IntegrationTest>
Some(Command::Run(opts)) => match &opts.tests { .into_iter()
Some(tests) => { .map(|test| {
for t in inventory::iter::<IntegrationTest> { Trial::test(test.name, move || {
if tests.contains(&t.name.into()) { (test.test_fn)();
exec_test!(t) Ok(())
} })
} })
} .collect();
None => { libtest_mimic::run(&args, tests).exit();
exec_all_tests!()
}
},
Some(Command::List) => {
for t in inventory::iter::<IntegrationTest> {
info!("{}", t.name);
}
}
None => {
exec_all_tests!()
}
}
Ok(())
} }

@ -145,7 +145,7 @@ impl RelocationTest {
/// - Generate the target BTF source with a mock main() /// - Generate the target BTF source with a mock main()
/// - Compile it with clang /// - Compile it with clang
/// - Extract the BTF with pahole /// - Extract the BTF with llvm-objcopy
fn build_btf(&self) -> Result<Btf> { fn build_btf(&self) -> Result<Btf> {
let target_btf = self.target_btf; let target_btf = self.target_btf;
let relocation_code = self.relocation_code; let relocation_code = self.relocation_code;
@ -171,12 +171,12 @@ impl RelocationTest {
"# "#
)) ))
.context("Failed to compile BTF")?; .context("Failed to compile BTF")?;
Command::new("pahole") Command::new("llvm-objcopy")
.current_dir(tmp_dir.path()) .current_dir(tmp_dir.path())
.arg("--btf_encode_detached=target.btf") .args(["--dump-section", ".BTF=target.btf"])
.arg(compiled_file) .arg(compiled_file)
.status() .status()
.context("Failed to run pahole")? .context("Failed to run llvm-objcopy")?
.success() .success()
.then_some(()) .then_some(())
.context("Failed to extract BTF")?; .context("Failed to extract BTF")?;

@ -185,4 +185,10 @@ trap stop_vm EXIT
cargo xtask build-integration-test --musl --libbpf-dir "$1" cargo xtask build-integration-test --musl --libbpf-dir "$1"
scp_vm ../target/x86_64-unknown-linux-musl/debug/integration-test 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

Loading…
Cancel
Save