Skip to contentSkip to conversation

lib: skip percpu_counter_tree boundary kunit tests on single-CPU

PATCH In review David Carlier 4 participants 6 messages Mar 17

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: skip percpu_counter_tree boundary kunit tests on single-CPU

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.

Fixes ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")
---
 lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/tests/percpu_counter_tree_kunit.c +6 -0
index 4d058bc78f7d..609992bfaa21 100644
@@ -101,6 +101,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
 	percpu_counter_tree_set(&pct, 0);
 	percpu_counter_tree_approximate_accuracy_range(&pct, &under, &over);
 
+	if (!under && !over)
+		kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
 	/*
 	 * With approx_sum = precise_sum = 0, from the accuracy invariant:
 	 *   approx_sum - over <= precise_sum <= approx_sum + under
@@ -214,6 +217,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
 	 */
 	combined = under + over;
 
+	if (!combined)
+		kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
 	/* --- percpu_counter_tree_approximate_compare --- */
 
 	/* At boundary: indeterminate */
Signature · 1 line
2.53.0
#1 lore raw
Quoted 9 lines · David Carlier

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.

AFAIU kunit_skip is implemented with kunit_try_catch_throw, which aborts the specific test function. The placement of those kunit_skip appears to leak memory allocated with kzalloc(). Am I missing something ?

Thanks,

Mathieu

Quoted 31 lines
Fixes ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")
---
  lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
  1 file changed, 6 insertions(+)
lib/tests/percpu_counter_tree_kunit.c +6 -0
index 4d058bc78f7d..609992bfaa21 100644
@@ -101,6 +101,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
  	percpu_counter_tree_set(&pct, 0);
  	percpu_counter_tree_approximate_accuracy_range(&pct, &under, &over);
 
+	if (!under && !over)
+		kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
  	/*
  	 * With approx_sum = precise_sum = 0, from the accuracy invariant:
  	 *   approx_sum - over <= precise_sum <= approx_sum + under
@@ -214,6 +217,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
  	 */
  	combined = under + over;
 
+	if (!combined)
+		kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
  	/* --- percpu_counter_tree_approximate_compare --- */
 
  	/* At boundary: indeterminate */
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
#2 lore raw

PATCH 1/1 lib: skip percpu_counter_tree boundary kunit tests on single-CPU

In reply to David Carlier

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")
---
 lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/tests/percpu_counter_tree_kunit.c +6 -0
index 4d058bc78f7d..b773d20867d4 100644
@@ -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);
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#3 lore raw
Quoted 6 lines · David Carlier

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.

Quoted 7 lines

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")

Thanks!

Quoted 28 lines
---
  lib/tests/percpu_counter_tree_kunit.c | 6 ++++++
  1 file changed, 6 insertions(+)
lib/tests/percpu_counter_tree_kunit.c +6 -0
index 4d058bc78f7d..b773d20867d4 100644
@@ -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);
Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
Reviewed-by on v1 1/1
#4 lore raw
In reply to David Carlier
Quoted 10 lines · David Carlier

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.

Thanks!

Reviewed-by on v1 1/1
#5 lore raw
In reply to David Carlier
Quoted 31 lines · David Carlier

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.

Fixes ebc1ff504f55 ("lib: add kunit boundary tests for percpu_counter_tree comparisons")

---
lib/tests/percpu_counter_tree_kunit.c | 6 ++++++

1 file changed, 6 insertions(+)
lib/tests/percpu_counter_tree_kunit.c +3 -0
index 4d058bc78f7d..609992bfaa21 100644
@@ -101,6 +101,9 @@ static void hpcc_test_compare_value_boundaries(struct kunit *test)
 	percpu_counter_tree_set(&pct, 0);
 	percpu_counter_tree_approximate_accuracy_range(&pct, &under, &over);
 
+	if (!under && !over)
+		kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
 	/*
 	 * With approx_sum = precise_sum = 0, from the accuracy invariant:
 	 *   approx_sum - over <= precise_sum <= approx_sum + under

lib/tests/percpu_counter_tree_kunit.c static void hpcc_test_compare_counter_boundaries(struct kunit *test) · line 225

Quoted 9 lines
lib/tests/percpu_counter_tree_kunit.c +3 -0
@@ -214,6 +217,9 @@ static void hpcc_test_compare_counter_boundaries(struct kunit *test)
 	 */
 	combined = under + over;
 
+	if (!combined)
+		kunit_skip(test, "no approximation accuracy on single-CPU topology");
+
 	/* --- percpu_counter_tree_approximate_compare --- */
 
 	/* At boundary: indeterminate */

Keep it up!
Have a great day!

V/R

Josh Law