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.

Dependency Surface

Detected Declarations

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

Implementation Notes