public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] lib/prime_numbers: convert self-test to KUnit
@ 2025-02-08 13:58 Tamir Duberstein
  2025-02-08 13:58 ` [PATCH v2 1/2] lib/math: Hook up tests/Makefile Tamir Duberstein
  2025-02-08 13:58 ` [PATCH v2 2/2] lib/prime_numbers: convert self-test to KUnit Tamir Duberstein
  0 siblings, 2 replies; 7+ messages in thread
From: Tamir Duberstein @ 2025-02-08 13:58 UTC (permalink / raw)
  To: David Gow, Shuah Khan, Luis Felipe Hernandez, Andrew Morton,
	Shuah Khan
  Cc: linux-kernel, linux-kselftest, Tamir Duberstein

This is a clear example of a unit test.

I tested this using:

$ tools/testing/kunit/kunit.py run --arch arm64 --make_options LLVM=1 math-prime_numbers

On success:
; [08:51:41] ============== math-prime_numbers (1 subtest) ==============
; [08:51:41] [PASSED] prime_numbers_test
; [08:51:41] =============== [PASSED] math-prime_numbers ================
; [08:51:41] ============================================================
; [08:51:41] Testing complete. Ran 1 tests: passed: 1

On failure:
; [08:50:19] ============== math-prime_numbers (1 subtest) ==============
; [08:50:19]     # prime_numbers_test: ASSERTION FAILED at lib/math/tests/prime_numbers_kunit.c:28
; [08:50:19]     Expected slow == fast, but
; [08:50:19]         slow == 0 (0x0)
; [08:50:19]         fast == 1 (0x1)
; [08:50:19] is-prime(2)
; [08:50:19] [FAILED] prime_numbers_test
; [08:50:19] # module: prime_numbers_kunit
; [08:50:19] # math-prime_numbers: primes.{last=61, .sz=64, .primes[]=...x28208a20a08a28ac} = 2-3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61
; [08:50:19] =============== [FAILED] math-prime_numbers ================
; [08:50:19] ============================================================
; [08:50:19] Testing complete. Ran 1 tests: failed: 1

Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
Changes in v2:
- Keep all the details hidden in prime_numbers.c; expose `with_primes`
  for debug logging in the test. (David Gow)
- Link to v1: https://lore.kernel.org/r/20250207-prime_numbers-kunit-convert-v1-0-6067f2b7c713@gmail.com

---
Tamir Duberstein (2):
      lib/math: Hook up tests/Makefile
      lib/prime_numbers: convert self-test to KUnit

 lib/Kconfig.debug                            | 14 +++++
 lib/math/Makefile                            |  4 +-
 lib/math/prime_numbers.c                     | 82 ++++------------------------
 lib/math/prime_numbers_private.h             | 17 ++++++
 lib/math/tests/Makefile                      |  1 +
 lib/math/tests/prime_numbers_kunit.c         | 59 ++++++++++++++++++++
 tools/testing/selftests/lib/config           |  1 -
 tools/testing/selftests/lib/prime_numbers.sh |  4 --
 8 files changed, 104 insertions(+), 78 deletions(-)
---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250207-prime_numbers-kunit-convert-71c9b3c1d1d4

Best regards,
-- 
Tamir Duberstein <tamird@gmail.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-02-08 22:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-08 13:58 [PATCH v2 0/2] lib/prime_numbers: convert self-test to KUnit Tamir Duberstein
2025-02-08 13:58 ` [PATCH v2 1/2] lib/math: Hook up tests/Makefile Tamir Duberstein
2025-02-08 13:58 ` [PATCH v2 2/2] lib/prime_numbers: convert self-test to KUnit Tamir Duberstein
2025-02-08 14:07   ` Tamir Duberstein
2025-02-08 21:36   ` kernel test robot
2025-02-08 22:29   ` kernel test robot
2025-02-08 22:50   ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox