Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Luis R. Rodriguez and committed by
Greg Kroah-Hartman
29a1c00c 0c8efd61

+51 -20
+4 -3
tools/testing/selftests/firmware/fw_fallback.sh
··· 1 - #!/bin/sh 1 + #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 # This validates that the kernel will fall back to using the fallback mechanism 4 4 # to load firmware it can't find on disk itself. We must request a firmware ··· 6 6 # won't find so that we can do the load ourself manually. 7 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 14 # CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/ 14 15 # These days no one enables CONFIG_FW_LOADER_USER_HELPER so check for that
+3 -17
tools/testing/selftests/firmware/fw_filesystem.sh
··· 1 - #!/bin/sh 1 + #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 # This validates that the kernel will load firmware out of its list of 4 4 # firmware locations on disk. Since the user helper does similar work, ··· 6 6 # know so we can be sure we're not accidentally testing the user helper. 7 7 set -e 8 8 9 - DIR=/sys/devices/virtual/misc/test_firmware 10 9 TEST_DIR=$(dirname $0) 10 + source $TEST_DIR/fw_lib.sh 11 11 12 - test_modprobe() 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 12 + check_mods 27 13 28 14 # CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/ 29 15 # These days most distros enable CONFIG_FW_LOADER_USER_HELPER but disable
+44
tools/testing/selftests/firmware/fw_lib.sh
··· 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 + }