Merge tag 'fixes-for-v4.0-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/balbi...
[linux/fpc-iii.git] / tools / testing / selftests / firmware / fw_filesystem.sh
blob3fc6c10c2479c7ce4a61ebd197e84d9c917db198
1 #!/bin/sh
2 # This validates that the kernel will load firmware out of its list of
3 # firmware locations on disk. Since the user helper does similar work,
4 # we reset the custom load directory to a location the user helper doesn't
5 # know so we can be sure we're not accidentally testing the user helper.
6 set -e
8 modprobe test_firmware
10 DIR=/sys/devices/virtual/misc/test_firmware
12 OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
13 OLD_FWPATH=$(cat /sys/module/firmware_class/parameters/path)
15 FWPATH=$(mktemp -d)
16 FW="$FWPATH/test-firmware.bin"
18 test_finish()
20 echo "$OLD_TIMEOUT" >/sys/class/firmware/timeout
21 echo -n "$OLD_PATH" >/sys/module/firmware_class/parameters/path
22 rm -f "$FW"
23 rmdir "$FWPATH"
26 trap "test_finish" EXIT
28 # Turn down the timeout so failures don't take so long.
29 echo 1 >/sys/class/firmware/timeout
30 # Set the kernel search path.
31 echo -n "$FWPATH" >/sys/module/firmware_class/parameters/path
33 # This is an unlikely real-world firmware content. :)
34 echo "ABCD0123" >"$FW"
36 NAME=$(basename "$FW")
38 # Request a firmware that doesn't exist, it should fail.
39 echo -n "nope-$NAME" >"$DIR"/trigger_request
40 if diff -q "$FW" /dev/test_firmware >/dev/null ; then
41 echo "$0: firmware was not expected to match" >&2
42 exit 1
43 else
44 echo "$0: timeout works"
47 # This should succeed via kernel load or will fail after 1 second after
48 # being handed over to the user helper, which won't find the fw either.
49 if ! echo -n "$NAME" >"$DIR"/trigger_request ; then
50 echo "$0: could not trigger request" >&2
51 exit 1
54 # Verify the contents are what we expect.
55 if ! diff -q "$FW" /dev/test_firmware >/dev/null ; then
56 echo "$0: firmware was not loaded" >&2
57 exit 1
58 else
59 echo "$0: filesystem loading works"
62 exit 0