Skip to contentSkip to conversation

lib/math: add KUnit test suite for polynomial_calc()

PATCH Applied Adi Nata 2 participants 2 messages Jun 6 – Jun 28

Subsystems (2)
lore
Share & tools
lore

Adi Nata

author
#0 lore raw

PATCH 1/1 lib/math: add KUnit test suite for polynomial_calc()

Add a KUnit test suite for the polynomial_calc() function, which had no in-kernel test coverage. The tests verify correct evaluation of constant, linear, quadratic, and cubic polynomials, including negative coefficients, negative input data, zero-coefficient terms.

The Kconfig entry uses 'select POLYNOMIAL' rather than 'depends on POLYNOMIAL' because POLYNOMIAL is a promptless tristate that cannot be manually enabled on UML without an explicit selector.

---
 lib/Kconfig.debug                 |  17 ++
 lib/math/tests/Makefile           |   1 +
 lib/math/tests/polynomial_kunit.c | 270 ++++++++++++++++++++++++++++++
 3 files changed, 288 insertions(+)
 create mode 100644 lib/math/tests/polynomial_kunit.c
lib/Kconfig.debug +17 -0
index 8ff5adcfe1e0..5dc1b4579903 100644
@@ -3489,6 +3489,23 @@ config GCD_KUNIT_TEST
 
 	  If unsure, say N
 
+config POLYNOMIAL_KUNIT_TEST
+	tristate "Polynomial calculation (polynomial_calc) test" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	select POLYNOMIAL
+	default KUNIT_ALL_TESTS
+	help
+	  This option enables the KUnit test suite for the polynomial_calc()
+	  function, which evaluates integer polynomials using factor
+	  redistribution to avoid overflow.
+
+	  The test suite verifies correctness for constant, linear, and
+	  quadratic polynomials, negative coefficients, per-step dividers,
+	  divider_leftover, total_divider scaling, and a real sensor
+	  N-to-temperature conversion polynomial.
+
+	  If unsure, say N
+
 config PRIME_NUMBERS_KUNIT_TEST
 	tristate "Prime number generator test" if !KUNIT_ALL_TESTS
 	depends on KUNIT
lib/math/tests/Makefile +1 -0
index 13dc96e48408..85e1ad59f29d 100644
@@ -4,5 +4,6 @@ obj-$(CONFIG_GCD_KUNIT_TEST)		+= gcd_kunit.o
 obj-$(CONFIG_INT_LOG_KUNIT_TEST)	+= int_log_kunit.o
 obj-$(CONFIG_INT_POW_KUNIT_TEST)	+= int_pow_kunit.o
 obj-$(CONFIG_INT_SQRT_KUNIT_TEST)	+= int_sqrt_kunit.o
+obj-$(CONFIG_POLYNOMIAL_KUNIT_TEST)	+= polynomial_kunit.o
 obj-$(CONFIG_PRIME_NUMBERS_KUNIT_TEST)	+= prime_numbers_kunit.o
 obj-$(CONFIG_RATIONAL_KUNIT_TEST)	+= rational_kunit.o
lib/math/tests/polynomial_kunit.c new file +270 -0

270 lines not on this page · raw message

Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 8 lines · On Sat, 6 Jun 2026 11:03:09 +0800 Adi Nata…

Add a KUnit test suite for the polynomial_calc() function, which had no in-kernel test coverage. The tests verify correct evaluation of constant, linear, quadratic, and cubic polynomials, including negative coefficients, negative input data, zero-coefficient terms.

The Kconfig entry uses 'select POLYNOMIAL' rather than 'depends on POLYNOMIAL' because POLYNOMIAL is a promptless tristate that cannot be manually enabled on UML without an explicit selector.

Looks nice, thanks. Let's cc the polynomial authors. And the hwmon people - the only subsystem which uses polynomial_calc().

And the Kunit people.

AI review thinks the Kconfig text doesn't match the code:

	https://sashiko.dev/#/patchset/[email protected]

From: Adi Nata <[email protected]>
Subject: lib/math: add KUnit test suite for polynomial_calc()
Date: Sat, 6 Jun 2026 11:03:09 +0800

Add a KUnit test suite for the polynomial_calc() function, which had no in-kernel test coverage. The tests verify correct evaluation of constant, linear, quadratic, and cubic polynomials, including negative coefficients, negative input data, zero-coefficient terms.

The Kconfig entry uses 'select POLYNOMIAL' rather than 'depends on POLYNOMIAL' because POLYNOMIAL is a promptless tristate that cannot be manually enabled on UML without an explicit selector.

---

 lib/Kconfig.debug                 |   17 +
 lib/math/tests/Makefile           |    1 
 lib/math/tests/polynomial_kunit.c |  270 ++++++++++++++++++++++++++++
 3 files changed, 288 insertions(+)
lib/Kconfig.debug renamed from lib/Kconfig.debug~lib-math-add-kunit-test-suite-for-polynomial_calc +17 -0
@@ -3476,6 +3476,23 @@ config GCD_KUNIT_TEST
 
 	  If unsure, say N
 
+config POLYNOMIAL_KUNIT_TEST
+	tristate "Polynomial calculation (polynomial_calc) test" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	select POLYNOMIAL
+	default KUNIT_ALL_TESTS
+	help
+	  This option enables the KUnit test suite for the polynomial_calc()
+	  function, which evaluates integer polynomials using factor
+	  redistribution to avoid overflow.
+
+	  The test suite verifies correctness for constant, linear, and
+	  quadratic polynomials, negative coefficients, per-step dividers,
+	  divider_leftover, total_divider scaling, and a real sensor
+	  N-to-temperature conversion polynomial.
+
+	  If unsure, say N
+
 config PRIME_NUMBERS_KUNIT_TEST
 	tristate "Prime number generator test" if !KUNIT_ALL_TESTS
 	depends on KUNIT
lib/math/tests/Makefile renamed from lib/math/tests/Makefile~lib-math-add-kunit-test-suite-for-polynomial_calc +1 -0
@@ -4,5 +4,6 @@ obj-$(CONFIG_GCD_KUNIT_TEST)		+= gcd_kun
 obj-$(CONFIG_INT_LOG_KUNIT_TEST)	+= int_log_kunit.o
 obj-$(CONFIG_INT_POW_KUNIT_TEST)	+= int_pow_kunit.o
 obj-$(CONFIG_INT_SQRT_KUNIT_TEST)	+= int_sqrt_kunit.o
+obj-$(CONFIG_POLYNOMIAL_KUNIT_TEST)	+= polynomial_kunit.o
 obj-$(CONFIG_PRIME_NUMBERS_KUNIT_TEST)	+= prime_numbers_kunit.o
 obj-$(CONFIG_RATIONAL_KUNIT_TEST)	+= rational_kunit.o
lib/math/tests/polynomial_kunit.c new file +270 -0

270 lines not on this page · raw message

_