tools/testing/selftests/kselftest_harness.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kselftest_harness.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kselftest_harness.h- Extension
.h- Size
- 36224 bytes
- Lines
- 1333
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
asm/types.hctype.herrno.hlinux/unistd.hpoll.hstdbool.hstdint.hstdio.hstdlib.hstring.hsys/mman.hsys/types.hsys/wait.hunistd.hkselftest.h
Detected Declarations
struct __test_resultsstruct __test_metadatastruct __fixture_variant_metadatastruct __fixture_metadatastruct __test_xfailstruct __fixture_variant_metadatastruct __test_metadatafunction Copyrightfunction EXPECT_GTfunction FIXTUREfunction FIXTURE_SETUPfunction FIXTURE_TEARDOWNfunction TEST_Ffunction __kselftest_memset_safefunction TESTfunction TESTfunction TESTfunction test_namefunction FIXTURE_SETUPfunction __attribute__function FIXTURE_TEARDOWN_PARENTfunction __attribute__function FIXTURE_SETUPfunction FIXTURE_VARIANTfunction __attribute__function __register_fixturefunction __register_fixture_variantfunction __test_passedfunction __register_testfunction __register_xfailfunction __bailfunction __wait_for_testfunction test_harness_list_testsfunction test_harness_argv_checkfunction test_enabledfunction __run_testfunction test_harness_runfunction __attribute__
Annotated Snippet
struct __test_results {
char reason[1024]; /* Reason for test result */
};
struct __test_metadata;
struct __fixture_variant_metadata;
/* Contains all the information about a fixture. */
struct __fixture_metadata {
const char *name;
struct __test_metadata *tests;
struct __fixture_variant_metadata *variant;
struct __fixture_metadata *prev, *next;
} _fixture_global __attribute__((unused)) = {
.name = "global",
.prev = &_fixture_global,
};
struct __test_xfail {
struct __fixture_metadata *fixture;
struct __fixture_variant_metadata *variant;
struct __test_metadata *test;
struct __test_xfail *prev, *next;
};
/**
* XFAIL_ADD() - mark variant + test case combination as expected to fail
* @fixture_name: name of the fixture
* @variant_name: name of the variant
* @test_name: name of the test case
*
* Mark a combination of variant + test case for a given fixture as expected
* to fail. Tests marked this way will report XPASS / XFAIL return codes,
* instead of PASS / FAIL,and use respective counters.
*/
#define XFAIL_ADD(fixture_name, variant_name, test_name) \
static struct __test_xfail \
_##fixture_name##_##variant_name##_##test_name##_xfail = \
{ \
.fixture = &_##fixture_name##_fixture_object, \
.variant = &_##fixture_name##_##variant_name##_object, \
}; \
static void __attribute__((constructor(KSELFTEST_PRIO_XFAIL))) \
_register_##fixture_name##_##variant_name##_##test_name##_xfail(void) \
{ \
_##fixture_name##_##variant_name##_##test_name##_xfail.test = \
_##fixture_name##_##test_name##_object; \
__register_xfail(&_##fixture_name##_##variant_name##_##test_name##_xfail); \
}
static struct __fixture_metadata *__fixture_list = &_fixture_global;
static bool __constructor_order_forward;
static inline void __register_fixture(struct __fixture_metadata *f)
{
__LIST_APPEND(__fixture_list, f);
}
struct __fixture_variant_metadata {
const char *name;
const void *data;
struct __test_xfail *xfails;
struct __fixture_variant_metadata *prev, *next;
};
static inline void
__register_fixture_variant(struct __fixture_metadata *f,
struct __fixture_variant_metadata *variant)
{
__LIST_APPEND(f->variant, variant);
}
/* Contains all the information for test execution and status checking. */
struct __test_metadata {
const char *name;
void (*fn)(struct __test_metadata *,
struct __fixture_variant_metadata *);
pid_t pid; /* pid of test when being run */
struct __fixture_metadata *fixture;
void (*teardown_fn)(bool in_parent, struct __test_metadata *_metadata,
void *self, const void *variant);
int termsig;
int exit_code;
int trigger; /* extra handler after the evaluation */
int timeout; /* seconds to wait for test timeout */
bool aborted; /* stopped test due to failed ASSERT */
bool *no_teardown; /* fixture needs teardown */
void *self;
const void *variant;
struct __test_results *results;
Annotation
- Immediate include surface: `asm/types.h`, `ctype.h`, `errno.h`, `linux/unistd.h`, `poll.h`, `stdbool.h`, `stdint.h`, `stdio.h`.
- Detected declarations: `struct __test_results`, `struct __test_metadata`, `struct __fixture_variant_metadata`, `struct __fixture_metadata`, `struct __test_xfail`, `struct __fixture_variant_metadata`, `struct __test_metadata`, `function Copyright`, `function EXPECT_GT`, `function FIXTURE`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.