lib/math/tests/prime_numbers_kunit.c
Source file repositories/reference/linux-study-clean/lib/math/tests/prime_numbers_kunit.c
File Facts
- System
- Linux kernel
- Corpus path
lib/math/tests/prime_numbers_kunit.c- Extension
.c- Size
- 1357 bytes
- Lines
- 58
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/module.hlinux/prime_numbers.h../prime_numbers_private.h
Detected Declarations
function dump_primesfunction prime_numbers_testfunction kunit_suite_exit
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#include <kunit/test.h>
#include <linux/module.h>
#include <linux/prime_numbers.h>
#include "../prime_numbers_private.h"
static void dump_primes(void *ctx, const struct primes *p)
{
struct kunit_suite *suite = ctx;
kunit_info(suite, "primes.{last=%lu, .sz=%lu, .primes[]=...x%lx} = %*pbl",
p->last, p->sz, p->primes[BITS_TO_LONGS(p->sz) - 1], (int)p->sz, p->primes);
}
static void prime_numbers_test(struct kunit *test)
{
const unsigned long max = 65536;
unsigned long x, last, next;
for (last = 0, x = 2; x < max; x++) {
const bool slow = slow_is_prime_number(x);
const bool fast = is_prime_number(x);
KUNIT_ASSERT_EQ_MSG(test, slow, fast, "is-prime(%lu)", x);
if (!slow)
continue;
next = next_prime_number(last);
KUNIT_ASSERT_EQ_MSG(test, next, x, "next-prime(%lu)", last);
last = next;
}
}
static void kunit_suite_exit(struct kunit_suite *suite)
{
with_primes(suite, dump_primes);
}
static struct kunit_case prime_numbers_cases[] = {
KUNIT_CASE(prime_numbers_test),
{},
};
static struct kunit_suite prime_numbers_suite = {
.name = "math-prime_numbers",
.suite_exit = kunit_suite_exit,
.test_cases = prime_numbers_cases,
};
kunit_test_suite(prime_numbers_suite);
MODULE_AUTHOR("Intel Corporation");
MODULE_DESCRIPTION("Prime number library");
MODULE_LICENSE("GPL");
Annotation
- Immediate include surface: `kunit/test.h`, `linux/module.h`, `linux/prime_numbers.h`, `../prime_numbers_private.h`.
- Detected declarations: `function dump_primes`, `function prime_numbers_test`, `function kunit_suite_exit`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.