tools/testing/selftests/kselftest.h
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kselftest.h
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kselftest.h- Extension
.h- Size
- 12095 bytes
- Lines
- 491
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
errno.hstdlib.hunistd.hstdarg.hstdbool.hstring.hstdio.hsys/utsname.h
Detected Declarations
struct ksft_countfunction ksft_test_numfunction ksft_inc_pass_cntfunction ksft_inc_fail_cntfunction ksft_inc_xfail_cntfunction ksft_inc_xpass_cntfunction ksft_inc_xskip_cntfunction ksft_inc_error_cntfunction ksft_get_pass_cntfunction ksft_get_fail_cntfunction ksft_get_xfail_cntfunction ksft_get_xpass_cntfunction ksft_get_xskip_cntfunction ksft_get_error_cntfunction ksft_print_headerfunction ksft_set_planfunction ksft_print_cntsfunction __printffunction ksft_print_dbg_msgfunction ksft_perrorfunction __printffunction __printffunction __printffunction __printffunction __printffunction __printffunction __printffunction ksft_test_result_reportfunction ksft_exit_passfunction ksft_exit_failfunction ksft_finishedfunction ksft_exit_fail_perrorfunction ksft_exit_xfailfunction ksft_exit_xpassfunction __printffunction ksft_min_kernel_versionfunction ksft_reset_state
Annotated Snippet
struct ksft_count {
unsigned int ksft_pass;
unsigned int ksft_fail;
unsigned int ksft_xfail;
unsigned int ksft_xpass;
unsigned int ksft_xskip;
unsigned int ksft_error;
};
static struct ksft_count ksft_cnt;
static unsigned int ksft_plan;
static bool ksft_debug_enabled;
static inline unsigned int ksft_test_num(void)
{
return ksft_cnt.ksft_pass + ksft_cnt.ksft_fail +
ksft_cnt.ksft_xfail + ksft_cnt.ksft_xpass +
ksft_cnt.ksft_xskip + ksft_cnt.ksft_error;
}
static inline void ksft_inc_pass_cnt(void) { ksft_cnt.ksft_pass++; }
static inline void ksft_inc_fail_cnt(void) { ksft_cnt.ksft_fail++; }
static inline void ksft_inc_xfail_cnt(void) { ksft_cnt.ksft_xfail++; }
static inline void ksft_inc_xpass_cnt(void) { ksft_cnt.ksft_xpass++; }
static inline void ksft_inc_xskip_cnt(void) { ksft_cnt.ksft_xskip++; }
static inline void ksft_inc_error_cnt(void) { ksft_cnt.ksft_error++; }
static inline int ksft_get_pass_cnt(void) { return ksft_cnt.ksft_pass; }
static inline int ksft_get_fail_cnt(void) { return ksft_cnt.ksft_fail; }
static inline int ksft_get_xfail_cnt(void) { return ksft_cnt.ksft_xfail; }
static inline int ksft_get_xpass_cnt(void) { return ksft_cnt.ksft_xpass; }
static inline int ksft_get_xskip_cnt(void) { return ksft_cnt.ksft_xskip; }
static inline int ksft_get_error_cnt(void) { return ksft_cnt.ksft_error; }
static inline void ksft_print_header(void)
{
/*
* Force line buffering; If stdout is not connected to a terminal, it
* will otherwise default to fully buffered, which can cause output
* duplication if there is content in the buffer when fork()ing. If
* there is a crash, line buffering also means the most recent output
* line will be visible.
*/
setvbuf(stdout, NULL, _IOLBF, 0);
if (!(getenv("KSFT_TAP_LEVEL")))
printf("TAP version 13\n");
}
static inline void ksft_set_plan(unsigned int plan)
{
ksft_plan = plan;
printf("1..%u\n", ksft_plan);
}
static inline void ksft_print_cnts(void)
{
if (ksft_cnt.ksft_xskip > 0)
printf(
"# %u skipped test(s) detected. Consider enabling relevant config options to improve coverage.\n",
ksft_cnt.ksft_xskip
);
if (ksft_plan != ksft_test_num())
printf("# Planned tests != run tests (%u != %u)\n",
ksft_plan, ksft_test_num());
printf("# Totals: pass:%u fail:%u xfail:%u xpass:%u skip:%u error:%u\n",
ksft_cnt.ksft_pass, ksft_cnt.ksft_fail,
ksft_cnt.ksft_xfail, ksft_cnt.ksft_xpass,
ksft_cnt.ksft_xskip, ksft_cnt.ksft_error);
}
static inline __printf(1, 2) void ksft_print_msg(const char *msg, ...)
{
int saved_errno = errno;
va_list args;
va_start(args, msg);
printf("# ");
errno = saved_errno;
vprintf(msg, args);
va_end(args);
}
static inline void ksft_print_dbg_msg(const char *msg, ...)
{
va_list args;
if (!ksft_debug_enabled)
return;
Annotation
- Immediate include surface: `errno.h`, `stdlib.h`, `unistd.h`, `stdarg.h`, `stdbool.h`, `string.h`, `stdio.h`, `sys/utsname.h`.
- Detected declarations: `struct ksft_count`, `function ksft_test_num`, `function ksft_inc_pass_cnt`, `function ksft_inc_fail_cnt`, `function ksft_inc_xfail_cnt`, `function ksft_inc_xpass_cnt`, `function ksft_inc_xskip_cnt`, `function ksft_inc_error_cnt`, `function ksft_get_pass_cnt`, `function ksft_get_fail_cnt`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.