test_firmware: expand on library with shared helpers
This expands our library with as many things we could find which both scripts we use share. Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
2cd7a1c6dc
commit
f5a614519e
|
@ -6,30 +6,17 @@
|
||||||
# won't find so that we can do the load ourself manually.
|
# won't find so that we can do the load ourself manually.
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
TEST_REQS_FW_SYSFS_FALLBACK="yes"
|
||||||
|
TEST_REQS_FW_SET_CUSTOM_PATH="no"
|
||||||
TEST_DIR=$(dirname $0)
|
TEST_DIR=$(dirname $0)
|
||||||
source $TEST_DIR/fw_lib.sh
|
source $TEST_DIR/fw_lib.sh
|
||||||
|
|
||||||
check_mods
|
check_mods
|
||||||
|
check_setup
|
||||||
|
verify_reqs
|
||||||
|
setup_tmp_file
|
||||||
|
|
||||||
HAS_FW_LOADER_USER_HELPER=$(kconfig_has CONFIG_FW_LOADER_USER_HELPER=y)
|
trap "test_finish" EXIT
|
||||||
HAS_FW_LOADER_USER_HELPER_FALLBACK=$(kconfig_has CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y)
|
|
||||||
|
|
||||||
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
|
|
||||||
OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
|
|
||||||
else
|
|
||||||
echo "usermode helper disabled so ignoring test"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
FWPATH=$(mktemp -d)
|
|
||||||
FW="$FWPATH/test-firmware.bin"
|
|
||||||
|
|
||||||
test_finish()
|
|
||||||
{
|
|
||||||
echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
|
|
||||||
rm -f "$FW"
|
|
||||||
rmdir "$FWPATH"
|
|
||||||
}
|
|
||||||
|
|
||||||
load_fw()
|
load_fw()
|
||||||
{
|
{
|
||||||
|
@ -168,12 +155,6 @@ load_fw_fallback_with_child()
|
||||||
return $RET
|
return $RET
|
||||||
}
|
}
|
||||||
|
|
||||||
trap "test_finish" EXIT
|
|
||||||
|
|
||||||
# This is an unlikely real-world firmware content. :)
|
|
||||||
echo "ABCD0123" >"$FW"
|
|
||||||
NAME=$(basename "$FW")
|
|
||||||
|
|
||||||
test_syfs_timeout()
|
test_syfs_timeout()
|
||||||
{
|
{
|
||||||
DEVPATH="$DIR"/"nope-$NAME"/loading
|
DEVPATH="$DIR"/"nope-$NAME"/loading
|
||||||
|
|
|
@ -6,38 +6,15 @@
|
||||||
# know so we can be sure we're not accidentally testing the user helper.
|
# know so we can be sure we're not accidentally testing the user helper.
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
TEST_REQS_FW_SYSFS_FALLBACK="no"
|
||||||
|
TEST_REQS_FW_SET_CUSTOM_PATH="yes"
|
||||||
TEST_DIR=$(dirname $0)
|
TEST_DIR=$(dirname $0)
|
||||||
source $TEST_DIR/fw_lib.sh
|
source $TEST_DIR/fw_lib.sh
|
||||||
|
|
||||||
check_mods
|
check_mods
|
||||||
|
check_setup
|
||||||
# CONFIG_FW_LOADER_USER_HELPER has a sysfs class under /sys/class/firmware/
|
verify_reqs
|
||||||
# These days most distros enable CONFIG_FW_LOADER_USER_HELPER but disable
|
setup_tmp_file
|
||||||
# CONFIG_FW_LOADER_USER_HELPER_FALLBACK. We use /sys/class/firmware/ as an
|
|
||||||
# indicator for CONFIG_FW_LOADER_USER_HELPER.
|
|
||||||
HAS_FW_LOADER_USER_HELPER=$(if [ -d /sys/class/firmware/ ]; then echo yes; else echo no; fi)
|
|
||||||
|
|
||||||
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
|
|
||||||
OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
|
|
||||||
fi
|
|
||||||
|
|
||||||
OLD_FWPATH=$(cat /sys/module/firmware_class/parameters/path)
|
|
||||||
|
|
||||||
FWPATH=$(mktemp -d)
|
|
||||||
FW="$FWPATH/test-firmware.bin"
|
|
||||||
|
|
||||||
test_finish()
|
|
||||||
{
|
|
||||||
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
|
|
||||||
echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
|
|
||||||
fi
|
|
||||||
if [ "$OLD_FWPATH" = "" ]; then
|
|
||||||
OLD_FWPATH=" "
|
|
||||||
fi
|
|
||||||
echo -n "$OLD_FWPATH" >/sys/module/firmware_class/parameters/path
|
|
||||||
rm -f "$FW"
|
|
||||||
rmdir "$FWPATH"
|
|
||||||
}
|
|
||||||
|
|
||||||
trap "test_finish" EXIT
|
trap "test_finish" EXIT
|
||||||
|
|
||||||
|
@ -46,14 +23,6 @@ if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
|
||||||
echo 1 >/sys/class/firmware/timeout
|
echo 1 >/sys/class/firmware/timeout
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Set the kernel search path.
|
|
||||||
echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path
|
|
||||||
|
|
||||||
# This is an unlikely real-world firmware content. :)
|
|
||||||
echo "ABCD0123" >"$FW"
|
|
||||||
|
|
||||||
NAME=$(basename "$FW")
|
|
||||||
|
|
||||||
if printf '\000' >"$DIR"/trigger_request 2> /dev/null; then
|
if printf '\000' >"$DIR"/trigger_request 2> /dev/null; then
|
||||||
echo "$0: empty filename should not succeed" >&2
|
echo "$0: empty filename should not succeed" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -43,6 +43,58 @@ check_mods()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check_setup()
|
||||||
|
{
|
||||||
|
HAS_FW_LOADER_USER_HELPER="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER=y)"
|
||||||
|
HAS_FW_LOADER_USER_HELPER_FALLBACK="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y)"
|
||||||
|
|
||||||
|
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
|
||||||
|
OLD_TIMEOUT="$(cat /sys/class/firmware/timeout)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
OLD_FWPATH="$(cat /sys/module/firmware_class/parameters/path)"
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_reqs()
|
||||||
|
{
|
||||||
|
if [ "$TEST_REQS_FW_SYSFS_FALLBACK" = "yes" ]; then
|
||||||
|
if [ ! "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
|
||||||
|
echo "usermode helper disabled so ignoring test"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_tmp_file()
|
||||||
|
{
|
||||||
|
FWPATH=$(mktemp -d)
|
||||||
|
FW="$FWPATH/test-firmware.bin"
|
||||||
|
echo "ABCD0123" >"$FW"
|
||||||
|
NAME=$(basename "$FW")
|
||||||
|
if [ "$TEST_REQS_FW_SET_CUSTOM_PATH" = "yes" ]; then
|
||||||
|
echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
test_finish()
|
||||||
|
{
|
||||||
|
if [ "$HAS_FW_LOADER_USER_HELPER" = "yes" ]; then
|
||||||
|
echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
|
||||||
|
fi
|
||||||
|
if [ "$OLD_FWPATH" = "" ]; then
|
||||||
|
OLD_FWPATH=" "
|
||||||
|
fi
|
||||||
|
if [ "$TEST_REQS_FW_SET_CUSTOM_PATH" = "yes" ]; then
|
||||||
|
echo -n "$OLD_FWPATH" >/sys/module/firmware_class/parameters/path
|
||||||
|
fi
|
||||||
|
if [ -f $FW ]; then
|
||||||
|
rm -f "$FW"
|
||||||
|
fi
|
||||||
|
if [ -d $FWPATH ]; then
|
||||||
|
rm -rf "$FWPATH"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
kconfig_has()
|
kconfig_has()
|
||||||
{
|
{
|
||||||
if [ -f $PROC_CONFIG ]; then
|
if [ -f $PROC_CONFIG ]; then
|
||||||
|
|
Loading…
Reference in New Issue