2 * by: John Stultz <john.stultz@linaro.org>
3 * (C) Copyright Linaro 2015
4 * Licensed under the GPLv2
6 * This test validates adjtimex interface with valid
7 * and invalid test data.
9 * Usage: valid-adjtimex
12 * $ gcc valid-adjtimex.c -o valid-adjtimex -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.
31 #include <sys/timex.h>
36 #include "../kselftest.h"
38 static inline int ksft_exit_pass(void)
42 static inline int ksft_exit_fail(void)
48 #define NSEC_PER_SEC 1000000000L
50 /* clear NTP time_status & time_state */
51 int clear_time_state(void)
56 tx.modes = ADJ_STATUS;
62 #define NUM_FREQ_VALID 32
63 #define NUM_FREQ_OUTOFRANGE 4
64 #define NUM_FREQ_INVALID 2
66 long valid_freq[NUM_FREQ_VALID] = {
100 long outofrange_freq[NUM_FREQ_OUTOFRANGE] = {
107 #define LONG_MAX (~0UL>>1)
108 #define LONG_MIN (-LONG_MAX - 1)
110 long invalid_freq[NUM_FREQ_INVALID] = {
115 int validate_freq(void)
123 memset(&tx, 0, sizeof(struct timex));
124 /* Set the leap second insert flag */
126 printf("Testing ADJ_FREQ... ");
127 for (i = 0; i < NUM_FREQ_VALID; i++) {
128 tx.modes = ADJ_FREQUENCY;
129 tx.freq = valid_freq[i];
134 printf("Error: adjtimex(ADJ_FREQ, %ld - %ld ppm\n",
135 valid_freq[i], valid_freq[i]>>16);
141 if (tx.freq != valid_freq[i]) {
142 printf("Warning: freq value %ld not what we set it (%ld)!\n",
143 tx.freq, valid_freq[i]);
146 for (i = 0; i < NUM_FREQ_OUTOFRANGE; i++) {
147 tx.modes = ADJ_FREQUENCY;
148 tx.freq = outofrange_freq[i];
153 printf("Error: adjtimex(ADJ_FREQ, %ld - %ld ppm\n",
154 outofrange_freq[i], outofrange_freq[i]>>16);
160 if (tx.freq == outofrange_freq[i]) {
162 printf("ERROR: out of range value %ld actually set!\n",
170 if (sizeof(long) == 8) { /* this case only applies to 64bit systems */
171 for (i = 0; i < NUM_FREQ_INVALID; i++) {
172 tx.modes = ADJ_FREQUENCY;
173 tx.freq = invalid_freq[i];
177 printf("Error: No failure on invalid ADJ_FREQUENCY %ld\n",
187 /* reset freq to zero */
188 tx.modes = ADJ_FREQUENCY;
196 int main(int argc, char **argv)
199 return ksft_exit_fail();
201 return ksft_exit_pass();