[PATCH sched_ext v2 2/2] selftests/sched_ext: check that a drained DSQ iterator stays NULL
From: Kang Chen
Date: Fri Nov 13 2026 - 01:20:33 EST
Extend the dequeue_iter selftest: after the DSQ iterator drains, call
bpf_iter_scx_dsq_next() once more and store the raw result. The
user-space test checks that at least one task was iterated and that the
extra next() returned NULL.
The test fails on a kernel without the drained cursor state: the cursor
was unlinked and the extra next() starts again from the DSQ head.
Signed-off-by: Kang Chen <k.chen@xxxxxxxxxxxxxxxx>
---
v2:
- New selftest in v2.
tools/testing/selftests/sched_ext/dequeue_iter.bpf.c | 7 ++++++-
tools/testing/selftests/sched_ext/dequeue_iter.c | 4 ++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/tools/testing/selftests/sched_ext/dequeue_iter.bpf.c b/tools/testing/selftests/sched_ext/dequeue_iter.bpf.c
index 76c2c71a90b6..38eb2df54a6b 100644
--- a/tools/testing/selftests/sched_ext/dequeue_iter.bpf.c
+++ b/tools/testing/selftests/sched_ext/dequeue_iter.bpf.c
@@ -18,6 +18,8 @@ UEI_DEFINE(uei);
#define TEST_DSQ_ID 1000
u64 dq_count;
+u64 iter_count;
+u64 next_after_drain = -1;
s32 BPF_STRUCT_OPS_SLEEPABLE(dequeue_iter_init)
{
@@ -47,7 +49,10 @@ void BPF_STRUCT_OPS(dequeue_iter_dequeue, struct task_struct *p, u64 deq_flags)
if (!bpf_iter_scx_dsq_new(&it, TEST_DSQ_ID, 0)) {
while ((t = bpf_iter_scx_dsq_next(&it)))
- ;
+ iter_count++;
+
+ /* NULL must stay final after the iterator is drained. */
+ next_after_drain = (__u64)bpf_iter_scx_dsq_next(&it);
}
bpf_iter_scx_dsq_destroy(&it);
diff --git a/tools/testing/selftests/sched_ext/dequeue_iter.c b/tools/testing/selftests/sched_ext/dequeue_iter.c
index f60711bf3b39..48e8c94b7bf1 100644
--- a/tools/testing/selftests/sched_ext/dequeue_iter.c
+++ b/tools/testing/selftests/sched_ext/dequeue_iter.c
@@ -59,6 +59,10 @@ static enum scx_test_status run(void *ctx)
return SCX_TEST_FAIL;
}
+ SCX_FAIL_IF(!skel->bss->iter_count,
+ "DSQ iterator drained no tasks");
+ SCX_EQ(skel->data->next_after_drain, 0);
+
return SCX_TEST_PASS;
}
--
2.34.1