Inseob Kim | fd922cf | 2021-10-18 19:49:00 +0900 | [diff] [blame] | 1 | # This script runs 256 MB file benchmark, both on host and on authfs. |
| 2 | # Usage: after connecting the device with adb, run: |
| 3 | # $ packages/modules/Virtualization/tests/benchmark/benchmark_example.sh <target> (e.g. aosp_oriole_pkvm-userdebug) |
| 4 | |
| 5 | set -e |
| 6 | |
| 7 | # Prerequisite: we need root to flush disk cache. |
| 8 | adb root |
| 9 | |
| 10 | # 1. Build needed artifacts, and install it to device |
| 11 | source build/make/rbesetup.sh |
| 12 | lunch $1 |
Inseob Kim | 6715ca7 | 2022-01-12 15:48:50 +0900 | [diff] [blame^] | 13 | m fs_benchmark MicrodroidFilesystemBenchmarkApp fsverity fsverity_metadata_generator |
Inseob Kim | fd922cf | 2021-10-18 19:49:00 +0900 | [diff] [blame] | 14 | adb push $OUT/system/bin/fs_benchmark /data/local/tmp |
| 15 | adb install $OUT/system/app/MicrodroidFilesystemBenchmarkApp/MicrodroidFilesystemBenchmarkApp.apk |
| 16 | |
| 17 | # 2. Generate testcases |
| 18 | # /data/local/tmp/testcase: 256 MB, signed by fsverity. |
| 19 | # /data/local/tmp/testcase2: empty file, used for authfs write test. |
| 20 | adb shell 'rm -rf /data/local/tmp/virt /data/local/tmp/testcase*' |
| 21 | adb shell 'mkdir -p /data/local/tmp/virt' |
| 22 | dd if=/dev/zero of=/tmp/testcase bs=1048576 count=256 |
Inseob Kim | 6715ca7 | 2022-01-12 15:48:50 +0900 | [diff] [blame^] | 23 | fsverity_metadata_generator --fsverity-path $(which fsverity) --signature none --hash-alg sha256 --out /tmp/testcase.fsv_meta /tmp/testcase |
Inseob Kim | fd922cf | 2021-10-18 19:49:00 +0900 | [diff] [blame] | 24 | adb shell 'dd if=/dev/zero of=/data/local/tmp/testcase bs=1048576 count=256' |
Inseob Kim | 6715ca7 | 2022-01-12 15:48:50 +0900 | [diff] [blame^] | 25 | adb push /tmp/testcase.fsv_meta /data/local/tmp |
Inseob Kim | fd922cf | 2021-10-18 19:49:00 +0900 | [diff] [blame] | 26 | |
| 27 | # 3. Run fd_server from host |
Inseob Kim | 6715ca7 | 2022-01-12 15:48:50 +0900 | [diff] [blame^] | 28 | adb shell 'exec 3</data/local/tmp/testcase 4</data/local/tmp/testcase.fsv_meta 6</data/local/tmp/testcase 7<>/data/local/tmp/testcase2 /apex/com.android.virt/bin/fd_server --ro-fds 3:4 --ro-fds 6 --rw-fds 7' & |
Inseob Kim | fd922cf | 2021-10-18 19:49:00 +0900 | [diff] [blame] | 29 | |
| 30 | # 4. Run VM and get the CID |
| 31 | result=$(adb shell "/apex/com.android.virt/bin/vm run-app --debug full --daemonize --log /data/local/tmp/virt/log.txt $(adb shell pm path com.android.microdroid.benchmark | cut -d':' -f2) /data/local/tmp/virt/MicrodroidFilesystemBenchmarkApp.apk.idsig /data/local/tmp/virt/instance.img assets/vm_config.json") |
| 32 | cid=$(echo $result | grep -P "with CID \d+" --only-matching --color=none | cut -d' ' -f3) |
| 33 | echo "CID IS $cid" |
| 34 | |
| 35 | # 5. Run host tests |
| 36 | echo "Running host read/write test..." |
| 37 | adb shell 'dd if=/dev/zero of=/data/local/tmp/testcase_host bs=1048576 count=256' |
| 38 | adb shell '/data/local/tmp/fs_benchmark /data/local/tmp/testcase_host 268435456 both 5' |
| 39 | |
| 40 | # 6. Connect to the VM |
| 41 | # We are cheating here. The VM is expected to finish booting, while the host tests are running. |
| 42 | adb forward tcp:8000 vsock:$cid:5555 |
| 43 | adb connect localhost:8000 |
| 44 | adb -s localhost:8000 root |
| 45 | sleep 10 |
| 46 | |
| 47 | # 7. Install artifacts and run authfs |
| 48 | adb -s localhost:8000 push $OUT/system/bin/fs_benchmark /data/local/tmp |
| 49 | adb -s localhost:8000 shell "mkdir -p /data/local/tmp/authfs" |
Inseob Kim | 6715ca7 | 2022-01-12 15:48:50 +0900 | [diff] [blame^] | 50 | adb -s localhost:8000 shell "/system/bin/authfs /data/local/tmp/authfs --cid 2 --remote-ro-file 3:sha256-$(fsverity digest /tmp/testcase --hash-alg sha256 --compact) --remote-ro-file-unverified 6 --remote-new-rw-file 7" & |
Inseob Kim | fd922cf | 2021-10-18 19:49:00 +0900 | [diff] [blame] | 51 | |
| 52 | # 8. Run guest tests |
| 53 | echo "Running guest block device read test..." |
| 54 | adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /dev/block/vda $(adb -s localhost:8000 shell blockdev --getsize64 /dev/block/vda) read 5" |
| 55 | echo "Running guest authfs read test..." |
| 56 | adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/3 268435456 read 5" |
| 57 | echo "Running guest authfs unverified read test..." |
| 58 | adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/6 268435456 read 5" |
| 59 | echo "Running guest authfs write test..." |
| 60 | adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/7 268435456 write 5" |