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 5set -e 6 7# Prerequisite: we need root to flush disk cache. 8adb root 9 10# 1. Build needed artifacts, and install it to device 11source build/make/rbesetup.sh 12lunch $1 13m fs_benchmark MicrodroidFilesystemBenchmarkApp fsverity fsverity_metadata_generator 14adb push $OUT/system/bin/fs_benchmark /data/local/tmp 15adb 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. 20adb shell 'rm -rf /data/local/tmp/virt /data/local/tmp/testcase*' 21adb shell 'mkdir -p /data/local/tmp/virt' 22dd if=/dev/zero of=/tmp/testcase bs=1048576 count=256 23fsverity_metadata_generator --fsverity-path $(which fsverity) --signature none --hash-alg sha256 --out /tmp/testcase.fsv_meta /tmp/testcase 24adb shell 'dd if=/dev/zero of=/data/local/tmp/testcase bs=1048576 count=256' 25adb push /tmp/testcase.fsv_meta /data/local/tmp 26 27# 3. Run fd_server from host 28adb 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' & 29 30# 4. Run VM and get the CID 31result=$(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") 32cid=$(echo $result | grep -P "with CID \d+" --only-matching --color=none | cut -d' ' -f3) 33echo "CID IS $cid" 34 35# 5. Run host tests 36echo "Running host read/write test..." 37adb shell 'dd if=/dev/zero of=/data/local/tmp/testcase_host bs=1048576 count=256' 38adb 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. 42adb forward tcp:8000 vsock:$cid:5555 43adb connect localhost:8000 44adb -s localhost:8000 root 45sleep 10 46 47# 7. Install artifacts and run authfs 48adb -s localhost:8000 push $OUT/system/bin/fs_benchmark /data/local/tmp 49adb -s localhost:8000 shell "mkdir -p /data/local/tmp/authfs" 50adb -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" & 51 52# 8. Run guest tests 53echo "Running guest block device read test..." 54adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /dev/block/vda $(adb -s localhost:8000 shell blockdev --getsize64 /dev/block/vda) read 5" 55echo "Running guest authfs read test..." 56adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/3 268435456 read 5" 57echo "Running guest authfs unverified read test..." 58adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/6 268435456 read 5" 59echo "Running guest authfs write test..." 60adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/7 268435456 write 5" 61