blob: 49cf2582f1a09f00e194fda4b78436e2d3dfa169 [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
13m fs_benchmark MicrodroidFilesystemBenchmarkApp fsverity
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 sign /tmp/testcase /tmp/testcase.fsv_sig --key=packages/modules/Virtualization/tests/benchmark/assets/benchmark.pem \
24 --out-merkle-tree=/tmp/testcase.merkle_dump --cert=packages/modules/Virtualization/tests/benchmark/assets/benchmark.x509.pem
25adb shell 'dd if=/dev/zero of=/data/local/tmp/testcase bs=1048576 count=256'
26adb push /tmp/testcase.fsv_sig /tmp/testcase.merkle_dump /data/local/tmp
27
28# 3. Run fd_server from host
29adb shell 'exec 3</data/local/tmp/testcase 4</data/local/tmp/testcase.merkle_dump 5</data/local/tmp/testcase.fsv_sig 6</data/local/tmp/testcase 7<>/data/local/tmp/testcase2 /apex/com.android.virt/bin/fd_server --ro-fds 3:4:5 --ro-fds 6 --rw-fds 7' &
30
31# 4. Run VM and get the CID
32result=$(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")
33cid=$(echo $result | grep -P "with CID \d+" --only-matching --color=none | cut -d' ' -f3)
34echo "CID IS $cid"
35
36# 5. Run host tests
37echo "Running host read/write test..."
38adb shell 'dd if=/dev/zero of=/data/local/tmp/testcase_host bs=1048576 count=256'
39adb shell '/data/local/tmp/fs_benchmark /data/local/tmp/testcase_host 268435456 both 5'
40
41# 6. Connect to the VM
42# We are cheating here. The VM is expected to finish booting, while the host tests are running.
43adb forward tcp:8000 vsock:$cid:5555
44adb connect localhost:8000
45adb -s localhost:8000 root
46sleep 10
47
48# 7. Install artifacts and run authfs
49adb -s localhost:8000 push $OUT/system/bin/fs_benchmark /data/local/tmp
50adb -s localhost:8000 shell "mkdir -p /data/local/tmp/authfs"
51adb -s localhost:8000 shell "/system/bin/authfs /data/local/tmp/authfs --cid 2 --remote-ro-file 3:/mnt/apk/assets/benchmark.x509.der --remote-ro-file-unverified 6 --remote-new-rw-file 7" &
52
53# 8. Run guest tests
54echo "Running guest block device read test..."
55adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /dev/block/vda $(adb -s localhost:8000 shell blockdev --getsize64 /dev/block/vda) read 5"
56echo "Running guest authfs read test..."
57adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/3 268435456 read 5"
58echo "Running guest authfs unverified read test..."
59adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/6 268435456 read 5"
60echo "Running guest authfs write test..."
61adb -s localhost:8000 shell "/data/local/tmp/fs_benchmark /data/local/tmp/authfs/7 268435456 write 5"