Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) /* Set tai offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2)  *              by: John Stultz <john.stultz@linaro.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *              (C) Copyright Linaro 2013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *              Licensed under the GPLv2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *   This program is free software: you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  *   it under the terms of the GNU General Public License as published by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *   the Free Software Foundation, either version 2 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  *   (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)  *   This program is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)  *   GNU General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <sys/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <sys/timex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "../kselftest.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int set_tai(int offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 	struct timex tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	memset(&tx, 0, sizeof(tx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	tx.modes = ADJ_TAI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	tx.constant = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	return adjtimex(&tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int get_tai(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	struct timex tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	memset(&tx, 0, sizeof(tx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	adjtimex(&tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	return tx.tai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int main(int argc, char **argv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	int i, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	ret = get_tai();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	printf("tai offset started at %i\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	printf("Checking tai offsets can be properly set: ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	fflush(stdout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	for (i = 1; i <= 60; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		ret = set_tai(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		ret = get_tai();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 		if (ret != i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 			printf("[FAILED] expected: %i got %i\n", i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 			return ksft_exit_fail();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	printf("[OK]\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	return ksft_exit_pass();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }