diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2016-08-01 16:51:02 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-08-01 16:51:02 -0400 |
commit | 1571a03daf626ff34705e5fb40404879d00ac463 (patch) | |
tree | ff2504c0c797ea9ca1a8d3707a0c9992709754a2 | |
parent | 2790aed095fe50b21ab7ed94dc34a0f410a3872c (diff) | |
parent | f80eb4289491f6ddb0788636ce0bd6f5d3a2012a (diff) |
Merge tag 'linux-kselftest-4.8-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull kselftest fixes from Shuah Khan:
- Add a new timer set-tz test case
- Fix a bug in exec test Makefile dependency list
* tag 'linux-kselftest-4.8-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
selftests/exec: Makefile is a run-time dependency, add it to the install list
kselftests: timers: Add set-tz test case
-rw-r--r-- | tools/testing/selftests/exec/Makefile | 3 | ||||
-rw-r--r-- | tools/testing/selftests/timers/Makefile | 3 | ||||
-rw-r--r-- | tools/testing/selftests/timers/set-tz.c | 119 |
3 files changed, 123 insertions, 2 deletions
diff --git a/tools/testing/selftests/exec/Makefile b/tools/testing/selftests/exec/Makefile index 4e400eb83657..d4300602bf37 100644 --- a/tools/testing/selftests/exec/Makefile +++ b/tools/testing/selftests/exec/Makefile | |||
@@ -18,7 +18,8 @@ execveat.denatured: execveat | |||
18 | $(CC) $(CFLAGS) -o $@ $^ | 18 | $(CC) $(CFLAGS) -o $@ $^ |
19 | 19 | ||
20 | TEST_PROGS := execveat | 20 | TEST_PROGS := execveat |
21 | TEST_FILES := $(DEPS) | 21 | # Makefile is a run-time dependency, since it's accessed by the execveat test |
22 | TEST_FILES := $(DEPS) Makefile | ||
22 | 23 | ||
23 | include ../lib.mk | 24 | include ../lib.mk |
24 | 25 | ||
diff --git a/tools/testing/selftests/timers/Makefile b/tools/testing/selftests/timers/Makefile index 4a1be1b75a7f..1d5556869137 100644 --- a/tools/testing/selftests/timers/Makefile +++ b/tools/testing/selftests/timers/Makefile | |||
@@ -10,7 +10,7 @@ TEST_PROGS = posix_timers nanosleep nsleep-lat set-timer-lat mqueue-lat \ | |||
10 | 10 | ||
11 | TEST_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ | 11 | TEST_PROGS_EXTENDED = alarmtimer-suspend valid-adjtimex adjtick change_skew \ |
12 | skew_consistency clocksource-switch leap-a-day \ | 12 | skew_consistency clocksource-switch leap-a-day \ |
13 | leapcrash set-tai set-2038 | 13 | leapcrash set-tai set-2038 set-tz |
14 | 14 | ||
15 | bins = $(TEST_PROGS) $(TEST_PROGS_EXTENDED) | 15 | bins = $(TEST_PROGS) $(TEST_PROGS_EXTENDED) |
16 | 16 | ||
@@ -30,6 +30,7 @@ run_destructive_tests: run_tests | |||
30 | ./clocksource-switch | 30 | ./clocksource-switch |
31 | ./leap-a-day -s -i 10 | 31 | ./leap-a-day -s -i 10 |
32 | ./leapcrash | 32 | ./leapcrash |
33 | ./set-tz | ||
33 | ./set-tai | 34 | ./set-tai |
34 | ./set-2038 | 35 | ./set-2038 |
35 | 36 | ||
diff --git a/tools/testing/selftests/timers/set-tz.c b/tools/testing/selftests/timers/set-tz.c new file mode 100644 index 000000000000..f4184928b16b --- /dev/null +++ b/tools/testing/selftests/timers/set-tz.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /* Set tz value | ||
2 | * by: John Stultz <john.stultz@linaro.org> | ||
3 | * (C) Copyright Linaro 2016 | ||
4 | * Licensed under the GPLv2 | ||
5 | * | ||
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. | ||
10 | * | ||
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. | ||
15 | */ | ||
16 | |||
17 | |||
18 | #include <stdio.h> | ||
19 | #include <stdlib.h> | ||
20 | #include <time.h> | ||
21 | #include <sys/time.h> | ||
22 | #include <sys/timex.h> | ||
23 | #include <string.h> | ||
24 | #include <signal.h> | ||
25 | #include <unistd.h> | ||
26 | #ifdef KTEST | ||
27 | #include "../kselftest.h" | ||
28 | #else | ||
29 | static inline int ksft_exit_pass(void) | ||
30 | { | ||
31 | exit(0); | ||
32 | } | ||
33 | static inline int ksft_exit_fail(void) | ||
34 | { | ||
35 | exit(1); | ||
36 | } | ||
37 | #endif | ||
38 | |||
39 | int set_tz(int min, int dst) | ||
40 | { | ||
41 | struct timezone tz; | ||
42 | |||
43 | tz.tz_minuteswest = min; | ||
44 | tz.tz_dsttime = dst; | ||
45 | |||
46 | return settimeofday(0, &tz); | ||
47 | } | ||
48 | |||
49 | int get_tz_min(void) | ||
50 | { | ||
51 | struct timezone tz; | ||
52 | struct timeval tv; | ||
53 | |||
54 | memset(&tz, 0, sizeof(tz)); | ||
55 | gettimeofday(&tv, &tz); | ||
56 | return tz.tz_minuteswest; | ||
57 | } | ||
58 | |||
59 | int get_tz_dst(void) | ||
60 | { | ||
61 | struct timezone tz; | ||
62 | struct timeval tv; | ||
63 | |||
64 | memset(&tz, 0, sizeof(tz)); | ||
65 | gettimeofday(&tv, &tz); | ||
66 | return tz.tz_dsttime; | ||
67 | } | ||
68 | |||
69 | int main(int argc, char **argv) | ||
70 | { | ||
71 | int i, ret; | ||
72 | int min, dst; | ||
73 | |||
74 | min = get_tz_min(); | ||
75 | dst = get_tz_dst(); | ||
76 | printf("tz_minuteswest started at %i, dst at %i\n", min, dst); | ||
77 | |||
78 | printf("Checking tz_minuteswest can be properly set: "); | ||
79 | for (i = -15*60; i < 15*60; i += 30) { | ||
80 | ret = set_tz(i, dst); | ||
81 | ret = get_tz_min(); | ||
82 | if (ret != i) { | ||
83 | printf("[FAILED] expected: %i got %i\n", i, ret); | ||
84 | goto err; | ||
85 | } | ||
86 | } | ||
87 | printf("[OK]\n"); | ||
88 | |||
89 | printf("Checking invalid tz_minuteswest values are caught: "); | ||
90 | |||
91 | if (!set_tz(-15*60-1, dst)) { | ||
92 | printf("[FAILED] %i didn't return failure!\n", -15*60-1); | ||
93 | goto err; | ||
94 | } | ||
95 | |||
96 | if (!set_tz(15*60+1, dst)) { | ||
97 | printf("[FAILED] %i didn't return failure!\n", 15*60+1); | ||
98 | goto err; | ||
99 | } | ||
100 | |||
101 | if (!set_tz(-24*60, dst)) { | ||
102 | printf("[FAILED] %i didn't return failure!\n", -24*60); | ||
103 | goto err; | ||
104 | } | ||
105 | |||
106 | if (!set_tz(24*60, dst)) { | ||
107 | printf("[FAILED] %i didn't return failure!\n", 24*60); | ||
108 | goto err; | ||
109 | } | ||
110 | |||
111 | printf("[OK]\n"); | ||
112 | |||
113 | set_tz(min, dst); | ||
114 | return ksft_exit_pass(); | ||
115 | |||
116 | err: | ||
117 | set_tz(min, dst); | ||
118 | return ksft_exit_fail(); | ||
119 | } | ||