1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <sys/time.h>
29#include <sys/timex.h>
30#include <time.h>
31#ifdef KTEST
32#include "../kselftest.h"
33#else
34static inline int ksft_exit_pass(void)
35{
36 exit(0);
37}
38static inline int ksft_exit_fail(void)
39{
40 exit(1);
41}
42#endif
43
44#define NSEC_PER_SEC 1000000000LL
45
46
47int change_skew_test(int ppm)
48{
49 struct timex tx;
50 int ret;
51
52 tx.modes = ADJ_FREQUENCY;
53 tx.freq = ppm << 16;
54
55 ret = adjtimex(&tx);
56 if (ret < 0) {
57 printf("Error adjusting freq\n");
58 return ret;
59 }
60
61 ret = system("./raw_skew");
62 ret |= system("./inconsistency-check");
63 ret |= system("./nanosleep");
64
65 return ret;
66}
67
68
69int main(int argv, char **argc)
70{
71 struct timex tx;
72 int i, ret;
73
74 int ppm[5] = {0, 250, 500, -250, -500};
75
76
77 ret = system("killall -9 ntpd");
78
79
80 tx.modes = ADJ_OFFSET;
81 tx.offset = 0;
82 ret = adjtimex(&tx);
83
84 if (ret < 0) {
85 printf("Maybe you're not running as root?\n");
86 return -1;
87 }
88
89 for (i = 0; i < 5; i++) {
90 printf("Using %i ppm adjustment\n", ppm[i]);
91 ret = change_skew_test(ppm[i]);
92 if (ret)
93 break;
94 }
95
96
97 tx.modes = ADJ_FREQUENCY;
98 tx.offset = 0;
99 adjtimex(&tx);
100
101 if (ret) {
102 printf("[FAIL]");
103 return ksft_exit_fail();
104 }
105 printf("[OK]");
106 return ksft_exit_pass();
107}
108