tools/testing/selftests/timers/clocksource-switch.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/timers/clocksource-switch.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/timers/clocksource-switch.c
Extension
.c
Size
4145 bytes
Lines
192
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

switch (opt) {
		case 's':
			do_sanity_check = 0;
			break;
		case 't':
			runtime = atoi(optarg);
			break;
		default:
			printf("Usage: %s [-s] [-t <secs>]\n", argv[0]);
			printf("	-s: skip sanity checks\n");
			printf("	-t: Number of seconds to run\n");
			exit(-1);
		}
	}

	get_cur_clocksource(orig_clk, 512);

	count = get_clocksources(clocksource_list);

	if (change_clocksource(clocksource_list[0])) {
		printf("Error: You probably need to run this as root\n");
		return -1;
	}

	/* Check everything is sane before we start switching asynchronously */
	if (do_sanity_check) {
		for (i = 0; i < count; i++) {
			ksft_print_msg("Validating clocksource %s\n",
					clocksource_list[i]);
			if (change_clocksource(clocksource_list[i])) {
				status = -1;
				goto out;
			}
			if (run_tests(5)) {
				status = -1;
				goto out;
			}
		}
	}

	ksft_print_msg("Running Asynchronous Switching Tests...\n");
	pid = fork();
	if (!pid)
		return run_tests(runtime);

	while (pid != waitpid(pid, &status, WNOHANG))
		for (i = 0; i < count; i++)
			if (change_clocksource(clocksource_list[i])) {
				status = -1;
				goto out;
			}
out:
	change_clocksource(orig_clk);

	/* Print at the end to not mix output with child process */
	ksft_print_header();
	ksft_set_plan(1);
	ksft_test_result(!status, "clocksource-switch\n");
	ksft_exit(!status);
}

Annotation

Implementation Notes