hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/tools/testing/selftests/firmware/fw_filesystem.sh
....@@ -86,6 +86,29 @@
8686 fi
8787 fi
8888
89
+# Try platform (EFI embedded fw) loading too
90
+if [ ! -e "$DIR"/trigger_request_platform ]; then
91
+ echo "$0: firmware loading: platform trigger not present, ignoring test" >&2
92
+else
93
+ if printf '\000' >"$DIR"/trigger_request_platform 2> /dev/null; then
94
+ echo "$0: empty filename should not succeed (platform)" >&2
95
+ exit 1
96
+ fi
97
+
98
+ # Note we echo a non-existing name, since files on the file-system
99
+ # are preferred over firmware embedded inside the platform's firmware
100
+ # The test adds a fake entry with the requested name to the platform's
101
+ # fw list, so the name does not matter as long as it does not exist
102
+ if ! echo -n "nope-$NAME" >"$DIR"/trigger_request_platform ; then
103
+ echo "$0: could not trigger request platform" >&2
104
+ exit 1
105
+ fi
106
+
107
+ # The test verifies itself that the loaded firmware contents matches
108
+ # the contents for the fake platform fw entry it added.
109
+ echo "$0: platform loading works"
110
+fi
111
+
89112 ### Batched requests tests
90113 test_config_present()
91114 {
....@@ -114,6 +137,36 @@
114137 config_set_name()
115138 {
116139 echo -n $1 > $DIR/config_name
140
+}
141
+
142
+config_set_into_buf()
143
+{
144
+ echo 1 > $DIR/config_into_buf
145
+}
146
+
147
+config_unset_into_buf()
148
+{
149
+ echo 0 > $DIR/config_into_buf
150
+}
151
+
152
+config_set_buf_size()
153
+{
154
+ echo $1 > $DIR/config_buf_size
155
+}
156
+
157
+config_set_file_offset()
158
+{
159
+ echo $1 > $DIR/config_file_offset
160
+}
161
+
162
+config_set_partial()
163
+{
164
+ echo 1 > $DIR/config_partial
165
+}
166
+
167
+config_unset_partial()
168
+{
169
+ echo 0 > $DIR/config_partial
117170 }
118171
119172 config_set_sync_direct()
....@@ -153,14 +206,51 @@
153206
154207 read_firmwares()
155208 {
209
+ if [ "$(cat $DIR/config_into_buf)" == "1" ]; then
210
+ fwfile="$FW_INTO_BUF"
211
+ else
212
+ fwfile="$FW"
213
+ fi
214
+ if [ "$1" = "xzonly" ]; then
215
+ fwfile="${fwfile}-orig"
216
+ fi
156217 for i in $(seq 0 3); do
157218 config_set_read_fw_idx $i
158219 # Verify the contents are what we expect.
159220 # -Z required for now -- check for yourself, md5sum
160221 # on $FW and DIR/read_firmware will yield the same. Even
161222 # cmp agrees, so something is off.
162
- if ! diff -q -Z "$FW" $DIR/read_firmware 2>/dev/null ; then
223
+ if ! diff -q -Z "$fwfile" $DIR/read_firmware 2>/dev/null ; then
163224 echo "request #$i: firmware was not loaded" >&2
225
+ exit 1
226
+ fi
227
+ done
228
+}
229
+
230
+read_partial_firmwares()
231
+{
232
+ if [ "$(cat $DIR/config_into_buf)" == "1" ]; then
233
+ fwfile="${FW_INTO_BUF}"
234
+ else
235
+ fwfile="${FW}"
236
+ fi
237
+
238
+ if [ "$1" = "xzonly" ]; then
239
+ fwfile="${fwfile}-orig"
240
+ fi
241
+
242
+ # Strip fwfile down to match partial offset and length
243
+ partial_data="$(cat $fwfile)"
244
+ partial_data="${partial_data:$2:$3}"
245
+
246
+ for i in $(seq 0 3); do
247
+ config_set_read_fw_idx $i
248
+
249
+ read_firmware="$(cat $DIR/read_firmware)"
250
+
251
+ # Verify the contents are what we expect.
252
+ if [ $read_firmware != $partial_data ]; then
253
+ echo "request #$i: partial firmware was not loaded" >&2
164254 exit 1
165255 fi
166256 done
....@@ -183,6 +273,33 @@
183273 echo -n "Batched request_firmware() nofile try #$1: "
184274 config_reset
185275 config_set_name nope-test-firmware.bin
276
+ config_trigger_sync
277
+ read_firmwares_expect_nofile
278
+ release_all_firmware
279
+ echo "OK"
280
+}
281
+
282
+test_batched_request_firmware_into_buf_nofile()
283
+{
284
+ echo -n "Batched request_firmware_into_buf() nofile try #$1: "
285
+ config_reset
286
+ config_set_name nope-test-firmware.bin
287
+ config_set_into_buf
288
+ config_trigger_sync
289
+ read_firmwares_expect_nofile
290
+ release_all_firmware
291
+ echo "OK"
292
+}
293
+
294
+test_request_partial_firmware_into_buf_nofile()
295
+{
296
+ echo -n "Test request_partial_firmware_into_buf() off=$1 size=$2 nofile: "
297
+ config_reset
298
+ config_set_name nope-test-firmware.bin
299
+ config_set_into_buf
300
+ config_set_partial
301
+ config_set_buf_size $2
302
+ config_set_file_offset $1
186303 config_trigger_sync
187304 read_firmwares_expect_nofile
188305 release_all_firmware
....@@ -246,17 +363,29 @@
246363
247364 test_batched_request_firmware()
248365 {
249
- echo -n "Batched request_firmware() try #$1: "
366
+ echo -n "Batched request_firmware() $2 try #$1: "
250367 config_reset
251368 config_trigger_sync
252
- read_firmwares
369
+ read_firmwares $2
370
+ release_all_firmware
371
+ echo "OK"
372
+}
373
+
374
+test_batched_request_firmware_into_buf()
375
+{
376
+ echo -n "Batched request_firmware_into_buf() $2 try #$1: "
377
+ config_reset
378
+ config_set_name $TEST_FIRMWARE_INTO_BUF_FILENAME
379
+ config_set_into_buf
380
+ config_trigger_sync
381
+ read_firmwares $2
253382 release_all_firmware
254383 echo "OK"
255384 }
256385
257386 test_batched_request_firmware_direct()
258387 {
259
- echo -n "Batched request_firmware_direct() try #$1: "
388
+ echo -n "Batched request_firmware_direct() $2 try #$1: "
260389 config_reset
261390 config_set_sync_direct
262391 config_trigger_sync
....@@ -266,7 +395,7 @@
266395
267396 test_request_firmware_nowait_uevent()
268397 {
269
- echo -n "Batched request_firmware_nowait(uevent=true) try #$1: "
398
+ echo -n "Batched request_firmware_nowait(uevent=true) $2 try #$1: "
270399 config_reset
271400 config_trigger_async
272401 release_all_firmware
....@@ -275,13 +404,33 @@
275404
276405 test_request_firmware_nowait_custom()
277406 {
278
- echo -n "Batched request_firmware_nowait(uevent=false) try #$1: "
407
+ echo -n "Batched request_firmware_nowait(uevent=false) $2 try #$1: "
279408 config_reset
280409 config_unset_uevent
281410 RANDOM_FILE_PATH=$(setup_random_file)
282411 RANDOM_FILE="$(basename $RANDOM_FILE_PATH)"
412
+ if [ "$2" = "both" ]; then
413
+ xz -9 -C crc32 -k $RANDOM_FILE_PATH
414
+ elif [ "$2" = "xzonly" ]; then
415
+ xz -9 -C crc32 $RANDOM_FILE_PATH
416
+ fi
283417 config_set_name $RANDOM_FILE
284418 config_trigger_async
419
+ release_all_firmware
420
+ echo "OK"
421
+}
422
+
423
+test_request_partial_firmware_into_buf()
424
+{
425
+ echo -n "Test request_partial_firmware_into_buf() off=$1 size=$2: "
426
+ config_reset
427
+ config_set_name $TEST_FIRMWARE_INTO_BUF_FILENAME
428
+ config_set_into_buf
429
+ config_set_partial
430
+ config_set_buf_size $2
431
+ config_set_file_offset $1
432
+ config_trigger_sync
433
+ read_partial_firmwares normal $1 $2
285434 release_all_firmware
286435 echo "OK"
287436 }
....@@ -294,20 +443,30 @@
294443 echo
295444 echo "Testing with the file present..."
296445 for i in $(seq 1 5); do
297
- test_batched_request_firmware $i
446
+ test_batched_request_firmware $i normal
298447 done
299448
300449 for i in $(seq 1 5); do
301
- test_batched_request_firmware_direct $i
450
+ test_batched_request_firmware_into_buf $i normal
302451 done
303452
304453 for i in $(seq 1 5); do
305
- test_request_firmware_nowait_uevent $i
454
+ test_batched_request_firmware_direct $i normal
306455 done
307456
308457 for i in $(seq 1 5); do
309
- test_request_firmware_nowait_custom $i
458
+ test_request_firmware_nowait_uevent $i normal
310459 done
460
+
461
+for i in $(seq 1 5); do
462
+ test_request_firmware_nowait_custom $i normal
463
+done
464
+
465
+# Partial loads cannot use fallback, so do not repeat tests.
466
+test_request_partial_firmware_into_buf 0 10
467
+test_request_partial_firmware_into_buf 0 5
468
+test_request_partial_firmware_into_buf 1 6
469
+test_request_partial_firmware_into_buf 2 10
311470
312471 # Test for file not found, errors are expected, the failure would be
313472 # a hung task, which would require a hard reset.
....@@ -315,6 +474,10 @@
315474 echo "Testing with the file missing..."
316475 for i in $(seq 1 5); do
317476 test_batched_request_firmware_nofile $i
477
+done
478
+
479
+for i in $(seq 1 5); do
480
+ test_batched_request_firmware_into_buf_nofile $i
318481 done
319482
320483 for i in $(seq 1 5); do
....@@ -329,4 +492,61 @@
329492 test_request_firmware_nowait_custom_nofile $i
330493 done
331494
495
+# Partial loads cannot use fallback, so do not repeat tests.
496
+test_request_partial_firmware_into_buf_nofile 0 10
497
+test_request_partial_firmware_into_buf_nofile 0 5
498
+test_request_partial_firmware_into_buf_nofile 1 6
499
+test_request_partial_firmware_into_buf_nofile 2 10
500
+
501
+test "$HAS_FW_LOADER_COMPRESS" != "yes" && exit 0
502
+
503
+# test with both files present
504
+xz -9 -C crc32 -k $FW
505
+config_set_name $NAME
506
+echo
507
+echo "Testing with both plain and xz files present..."
508
+for i in $(seq 1 5); do
509
+ test_batched_request_firmware $i both
510
+done
511
+
512
+for i in $(seq 1 5); do
513
+ test_batched_request_firmware_into_buf $i both
514
+done
515
+
516
+for i in $(seq 1 5); do
517
+ test_batched_request_firmware_direct $i both
518
+done
519
+
520
+for i in $(seq 1 5); do
521
+ test_request_firmware_nowait_uevent $i both
522
+done
523
+
524
+for i in $(seq 1 5); do
525
+ test_request_firmware_nowait_custom $i both
526
+done
527
+
528
+# test with only xz file present
529
+mv "$FW" "${FW}-orig"
530
+echo
531
+echo "Testing with only xz file present..."
532
+for i in $(seq 1 5); do
533
+ test_batched_request_firmware $i xzonly
534
+done
535
+
536
+for i in $(seq 1 5); do
537
+ test_batched_request_firmware_into_buf $i xzonly
538
+done
539
+
540
+for i in $(seq 1 5); do
541
+ test_batched_request_firmware_direct $i xzonly
542
+done
543
+
544
+for i in $(seq 1 5); do
545
+ test_request_firmware_nowait_uevent $i xzonly
546
+done
547
+
548
+for i in $(seq 1 5); do
549
+ test_request_firmware_nowait_custom $i xzonly
550
+done
551
+
332552 exit 0