Add minimal cargo project to test bpftool. An environment variable `BPFTOOL_PATH` can be used to provide the path to bpftool, defaulting to /usr/sbin/bpftool $ cargo check --tests Finished dev [unoptimized + debuginfo] target(s) in 0.00s $ cargo clippy --tests Finished dev [unoptimized + debuginfo] target(s) in 0.05s $ BPFTOOL_PATH='../bpftool' cargo test -- --nocapture Finished test [unoptimized + debuginfo] target(s) in 0.05s Running unittests src/main.rs (target/debug/deps/bpftool_tests-172b867215e9364e) running 1 test Running command "../bpftool" "version" test bpftool_tests::run_bpftool ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s Signed-off-by: Manu Bretelle <chantr4@xxxxxxxxx> --- .../selftests/bpf/bpftool_tests/.gitignore | 3 +++ .../selftests/bpf/bpftool_tests/Cargo.toml | 4 ++++ .../bpf/bpftool_tests/src/bpftool_tests.rs | 20 +++++++++++++++++++ .../selftests/bpf/bpftool_tests/src/main.rs | 3 +++ 4 files changed, 30 insertions(+) create mode 100644 tools/testing/selftests/bpf/bpftool_tests/.gitignore create mode 100644 tools/testing/selftests/bpf/bpftool_tests/Cargo.toml create mode 100644 tools/testing/selftests/bpf/bpftool_tests/src/bpftool_tests.rs create mode 100644 tools/testing/selftests/bpf/bpftool_tests/src/main.rs diff --git a/tools/testing/selftests/bpf/bpftool_tests/.gitignore b/tools/testing/selftests/bpf/bpftool_tests/.gitignore new file mode 100644 index 000000000000..cf8177c6aabd --- /dev/null +++ b/tools/testing/selftests/bpf/bpftool_tests/.gitignore @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +/target/** +/Cargo.lock diff --git a/tools/testing/selftests/bpf/bpftool_tests/Cargo.toml b/tools/testing/selftests/bpf/bpftool_tests/Cargo.toml new file mode 100644 index 000000000000..34df3002003f --- /dev/null +++ b/tools/testing/selftests/bpf/bpftool_tests/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "bpftool_tests" +version = "0.1.0" +edition = "2021" diff --git a/tools/testing/selftests/bpf/bpftool_tests/src/bpftool_tests.rs b/tools/testing/selftests/bpf/bpftool_tests/src/bpftool_tests.rs new file mode 100644 index 000000000000..251dbf3861fe --- /dev/null +++ b/tools/testing/selftests/bpf/bpftool_tests/src/bpftool_tests.rs @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +use std::process::Command; + +const BPFTOOL_PATH_ENV: &str = "BPFTOOL_PATH"; +const BPFTOOL_PATH: &str = "/usr/sbin/bpftool"; + +/// Run a bpftool command and returns the output +fn run_bpftool_command(args: &[&str]) -> std::process::Output { + let mut cmd = Command::new(std::env::var(BPFTOOL_PATH_ENV).unwrap_or(BPFTOOL_PATH.to_string())); + cmd.args(args); + println!("Running command {:?}", cmd); + cmd.output().expect("failed to execute process") +} + +/// Simple test to make sure we can run bpftool +#[test] +fn run_bpftool() { + let output = run_bpftool_command(&["version"]); + assert!(output.status.success()); +} diff --git a/tools/testing/selftests/bpf/bpftool_tests/src/main.rs b/tools/testing/selftests/bpf/bpftool_tests/src/main.rs new file mode 100644 index 000000000000..6b4ffcde7406 --- /dev/null +++ b/tools/testing/selftests/bpf/bpftool_tests/src/main.rs @@ -0,0 +1,3 @@ +// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause +#[cfg(test)] +mod bpftool_tests; -- 2.39.3