[PATCH] lib: skip percpu_counter_tree boundary kunit tests on single-CPU
From: David Carlier
Date: Tue Mar 17 2026 - 11:40:27 EST
On single-CPU topologies, accuracy_multiplier is zero, making both
approx_accuracy_range.under and .over zero. The boundary tests in
hpcc_test_compare_value_boundaries and hpcc_test_compare_counter_boundaries
then degenerate to comparing 0 vs 0, which correctly returns 0 (equal)
but the tests expect nonzero results.
Skip these boundary tests with kunit_skip() when accuracy is zero,
since approximation boundaries are meaningless without multi-CPU carry
propagation. Use percpu_counter_tree_items_size() as the topology check
before any allocations to avoid leaking memory on skip.
Fixes: ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")
Signed-off-by: David Carlier <devnexen@xxxxxxxxx>
---
lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/lib/tests/percpu_counter_tree_kunit.c b/lib/tests/percpu_counter_tree_kunit.c
index 4d058bc78f7d..b773d20867d4 100644
--- a/lib/tests/percpu_counter_tree_kunit.c
+++ b/lib/tests/percpu_counter_tree_kunit.c
@@ -93,6 +93,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
unsigned long under = 0, over = 0;
int ret;
+ if (!percpu_counter_tree_items_size())
+ kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
counter_items = kzalloc(percpu_counter_tree_items_size(), GFP_KERNEL);
KUNIT_ASSERT_PTR_NE(test, counter_items, NULL);
ret = percpu_counter_tree_init(&pct, counter_items, 32, GFP_KERNEL);
@@ -197,6 +200,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
unsigned long combined;
int ret;
+ if (!percpu_counter_tree_items_size())
+ kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
counter_items = kzalloc(percpu_counter_tree_items_size() * 2,
GFP_KERNEL);
KUNIT_ASSERT_PTR_NE(test, counter_items, NULL);
--
2.53.0