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
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

@ -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"

@ -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<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<()> {
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::<IntegrationTest> {
if tests.contains(&t.name.into()) {
exec_test!(t)
}
}
}
None => {
exec_all_tests!()
}
},
Some(Command::List) => {
for t in inventory::iter::<IntegrationTest> {
info!("{}", t.name);
}
}
None => {
exec_all_tests!()
}
}
let mut args = Arguments::from_args();
// Force to run single-threaded
args.test_threads = Some(1);
let tests = inventory::iter::<IntegrationTest>
.into_iter()
.map(|test| {
Trial::test(test.name, move || {
(test.test_fn)();
Ok(())
})
})
.collect();
libtest_mimic::run(&args, tests).exit();
}

@ -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<Btf> {
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")?;

@ -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

Loading…
Cancel
Save