Back to home page

OSCL-LXR

 
 

    


0001 /* Set tai offset
0002  *              by: John Stultz <john.stultz@linaro.org>
0003  *              (C) Copyright Linaro 2013
0004  *              Licensed under the GPLv2
0005  *
0006  *   This program is free software: you can redistribute it and/or modify
0007  *   it under the terms of the GNU General Public License as published by
0008  *   the Free Software Foundation, either version 2 of the License, or
0009  *   (at your option) any later version.
0010  *
0011  *   This program is distributed in the hope that it will be useful,
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  *   GNU General Public License for more details.
0015  */
0016 
0017 
0018 #include <stdio.h>
0019 #include <stdlib.h>
0020 #include <time.h>
0021 #include <sys/time.h>
0022 #include <sys/timex.h>
0023 #include <string.h>
0024 #include <signal.h>
0025 #include <unistd.h>
0026 #include "../kselftest.h"
0027 
0028 int set_tai(int offset)
0029 {
0030     struct timex tx;
0031 
0032     memset(&tx, 0, sizeof(tx));
0033 
0034     tx.modes = ADJ_TAI;
0035     tx.constant = offset;
0036 
0037     return adjtimex(&tx);
0038 }
0039 
0040 int get_tai(void)
0041 {
0042     struct timex tx;
0043 
0044     memset(&tx, 0, sizeof(tx));
0045 
0046     adjtimex(&tx);
0047     return tx.tai;
0048 }
0049 
0050 int main(int argc, char **argv)
0051 {
0052     int i, ret;
0053 
0054     ret = get_tai();
0055     printf("tai offset started at %i\n", ret);
0056 
0057     printf("Checking tai offsets can be properly set: ");
0058     fflush(stdout);
0059     for (i = 1; i <= 60; i++) {
0060         ret = set_tai(i);
0061         ret = get_tai();
0062         if (ret != i) {
0063             printf("[FAILED] expected: %i got %i\n", i, ret);
0064             return ksft_exit_fail();
0065         }
0066     }
0067     printf("[OK]\n");
0068     return ksft_exit_pass();
0069 }