tools/testing/selftests/timers/inconsistency-check.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/timers/inconsistency-check.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/timers/inconsistency-check.c
Extension
.c
Size
4710 bytes
Lines
187
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 (inconsistent >= 0) {
			unsigned long long delta;

			ksft_print_msg("\%s\n", start_str);
			for (i = 0; i < CALLS_PER_LOOP; i++) {
				if (i == inconsistent)
					ksft_print_msg("--------------------\n");
				ksft_print_msg("%lu:%lu\n", list[i].tv_sec,
							list[i].tv_nsec);
				if (i == inconsistent + 1)
					ksft_print_msg("--------------------\n");
			}
			delta = list[inconsistent].tv_sec * NSEC_PER_SEC;
			delta += list[inconsistent].tv_nsec;
			delta -= list[inconsistent+1].tv_sec * NSEC_PER_SEC;
			delta -= list[inconsistent+1].tv_nsec;
			ksft_print_msg("Delta: %llu ns\n", delta);
			fflush(0);
			/* timestamp inconsistency*/
			t = time(0);
			ksft_print_msg("%s\n", ctime(&t));
			return -1;
		}
		now = list[0].tv_sec;
	}
	return 0;
}


int main(int argc, char *argv[])
{
	int clockid, opt;
	int userclock = CLOCK_REALTIME;
	int maxclocks = CLOCK_TAI + 1;
	int runtime = 10;
	struct timespec ts;

	/* Process arguments */
	while ((opt = getopt(argc, argv, "t:c:")) != -1) {
		switch (opt) {
		case 't':
			runtime = atoi(optarg);
			break;
		case 'c':
			userclock = atoi(optarg);
			maxclocks = userclock + 1;
			break;
		default:
			printf("Usage: %s [-t <secs>] [-c <clockid>]\n", argv[0]);
			printf("	-t: Number of seconds to run\n");
			printf("	-c: clockid to use (default, all clockids)\n");
			exit(-1);
		}
	}

	setbuf(stdout, NULL);

	ksft_print_header();
	ksft_set_plan(maxclocks - userclock);

	for (clockid = userclock; clockid < maxclocks; clockid++) {

		if (clockid == CLOCK_HWSPECIFIC || clock_gettime(clockid, &ts)) {
			ksft_test_result_skip("%-31s\n", clockstring(clockid));
			continue;
		}

		if (consistency_test(clockid, runtime)) {
			ksft_test_result_fail("%-31s\n", clockstring(clockid));
			ksft_exit_fail();
		} else {
			ksft_test_result_pass("%-31s\n", clockstring(clockid));
		}
	}
	ksft_exit_pass();
}

Annotation

Implementation Notes