lib/kunit/debugfs.c
Source file repositories/reference/linux-study-clean/lib/kunit/debugfs.c
File Facts
- System
- Linux kernel
- Corpus path
lib/kunit/debugfs.c- Extension
.c- Size
- 6020 bytes
- Lines
- 231
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/debugfs.hlinux/module.hkunit/test.hkunit/test-bug.hstring-stream.hdebugfs.h
Detected Declarations
function kunit_debugfs_cleanupfunction kunit_debugfs_initfunction debugfs_print_resultfunction debugfs_print_resultsfunction debugfs_releasefunction debugfs_results_openfunction debugfs_print_runfunction debugfs_run_openfunction debugfs_runfunction kunit_debugfs_create_suitefunction kunit_suite_for_each_test_casefunction kunit_debugfs_destroy_suite
Annotated Snippet
static const struct file_operations debugfs_results_fops = {
.open = debugfs_results_open,
.read = seq_read,
.llseek = seq_lseek,
.release = debugfs_release,
};
static const struct file_operations debugfs_run_fops = {
.open = debugfs_run_open,
.read = seq_read,
.write = debugfs_run,
.llseek = seq_lseek,
.release = debugfs_release,
};
void kunit_debugfs_create_suite(struct kunit_suite *suite)
{
struct kunit_case *test_case;
struct string_stream *stream;
/* If suite log already allocated, do not create new debugfs files. */
if (suite->log)
return;
/*
* Allocate logs before creating debugfs representation.
* The suite->log and test_case->log pointer are expected to be NULL
* if there isn't a log, so only set it if the log stream was created
* successfully.
*/
stream = alloc_string_stream(GFP_KERNEL);
if (IS_ERR(stream))
return;
string_stream_set_append_newlines(stream, true);
suite->log = stream;
kunit_suite_for_each_test_case(suite, test_case) {
stream = alloc_string_stream(GFP_KERNEL);
if (IS_ERR(stream))
goto err;
string_stream_set_append_newlines(stream, true);
test_case->log = stream;
}
suite->debugfs = debugfs_create_dir(suite->name, debugfs_rootdir);
debugfs_create_file(KUNIT_DEBUGFS_RESULTS, S_IFREG | 0444,
suite->debugfs,
suite, &debugfs_results_fops);
/* Do not create file to re-run test if test runs on init */
if (!suite->is_init) {
debugfs_create_file(KUNIT_DEBUGFS_RUN, S_IFREG | 0644,
suite->debugfs,
suite, &debugfs_run_fops);
}
return;
err:
string_stream_destroy(suite->log);
suite->log = NULL;
kunit_suite_for_each_test_case(suite, test_case) {
string_stream_destroy(test_case->log);
test_case->log = NULL;
}
}
void kunit_debugfs_destroy_suite(struct kunit_suite *suite)
{
struct kunit_case *test_case;
debugfs_remove_recursive(suite->debugfs);
string_stream_destroy(suite->log);
kunit_suite_for_each_test_case(suite, test_case)
string_stream_destroy(test_case->log);
}
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/module.h`, `kunit/test.h`, `kunit/test-bug.h`, `string-stream.h`, `debugfs.h`.
- Detected declarations: `function kunit_debugfs_cleanup`, `function kunit_debugfs_init`, `function debugfs_print_result`, `function debugfs_print_results`, `function debugfs_release`, `function debugfs_results_open`, `function debugfs_print_run`, `function debugfs_run_open`, `function debugfs_run`, `function kunit_debugfs_create_suite`.
- Atlas domain: Kernel Services / lib.
- Implementation status: pattern 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.