2 # SPDX-License-Identifier: GPL-2.0
3 # This validates the user-initiated fw upload mechanism of the firmware
4 # loader. It verifies that one or more firmware devices can be created
5 # for a device driver. It also verifies the data transfer, the
6 # cancellation support, and the error flows.
9 TEST_REQS_FW_UPLOAD
="yes"
10 TEST_DIR
=$
(dirname $0)
12 progress_states
="preparing transferring programming"
19 error_abort
="user-abort"
24 source $TEST_DIR/fw_lib.sh
30 trap "upload_finish" EXIT
33 local fwdevs
="$fwname1 $fwname2 $fwname3"
35 for name
in $fwdevs; do
36 if [ -e "$DIR/$name" ]; then
37 echo -n "$name" > "$DIR"/upload_unregister
46 echo 1 > "$DIR"/"$name"/loading
47 cat "$file" > "$DIR"/"$name"/data
48 echo 0 > "$DIR"/"$name"/loading
55 echo -n "$name" > "$DIR"/config_upload_name
56 if ! cmp "$file" "$DIR"/upload_read
> /dev
/null
2>&1; then
57 echo "$0: firmware compare for $name did not match" >&2
61 echo "$0: firmware upload for $name works" >&2
70 echo 1 > "$DIR"/"$name"/loading
71 echo -n "inject":"$status":"$error" > "$DIR"/"$name"/data
72 echo 0 > "$DIR"/"$name"/loading
82 while [ $i -lt 50 ]; do
83 status
=$
(cat "$DIR"/"$name"/status
)
84 if [ "$status" = "$expected" ]; then
91 echo "$0: Invalid status: Expected $expected, Actual $status" >&2
98 await_status
"$name" "idle"
105 local error
=$
(cat "$DIR"/"$name"/error
)
107 if [ "$error" != "$expected" ]; then
108 echo "Invalid error: Expected $expected, Actual $error" >&2
118 local file=$
(mktemp
-p /tmp uploadfwXXX.bin
)
120 dd if=/dev
/urandom of
="$file" bs
="$bs" count
="$count" > /dev
/null
2>&1
124 test_upload_cancel
() {
128 for status
in $progress_states; do
129 inject_error
$name $status $error_abort
130 if ! await_status
$name $status; then
134 echo 1 > "$DIR"/"$name"/cancel
136 if ! await_idle
$name; then
140 if ! expect_error
$name "$status":"$error_abort"; then
145 echo "$0: firmware upload cancellation works"
149 test_error_handling
() {
154 for status
in $progress_states; do
155 for error
in $errors; do
156 inject_error
$name $status $error
158 if ! await_idle
$name; then
162 if ! expect_error
$name "$status":"$error"; then
168 echo "$0: firmware upload error handling works"
173 local fw_too_big
=`random_firmware 512 5`
174 local expected
="preparing:invalid-file-size"
176 upload_fw
$name $fw_too_big
179 if ! await_idle
$name; then
183 if ! expect_error
$name $expected; then
187 echo "$0: oversized firmware error handling works"
190 echo -n "$fwname1" > "$DIR"/upload_register
191 echo -n "$fwname2" > "$DIR"/upload_register
192 echo -n "$fwname3" > "$DIR"/upload_register
194 test_upload_cancel
$fwname1
195 test_error_handling
$fwname1
196 test_fw_too_big
$fwname1
198 fw_file1
=`random_firmware 512 4`
199 fw_file2
=`random_firmware 512 3`
200 fw_file3
=`random_firmware 512 2`
202 upload_fw
$fwname1 $fw_file1
203 upload_fw
$fwname2 $fw_file2
204 upload_fw
$fwname3 $fw_file3
206 verify_fw
${fwname1} ${fw_file1}
207 verify_fw
${fwname2} ${fw_file2}
208 verify_fw
${fwname3} ${fw_file3}
210 echo -n "$fwname1" > "$DIR"/upload_unregister
211 echo -n "$fwname2" > "$DIR"/upload_unregister
212 echo -n "$fwname3" > "$DIR"/upload_unregister