From: Manu Bretelle <chantr4@gmail.com>
To: bpf@vger.kernel.org, quentin@isovalent.com, andrii@kernel.org,
daniel@iogearbox.net, ast@kernel.org, martin.lau@linux.dev,
song@kernel.org, john.fastabend@gmail.com, kpsingh@kernel.org,
sdf@google.com, haoluo@google.com, jolsa@kernel.org
Subject: [PATCH v1 bpf-next 1/9] bpftool: add testing skeleton
Date: Thu, 16 Nov 2023 11:42:28 -0800 [thread overview]
Message-ID: <20231116194236.1345035-2-chantr4@gmail.com> (raw)
In-Reply-To: <20231116194236.1345035-1-chantr4@gmail.com>
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@gmail.com>
---
.../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
next prev parent reply other threads:[~2023-11-16 19:43 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-16 19:42 [PATCH v1 bpf-next 0/9] bpftool: Add end-to-end testing Manu Bretelle
2023-11-16 19:42 ` Manu Bretelle [this message]
2023-11-21 1:37 ` [PATCH v1 bpf-next 1/9] bpftool: add testing skeleton Alexei Starovoitov
2023-11-21 16:26 ` Quentin Monnet
2023-11-21 16:42 ` Alexei Starovoitov
2023-11-21 19:50 ` Andrii Nakryiko
2023-11-27 17:07 ` Quentin Monnet
2023-11-27 18:39 ` Andrii Nakryiko
2023-12-15 6:26 ` Manu Bretelle
2023-11-27 17:07 ` Quentin Monnet
2023-12-15 6:37 ` Manu Bretelle
2023-11-21 16:26 ` Quentin Monnet
2023-11-16 19:42 ` [PATCH v1 bpf-next 2/9] bpftool: add libbpf-rs dependency and minimal bpf program Manu Bretelle
2023-11-16 19:42 ` [PATCH v1 bpf-next 3/9] bpftool: open and load bpf object Manu Bretelle
2023-11-16 19:42 ` [PATCH v1 bpf-next 4/9] bpftool: Add test to verify that pids are associated to maps Manu Bretelle
2023-11-21 16:26 ` Quentin Monnet
2023-11-16 19:42 ` [PATCH v1 bpf-next 5/9] bpftool: add test for bpftool prog Manu Bretelle
2023-11-21 16:26 ` Quentin Monnet
2023-11-16 19:42 ` [PATCH v1 bpf-next 6/9] bpftool: test that we can dump and read the content of a map Manu Bretelle
2023-11-21 16:26 ` Quentin Monnet
2023-11-16 19:42 ` [PATCH v1 bpf-next 7/9] bpftool: Add struct_ops tests Manu Bretelle
2023-11-16 19:42 ` [PATCH v1 bpf-next 8/9] bpftool: Add bpftool_tests README.md Manu Bretelle
2023-11-21 16:26 ` Quentin Monnet
2023-11-16 19:42 ` [PATCH v1 bpf-next 9/9] bpftool: Add Makefile to facilitate bpftool_tests usage Manu Bretelle
2023-11-21 16:26 ` Quentin Monnet
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231116194236.1345035-2-chantr4@gmail.com \
--to=chantr4@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=martin.lau@linux.dev \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.