blob: 7ba0c6d74c42d9020b87b1f65a1ea6ee36c7ba3d [file] [log] [blame]
Inseob Kimfd922cf2021-10-18 19:49:00 +09001# 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
Inseob Kim6715ca72022-01-12 15:48:50 +090013m fs_benchmark MicrodroidFilesystemBenchmarkApp fsverity fsverity_metadata_generator
Inseob Kimfd922cf2021-10-18 19:49:00 +090014adb 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
Inseob Kim6715ca72022-01-12 15:48:50 +090023fsverity_metadata_generator --fsverity-path $(which fsverity) --signature none --hash-alg sha256 --out /tmp/testcase.fsv_meta /tmp/testcase
Inseob Kimfd922cf2021-10-18 19:49:00 +090024adb shell 'dd if=/dev/zero of=/data/local/tmp/testcase bs=1048576 count=256'
Inseob Kim6715ca72022-01-12 15:48:50 +090025adb push /tmp/testcase.fsv_meta /data/local/tmp
Inseob Kimfd922cf2021-10-18 19:49:00 +090026
27# 3. Run fd_server from host
Inseob Kim6715ca72022-01-12 15:48:50 +090028adb 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 Kimfd922cf2021-10-18 19:49:00 +090029
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"
Inseob Kim6715ca72022-01-12 15:48:50 +090050adb -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 Kimfd922cf2021-10-18 19:49:00 +090051
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"