diff mbox series

[RFC,bpf-next,16/16] selftests/bpf: Add attach batch test (NOT TO BE MERGED)

Message ID 20201022082138.2322434-17-jolsa@kernel.org
State Not Applicable
Delegated to: BPF Maintainers
Headers show
Series bpf: Speed up trampoline attach | expand


Context Check Description
jkicinski/cover_letter success Link
jkicinski/fixes_present success Link
jkicinski/patch_count fail Series longer than 15 patches
jkicinski/tree_selection success Clearly marked for bpf-next
jkicinski/subject_prefix success Link
jkicinski/source_inline success Was 0 now: 0
jkicinski/verify_signedoff success Link
jkicinski/module_param success Was 0 now: 0
jkicinski/build_32bit fail Errors and warnings before: 10 this patch: 60
jkicinski/kdoc success Errors and warnings before: 0 this patch: 0
jkicinski/verify_fixes success Link
jkicinski/checkpatch fail ERROR: inline keyword should sit between storage class and type WARNING: Macros with flow control statements should be avoided WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
jkicinski/build_allmodconfig_warn fail Errors and warnings before: 10 this patch: 60
jkicinski/header_inline success Link
jkicinski/stable success Stable not CCed

Commit Message

Jiri Olsa Oct. 22, 2020, 8:21 a.m. UTC
Adding test that attaches to 50 known functions,
that are also added to kernel.

This test is meant only for fast check on attach times,
and can be probably in a different mergeable way, but
at the moment it fits the need.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
 net/bpf/test_run.c                            | 55 ++++++++++++++++
 .../selftests/bpf/prog_tests/attach_test.c    | 27 ++++++++
 .../testing/selftests/bpf/progs/attach_test.c | 62 +++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/attach_test.c
 create mode 100644 tools/testing/selftests/bpf/progs/attach_test.c
diff mbox series


diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index c1c30a9f76f3..8fc6d27fc07f 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -167,6 +167,61 @@  int noinline bpf_modify_return_test(int a, int *b)
 	*b += 1;
 	return a + *b;
+#define ATTACH_TEST(__n) \
+	int noinline __PASTE(bpf_attach_test, __n)(void) { return 0; }
 ALLOW_ERROR_INJECTION(bpf_modify_return_test, ERRNO);
diff --git a/tools/testing/selftests/bpf/prog_tests/attach_test.c b/tools/testing/selftests/bpf/prog_tests/attach_test.c
new file mode 100644
index 000000000000..c5c6534c49c9
--- /dev/null
+++ b/tools/testing/selftests/bpf/prog_tests/attach_test.c
@@ -0,0 +1,27 @@ 
+// SPDX-License-Identifier: GPL-2.0
+#include <test_progs.h>
+#include "attach_test.skel.h"
+void test_attach_test(void)
+	DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts);
+	struct attach_test *attach_skel = NULL;
+	__u32 duration = 0;
+	int err;
+	opts.trampoline_attach_batch = true;
+	attach_skel = attach_test__open_opts(&opts);
+	if (CHECK(!attach_skel, "attach_test__open_opts", "open skeleton failed\n"))
+		goto cleanup;
+	err = attach_test__load(attach_skel);
+	if (CHECK(err, "attach_skel_load", "attach skeleton failed\n"))
+		goto cleanup;
+	err = attach_test__attach(attach_skel);
+	if (CHECK(err, "attach", "attach failed: %d\n", err))
+		goto cleanup;
+	attach_test__destroy(attach_skel);
diff --git a/tools/testing/selftests/bpf/progs/attach_test.c b/tools/testing/selftests/bpf/progs/attach_test.c
new file mode 100644
index 000000000000..51b18f83c109
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/attach_test.c
@@ -0,0 +1,62 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (c) 2019 Facebook */
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+char _license[] SEC("license") = "GPL";
+#define ATTACH_PROG(__n)			\
+SEC("fentry/bpf_attach_test" #__n)		\
+int BPF_PROG(prog ## __n) { return 0; }