blob: 82aa6bc18621162c0b6ff81c2b46d9b6eb25fbf3 [file] [log] [blame]
Victor Hsiehf01f3232020-12-11 13:31:31 -08001#!/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 Hsieh6a47e7f2021-03-03 15:53:49 -08009# $ adb push tools/device-test.sh /data/local/tmp/
Victor Hsiehf01f3232020-12-11 13:31:31 -080010#
11# Shell 1:
Victor Hsieh6a47e7f2021-03-03 15:53:49 -080012# $ adb shell /data/local/tmp/device-test.sh --run-fd-server
Victor Hsiehf01f3232020-12-11 13:31:31 -080013#
14# Shell 2:
Victor Hsieh6a47e7f2021-03-03 15:53:49 -080015# $ adb shell /data/local/tmp/device-test.sh
16
17cd /data/local/tmp
18cat /dev/null > output
19
20if [[ $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
24fi
Victor Hsiehf01f3232020-12-11 13:31:31 -080025
26# Run with -u to enter new namespace.
27if [[ $1 == "-u" ]]; then
28 exec unshare -mUr $0
29fi
30
Victor Hsiehf01f3232020-12-11 13:31:31 -080031MOUNTPOINT=/data/local/tmp/authfs
32trap "umount ${MOUNTPOINT}" EXIT;
33mkdir -p ${MOUNTPOINT}
34
35size=$(du -b /system/bin/sh |awk '{print $1}')
36size2=$(du -b input.4m |awk '{print $1}')
37
38echo "Mounting authfs in background ..."
39
40# TODO(170494765): Replace /dev/null (currently not used) with a valid
41# certificate.
42authfs \
43 ${MOUNTPOINT} \
Victor Hsieh09e26262021-03-03 16:00:55 -080044 --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 Hsieh6a47e7f2021-03-03 15:53:49 -080050 --remote-ro-file 8:6:${size2}:/dev/null \
51 --remote-new-rw-file 9:3 \
Victor Hsiehf01f3232020-12-11 13:31:31 -080052 &
53sleep 0.1
54
55echo "Accessing files in authfs ..."
56md5sum ${MOUNTPOINT}/2 input.4m
57echo
58md5sum ${MOUNTPOINT}/3 input.4k1
59echo
60md5sum ${MOUNTPOINT}/4 input.4k
61echo
62md5sum ${MOUNTPOINT}/5 /system/bin/sh
63md5sum ${MOUNTPOINT}/6
64echo
65md5sum ${MOUNTPOINT}/7 input.4m
66echo
Victor Hsieh6a47e7f2021-03-03 15:53:49 -080067cat input.4m > ${MOUNTPOINT}/9
68md5sum ${MOUNTPOINT}/9 output
69echo
Victor Hsiehf01f3232020-12-11 13:31:31 -080070echo Checking error cases...
71cat /data/local/tmp/authfs/8 2>&1 |grep -q ": I/O error" || echo "Failed to catch the problem"
72echo "Done!"