tools/testing/selftests/breakpoints/step_after_suspend_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/breakpoints/step_after_suspend_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/breakpoints/step_after_suspend_test.c- Extension
.c- Size
- 5239 bytes
- Lines
- 250
- 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.hfcntl.hsched.hsignal.hstdbool.hstdio.hstring.hunistd.hsys/ptrace.hsys/stat.hsys/timerfd.hsys/types.hsys/wait.hkselftest.h
Detected Declarations
function Copyrightfunction run_testfunction get_suspend_success_count_or_failfunction suspendfunction main
Annotated Snippet
if (errno == EIO) {
ksft_print_msg(
"ptrace(PTRACE_SINGLESTEP) not supported on this architecture: %s\n",
strerror(errno));
return KSFT_SKIP;
}
ksft_print_msg("ptrace(PTRACE_SINGLESTEP) failed: %s\n",
strerror(errno));
return KSFT_FAIL;
}
wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) {
ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
return KSFT_FAIL;
}
if (WIFEXITED(status)) {
ksft_print_msg("child did not single-step: %s\n",
strerror(errno));
return KSFT_FAIL;
}
if (!WIFSTOPPED(status)) {
ksft_print_msg("child did not stop: %s\n", strerror(errno));
return KSFT_FAIL;
}
if (WSTOPSIG(status) != SIGTRAP) {
ksft_print_msg("child did not stop with SIGTRAP: %s\n",
strerror(errno));
return KSFT_FAIL;
}
if (ptrace(PTRACE_CONT, pid, NULL, NULL) < 0) {
ksft_print_msg("ptrace(PTRACE_CONT) failed: %s\n",
strerror(errno));
return KSFT_FAIL;
}
wpid = waitpid(pid, &status, __WALL);
if (wpid != pid) {
ksft_print_msg("waitpid() failed: %s\n", strerror(errno));
return KSFT_FAIL;
}
if (!WIFEXITED(status)) {
ksft_print_msg("child did not exit after PTRACE_CONT: %s\n",
strerror(errno));
return KSFT_FAIL;
}
return KSFT_PASS;
}
/*
* Reads the suspend success count from sysfs.
* Returns the count on success or exits on failure.
*/
static int get_suspend_success_count_or_fail(void)
{
FILE *fp;
int val;
fp = fopen("/sys/power/suspend_stats/success", "r");
if (!fp)
ksft_exit_fail_msg(
"Failed to open suspend_stats/success: %s\n",
strerror(errno));
if (fscanf(fp, "%d", &val) != 1) {
fclose(fp);
ksft_exit_fail_msg(
"Failed to read suspend success count\n");
}
fclose(fp);
return val;
}
void suspend(void)
{
int timerfd;
int err;
int count_before;
int count_after;
struct itimerspec spec = {};
if (getuid() != 0)
ksft_exit_skip("Please run the test as root - Exiting.\n");
timerfd = timerfd_create(CLOCK_BOOTTIME_ALARM, 0);
if (timerfd < 0)
ksft_exit_fail_msg("timerfd_create() failed\n");
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `sched.h`, `signal.h`, `stdbool.h`, `stdio.h`, `string.h`, `unistd.h`.
- Detected declarations: `function Copyright`, `function run_test`, `function get_suspend_success_count_or_fail`, `function suspend`, `function main`.
- 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.