[PATCH] selftests: firmware: compare uploaded firmware through a pipe

From: Danish Khateeb

Date: Wed Oct 28 2026 - 17:11:06 EST


verify_fw() checks the data read back from the upload_read sysfs file
with cmp, sending its output to /dev/null. When the output goes to
/dev/null, GNU cmp only needs the exit status and treats regular files
of different sizes as different without reading them. Sysfs attributes
report a size of 4096, so the check fails although the data matches, and
the test stops at the first upload:

./fw_upload.sh: firmware compare for fw1 did not match

Feed the sysfs file to cmp through a pipe, so that its contents are
compared.

Fixes: a37ddddd8603 ("selftests: firmware: Add firmware upload selftests")
Signed-off-by: Danish Khateeb <danishkhateeb03@xxxxxxxxx>
---

Notes:
Seen with GNU diffutils 3.12. Tested under virtme-ng on mainline
62c457528529 with CONFIG_TEST_FIRMWARE and CONFIG_FW_UPLOAD: without
this patch fw_upload.sh fails at the first compare, with it the test
passes in 3 of 3 runs. A copy of a sysfs file that differs in one byte
is still reported as different.

An LLM was used to help with this patch.

tools/testing/selftests/firmware/fw_upload.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/firmware/fw_upload.sh b/tools/testing/selftests/firmware/fw_upload.sh
index c7a6f06c9adb..1b234632b611 100755
--- a/tools/testing/selftests/firmware/fw_upload.sh
+++ b/tools/testing/selftests/firmware/fw_upload.sh
@@ -53,7 +53,7 @@ verify_fw() {
local file="$2"

echo -n "$name" > "$DIR"/config_upload_name
- if ! cmp "$file" "$DIR"/upload_read > /dev/null 2>&1; then
+ if ! cat "$DIR"/upload_read | cmp "$file" - > /dev/null 2>&1; then
echo "$0: firmware compare for $name did not match" >&2
exit 1
fi

base-commit: 62c457528529cdcfa32bc52b331ceca10f3937b6
--
2.56.0