2 * by: John Stultz <john.stultz@linaro.org>
3 * (C) Copyright Linaro 2016
4 * Licensed under the GPLv2
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
22 #include <sys/timex.h>
27 #include "../kselftest.h"
29 static inline int ksft_exit_pass(void)
33 static inline int ksft_exit_fail(void)
39 int set_tz(int min, int dst)
43 tz.tz_minuteswest = min;
46 return settimeofday(0, &tz);
54 memset(&tz, 0, sizeof(tz));
55 gettimeofday(&tv, &tz);
56 return tz.tz_minuteswest;
64 memset(&tz, 0, sizeof(tz));
65 gettimeofday(&tv, &tz);
69 int main(int argc, char **argv)
76 printf("tz_minuteswest started at %i, dst at %i\n", min, dst);
78 printf("Checking tz_minuteswest can be properly set: ");
79 for (i = -15*60; i < 15*60; i += 30) {
83 printf("[FAILED] expected: %i got %i\n", i, ret);
89 printf("Checking invalid tz_minuteswest values are caught: ");
91 if (!set_tz(-15*60-1, dst)) {
92 printf("[FAILED] %i didn't return failure!\n", -15*60-1);
96 if (!set_tz(15*60+1, dst)) {
97 printf("[FAILED] %i didn't return failure!\n", 15*60+1);
101 if (!set_tz(-24*60, dst)) {
102 printf("[FAILED] %i didn't return failure!\n", -24*60);
106 if (!set_tz(24*60, dst)) {
107 printf("[FAILED] %i didn't return failure!\n", 24*60);
114 return ksft_exit_pass();
118 return ksft_exit_fail();