HID: hiddev: Fix slab-out-of-bounds write in hiddev_ioctl_usage()
[linux/fpc-iii.git] / tools / testing / selftests / timers / change_skew.c
blobcb1968977c04db7ecb7b58da665c17e44df76b0d
1 /* ADJ_FREQ Skew change test
2 * by: john stultz (johnstul@us.ibm.com)
3 * (C) Copyright IBM 2012
4 * Licensed under the GPLv2
6 * NOTE: This is a meta-test which cranks the ADJ_FREQ knob and
7 * then uses other tests to detect problems. Thus this test requires
8 * that the raw_skew, inconsistency-check and nanosleep tests be
9 * present in the same directory it is run from.
11 * To build:
12 * $ gcc change_skew.c -o change_skew -lrt
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
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
34 static inline int ksft_exit_pass(void)
36 exit(0);
38 static inline int ksft_exit_fail(void)
40 exit(1);
42 #endif
44 #define NSEC_PER_SEC 1000000000LL
47 int change_skew_test(int ppm)
49 struct timex tx;
50 int ret;
52 tx.modes = ADJ_FREQUENCY;
53 tx.freq = ppm << 16;
55 ret = adjtimex(&tx);
56 if (ret < 0) {
57 printf("Error adjusting freq\n");
58 return ret;
61 ret = system("./raw_skew");
62 ret |= system("./inconsistency-check");
63 ret |= system("./nanosleep");
65 return ret;
69 int main(int argv, char **argc)
71 struct timex tx;
72 int i, ret;
74 int ppm[5] = {0, 250, 500, -250, -500};
76 /* Kill ntpd */
77 ret = system("killall -9 ntpd");
79 /* Make sure there's no offset adjustment going on */
80 tx.modes = ADJ_OFFSET;
81 tx.offset = 0;
82 ret = adjtimex(&tx);
84 if (ret < 0) {
85 printf("Maybe you're not running as root?\n");
86 return -1;
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;
96 /* Set things back */
97 tx.modes = ADJ_FREQUENCY;
98 tx.offset = 0;
99 adjtimex(&tx);
101 if (ret) {
102 printf("[FAIL]");
103 return ksft_exit_fail();
105 printf("[OK]");
106 return ksft_exit_pass();