Skip to contentSkip to conversation

lib/math: Add Kunit test suite for gcd()

PATCH In review Yu-Chun Lin 2 participants 2 messages Feb 3, 2025 – Feb 4, 2025 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/math: Add Kunit test suite for gcd()

Add a KUnit test suite for the gcd() function.
This test suite verifies the correctness of gcd() across various scenarios, including edge cases.

---
 lib/Kconfig.debug          | 13 +++++++++
 lib/math/Makefile          |  3 +-
 lib/math/tests/Makefile    |  1 +
 lib/math/tests/gcd_kunit.c | 56 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 1 deletion(-)
 create mode 100644 lib/math/tests/gcd_kunit.c
lib/Kconfig.debug +13 -0
index 775966cf6114..66b04683a3b6 100644
@@ -3211,6 +3211,19 @@ config INT_SQRT_KUNIT_TEST
 
 	  If unsure, say N
 
+config GCD_KUNIT_TEST
+	tristate "Greatest common divisor test" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This option enables the KUnit test suite for the gcd() function,
+	  which computes the greatest common divisor of two numbers.
+
+	  This test suite verifies the correctness of gcd() across various
+	  scenarios, including edge cases.
+
+	  If unsure, say N
+
 endif # RUNTIME_TESTING_MENU
 
 config ARCH_USE_MEMTEST
lib/math/Makefile +2 -1
index 853f023ae537..3484078177af 100644
@@ -9,4 +9,5 @@ obj-$(CONFIG_INT_POW_TEST)  += tests/int_pow_kunit.o
 obj-$(CONFIG_TEST_DIV64)	+= test_div64.o
 obj-$(CONFIG_TEST_MULDIV64)	+= test_mul_u64_u64_div_u64.o
 obj-$(CONFIG_RATIONAL_KUNIT_TEST) += rational-test.o
-obj-$(CONFIG_INT_SQRT_KUNIT_TEST) += tests/int_sqrt_kunit.o
\ No newline at end of file
+obj-$(CONFIG_INT_SQRT_KUNIT_TEST) += tests/int_sqrt_kunit.o
+obj-$(CONFIG_GCD_KUNIT_TEST) += tests/gcd_kunit.o
lib/math/tests/Makefile +1 -0
index e1a79f093b2d..6a04b4eb22b6 100644
@@ -2,3 +2,4 @@
 
 obj-$(CONFIG_INT_POW_TEST) += int_pow_kunit.o
 obj-$(CONFIG_INT_SQRT_KUNIT_TEST) += int_sqrt_kunit.o
+obj-$(CONFIG_GCD_KUNIT_TEST) += gcd_kunit.o
lib/math/tests/gcd_kunit.c new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.43.0