diff mbox series

[RFC,v8,12/20] selftests/bpf: Modify linked_list tests to work with macro-ified removes

Message ID 20240510192412.3297104-13-amery.hung@bytedance.com (mailing list archive)
State RFC
Delegated to: BPF
Headers show
Series bpf qdisc | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply, async

Commit Message

Amery Hung May 10, 2024, 7:24 p.m. UTC
Since a hidden arguement is added to bpf list remove kfuncs, and
bpf_list_pop_back/front are macrofied, we modify selftests so that it can
be compiled.

Signed-off-by: Amery Hung <amery.hung@bytedance.com>
---
 .../selftests/bpf/progs/linked_list_fail.c      | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/progs/linked_list_fail.c b/tools/testing/selftests/bpf/progs/linked_list_fail.c
index 5f8063ecc448..d260f80ea64d 100644
--- a/tools/testing/selftests/bpf/progs/linked_list_fail.c
+++ b/tools/testing/selftests/bpf/progs/linked_list_fail.c
@@ -49,8 +49,7 @@ 
 	int test##_missing_lock_##op(void *ctx)             \
 	{                                                   \
 		INIT;                                       \
-		void (*p)(void *) = (void *)&bpf_list_##op; \
-		p(hexpr);                                   \
+		bpf_list_##op(hexpr);                       \
 		return 0;                                   \
 	}
 
@@ -96,9 +95,8 @@  CHECK(inner_map, push_back, &iv->head, &f->node2);
 	int test##_incorrect_lock_##op(void *ctx)           \
 	{                                                   \
 		INIT;                                       \
-		void (*p)(void *) = (void *)&bpf_list_##op; \
 		bpf_spin_lock(lexpr);                       \
-		p(hexpr);                                   \
+		bpf_list_##op(hexpr);                       \
 		return 0;                                   \
 	}
 
@@ -576,7 +574,7 @@  int incorrect_head_off2(void *ctx)
 }
 
 static __always_inline
-int pop_ptr_off(void *(*op)(void *head))
+int pop_ptr_off(bool pop_front)
 {
 	struct {
 		struct bpf_list_head head __contains(foo, node2);
@@ -588,7 +586,10 @@  int pop_ptr_off(void *(*op)(void *head))
 	if (!p)
 		return 0;
 	bpf_spin_lock(&p->lock);
-	n = op(&p->head);
+	if (pop_front)
+		n = bpf_list_pop_front(&p->head);
+	else
+		n = bpf_list_pop_back(&p->head);
 	bpf_spin_unlock(&p->lock);
 
 	if (!n)
@@ -600,13 +601,13 @@  int pop_ptr_off(void *(*op)(void *head))
 SEC("?tc")
 int pop_front_off(void *ctx)
 {
-	return pop_ptr_off((void *)bpf_list_pop_front);
+	return pop_ptr_off(true);
 }
 
 SEC("?tc")
 int pop_back_off(void *ctx)
 {
-	return pop_ptr_off((void *)bpf_list_pop_back);
+	return pop_ptr_off(false);
 }
 
 SEC("?tc")