[PATCH v1 bpf-next 9/9] bpftool: Add Makefile to facilitate bpftool_tests usage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Provide some Makefile targets to run the linter, build the tests, and
run them on the host or in a VM.

    $ make vmtest
    cargo test --no-run --offline
        Finished test [unoptimized + debuginfo] target(s) in 0.05s
      Executable unittests src/main.rs
    (target/debug/deps/bpftool_tests-afa5a7eef3cdeafb)
    vmtest -k /data/users/chantra/bpf-next/arch/x86/boot/bzImage
    "RUST_TEST_THREADS=1 BPFTOOL_PATH=../tools/build/bpftool/bpftool cargo
    test"
    => bzImage
    ===> Booting
    ===> Setting up VM
    ===> Running command
        Finished test [unoptimized + debuginfo] target(s) in 2.05s
         Running unittests src/main.rs
    (target/debug/deps/bpftool_tests-afa5a7eef3cdeafb)

    running 11 tests
    test bpftool_tests::run_bpftool ... ok
    test bpftool_tests::run_bpftool_map_dump_id ... ok
    test bpftool_tests::run_bpftool_map_list ... ok
    test bpftool_tests::run_bpftool_map_pids ... ok
    test bpftool_tests::run_bpftool_prog_list ... ok
    test bpftool_tests::run_bpftool_prog_pids ... ok
    test bpftool_tests::run_bpftool_prog_show_id ... ok
    test bpftool_tests::run_bpftool_struct_ops_can_unregister_id ... ok
    test bpftool_tests::run_bpftool_struct_ops_can_unregister_name ... ok
    test bpftool_tests::run_bpftool_struct_ops_dump_name ... ok
    test bpftool_tests::run_bpftool_struct_ops_list ... ok

    test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 0 filtered
    out; finished in 2.88s

Signed-off-by: Manu Bretelle <chantr4@xxxxxxxxx>
---
 .../selftests/bpf/bpftool_tests/Makefile      | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/bpftool_tests/Makefile

diff --git a/tools/testing/selftests/bpf/bpftool_tests/Makefile b/tools/testing/selftests/bpf/bpftool_tests/Makefile
new file mode 100644
index 000000000000..0b5633cda8b4
--- /dev/null
+++ b/tools/testing/selftests/bpf/bpftool_tests/Makefile
@@ -0,0 +1,22 @@
+BPFTOOL := ../tools/build/bpftool/bpftool
+
+lint:
+	cargo clippy --tests
+	cargo check --tests
+
+# Build the tests but do not run them.
+build-test:
+	cargo test --no-run --offline
+
+# Run the tests on the host using sudo
+test: build-test
+	RUST_TEST_THREADS=1 BPFTOOL_PATH=$(BPFTOOL) sudo -E $(shell which cargo) test --offline
+
+# Run the tests in a vm. Requires danobi/vmtest.
+vmtest: build-test
+	$(eval repo_root := $(shell git rev-parse --show-toplevel))
+	$(eval kernel_img := $(shell make -s -C $(repo_root) image_name))
+	vmtest -k $(repo_root)/$(kernel_img) "RUST_TEST_THREADS=1 BPFTOOL_PATH=$(BPFTOOL) cargo test"
+
+clean:
+	cargo clean
-- 
2.39.3





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux