diff options
author | Luis R. Rodriguez <mcgrof@kernel.org> | 2018-03-10 09:14:42 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-03-14 14:49:23 -0400 |
commit | 29a1c00ce1df8a75bea6e6a86876a10c8dcc2c59 (patch) | |
tree | 285c27cac716f0b0385c4a601f3a65f56088ab1e | |
parent | 0c8efd610b58cb23cefdfa12015799079aef94ae (diff) |
test_firmware: add simple firmware firmware test library
We'll expland on this later, for now just add basic module checker.
While at it, move this all to use /bin/bash as we'll have much more
flexibility with it.
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rwxr-xr-x | tools/testing/selftests/firmware/fw_fallback.sh | 7 | ||||
-rwxr-xr-x | tools/testing/selftests/firmware/fw_filesystem.sh | 20 | ||||
-rwxr-xr-x | tools/testing/selftests/firmware/fw_lib.sh | 44 |
3 files changed, 51 insertions, 20 deletions
diff --git a/tools/testing/selftests/firmware/fw_fallback.sh b/tools/testing/selftests/firmware/fw_fallback.sh index 722cad91df74..755147a8c967 100755 --- a/tools/testing/selftests/firmware/fw_fallback.sh +++ b/tools/testing/selftests/firmware/fw_fallback.sh | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/bash |
2 | # SPDX-License-Identifier: GPL-2.0 | 2 | # SPDX-License-Identifier: GPL-2.0 |
3 | # This validates that the kernel will fall back to using the fallback mechanism | 3 | # This validates that the kernel will fall back to using the fallback mechanism |
4 | # to load firmware it can't find on disk itself. We must request a firmware | 4 | # to load firmware it can't find on disk itself. We must request a firmware |
@@ -6,9 +6,10 @@ | |||
6 | # won't find so that we can do the load ourself manually. | 6 | # won't find so that we can do the load ourself manually. |
7 | set -e | 7 | set -e |
8 | 8 | ||
9 | modprobe test_firmware | 9 | TEST_DIR=$(dirname $0) |
10 | source $TEST_DIR/fw_lib.sh | ||
10 | 11 | ||
11 | DIR=/sys/devices/virtual/misc/test_firmware | 12 | check_mods |
12 | 13 | ||
13 | # CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/ | 14 | # CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/ |
14 | # These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that | 15 | # These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that |
diff --git a/tools/testing/selftests/firmware/fw_filesystem.sh b/tools/testing/selftests/firmware/fw_filesystem.sh index f9508e1a4058..748f2f5737e9 100755 --- a/tools/testing/selftests/firmware/fw_filesystem.sh +++ b/tools/testing/selftests/firmware/fw_filesystem.sh | |||
@@ -1,4 +1,4 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/bash |
2 | # SPDX-License-Identifier: GPL-2.0 | 2 | # SPDX-License-Identifier: GPL-2.0 |
3 | # This validates that the kernel will load firmware out of its list of | 3 | # This validates that the kernel will load firmware out of its list of |
4 | # firmware locations on disk. Since the user helper does similar work, | 4 | # firmware locations on disk. Since the user helper does similar work, |
@@ -6,24 +6,10 @@ | |||
6 | # know so we can be sure we're not accidentally testing the user helper. | 6 | # know so we can be sure we're not accidentally testing the user helper. |
7 | set -e | 7 | set -e |
8 | 8 | ||
9 | DIR=/sys/devices/virtual/misc/test_firmware | ||
10 | TEST_DIR=$(dirname $0) | 9 | TEST_DIR=$(dirname $0) |
10 | source $TEST_DIR/fw_lib.sh | ||
11 | 11 | ||
12 | test_modprobe() | 12 | check_mods |
13 | { | ||
14 | if [ ! -d $DIR ]; then | ||
15 | echo "$0: $DIR not present" | ||
16 | echo "You must have the following enabled in your kernel:" | ||
17 | cat $TEST_DIR/config | ||
18 | exit 1 | ||
19 | fi | ||
20 | } | ||
21 | |||
22 | trap "test_modprobe" EXIT | ||
23 | |||
24 | if [ ! -d $DIR ]; then | ||
25 | modprobe test_firmware | ||
26 | fi | ||
27 | 13 | ||
28 | # CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/ | 14 | # CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/ |
29 | # These days most distros enable CONFIG_FW_LOADER_USER_HELPER but disable | 15 | # These days most distros enable CONFIG_FW_LOADER_USER_HELPER but disable |
diff --git a/tools/testing/selftests/firmware/fw_lib.sh b/tools/testing/selftests/firmware/fw_lib.sh new file mode 100755 index 000000000000..c14bbca7ecf9 --- /dev/null +++ b/tools/testing/selftests/firmware/fw_lib.sh | |||
@@ -0,0 +1,44 @@ | |||
1 | #!/bin/bash | ||
2 | # SPDX-License-Identifier: GPL-2.0 | ||
3 | |||
4 | # Library of helpers for test scripts. | ||
5 | set -e | ||
6 | |||
7 | DIR=/sys/devices/virtual/misc/test_firmware | ||
8 | |||
9 | PROC_CONFIG="/proc/config.gz" | ||
10 | TEST_DIR=$(dirname $0) | ||
11 | |||
12 | print_reqs_exit() | ||
13 | { | ||
14 | echo "You must have the following enabled in your kernel:" >&2 | ||
15 | cat $TEST_DIR/config >&2 | ||
16 | exit 1 | ||
17 | } | ||
18 | |||
19 | test_modprobe() | ||
20 | { | ||
21 | if [ ! -d $DIR ]; then | ||
22 | print_reqs_exit | ||
23 | fi | ||
24 | } | ||
25 | |||
26 | check_mods() | ||
27 | { | ||
28 | trap "test_modprobe" EXIT | ||
29 | if [ ! -d $DIR ]; then | ||
30 | modprobe test_firmware | ||
31 | fi | ||
32 | if [ ! -f $PROC_CONFIG ]; then | ||
33 | if modprobe configs 2>/dev/null; then | ||
34 | echo "Loaded configs module" | ||
35 | if [ ! -f $PROC_CONFIG ]; then | ||
36 | echo "You must have the following enabled in your kernel:" >&2 | ||
37 | cat $TEST_DIR/config >&2 | ||
38 | echo "Resorting to old heuristics" >&2 | ||
39 | fi | ||
40 | else | ||
41 | echo "Failed to load configs module, using old heuristics" >&2 | ||
42 | fi | ||
43 | fi | ||
44 | } | ||