bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yucong Sun <fallentree@fb.com>
To: <bpf@vger.kernel.org>
Cc: <andrii@kernel.org>, <sunyucong@gmail.com>
Subject: [PATCH bpf-next v6 10/14] selftests/bpf: adding pid filtering for atomics test
Date: Wed, 6 Oct 2021 11:56:15 -0700	[thread overview]
Message-ID: <20211006185619.364369-11-fallentree@fb.com> (raw)
In-Reply-To: <20211006185619.364369-1-fallentree@fb.com>

From: Yucong Sun <sunyucong@gmail.com>

This make atomics test able to run in parallel with other tests.

Signed-off-by: Yucong Sun <sunyucong@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/atomics.c |  1 +
 tools/testing/selftests/bpf/progs/atomics.c      | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/tools/testing/selftests/bpf/prog_tests/atomics.c b/tools/testing/selftests/bpf/prog_tests/atomics.c
index ba0e1efe5a45..1486be5d3209 100644
--- a/tools/testing/selftests/bpf/prog_tests/atomics.c
+++ b/tools/testing/selftests/bpf/prog_tests/atomics.c
@@ -225,6 +225,7 @@ void test_atomics(void)
 		test__skip();
 		goto cleanup;
 	}
+	skel->bss->pid = getpid();
 
 	if (test__start_subtest("add"))
 		test_add(skel);
diff --git a/tools/testing/selftests/bpf/progs/atomics.c b/tools/testing/selftests/bpf/progs/atomics.c
index c245345e41ca..16e57313204a 100644
--- a/tools/testing/selftests/bpf/progs/atomics.c
+++ b/tools/testing/selftests/bpf/progs/atomics.c
@@ -10,6 +10,8 @@ bool skip_tests __attribute((__section__(".data"))) = false;
 bool skip_tests = true;
 #endif
 
+__u32 pid = 0;
+
 __u64 add64_value = 1;
 __u64 add64_result = 0;
 __u32 add32_value = 1;
