diff options
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r-- | tools/testing/selftests/Makefile | 19 | ||||
-rw-r--r-- | tools/testing/selftests/kselftest/runner.sh | 36 | ||||
-rwxr-xr-x | tools/testing/selftests/kselftest_install.sh | 4 | ||||
-rw-r--r-- | tools/testing/selftests/rtc/settings | 1 | ||||
-rw-r--r-- | tools/testing/selftests/watchdog/watchdog-test.c | 27 |
5 files changed, 79 insertions, 8 deletions
diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index c3feccb99ff5..4cdbae6f4e61 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile | |||
@@ -63,6 +63,13 @@ TARGETS += zram | |||
63 | TARGETS_HOTPLUG = cpu-hotplug | 63 | TARGETS_HOTPLUG = cpu-hotplug |
64 | TARGETS_HOTPLUG += memory-hotplug | 64 | TARGETS_HOTPLUG += memory-hotplug |
65 | 65 | ||
66 | # User can optionally provide a TARGETS skiplist. | ||
67 | SKIP_TARGETS ?= | ||
68 | ifneq ($(SKIP_TARGETS),) | ||
69 | TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS)) | ||
70 | override TARGETS := $(TMP) | ||
71 | endif | ||
72 | |||
66 | # Clear LDFLAGS and MAKEFLAGS if called from main | 73 | # Clear LDFLAGS and MAKEFLAGS if called from main |
67 | # Makefile to avoid test build failures when test | 74 | # Makefile to avoid test build failures when test |
68 | # Makefile doesn't have explicit build rules. | 75 | # Makefile doesn't have explicit build rules. |
@@ -171,9 +178,12 @@ run_pstore_crash: | |||
171 | # 1. output_dir=kernel_src | 178 | # 1. output_dir=kernel_src |
172 | # 2. a separate output directory is specified using O= KBUILD_OUTPUT | 179 | # 2. a separate output directory is specified using O= KBUILD_OUTPUT |
173 | # 3. a separate output directory is specified using KBUILD_OUTPUT | 180 | # 3. a separate output directory is specified using KBUILD_OUTPUT |
181 | # Avoid conflict with INSTALL_PATH set by the main Makefile | ||
174 | # | 182 | # |
175 | INSTALL_PATH ?= $(BUILD)/install | 183 | KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install |
176 | INSTALL_PATH := $(abspath $(INSTALL_PATH)) | 184 | KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH)) |
185 | # Avoid changing the rest of the logic here and lib.mk. | ||
186 | INSTALL_PATH := $(KSFT_INSTALL_PATH) | ||
177 | ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh | 187 | ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh |
178 | 188 | ||
179 | install: all | 189 | install: all |
@@ -198,11 +208,16 @@ ifdef INSTALL_PATH | |||
198 | echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT) | 208 | echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT) |
199 | echo "fi" >> $(ALL_SCRIPT) | 209 | echo "fi" >> $(ALL_SCRIPT) |
200 | 210 | ||
211 | @# While building run_kselftest.sh skip also non-existent TARGET dirs: | ||
212 | @# they could be the result of a build failure and should NOT be | ||
213 | @# included in the generated runlist. | ||
201 | for TARGET in $(TARGETS); do \ | 214 | for TARGET in $(TARGETS); do \ |
202 | BUILD_TARGET=$$BUILD/$$TARGET; \ | 215 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
216 | [ ! -d $$INSTALL_PATH/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ | ||
203 | echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ | 217 | echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ |
204 | echo "cd $$TARGET" >> $(ALL_SCRIPT); \ | 218 | echo "cd $$TARGET" >> $(ALL_SCRIPT); \ |
205 | echo -n "run_many" >> $(ALL_SCRIPT); \ | 219 | echo -n "run_many" >> $(ALL_SCRIPT); \ |
220 | echo -n "Emit Tests for $$TARGET\n"; \ | ||
206 | $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ | 221 | $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ |
207 | echo "" >> $(ALL_SCRIPT); \ | 222 | echo "" >> $(ALL_SCRIPT); \ |
208 | echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ | 223 | echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ |
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh index 00c9020bdda8..84de7bc74f2c 100644 --- a/tools/testing/selftests/kselftest/runner.sh +++ b/tools/testing/selftests/kselftest/runner.sh | |||
@@ -3,9 +3,14 @@ | |||
3 | # | 3 | # |
4 | # Runs a set of tests in a given subdirectory. | 4 | # Runs a set of tests in a given subdirectory. |
5 | export skip_rc=4 | 5 | export skip_rc=4 |
6 | export timeout_rc=124 | ||
6 | export logfile=/dev/stdout | 7 | export logfile=/dev/stdout |
7 | export per_test_logging= | 8 | export per_test_logging= |
8 | 9 | ||
10 | # Defaults for "settings" file fields: | ||
11 | # "timeout" how many seconds to let each test run before failing. | ||
12 | export kselftest_default_timeout=45 | ||
13 | |||
9 | # There isn't a shell-agnostic way to find the path of a sourced file, | 14 | # There isn't a shell-agnostic way to find the path of a sourced file, |
10 | # so we must rely on BASE_DIR being set to find other tools. | 15 | # so we must rely on BASE_DIR being set to find other tools. |
11 | if [ -z "$BASE_DIR" ]; then | 16 | if [ -z "$BASE_DIR" ]; then |
@@ -24,6 +29,16 @@ tap_prefix() | |||
24 | fi | 29 | fi |
25 | } | 30 | } |
26 | 31 | ||
32 | tap_timeout() | ||
33 | { | ||
34 | # Make sure tests will time out if utility is available. | ||
35 | if [ -x /usr/bin/timeout ] ; then | ||
36 | /usr/bin/timeout "$kselftest_timeout" "$1" | ||
37 | else | ||
38 | "$1" | ||
39 | fi | ||
40 | } | ||
41 | |||
27 | run_one() | 42 | run_one() |
28 | { | 43 | { |
29 | DIR="$1" | 44 | DIR="$1" |
@@ -32,6 +47,18 @@ run_one() | |||
32 | 47 | ||
33 | BASENAME_TEST=$(basename $TEST) | 48 | BASENAME_TEST=$(basename $TEST) |
34 | 49 | ||
50 | # Reset any "settings"-file variables. | ||
51 | export kselftest_timeout="$kselftest_default_timeout" | ||
52 | # Load per-test-directory kselftest "settings" file. | ||
53 | settings="$BASE_DIR/$DIR/settings" | ||
54 | if [ -r "$settings" ] ; then | ||
55 | while read line ; do | ||
56 | field=$(echo "$line" | cut -d= -f1) | ||
57 | value=$(echo "$line" | cut -d= -f2-) | ||
58 | eval "kselftest_$field"="$value" | ||
59 | done < "$settings" | ||
60 | fi | ||
61 | |||
35 | TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST" | 62 | TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST" |
36 | echo "# $TEST_HDR_MSG" | 63 | echo "# $TEST_HDR_MSG" |
37 | if [ ! -x "$TEST" ]; then | 64 | if [ ! -x "$TEST" ]; then |
@@ -44,14 +71,17 @@ run_one() | |||
44 | echo "not ok $test_num $TEST_HDR_MSG" | 71 | echo "not ok $test_num $TEST_HDR_MSG" |
45 | else | 72 | else |
46 | cd `dirname $TEST` > /dev/null | 73 | cd `dirname $TEST` > /dev/null |
47 | (((((./$BASENAME_TEST 2>&1; echo $? >&3) | | 74 | ((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) | |
48 | tap_prefix >&4) 3>&1) | | 75 | tap_prefix >&4) 3>&1) | |
49 | (read xs; exit $xs)) 4>>"$logfile" && | 76 | (read xs; exit $xs)) 4>>"$logfile" && |
50 | echo "ok $test_num $TEST_HDR_MSG") || | 77 | echo "ok $test_num $TEST_HDR_MSG") || |
51 | (if [ $? -eq $skip_rc ]; then \ | 78 | (rc=$?; \ |
79 | if [ $rc -eq $skip_rc ]; then \ | ||
52 | echo "not ok $test_num $TEST_HDR_MSG # SKIP" | 80 | echo "not ok $test_num $TEST_HDR_MSG # SKIP" |
81 | elif [ $rc -eq $timeout_rc ]; then \ | ||
82 | echo "not ok $test_num $TEST_HDR_MSG # TIMEOUT" | ||
53 | else | 83 | else |
54 | echo "not ok $test_num $TEST_HDR_MSG" | 84 | echo "not ok $test_num $TEST_HDR_MSG # exit=$rc" |
55 | fi) | 85 | fi) |
56 | cd - >/dev/null | 86 | cd - >/dev/null |
57 | fi | 87 | fi |
diff --git a/tools/testing/selftests/kselftest_install.sh b/tools/testing/selftests/kselftest_install.sh index ec304463883c..e2e1911d62d5 100755 --- a/tools/testing/selftests/kselftest_install.sh +++ b/tools/testing/selftests/kselftest_install.sh | |||
@@ -24,12 +24,12 @@ main() | |||
24 | echo "$0: Installing in specified location - $install_loc ..." | 24 | echo "$0: Installing in specified location - $install_loc ..." |
25 | fi | 25 | fi |
26 | 26 | ||
27 | install_dir=$install_loc/kselftest | 27 | install_dir=$install_loc/kselftest_install |
28 | 28 | ||
29 | # Create install directory | 29 | # Create install directory |
30 | mkdir -p $install_dir | 30 | mkdir -p $install_dir |
31 | # Build tests | 31 | # Build tests |
32 | INSTALL_PATH=$install_dir make install | 32 | KSFT_INSTALL_PATH=$install_dir make install |
33 | } | 33 | } |
34 | 34 | ||
35 | main "$@" | 35 | main "$@" |
diff --git a/tools/testing/selftests/rtc/settings b/tools/testing/selftests/rtc/settings new file mode 100644 index 000000000000..ba4d85f74cd6 --- /dev/null +++ b/tools/testing/selftests/rtc/settings | |||
@@ -0,0 +1 @@ | |||
timeout=90 | |||
diff --git a/tools/testing/selftests/watchdog/watchdog-test.c b/tools/testing/selftests/watchdog/watchdog-test.c index afff120c7be6..f45e510500c0 100644 --- a/tools/testing/selftests/watchdog/watchdog-test.c +++ b/tools/testing/selftests/watchdog/watchdog-test.c | |||
@@ -19,7 +19,7 @@ | |||
19 | 19 | ||
20 | int fd; | 20 | int fd; |
21 | const char v = 'V'; | 21 | const char v = 'V'; |
22 | static const char sopts[] = "bdehp:t:Tn:NLf:"; | 22 | static const char sopts[] = "bdehp:t:Tn:NLf:i"; |
23 | static const struct option lopts[] = { | 23 | static const struct option lopts[] = { |
24 | {"bootstatus", no_argument, NULL, 'b'}, | 24 | {"bootstatus", no_argument, NULL, 'b'}, |
25 | {"disable", no_argument, NULL, 'd'}, | 25 | {"disable", no_argument, NULL, 'd'}, |
@@ -32,6 +32,7 @@ static const struct option lopts[] = { | |||
32 | {"getpretimeout", no_argument, NULL, 'N'}, | 32 | {"getpretimeout", no_argument, NULL, 'N'}, |
33 | {"gettimeleft", no_argument, NULL, 'L'}, | 33 | {"gettimeleft", no_argument, NULL, 'L'}, |
34 | {"file", required_argument, NULL, 'f'}, | 34 | {"file", required_argument, NULL, 'f'}, |
35 | {"info", no_argument, NULL, 'i'}, | ||
35 | {NULL, no_argument, NULL, 0x0} | 36 | {NULL, no_argument, NULL, 0x0} |
36 | }; | 37 | }; |
37 | 38 | ||
@@ -72,6 +73,7 @@ static void usage(char *progname) | |||
72 | printf("Usage: %s [options]\n", progname); | 73 | printf("Usage: %s [options]\n", progname); |
73 | printf(" -f, --file\t\tOpen watchdog device file\n"); | 74 | printf(" -f, --file\t\tOpen watchdog device file\n"); |
74 | printf("\t\t\tDefault is /dev/watchdog\n"); | 75 | printf("\t\t\tDefault is /dev/watchdog\n"); |
76 | printf(" -i, --info\t\tShow watchdog_info\n"); | ||
75 | printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n"); | 77 | printf(" -b, --bootstatus\tGet last boot status (Watchdog/POR)\n"); |
76 | printf(" -d, --disable\t\tTurn off the watchdog timer\n"); | 78 | printf(" -d, --disable\t\tTurn off the watchdog timer\n"); |
77 | printf(" -e, --enable\t\tTurn on the watchdog timer\n"); | 79 | printf(" -e, --enable\t\tTurn on the watchdog timer\n"); |
@@ -97,6 +99,7 @@ int main(int argc, char *argv[]) | |||
97 | int c; | 99 | int c; |
98 | int oneshot = 0; | 100 | int oneshot = 0; |
99 | char *file = "/dev/watchdog"; | 101 | char *file = "/dev/watchdog"; |
102 | struct watchdog_info info; | ||
100 | 103 | ||
101 | setbuf(stdout, NULL); | 104 | setbuf(stdout, NULL); |
102 | 105 | ||
@@ -118,6 +121,16 @@ int main(int argc, char *argv[]) | |||
118 | exit(-1); | 121 | exit(-1); |
119 | } | 122 | } |
120 | 123 | ||
124 | /* | ||
125 | * Validate that `file` is a watchdog device | ||
126 | */ | ||
127 | ret = ioctl(fd, WDIOC_GETSUPPORT, &info); | ||
128 | if (ret) { | ||
129 | printf("WDIOC_GETSUPPORT error '%s'\n", strerror(errno)); | ||
130 | close(fd); | ||
131 | exit(ret); | ||
132 | } | ||
133 | |||
121 | optind = 0; | 134 | optind = 0; |
122 | 135 | ||
123 | while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { | 136 | while ((c = getopt_long(argc, argv, sopts, lopts, NULL)) != -1) { |
@@ -205,6 +218,18 @@ int main(int argc, char *argv[]) | |||
205 | case 'f': | 218 | case 'f': |
206 | /* Handled above */ | 219 | /* Handled above */ |
207 | break; | 220 | break; |
221 | case 'i': | ||
222 | /* | ||
223 | * watchdog_info was obtained as part of file open | ||
224 | * validation. So we just show it here. | ||
225 | */ | ||
226 | oneshot = 1; | ||
227 | printf("watchdog_info:\n"); | ||
228 | printf(" identity:\t\t%s\n", info.identity); | ||
229 | printf(" firmware_version:\t%u\n", | ||
230 | info.firmware_version); | ||
231 | printf(" options:\t\t%08x\n", info.options); | ||
232 | break; | ||
208 | 233 | ||
209 | default: | 234 | default: |
210 | usage(argv[0]); | 235 | usage(argv[0]); |