Back to home page

OSCL-LXR

 
 

    


0001 /* ADJ_FREQ Skew change test
0002  *      by: john stultz (johnstul@us.ibm.com)
0003  *      (C) Copyright IBM 2012
0004  *      Licensed under the GPLv2
0005  *
0006  *  NOTE: This is a meta-test which cranks the ADJ_FREQ knob and
0007  *  then uses other tests to detect problems. Thus this test requires
0008  *  that the raw_skew, inconsistency-check and nanosleep tests be
0009  *  present in the same directory it is run from.
0010  *
0011  *  To build:
0012  *  $ gcc change_skew.c -o change_skew -lrt
0013  *
0014  *   This program is free software: you can redistribute it and/or modify
0015  *   it under the terms of the GNU General Public License as published by
0016  *   the Free Software Foundation, either version 2 of the License, or
0017  *   (at your option) any later version.
0018  *
0019  *   This program is distributed in the hope that it will be useful,
0020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0022  *   GNU General Public License for more details.
0023  */
0024 
0025 
0026 #include <stdio.h>
0027 #include <stdlib.h>
0028 #include <sys/time.h>
0029 #include <sys/timex.h>
0030 #include <time.h>
0031 #include "../kselftest.h"
0032 
0033 #define NSEC_PER_SEC 1000000000LL
0034 
0035 
0036 int change_skew_test(int ppm)
0037 {
0038     struct timex tx;
0039     int ret;
0040 
0041     tx.modes = ADJ_FREQUENCY;
0042     tx.freq = ppm << 16;
0043 
0044     ret = adjtimex(&tx);
0045     if (ret < 0) {
0046         printf("Error adjusting freq\n");
0047         return ret;
0048     }
0049 
0050     ret = system("./raw_skew");
0051     ret |= system("./inconsistency-check");
0052     ret |= system("./nanosleep");
0053 
0054     return ret;
0055 }
0056 
0057 
0058 int main(int argc, char **argv)
0059 {
0060     struct timex tx;
0061     int i, ret;
0062 
0063     int ppm[5] = {0, 250, 500, -250, -500};
0064 
0065     /* Kill ntpd */
0066     ret = system("killall -9 ntpd");
0067 
0068     /* Make sure there's no offset adjustment going on */
0069     tx.modes = ADJ_OFFSET;
0070     tx.offset = 0;
0071     ret = adjtimex(&tx);
0072 
0073     if (ret < 0) {
0074         printf("Maybe you're not running as root?\n");
0075         return -1;
0076     }
0077 
0078     for (i = 0; i < 5; i++) {
0079         printf("Using %i ppm adjustment\n", ppm[i]);
0080         ret = change_skew_test(ppm[i]);
0081         if (ret)
0082             break;
0083     }
0084 
0085     /* Set things back */
0086     tx.modes = ADJ_FREQUENCY;
0087     tx.offset = 0;
0088     adjtimex(&tx);
0089 
0090     if (ret) {
0091         printf("[FAIL]");
0092         return ksft_exit_fail();
0093     }
0094     printf("[OK]");
0095     return ksft_exit_pass();
0096 }