Commit bc67cac1 authored by Takashi Iwai's avatar Takashi Iwai Committed by Greg Kroah-Hartman

selftests: firmware: Add ZSTD compressed file tests

It's similar like XZ compressed files.  For the simplicity, both XZ
and ZSTD tests are done in a single function.  The format is specified
via $COMPRESS_FORMAT and the compression function is pre-defined.

Link: https://lore.kernel.org/r/20210127154939.13288-5-tiwai@suse.deSigned-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/r/20220421152908.4718-6-tiwai@suse.deSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent f18b45ff
...@@ -12,6 +12,7 @@ TEST_DIR=$(dirname $0) ...@@ -12,6 +12,7 @@ TEST_DIR=$(dirname $0)
source $TEST_DIR/fw_lib.sh source $TEST_DIR/fw_lib.sh
RUN_XZ="xz -C crc32 --lzma2=dict=2MiB" RUN_XZ="xz -C crc32 --lzma2=dict=2MiB"
RUN_ZSTD="zstd -q"
check_mods check_mods
check_setup check_setup
...@@ -213,7 +214,7 @@ read_firmwares() ...@@ -213,7 +214,7 @@ read_firmwares()
else else
fwfile="$FW" fwfile="$FW"
fi fi
if [ "$1" = "xzonly" ]; then if [ "$1" = "componly" ]; then
fwfile="${fwfile}-orig" fwfile="${fwfile}-orig"
fi fi
for i in $(seq 0 3); do for i in $(seq 0 3); do
...@@ -237,7 +238,7 @@ read_partial_firmwares() ...@@ -237,7 +238,7 @@ read_partial_firmwares()
fwfile="${FW}" fwfile="${FW}"
fi fi
if [ "$1" = "xzonly" ]; then if [ "$1" = "componly" ]; then
fwfile="${fwfile}-orig" fwfile="${fwfile}-orig"
fi fi
...@@ -411,10 +412,8 @@ test_request_firmware_nowait_custom() ...@@ -411,10 +412,8 @@ test_request_firmware_nowait_custom()
config_unset_uevent config_unset_uevent
RANDOM_FILE_PATH=$(setup_random_file) RANDOM_FILE_PATH=$(setup_random_file)
RANDOM_FILE="$(basename $RANDOM_FILE_PATH)" RANDOM_FILE="$(basename $RANDOM_FILE_PATH)"
if [ "$2" = "both" ]; then if [ -n "$2" -a "$2" != "normal" ]; then
$RUN_XZ -k $RANDOM_FILE_PATH compress_"$2"_"$COMPRESS_FORMAT" $RANDOM_FILE_PATH
elif [ "$2" = "xzonly" ]; then
$RUN_XZ $RANDOM_FILE_PATH
fi fi
config_set_name $RANDOM_FILE config_set_name $RANDOM_FILE
config_trigger_async config_trigger_async
...@@ -490,21 +489,58 @@ test_request_partial_firmware_into_buf_nofile 0 5 ...@@ -490,21 +489,58 @@ test_request_partial_firmware_into_buf_nofile 0 5
test_request_partial_firmware_into_buf_nofile 1 6 test_request_partial_firmware_into_buf_nofile 1 6
test_request_partial_firmware_into_buf_nofile 2 10 test_request_partial_firmware_into_buf_nofile 2 10
test "$HAS_FW_LOADER_COMPRESS" != "yes" && exit 0 test_request_firmware_compressed ()
{
export COMPRESS_FORMAT="$1"
# test with both files present # test with both files present
$RUN_XZ -k $FW compress_both_"$COMPRESS_FORMAT" $FW
$RUN_XZ -k $FW_INTO_BUF compress_both_"$COMPRESS_FORMAT" $FW_INTO_BUF
config_set_name $NAME
echo
echo "Testing with both plain and xz files present..."
do_tests both
# test with only xz file present config_set_name $NAME
mv "$FW" "${FW}-orig" echo
mv "$FW_INTO_BUF" "${FW_INTO_BUF}-orig" echo "Testing with both plain and $COMPRESS_FORMAT files present..."
echo do_tests both
echo "Testing with only xz file present..."
do_tests xzonly # test with only compressed file present
mv "$FW" "${FW}-orig"
mv "$FW_INTO_BUF" "${FW_INTO_BUF}-orig"
config_set_name $NAME
echo
echo "Testing with only $COMPRESS_FORMAT file present..."
do_tests componly
mv "${FW}-orig" "$FW"
mv "${FW_INTO_BUF}-orig" "$FW_INTO_BUF"
}
compress_both_XZ ()
{
$RUN_XZ -k "$@"
}
compress_componly_XZ ()
{
$RUN_XZ "$@"
}
compress_both_ZSTD ()
{
$RUN_ZSTD -k "$@"
}
compress_componly_ZSTD ()
{
$RUN_ZSTD --rm "$@"
}
if test "$HAS_FW_LOADER_COMPRESS_XZ" = "yes"; then
test_request_firmware_compressed XZ
fi
if test "$HAS_FW_LOADER_COMPRESS_ZSTD" = "yes"; then
test_request_firmware_compressed ZSTD
fi
exit 0 exit 0
...@@ -62,7 +62,8 @@ check_setup() ...@@ -62,7 +62,8 @@ check_setup()
{ {
HAS_FW_LOADER_USER_HELPER="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER=y)" 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)" HAS_FW_LOADER_USER_HELPER_FALLBACK="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y)"
HAS_FW_LOADER_COMPRESS="$(kconfig_has CONFIG_FW_LOADER_COMPRESS=y)" HAS_FW_LOADER_COMPRESS_XZ="$(kconfig_has CONFIG_FW_LOADER_COMPRESS_XZ=y)"
HAS_FW_LOADER_COMPRESS_ZSTD="$(kconfig_has CONFIG_FW_LOADER_COMPRESS_ZSTD=y)"
PROC_FW_IGNORE_SYSFS_FALLBACK="0" PROC_FW_IGNORE_SYSFS_FALLBACK="0"
PROC_FW_FORCE_SYSFS_FALLBACK="0" PROC_FW_FORCE_SYSFS_FALLBACK="0"
...@@ -98,9 +99,14 @@ check_setup() ...@@ -98,9 +99,14 @@ check_setup()
OLD_FWPATH="$(cat /sys/module/firmware_class/parameters/path)" OLD_FWPATH="$(cat /sys/module/firmware_class/parameters/path)"
if [ "$HAS_FW_LOADER_COMPRESS" = "yes" ]; then if [ "$HAS_FW_LOADER_COMPRESS_XZ" = "yes" ]; then
if ! which xz 2> /dev/null > /dev/null; then if ! which xz 2> /dev/null > /dev/null; then
HAS_FW_LOADER_COMPRESS="" HAS_FW_LOADER_COMPRESS_XZ=""
fi
fi
if [ "$HAS_FW_LOADER_COMPRESS_ZSTD" = "yes" ]; then
if ! which zstd 2> /dev/null > /dev/null; then
HAS_FW_LOADER_COMPRESS_ZSTD=""
fi fi
fi fi
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment