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

selftests: firmware: Add compressed firmware tests

This patch adds the test cases for checking compressed firmware load.
Two more cases are added to fw_filesystem.sh:
- Both a plain file and an xz file are present, and load the former
- Only an xz file is present, and load without '.xz' suffix

The tests are enabled only when CONFIG_FW_LOADER_COMPRESS is enabled
and xz program is installed.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Takashi Iwai and committed by
Greg Kroah-Hartman
108ae07c 82fd7a81

+71 -10
+63 -10
tools/testing/selftests/firmware/fw_filesystem.sh
··· 153 153 154 154 read_firmwares() 155 155 { 156 + if [ "$1" = "xzonly" ]; then 157 + fwfile="${FW}-orig" 158 + else 159 + fwfile="$FW" 160 + fi 156 161 for i in $(seq 0 3); do 157 162 config_set_read_fw_idx $i 158 163 # Verify the contents are what we expect. 159 164 # -Z required for now -- check for yourself, md5sum 160 165 # on $FW and DIR/read_firmware will yield the same. Even 161 166 # cmp agrees, so something is off. 162 - if ! diff -q -Z "$FW" $DIR/read_firmware 2>/dev/null ; then 167 + if ! diff -q -Z "$fwfile" $DIR/read_firmware 2>/dev/null ; then 163 168 echo "request #$i: firmware was not loaded" >&2 164 169 exit 1 165 170 fi ··· 251 246 252 247 test_batched_request_firmware() 253 248 { 254 - echo -n "Batched request_firmware() try #$1: " 249 + echo -n "Batched request_firmware() $2 try #$1: " 255 250 config_reset 256 251 config_trigger_sync 257 - read_firmwares 252 + read_firmwares $2 258 253 release_all_firmware 259 254 echo "OK" 260 255 } 261 256 262 257 test_batched_request_firmware_direct() 263 258 { 264 - echo -n "Batched request_firmware_direct() try #$1: " 259 + echo -n "Batched request_firmware_direct() $2 try #$1: " 265 260 config_reset 266 261 config_set_sync_direct 267 262 config_trigger_sync ··· 271 266 272 267 test_request_firmware_nowait_uevent() 273 268 { 274 - echo -n "Batched request_firmware_nowait(uevent=true) try #$1: " 269 + echo -n "Batched request_firmware_nowait(uevent=true) $2 try #$1: " 275 270 config_reset 276 271 config_trigger_async 277 272 release_all_firmware ··· 280 275 281 276 test_request_firmware_nowait_custom() 282 277 { 283 - echo -n "Batched request_firmware_nowait(uevent=false) try #$1: " 278 + echo -n "Batched request_firmware_nowait(uevent=false) $2 try #$1: " 284 279 config_reset 285 280 config_unset_uevent 286 281 RANDOM_FILE_PATH=$(setup_random_file) 287 282 RANDOM_FILE="$(basename $RANDOM_FILE_PATH)" 283 + if [ "$2" = "both" ]; then 284 + xz -9 -C crc32 -k $RANDOM_FILE_PATH 285 + elif [ "$2" = "xzonly" ]; then 286 + xz -9 -C crc32 $RANDOM_FILE_PATH 287 + fi 288 288 config_set_name $RANDOM_FILE 289 289 config_trigger_async 290 290 release_all_firmware ··· 304 294 echo 305 295 echo "Testing with the file present..." 306 296 for i in $(seq 1 5); do 307 - test_batched_request_firmware $i 297 + test_batched_request_firmware $i normal 308 298 done 309 299 310 300 for i in $(seq 1 5); do 311 - test_batched_request_firmware_direct $i 301 + test_batched_request_firmware_direct $i normal 312 302 done 313 303 314 304 for i in $(seq 1 5); do 315 - test_request_firmware_nowait_uevent $i 305 + test_request_firmware_nowait_uevent $i normal 316 306 done 317 307 318 308 for i in $(seq 1 5); do 319 - test_request_firmware_nowait_custom $i 309 + test_request_firmware_nowait_custom $i normal 320 310 done 321 311 322 312 # Test for file not found, errors are expected, the failure would be ··· 337 327 338 328 for i in $(seq 1 5); do 339 329 test_request_firmware_nowait_custom_nofile $i 330 + done 331 + 332 + test "$HAS_FW_LOADER_COMPRESS" != "yes" && exit 0 333 + 334 + # test with both files present 335 + xz -9 -C crc32 -k $FW 336 + config_set_name $NAME 337 + echo 338 + echo "Testing with both plain and xz files present..." 339 + for i in $(seq 1 5); do 340 + test_batched_request_firmware $i both 341 + done 342 + 343 + for i in $(seq 1 5); do 344 + test_batched_request_firmware_direct $i both 345 + done 346 + 347 + for i in $(seq 1 5); do 348 + test_request_firmware_nowait_uevent $i both 349 + done 350 + 351 + for i in $(seq 1 5); do 352 + test_request_firmware_nowait_custom $i both 353 + done 354 + 355 + # test with only xz file present 356 + mv "$FW" "${FW}-orig" 357 + echo 358 + echo "Testing with only xz file present..." 359 + for i in $(seq 1 5); do 360 + test_batched_request_firmware $i xzonly 361 + done 362 + 363 + for i in $(seq 1 5); do 364 + test_batched_request_firmware_direct $i xzonly 365 + done 366 + 367 + for i in $(seq 1 5); do 368 + test_request_firmware_nowait_uevent $i xzonly 369 + done 370 + 371 + for i in $(seq 1 5); do 372 + test_request_firmware_nowait_custom $i xzonly 340 373 done 341 374 342 375 exit 0
+7
tools/testing/selftests/firmware/fw_lib.sh
··· 50 50 { 51 51 HAS_FW_LOADER_USER_HELPER="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER=y)" 52 52 HAS_FW_LOADER_USER_HELPER_FALLBACK="$(kconfig_has CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y)" 53 + HAS_FW_LOADER_COMPRESS="$(kconfig_has CONFIG_FW_LOADER_COMPRESS=y)" 53 54 PROC_FW_IGNORE_SYSFS_FALLBACK="0" 54 55 PROC_FW_FORCE_SYSFS_FALLBACK="0" 55 56 ··· 85 84 fi 86 85 87 86 OLD_FWPATH="$(cat /sys/module/firmware_class/parameters/path)" 87 + 88 + if [ "$HAS_FW_LOADER_COMPRESS" = "yes" ]; then 89 + if ! which xz 2> /dev/null > /dev/null; then 90 + HAS_FW_LOADER_COMPRESS="" 91 + fi 92 + fi 88 93 } 89 94 90 95 verify_reqs()
+1
tools/testing/selftests/firmware/fw_run_tests.sh
··· 11 11 12 12 export HAS_FW_LOADER_USER_HELPER="" 13 13 export HAS_FW_LOADER_USER_HELPER_FALLBACK="" 14 + export HAS_FW_LOADER_COMPRESS="" 14 15 15 16 run_tests() 16 17 {