@@ -21,6 +23,8 @@ __u64 add_noreturn_value = 1;
 SEC("fentry/bpf_fentry_test1")
 int BPF_PROG(add, int a)
 {
+	if (pid != (bpf_get_current_pid_tgid() >> 32))
+		return 0;
 #ifdef ENABLE_ATOMICS_TESTS
 	__u64 add_stack_value = 1;
 
@@ -45,6 +49,8 @@ __s64 sub_noreturn_value = 1;
 SEC("fentry/bpf_fentry_test1")
 int BPF_PROG(sub, int a)
 {
+	if (pid != (bpf_get_current_pid_tgid() >> 32))
+		return 0;
 #ifdef ENABLE_ATOMICS_TESTS
 	__u64 sub_stack_value = 1;
 
@@ -67,6 +73,8 @@ __u64 and_noreturn_value = (0x110ull << 32);
 SEC("fentry/bpf_fentry_test1")
 int BPF_PROG(and, int a)
 {
+	if (pid != (bpf_get_current_pid_tgid() >> 32))
+		return 0;
 #ifdef ENABLE_ATOMICS_TESTS
 
 	and64_result = __sync_fetch_and_and(&and64_value, 0x011ull << 32);
@@ -86,6 +94,8 @@ __u64 or_noreturn_value = (0x110ull << 32);
 SEC("fentry/bpf_fentry_test1")
 int BPF_PROG(or, int a)
 {
+	if (pid != (bpf_get_current_pid_tgid() >> 32))
+		return 0;
 #ifdef ENABLE_ATOMICS_TESTS
 	or64_result = __sync_fetch_and_or(&or64_value, 0x011ull << 32);
 	or32_result = __sync_fetch_and_or(&or32_value, 0x011);
@@ -104,6 +114,8 @@ __u64 xor_noreturn_value = (0x110ull << 32);
 SEC("fentry/bpf_fentry_test1")
 int BPF_PROG(xor, int a)
 {
+	if (pid != (bpf_get_current_pid_tgid() >> 32))
+		return 0;
 #ifdef ENABLE_ATOMICS_TESTS
 	xor64_result = __sync_fetch_and_xor(&xor64_value, 0x011ull << 32);
 	xor32_result = __sync_fetch_and_xor(&xor32_value, 0x011);
@@ -123,6 +135,8 @@ __u32 cmpxchg32_result_succeed = 0;
 SEC("fentry/bpf_fentry_test1")
 int BPF_PROG(cmpxchg, int a)
 {
+	if (pid != (bpf_get_current_pid_tgid() >> 32))
+		return 0;
 #ifdef ENABLE_ATOMICS_TESTS
 	cmpxchg64_result_fail = __sync_val_compare_and_swap(&cmpxchg64_value, 0, 3);
 	cmpxchg64_result_succeed = __sync_val_compare_and_swap(&cmpxchg64_value, 1, 2);
@@ -142,6 +156,8 @@ __u32 xchg32_result = 0;
 SEC("fentry/bpf_fentry_test1")
 int BPF_PROG(xchg, int a)
 {
+	if (pid != (bpf_get_current_pid_tgid() >> 32))
+		return 0;
 #ifdef ENABLE_ATOMICS_TESTS
 	__u64 val64 = 2;
 	__u32 val32 = 2;
-- 
2.30.2


  parent reply	other threads:[~2021-10-06 18:56 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 18:56 [PATCH bpf-next v6 00/14] selftests/bpf: Add parallelism to test_progs Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 01/14] " Yucong Sun
2021-10-08 22:26   ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 02/14] selftests/bpf: Allow some tests to be executed in sequence Yucong Sun
2021-10-08 22:26   ` Andrii Nakryiko
2021-10-08 23:06     ` sunyucong
2021-10-09  3:17       ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 03/14] selftests/bpf: disable perf rate limiting when running tests Yucong Sun
2021-10-08 22:26   ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 04/14] selftests/bpf: add per worker cgroup suffix Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 05/14] selftests/bpf: adding read_perf_max_sample_freq() helper Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 22:49     ` sunyucong
2022-03-08 20:22       ` sunyucong
2021-10-06 18:56 ` [PATCH bpf-next v6 06/14] selftests/bpf: fix race condition in enable_stats Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 07/14] selftests/bpf: make cgroup_v1v2 use its own port Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 08/14] selftests/bpf: adding a namespace reset for tc_redirect Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 23:07     ` sunyucong
2021-10-06 18:56 ` [PATCH bpf-next v6 09/14] selftests/bpf: Make uprobe tests use different attach functions Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 22:46     ` sunyucong
2021-10-09  3:13       ` Andrii Nakryiko
2021-10-06 18:56 ` Yucong Sun [this message]
2021-10-06 18:56 ` [PATCH bpf-next v6 11/14] selftests/bpf: adding random delay for send_signal test Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-06 18:56 ` [PATCH bpf-next v6 12/14] selftests/bpf: Fix pid check in fexit_sleep test Yucong Sun
2021-10-06 18:56 ` [PATCH bpf-next v6 13/14] selftests/bpf: increase loop count for perf_branches Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 22:57     ` sunyucong
2021-10-06 18:56 ` [PATCH bpf-next v6 14/14] selfetest/bpf: make some tests serial Yucong Sun
2021-10-08 22:27   ` Andrii Nakryiko
2021-10-08 22:55     ` sunyucong
2021-10-09  3:14       ` Andrii Nakryiko
2021-10-08 22:26 ` [PATCH bpf-next v6 00/14] selftests/bpf: Add parallelism to test_progs Andrii Nakryiko
2021-10-08 22:42   ` Andrii Nakryiko
2021-10-08 23:37     ` Steven Rostedt
2021-10-09  3:20       ` Andrii Nakryiko
2021-10-09  3:28         ` Steven Rostedt

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=20211006185619.364369-11-fallentree@fb.com \
    --to=fallentree@fb.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=sunyucong@gmail.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).