lib/kunit/test.c
Source file repositories/reference/linux-study-clean/lib/kunit/test.c
File Facts
- System
- Linux kernel
- Corpus path
lib/kunit/test.c- Extension
.c- Size
- 27842 bytes
- Lines
- 1084
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/resource.hkunit/test.hkunit/test-bug.hkunit/attributes.hlinux/kernel.hlinux/module.hlinux/moduleparam.hlinux/mutex.hlinux/panic.hlinux/sched/debug.hlinux/sched.hlinux/mm.hdebugfs.hdevice-impl.hhooks-impl.hstring-stream.htry-catch-impl.h
Detected Declarations
struct kunit_result_statsstruct kunit_try_catch_contextfunction __printffunction kunit_should_print_statsfunction kunit_print_test_statsfunction kunit_log_appendfunction kunit_suite_num_test_casesfunction kunit_print_suite_startfunction kunit_print_ok_not_okfunction kunit_suite_has_succeededfunction kunit_suite_for_each_test_casefunction kunit_print_suite_endfunction kunit_test_case_numfunction kunit_suite_for_each_test_casefunction kunit_print_string_streamfunction list_for_each_entryfunction kunit_failfunction __kunit_abortfunction __kunit_do_failed_assertionfunction kunit_init_paramsfunction kunit_init_testfunction kunit_run_case_check_speedfunction kunit_timeout_multfunction kunit_test_timeoutfunction kunit_run_case_internalfunction kunit_case_internal_cleanupfunction kunit_run_case_cleanupfunction kunit_try_run_casefunction kunit_try_run_case_cleanupfunction kunit_catch_run_case_cleanupfunction kunit_catch_run_casefunction kunit_run_case_catch_errorsfunction kunit_print_suite_statsfunction kunit_update_statsfunction kunit_accumulate_statsfunction kunit_init_parent_param_testfunction kunit_run_param_testfunction kunit_run_one_testfunction kunit_run_testsfunction kunit_init_suitefunction kunit_enabledfunction __kunit_test_suites_initfunction kunit_exit_suitefunction __kunit_test_suites_exitfunction kunit_module_initfunction kunit_module_exitfunction kunit_module_notifyfunction kunit_kfree
Annotated Snippet
struct kunit_result_stats {
unsigned long passed;
unsigned long skipped;
unsigned long failed;
unsigned long total;
};
static bool kunit_should_print_stats(struct kunit_result_stats *stats)
{
if (kunit_stats_enabled == 0)
return false;
if (kunit_stats_enabled == 2)
return true;
return (stats->total > 1);
}
static void kunit_print_test_stats(struct kunit *test,
struct kunit_result_stats *stats)
{
if (!kunit_should_print_stats(stats))
return;
kunit_log(KERN_INFO, test,
KUNIT_SUBTEST_INDENT
"# %s: pass:%lu fail:%lu skip:%lu total:%lu",
test->name,
stats->passed,
stats->failed,
stats->skipped,
stats->total);
}
/* Append formatted message to log. */
void kunit_log_append(struct string_stream *log, const char *fmt, ...)
{
va_list args;
if (!log)
return;
va_start(args, fmt);
string_stream_vadd(log, fmt, args);
va_end(args);
}
EXPORT_SYMBOL_GPL(kunit_log_append);
size_t kunit_suite_num_test_cases(struct kunit_suite *suite)
{
struct kunit_case *test_case;
size_t len = 0;
kunit_suite_for_each_test_case(suite, test_case)
len++;
return len;
}
EXPORT_SYMBOL_GPL(kunit_suite_num_test_cases);
/* Currently supported test levels */
enum {
KUNIT_LEVEL_SUITE = 0,
KUNIT_LEVEL_CASE,
KUNIT_LEVEL_CASE_PARAM,
};
static void kunit_print_suite_start(struct kunit_suite *suite)
{
/*
* We do not log the test suite header as doing so would
* mean debugfs display would consist of the test suite
* header prior to individual test results.
* Hence directly printk the suite status, and we will
* separately seq_printf() the suite header for the debugfs
* representation.
*/
pr_info(KUNIT_SUBTEST_INDENT "KTAP version 1\n");
pr_info(KUNIT_SUBTEST_INDENT "# Subtest: %s\n",
suite->name);
kunit_print_attr((void *)suite, false, KUNIT_LEVEL_CASE);
pr_info(KUNIT_SUBTEST_INDENT "1..%zd\n",
kunit_suite_num_test_cases(suite));
}
static void kunit_print_ok_not_ok(struct kunit *test,
unsigned int test_level,
enum kunit_status status,
size_t test_number,
const char *description,
Annotation
- Immediate include surface: `kunit/resource.h`, `kunit/test.h`, `kunit/test-bug.h`, `kunit/attributes.h`, `linux/kernel.h`, `linux/module.h`, `linux/moduleparam.h`, `linux/mutex.h`.
- Detected declarations: `struct kunit_result_stats`, `struct kunit_try_catch_context`, `function __printf`, `function kunit_should_print_stats`, `function kunit_print_test_stats`, `function kunit_log_append`, `function kunit_suite_num_test_cases`, `function kunit_print_suite_start`, `function kunit_print_ok_not_ok`, `function kunit_suite_has_succeeded`.
- Atlas domain: Kernel Services / lib.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.