Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 1 | #!/system/bin/sh |
| 2 | |
| 3 | # TODO(victorhsieh): Create a standard Android test for continuous integration. |
| 4 | # |
| 5 | # How to run this test: |
| 6 | # |
| 7 | # Setup: |
| 8 | # $ adb push testdata/input.4m* /data/local/tmp |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame^] | 9 | # $ adb push tools/device-test.sh /data/local/tmp/ |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 10 | # |
| 11 | # Shell 1: |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame^] | 12 | # $ adb shell /data/local/tmp/device-test.sh --run-fd-server |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 13 | # |
| 14 | # Shell 2: |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame^] | 15 | # $ adb shell /data/local/tmp/device-test.sh |
| 16 | |
| 17 | cd /data/local/tmp |
| 18 | cat /dev/null > output |
| 19 | |
| 20 | if [[ $1 == "--run-fd-server" ]]; then |
| 21 | exec 9</system/bin/sh 8<input.4m 7<input.4m.merkle_dump 6<input.4m \ |
| 22 | 5<input.4m.merkle_dump.bad 4<input.4m.fsv_sig 3<>output \ |
| 23 | fd_server --ro-fds 9 --ro-fds 8:7:4 --ro-fds 6:5:4 --rw-fds 3 |
| 24 | fi |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 25 | |
| 26 | # Run with -u to enter new namespace. |
| 27 | if [[ $1 == "-u" ]]; then |
| 28 | exec unshare -mUr $0 |
| 29 | fi |
| 30 | |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 31 | MOUNTPOINT=/data/local/tmp/authfs |
| 32 | trap "umount ${MOUNTPOINT}" EXIT; |
| 33 | mkdir -p ${MOUNTPOINT} |
| 34 | |
| 35 | size=$(du -b /system/bin/sh |awk '{print $1}') |
| 36 | size2=$(du -b input.4m |awk '{print $1}') |
| 37 | |
| 38 | echo "Mounting authfs in background ..." |
| 39 | |
| 40 | # TODO(170494765): Replace /dev/null (currently not used) with a valid |
| 41 | # certificate. |
| 42 | authfs \ |
| 43 | ${MOUNTPOINT} \ |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 44 | --local-ro-file 2:input.4m:input.4m.merkle_dump:input.4m.fsv_sig:/dev/null \ |
| 45 | --local-ro-file 3:input.4k1:input.4k1.merkle_dump:input.4k1.fsv_sig:/dev/null \ |
| 46 | --local-ro-file 4:input.4k:input.4k.merkle_dump:input.4k.fsv_sig:/dev/null \ |
| 47 | --local-ro-file-unverified 5:/system/bin/sh \ |
| 48 | --remote-ro-file-unverified 6:9:${size} \ |
| 49 | --remote-ro-file 7:8:${size2}:/dev/null \ |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame^] | 50 | --remote-ro-file 8:6:${size2}:/dev/null \ |
| 51 | --remote-new-rw-file 9:3 \ |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 52 | & |
| 53 | sleep 0.1 |
| 54 | |
| 55 | echo "Accessing files in authfs ..." |
| 56 | md5sum ${MOUNTPOINT}/2 input.4m |
| 57 | echo |
| 58 | md5sum ${MOUNTPOINT}/3 input.4k1 |
| 59 | echo |
| 60 | md5sum ${MOUNTPOINT}/4 input.4k |
| 61 | echo |
| 62 | md5sum ${MOUNTPOINT}/5 /system/bin/sh |
| 63 | md5sum ${MOUNTPOINT}/6 |
| 64 | echo |
| 65 | md5sum ${MOUNTPOINT}/7 input.4m |
| 66 | echo |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame^] | 67 | cat input.4m > ${MOUNTPOINT}/9 |
| 68 | md5sum ${MOUNTPOINT}/9 output |
| 69 | echo |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 70 | echo Checking error cases... |
| 71 | cat /data/local/tmp/authfs/8 2>&1 |grep -q ": I/O error" || echo "Failed to catch the problem" |
| 72 | echo "Done!" |