linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tamir Duberstein <tamird@gmail.com>
To: David Gow <davidgow@google.com>,
	Shuah Khan <skhan@linuxfoundation.org>,
	 Luis Felipe Hernandez <luis.hernandez093@gmail.com>,
	 Andrew Morton <akpm@linux-foundation.org>,
	Shuah Khan <shuah@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	 Tamir Duberstein <tamird@gmail.com>
Subject: [PATCH v5 0/2] lib/prime_numbers: convert self-test to KUnit
Date: Sat, 08 Feb 2025 21:44:37 -0500	[thread overview]
Message-ID: <20250208-prime_numbers-kunit-convert-v5-0-b0cb82ae7c7d@gmail.com> (raw)

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 v5:
- Rebase against mm/mm-everything.
- Correctly EXPORT_SYMBOL(with_primes).
- Link to v4: https://lore.kernel.org/r/20250208-prime_numbers-kunit-convert-v4-0-76e36bca06a5@gmail.com

Apologies for the churn.

Changes in v4:
- Use `#if IS_ENABLED` to handle `CONFIG_PRIME_NUMBERS_KUNIT_TEST=m`.
  (Andrew Morton)
- Link to v3: https://lore.kernel.org/r/20250208-prime_numbers-kunit-convert-v3-0-8ffd5816d8dc@gmail.com

Changes in v3:
- Remove `selftest_max` again; snuck into v2.
- Restore `#include <linux/slab.h>`.
- Sending v3 early because kernel test robot is sad.
- Link to v2: https://lore.kernel.org/r/20250208-prime_numbers-kunit-convert-v2-0-863119447e04@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                            |  5 +-
 lib/math/prime_numbers.c                     | 87 +++++-----------------------
 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, 108 insertions(+), 80 deletions(-)
---
base-commit: feb950f421d199acfe2503302f49632abfcf8663
change-id: 20250207-prime_numbers-kunit-convert-71c9b3c1d1d4

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


             reply	other threads:[~2025-02-09  2:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-09  2:44 Tamir Duberstein [this message]
2025-02-09  2:44 ` [PATCH v5 1/2] lib/math: Hook up tests/Makefile Tamir Duberstein
2025-02-09  2:44 ` [PATCH v5 2/2] lib/prime_numbers: convert self-test to KUnit Tamir Duberstein
2025-02-11  2:37   ` Kees Cook
2025-02-11  2:47     ` Tamir Duberstein
2025-02-11  2:52       ` Tamir Duberstein
2025-02-11 11:51         ` Tamir Duberstein
2025-02-11 16:38           ` Kees Cook
2025-02-11 16:39             ` Tamir Duberstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250208-prime_numbers-kunit-convert-v5-0-b0cb82ae7c7d@gmail.com \
    --to=tamird@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=davidgow@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luis.hernandez093@gmail.com \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).