diff mbox series

[bpf-next,4/4] bpf/selftests: add simple selftest for bpf_smc_ops

Message ID 1729737768-124596-5-git-send-email-alibuda@linux.alibaba.com (mailing list archive)
State New
Delegated to: BPF
Headers show
Series net/smc: Introduce smc_bpf_ops | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit fail Errors and warnings before: 13 this patch: 20
netdev/build_tools success Errors and warnings before: 2 (+1) this patch: 2 (+1)
netdev/cc_maintainers warning 5 maintainers not CCed: linux-kselftest@vger.kernel.org shuah@kernel.org yonghong.song@linux.dev mykolal@fb.com eddyz87@gmail.com
netdev/build_clang fail Errors and warnings before: 38 this patch: 15
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn fail Errors and warnings before: 201 this patch: 390
netdev/checkpatch warning CHECK: No space is necessary after a cast WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-0 success Logs for Lint
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Unittests
bpf/vmtest-bpf-next-VM_Test-5 success Logs for aarch64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Validate matrix.py
bpf/vmtest-bpf-next-VM_Test-6 success Logs for aarch64-gcc / test
bpf/vmtest-bpf-next-VM_Test-4 fail Logs for aarch64-gcc / build / build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-9 success Logs for s390x-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-7 success Logs for aarch64-gcc / veristat
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-24 success Logs for x86_64-llvm-18 / veristat
bpf/vmtest-bpf-next-VM_Test-10 success Logs for s390x-gcc / test
bpf/vmtest-bpf-next-VM_Test-18 fail Logs for x86_64-llvm-17 / build-release / build for x86_64 with llvm-17-O2
bpf/vmtest-bpf-next-VM_Test-13 fail Logs for x86_64-gcc / build / build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-8 fail Logs for s390x-gcc / build / build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-23 success Logs for x86_64-llvm-18 / test
bpf/vmtest-bpf-next-VM_Test-16 success Logs for x86_64-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-22 fail Logs for x86_64-llvm-18 / build-release / build for x86_64 with llvm-18-O2
bpf/vmtest-bpf-next-VM_Test-21 fail Logs for x86_64-llvm-18 / build / build for x86_64 with llvm-18
bpf/vmtest-bpf-next-VM_Test-15 success Logs for x86_64-gcc / test
bpf/vmtest-bpf-next-VM_Test-12 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-14 success Logs for x86_64-gcc / build-release
bpf/vmtest-bpf-next-VM_Test-11 success Logs for s390x-gcc / veristat
bpf/vmtest-bpf-next-VM_Test-19 success Logs for x86_64-llvm-17 / test
bpf/vmtest-bpf-next-VM_Test-20 success Logs for x86_64-llvm-17 / veristat
bpf/vmtest-bpf-next-VM_Test-17 fail Logs for x86_64-llvm-17 / build / build for x86_64 with llvm-17

Commit Message

D. Wythe Oct. 24, 2024, 2:42 a.m. UTC
From: "D. Wythe" <alibuda@linux.alibaba.com>

This PATCH adds a tiny selftest for bpf_smc_ops, to verify the ability
to attach and write access.

Follow the steps below to run this test.

make -C tools/testing/selftests/bpf
cd tools/testing/selftests/bpf
sudo ./test_progs -t smc

Results shows:
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED

Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
---
 .../selftests/bpf/prog_tests/test_bpf_smc.c        | 21 +++++++++++
 tools/testing/selftests/bpf/progs/bpf_smc.c        | 44 ++++++++++++++++++++++
 2 files changed, 65 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c
 create mode 100644 tools/testing/selftests/bpf/progs/bpf_smc.c

Comments

D. Wythe Oct. 24, 2024, 4:04 a.m. UTC | #1
On 10/24/24 10:42 AM, D. Wythe wrote:
> From: "D. Wythe" <alibuda@linux.alibaba.com>
> 
> This PATCH adds a tiny selftest for bpf_smc_ops, to verify the ability
> to attach and write access.
> 
> Follow the steps below to run this test.
> 
> make -C tools/testing/selftests/bpf
> cd tools/testing/selftests/bpf
> sudo ./test_progs -t smc
> 
> Results shows:
> Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED


