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

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

 



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@xxxxxxxxxx>
---
 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 --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; }
+
+ATTACH_TEST(0)
+ATTACH_TEST(1)
+ATTACH_TEST(2)
+ATTACH_TEST(3)
+ATTACH_TEST(4)
+ATTACH_TEST(5)
+ATTACH_TEST(6)
+ATTACH_TEST(7)
+ATTACH_TEST(8)
+ATTACH_TEST(9)
+ATTACH_TEST(10)
+ATTACH_TEST(11)
+ATTACH_TEST(12)
+ATTACH_TEST(13)
+ATTACH_TEST(14)
+ATTACH_TEST(15)
+ATTACH_TEST(16)
+ATTACH_TEST(17)
+ATTACH_TEST(18)
+ATTACH_TEST(19)
+ATTACH_TEST(20)
+ATTACH_TEST(21)
+ATTACH_TEST(22)
+ATTACH_TEST(23)
+ATTACH_TEST(24)
+ATTACH_TEST(25)
+ATTACH_TEST(26)
+ATTACH_TEST(27)
+ATTACH_TEST(28)
+ATTACH_TEST(29)
+ATTACH_TEST(30)
+ATTACH_TEST(31)
+ATTACH_TEST(32)
+ATTACH_TEST(33)
+ATTACH_TEST(34)
+ATTACH_TEST(35)
+ATTACH_TEST(36)
+ATTACH_TEST(37)
+ATTACH_TEST(38)
+ATTACH_TEST(39)
+ATTACH_TEST(40)
+ATTACH_TEST(41)
+ATTACH_TEST(42)
+ATTACH_TEST(43)
+ATTACH_TEST(44)
+ATTACH_TEST(45)
+ATTACH_TEST(46)
+ATTACH_TEST(47)
+ATTACH_TEST(48)
+ATTACH_TEST(49)
+
 __diag_pop();
 
 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;
+
+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; }
+
+ATTACH_PROG(0)
+ATTACH_PROG(1)
+ATTACH_PROG(2)
+ATTACH_PROG(3)
+ATTACH_PROG(4)
+ATTACH_PROG(5)
+ATTACH_PROG(6)
+ATTACH_PROG(7)
+ATTACH_PROG(8)
+ATTACH_PROG(9)
+ATTACH_PROG(10)
+ATTACH_PROG(11)
+ATTACH_PROG(12)
+ATTACH_PROG(13)
+ATTACH_PROG(14)
+ATTACH_PROG(15)
+ATTACH_PROG(16)
+ATTACH_PROG(17)
+ATTACH_PROG(18)
+ATTACH_PROG(19)
+ATTACH_PROG(20)
+ATTACH_PROG(21)
+ATTACH_PROG(22)
+ATTACH_PROG(23)
+ATTACH_PROG(24)
+ATTACH_PROG(25)
+ATTACH_PROG(26)
+ATTACH_PROG(27)
+ATTACH_PROG(28)
+ATTACH_PROG(29)
+ATTACH_PROG(30)
+ATTACH_PROG(31)
+ATTACH_PROG(32)
+ATTACH_PROG(33)
+ATTACH_PROG(34)
+ATTACH_PROG(35)
+ATTACH_PROG(36)
+ATTACH_PROG(37)
+ATTACH_PROG(38)
+ATTACH_PROG(39)
+ATTACH_PROG(40)
+ATTACH_PROG(41)
+ATTACH_PROG(42)
+ATTACH_PROG(43)
+ATTACH_PROG(44)
+ATTACH_PROG(45)
+ATTACH_PROG(46)
+ATTACH_PROG(47)
+ATTACH_PROG(48)
+ATTACH_PROG(49)
-- 
2.26.2




[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