Skip to contentSkip to conversation

lib/math: Add int_pow test suite

PATCH In review Luis Felipe Hernandez 3 participants 3 messages Sep 10, 2024 – Sep 12, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 lib/math: Add int_pow test suite

Adds test suite for integer based power function.

---
Changes in v5:
- Fix kernel test bot warning
- Rebase with latest
Changes in v4:
- Address checkpatch warning and make kconfig description longer
- Use GPL-2.0-only for consistency
- Spelling fix fith -> fifth
Changes in v3:
- Fix compiler warning: explicitly define constant as unsigned int
- Add changes in patch revisions
Changes in v2:
- Address review feedback
- Add kconfig entry
- Use correct dir and file convention for KUnit
- Fix typo
- Remove unused static_stub header
- Refactor test suite to use paramerterized test cases
- Add close to max allowable value to in large_result test case
- Add test case with non-power of two exponent
- Fix module license

---
 lib/Kconfig.debug              | 16 +++++++++++
 lib/math/Makefile              |  1 +
 lib/math/tests/Makefile        |  3 ++
 lib/math/tests/int_pow_kunit.c | 52 ++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+)
 create mode 100644 lib/math/tests/Makefile
 create mode 100644 lib/math/tests/int_pow_kunit.c
lib/Kconfig.debug +16 -0
index a30c03a66172..c415f8ca43a7 100644
@@ -3051,3 +3051,19 @@ config RUST_KERNEL_DOCTESTS
 endmenu # "Rust"
 
 endmenu # Kernel hacking
+
+config INT_POW_TEST
+	tristate "Integer exponentiation (int_pow) test" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This option enables the KUnit test suite for the int_pow function,
+	  which performs integer exponentiation. The test suite is designed to
+	  verify that the implementation of int_pow correctly computes the power
+	  of a given base raised to a given exponent.
+
+	  Enabling this option will include tests that check various scenarios
+	  and edge cases to ensure the accuracy and reliability of the exponentiation
+	  function.
+	  
+	  If unsure, say N
lib/math/Makefile +1 -0
index 91fcdb0c9efe..3c1f92a7459d 100644
@@ -5,5 +5,6 @@ obj-$(CONFIG_CORDIC)		+= cordic.o
 obj-$(CONFIG_PRIME_NUMBERS)	+= prime_numbers.o
 obj-$(CONFIG_RATIONAL)		+= rational.o
 
+obj-$(CONFIG_INT_POW_TEST)  += tests/int_pow_kunit.o
 obj-$(CONFIG_TEST_DIV64)	+= test_div64.o
 obj-$(CONFIG_RATIONAL_KUNIT_TEST) += rational-test.o
lib/math/tests/Makefile new file +3 -0
new file mode 100644
index 000000000000..6a169123320a
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+obj-$(CONFIG_INT_POW_TEST) += int_pow_kunit.o
lib/math/tests/int_pow_kunit.c new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.46.0
Reviewed-by on v5 1/1
#1 lore raw
Quoted 18 lines · Luis Felipe Hernandez

Adds test suite for integer based power function.

---
Changes in v5:
- Fix kernel test bot warning
- Rebase with latest
Changes in v4:
- Address checkpatch warning and make kconfig description longer
- Use GPL-2.0-only for consistency
- Spelling fix fith -> fifth
Changes in v3:
- Fix compiler warning: explicitly define constant as unsigned int
- Add changes in patch revisions
Changes in v2:
- Address review feedback
- Add kconfig entry

Quoted 8 lines

- Use correct dir and file convention for KUnit
- Fix typo
- Remove unused static_stub header
- Refactor test suite to use paramerterized test cases
- Add close to max allowable value to in large_result test case
- Add test case with non-power of two exponent
- Fix module license
---

Looks good to me, thanks!

Cheers,
-- David

maintainer
#2 lore raw
Quoted 4 lines · David Gow
Quoted 2 lines · Luis Felipe Hernandez

Adds test suite for integer based power function.

It would be nice to see more details on what this test does> What's the output look like?

I fixed it up with the details from the Kconfig. Please do make sure to add test details in the commit long in the future.

There was a trailing whitespace I had to fix. Run checkpatch to verify that there are no issues with the patch in future.

Quoted 25 lines
Quoted 16 lines

---
Changes in v5:
- Fix kernel test bot warning
- Rebase with latest
Changes in v4:
- Address checkpatch warning and make kconfig description longer
- Use GPL-2.0-only for consistency
- Spelling fix fith -> fifth
Changes in v3:
- Fix compiler warning: explicitly define constant as unsigned int
- Add changes in patch revisions
Changes in v2:
- Address review feedback
- Add kconfig entry

Quoted 8 lines

- Use correct dir and file convention for KUnit
- Fix typo
- Remove unused static_stub header
- Refactor test suite to use paramerterized test cases
- Add close to max allowable value to in large_result test case
- Add test case with non-power of two exponent
- Fix module license
---

Quoted 6 lines

Looks good to me, thanks!

Cheers,
-- David

thanks,
-- Shuah