include/kunit/test.h
Source file repositories/reference/linux-study-clean/include/kunit/test.h
File Facts
- System
- Linux kernel
- Corpus path
include/kunit/test.h- Extension
.h- Size
- 69781 bytes
- Lines
- 1898
- Domain
- Repository Root And Misc
- Bucket
- include
- Inferred role
- Repository Root And Misc: implementation source
- Status
- source implementation candidate
Why This File Exists
Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.
- Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.
- 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/assert.hkunit/try-catch.hlinux/args.hlinux/compiler.hlinux/container_of.hlinux/err.hlinux/init.hlinux/jump_label.hlinux/kconfig.hlinux/kref.hlinux/list.hlinux/module.hlinux/slab.hlinux/spinlock.hlinux/string.hlinux/types.hasm/rwonce.hasm/sections.hkunit/resource.h
Detected Declarations
struct kunitstruct string_streamstruct kunit_attributesstruct kunit_casestruct kunit_suitestruct kunit_suite_setstruct kunit_paramsstruct kunitstruct kunit_suppressed_warningenum kunit_statusenum kunit_speedfunction kunit_set_failurefunction kunit_run_all_testsfunction kunit_kmallocfunction kunit_kzallocfunction kunit_kcallocfunction kunit_kstrdupfunction KUNIT_FAILfunction KUNIT_EXPECT_SUPPRESSED_WARNING_COUNT
Annotated Snippet
struct kunit_attributes {
enum kunit_speed speed;
};
/**
* struct kunit_case - represents an individual test case.
*
* @run_case: the function representing the actual test case.
* @name: the name of the test case.
* @generate_params: the generator function for parameterized tests.
* @attr: the attributes associated with the test
* @param_init: The init function to run before a parameterized test.
* @param_exit: The exit function to run after a parameterized test.
*
* A test case is a function with the signature,
* ``void (*)(struct kunit *)``
* that makes expectations and assertions (see KUNIT_EXPECT_TRUE() and
* KUNIT_ASSERT_TRUE()) about code under test. Each test case is associated
* with a &struct kunit_suite and will be run after the suite's init
* function and followed by the suite's exit function.
*
* A test case should be static and should only be created with the
* KUNIT_CASE() macro; additionally, every array of test cases should be
* terminated with an empty test case.
*
* Example:
*
* .. code-block:: c
*
* void add_test_basic(struct kunit *test)
* {
* KUNIT_EXPECT_EQ(test, 1, add(1, 0));
* KUNIT_EXPECT_EQ(test, 2, add(1, 1));
* KUNIT_EXPECT_EQ(test, 0, add(-1, 1));
* KUNIT_EXPECT_EQ(test, INT_MAX, add(0, INT_MAX));
* KUNIT_EXPECT_EQ(test, -1, add(INT_MAX, INT_MIN));
* }
*
* static struct kunit_case example_test_cases[] = {
* KUNIT_CASE(add_test_basic),
* {}
* };
*
*/
struct kunit_case {
void (*run_case)(struct kunit *test);
const char *name;
const void* (*generate_params)(struct kunit *test,
const void *prev, char *desc);
struct kunit_attributes attr;
int (*param_init)(struct kunit *test);
void (*param_exit)(struct kunit *test);
/* private: internal use only. */
enum kunit_status status;
char *module_name;
struct string_stream *log;
};
static inline char *kunit_status_to_ok_not_ok(enum kunit_status status)
{
switch (status) {
case KUNIT_SKIPPED:
case KUNIT_SUCCESS:
return "ok";
case KUNIT_FAILURE:
return "not ok";
}
return "invalid";
}
/**
* KUNIT_CASE - A helper for creating a &struct kunit_case
*
* @test_name: a reference to a test case function.
*
* Takes a symbol for a function representing a test case and creates a
* &struct kunit_case object from it. See the documentation for
* &struct kunit_case for an example on how to use it.
*/
#define KUNIT_CASE(test_name) \
{ .run_case = test_name, .name = #test_name, \
.module_name = KBUILD_MODNAME}
/**
* KUNIT_CASE_ATTR - A helper for creating a &struct kunit_case
* with attributes
*
* @test_name: a reference to a test case function.
* @attributes: a reference to a struct kunit_attributes object containing
Annotation
- Immediate include surface: `kunit/assert.h`, `kunit/try-catch.h`, `linux/args.h`, `linux/compiler.h`, `linux/container_of.h`, `linux/err.h`, `linux/init.h`, `linux/jump_label.h`.
- Detected declarations: `struct kunit`, `struct string_stream`, `struct kunit_attributes`, `struct kunit_case`, `struct kunit_suite`, `struct kunit_suite_set`, `struct kunit_params`, `struct kunit`, `struct kunit_suppressed_warning`, `enum kunit_status`.
- Atlas domain: Repository Root And Misc / include.
- 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.