xref: /OK3568_Linux_fs/kernel/tools/testing/selftests/timers/skew_consistency.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* ADJ_FREQ Skew consistency test
2*4882a593Smuzhiyun  *		by: john stultz (johnstul@us.ibm.com)
3*4882a593Smuzhiyun  *		(C) Copyright IBM 2012
4*4882a593Smuzhiyun  *		Licensed under the GPLv2
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  *  NOTE: This is a meta-test which cranks the ADJ_FREQ knob back
7*4882a593Smuzhiyun  *  and forth and watches for consistency problems. Thus this test requires
8*4882a593Smuzhiyun  *  that the inconsistency-check tests be present in the same directory it
9*4882a593Smuzhiyun  *  is run from.
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  *  To build:
12*4882a593Smuzhiyun  *	$ gcc skew_consistency.c -o skew_consistency -lrt
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  *   This program is free software: you can redistribute it and/or modify
15*4882a593Smuzhiyun  *   it under the terms of the GNU General Public License as published by
16*4882a593Smuzhiyun  *   the Free Software Foundation, either version 2 of the License, or
17*4882a593Smuzhiyun  *   (at your option) any later version.
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  *   This program is distributed in the hope that it will be useful,
20*4882a593Smuzhiyun  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
21*4882a593Smuzhiyun  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22*4882a593Smuzhiyun  *   GNU General Public License for more details.
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #include <stdio.h>
27*4882a593Smuzhiyun #include <stdlib.h>
28*4882a593Smuzhiyun #include <unistd.h>
29*4882a593Smuzhiyun #include <sys/time.h>
30*4882a593Smuzhiyun #include <sys/timex.h>
31*4882a593Smuzhiyun #include <time.h>
32*4882a593Smuzhiyun #include <sys/types.h>
33*4882a593Smuzhiyun #include <sys/stat.h>
34*4882a593Smuzhiyun #include <fcntl.h>
35*4882a593Smuzhiyun #include <string.h>
36*4882a593Smuzhiyun #include <sys/wait.h>
37*4882a593Smuzhiyun #include "../kselftest.h"
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #define NSEC_PER_SEC 1000000000LL
40*4882a593Smuzhiyun 
main(int argv,char ** argc)41*4882a593Smuzhiyun int main(int argv, char **argc)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun 	struct timex tx;
44*4882a593Smuzhiyun 	int ret, ppm;
45*4882a593Smuzhiyun 	pid_t pid;
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	printf("Running Asynchronous Frequency Changing Tests...\n");
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	pid = fork();
51*4882a593Smuzhiyun 	if (!pid)
52*4882a593Smuzhiyun 		return system("./inconsistency-check -c 1 -t 600");
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun 	ppm = 500;
55*4882a593Smuzhiyun 	ret = 0;
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun 	while (pid != waitpid(pid, &ret, WNOHANG)) {
58*4882a593Smuzhiyun 		ppm = -ppm;
59*4882a593Smuzhiyun 		tx.modes = ADJ_FREQUENCY;
60*4882a593Smuzhiyun 		tx.freq = ppm << 16;
61*4882a593Smuzhiyun 		adjtimex(&tx);
62*4882a593Smuzhiyun 		usleep(500000);
63*4882a593Smuzhiyun 	}
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun 	/* Set things back */
66*4882a593Smuzhiyun 	tx.modes = ADJ_FREQUENCY;
67*4882a593Smuzhiyun 	tx.offset = 0;
68*4882a593Smuzhiyun 	adjtimex(&tx);
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	if (ret) {
72*4882a593Smuzhiyun 		printf("[FAILED]\n");
73*4882a593Smuzhiyun 		return ksft_exit_fail();
74*4882a593Smuzhiyun 	}
75*4882a593Smuzhiyun 	printf("[OK]\n");
76*4882a593Smuzhiyun 	return ksft_exit_pass();
77*4882a593Smuzhiyun }
78