Sorry for just found an issue with vary config. I will fix this issues
in the next version.

D. Wythe
Tianchen Ding Oct. 24, 2024, 4:49 a.m. UTC | #2
On 2024/10/24 12:04, D. Wythe wrote:
> 
> 
> On 10/24/24 10:42 AM, D. Wythe wrote:
>> From: "D. Wythe" <alibuda@linux.alibaba.com>
>>
>> This PATCH adds a tiny selftest for bpf_smc_ops, to verify the ability
>> to attach and write access.
>>
>> Follow the steps below to run this test.
>>
>> make -C tools/testing/selftests/bpf
>> cd tools/testing/selftests/bpf
>> sudo ./test_progs -t smc
>>
>> Results shows:
>> Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
> 
> 
> Sorry for just found an issue with vary config. I will fix this issues
> in the next version.
> 
> D. Wythe

This doesn't build with !CONFIG_SMC.

Maybe you should create an individual dir. (like what sched_ext does)
D. Wythe Oct. 24, 2024, 5:49 a.m. UTC | #3
On 10/24/24 12:49 PM, Tianchen Ding wrote:
> On 2024/10/24 12:04, D. Wythe wrote:
>>
>>
>> On 10/24/24 10:42 AM, D. Wythe wrote:
>>> From: "D. Wythe" <alibuda@linux.alibaba.com>
>>>
>>> This PATCH adds a tiny selftest for bpf_smc_ops, to verify the ability
>>> to attach and write access.
>>>
>>> Follow the steps below to run this test.
>>>
>>> make -C tools/testing/selftests/bpf
>>> cd tools/testing/selftests/bpf
>>> sudo ./test_progs -t smc
>>>
>>> Results shows:
>>> Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED
>>
>>
>> Sorry for just found an issue with vary config. I will fix this issues
>> in the next version.
>>
>> D. Wythe
> 
> This doesn't build with !CONFIG_SMC.
> 
> Maybe you should create an individual dir. (like what sched_ext does)

It's true, I do intend to create an individual dir, and send the patches for
BPF and SMC separately. Thanks for your advises.

Best wishes,
D. Wythe
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c b/tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c
new file mode 100644
index 00000000..2299853
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/test_bpf_smc.c
@@ -0,0 +1,21 @@ 
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+
+#include "bpf_smc.skel.h"
+
+static void load(void)
+{
+	struct bpf_smc *skel;
+
+	skel = bpf_smc__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "bpf_smc__open_and_load"))
+		return;
+
+	bpf_smc__destroy(skel);
+}
+
+void test_bpf_smc(void)
+{
+	if (test__start_subtest("load"))
+		load();
+}
diff --git a/tools/testing/selftests/bpf/progs/bpf_smc.c b/tools/testing/selftests/bpf/progs/bpf_smc.c
new file mode 100644
index 00000000..ebff477
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/bpf_smc.c
@@ -0,0 +1,44 @@ 
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+struct smc_bpf_ops_ctx {
+	struct {
+		struct tcp_sock *tp;
+	} set_option;
+	struct {
+		const struct tcp_sock *tp;
+		struct inet_request_sock *ireq;
+		int smc_ok;
+	} set_option_cond;
+};
+
+struct smc_bpf_ops {
+	void (*set_option)(struct smc_bpf_ops_ctx *ctx);
+	void (*set_option_cond)(struct smc_bpf_ops_ctx *ctx);
+};
+
+SEC("struct_ops/bpf_smc_set_tcp_option_cond")
+void BPF_PROG(bpf_smc_set_tcp_option_cond, struct smc_bpf_ops_ctx *arg)
+{
+	arg->set_option_cond.smc_ok = 1;
+}
+
+SEC("struct_ops/bpf_smc_set_tcp_option")
+void BPF_PROG(bpf_smc_set_tcp_option, struct smc_bpf_ops_ctx *arg)
+{
+	struct tcp_sock *tp = arg->set_option.tp;
+
+	tp->syn_smc = 1;
+}
+
+SEC(".struct_ops.link")
+struct smc_bpf_ops sample_smc_bpf_ops = {
+	.set_option         = (void *) bpf_smc_set_tcp_option,
+	.set_option_cond    = (void *) bpf_smc_set_tcp_option_cond,
+};