Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / tools / testing / selftests / firmware / fw_filesystem.sh
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
7
8 modprobe test_firmware
9
10 DIR=/sys/devices/virtual/misc/test_firmware
11
12 OLD_TIMEOUT=$(cat /sys/class/firmware/timeout)
13 OLD_FWPATH=$(cat /sys/module/firmware_class/parameters/path)
14
15 FWPATH=$(mktemp -d)
16 FW="$FWPATH/test-firmware.bin"
17
18 test_finish()
19 {
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"
24 }
25
26 trap "test_finish" EXIT
27
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
32
33 # This is an unlikely real-world firmware content. :)
34 echo "ABCD0123" >"$FW"
35
36 NAME=$(basename "$FW")
37
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"
45 fi
46
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
52 fi
53
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"
60 fi
61
62 exit 0