Linux Audio

Check our new training course

Loading...
v6.13.7
 1/* ADJ_FREQ Skew change test
 2 *		by: john stultz (johnstul@us.ibm.com)
 3 *		(C) Copyright IBM 2012
 4 *		Licensed under the GPLv2
 5 *
 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.
10 *
11 *  To build:
12 *	$ gcc change_skew.c -o change_skew -lrt
13 *
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.
18 *
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.
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#include "../kselftest.h"
32
 
 
 
33int change_skew_test(int ppm)
34{
35	struct timex tx;
36	int ret;
37
38	tx.modes = ADJ_FREQUENCY;
39	tx.freq = ppm << 16;
40
41	ret = adjtimex(&tx);
42	if (ret < 0) {
43		printf("Error adjusting freq\n");
44		return ret;
45	}
46
47	ret = system("./raw_skew");
48	ret |= system("./inconsistency-check");
49	ret |= system("./nanosleep");
50
51	return ret;
52}
53
54
55int main(int argc, char **argv)
56{
57	struct timex tx;
58	int i, ret;
59
60	int ppm[5] = {0, 250, 500, -250, -500};
61
62	/* Kill ntpd */
63	ret = system("killall -9 ntpd");
64
65	/* Make sure there's no offset adjustment going on */
66	tx.modes = ADJ_OFFSET;
67	tx.offset = 0;
68	ret = adjtimex(&tx);
69
70	if (ret < 0) {
71		printf("Maybe you're not running as root?\n");
72		return -1;
73	}
74
75	for (i = 0; i < 5; i++) {
76		printf("Using %i ppm adjustment\n", ppm[i]);
77		ret = change_skew_test(ppm[i]);
78		if (ret)
79			break;
80	}
81
82	/* Set things back */
83	tx.modes = ADJ_FREQUENCY;
84	tx.offset = 0;
85	adjtimex(&tx);
86
87	if (ret) {
88		printf("[FAIL]");
89		ksft_exit_fail();
90	}
91	printf("[OK]");
92	ksft_exit_pass();
93}
v4.17
 1/* ADJ_FREQ Skew change test
 2 *		by: john stultz (johnstul@us.ibm.com)
 3 *		(C) Copyright IBM 2012
 4 *		Licensed under the GPLv2
 5 *
 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.
10 *
11 *  To build:
12 *	$ gcc change_skew.c -o change_skew -lrt
13 *
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.
18 *
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.
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#include "../kselftest.h"
32
33#define NSEC_PER_SEC 1000000000LL
34
35
36int change_skew_test(int ppm)
37{
38	struct timex tx;
39	int ret;
40
41	tx.modes = ADJ_FREQUENCY;
42	tx.freq = ppm << 16;
43
44	ret = adjtimex(&tx);
45	if (ret < 0) {
46		printf("Error adjusting freq\n");
47		return ret;
48	}
49
50	ret = system("./raw_skew");
51	ret |= system("./inconsistency-check");
52	ret |= system("./nanosleep");
53
54	return ret;
55}
56
57
58int main(int argv, char **argc)
59{
60	struct timex tx;
61	int i, ret;
62
63	int ppm[5] = {0, 250, 500, -250, -500};
64
65	/* Kill ntpd */
66	ret = system("killall -9 ntpd");
67
68	/* Make sure there's no offset adjustment going on */
69	tx.modes = ADJ_OFFSET;
70	tx.offset = 0;
71	ret = adjtimex(&tx);
72
73	if (ret < 0) {
74		printf("Maybe you're not running as root?\n");
75		return -1;
76	}
77
78	for (i = 0; i < 5; i++) {
79		printf("Using %i ppm adjustment\n", ppm[i]);
80		ret = change_skew_test(ppm[i]);
81		if (ret)
82			break;
83	}
84
85	/* Set things back */
86	tx.modes = ADJ_FREQUENCY;
87	tx.offset = 0;
88	adjtimex(&tx);
89
90	if (ret) {
91		printf("[FAIL]");
92		return ksft_exit_fail();
93	}
94	printf("[OK]");
95	return ksft_exit_pass();
96}