1*e17b4558SAndroid Build Coastguard Worker# Vogar 2*e17b4558SAndroid Build Coastguard Worker 3*e17b4558SAndroid Build Coastguard WorkerVogar is a generic code/test/benchmark runner tool for Android. It is 4*e17b4558SAndroid Build Coastguard Workerprimarily used to run libcore and art tests and benchmarks, however 5*e17b4558SAndroid Build Coastguard Workerthis tool can also run arbitrary Java files either on host or target 6*e17b4558SAndroid Build Coastguard Workerdevice. 7*e17b4558SAndroid Build Coastguard Worker 8*e17b4558SAndroid Build Coastguard WorkerVogar supports multiple testing frameworks and configurations: 9*e17b4558SAndroid Build Coastguard Worker 10*e17b4558SAndroid Build Coastguard Worker * Allows running JUnit tests, TestNG tests, jtreg tests, Caliper 11*e17b4558SAndroid Build Coastguard Worker benchmarks or executable Java classes. It supports running 12*e17b4558SAndroid Build Coastguard Worker fine-grained tests that can be specified with hash symbol, e.g. 13*e17b4558SAndroid Build Coastguard Worker "com.android.Test#test". 14*e17b4558SAndroid Build Coastguard Worker 15*e17b4558SAndroid Build Coastguard Worker * Allows running tests and benchmarks using five available runtime 16*e17b4558SAndroid Build Coastguard Worker modes: `activity`, `app_process`, `device`, `host` or `jvm`. 17*e17b4558SAndroid Build Coastguard Worker 18*e17b4558SAndroid Build Coastguard Worker## Building and running 19*e17b4558SAndroid Build Coastguard Worker 20*e17b4558SAndroid Build Coastguard WorkerFirst build it: 21*e17b4558SAndroid Build Coastguard Worker 22*e17b4558SAndroid Build Coastguard Worker* With a minimal `aosp/master-art` tree: 23*e17b4558SAndroid Build Coastguard Worker```bash 24*e17b4558SAndroid Build Coastguard Workerexport SOONG_ALLOW_MISSING_DEPENDENCIES=true 25*e17b4558SAndroid Build Coastguard Worker${ANDROID_BUILD_TOP}/art/tools/buildbot-build.sh --target 26*e17b4558SAndroid Build Coastguard Worker``` 27*e17b4558SAndroid Build Coastguard Worker 28*e17b4558SAndroid Build Coastguard Worker* With a full Android (AOSP) `aosp/master` tree: 29*e17b4558SAndroid Build Coastguard Worker```bash 30*e17b4558SAndroid Build Coastguard Workerm vogar 31*e17b4558SAndroid Build Coastguard Worker``` 32*e17b4558SAndroid Build Coastguard Worker 33*e17b4558SAndroid Build Coastguard Worker## Features 34*e17b4558SAndroid Build Coastguard Worker 35*e17b4558SAndroid Build Coastguard WorkerVogar supports running tests and/or benchmarks (called "actions" below in the document) 36*e17b4558SAndroid Build Coastguard Workerin five different modes (specified with `--mode` option). An "action" is a `.java` file, 37*e17b4558SAndroid Build Coastguard Workerdirectory or class names: 38*e17b4558SAndroid Build Coastguard Worker 39*e17b4558SAndroid Build Coastguard Worker 1. Activity (`--mode=activity`) 40*e17b4558SAndroid Build Coastguard Worker 41*e17b4558SAndroid Build Coastguard Worker Vogar runs given action in the context of an [`android.app.Activity`](https://developer.android.com/reference/android/app/Activity) on a device. 42*e17b4558SAndroid Build Coastguard Worker 43*e17b4558SAndroid Build Coastguard Worker 2. App (`--mode=app_process`) 44*e17b4558SAndroid Build Coastguard Worker 45*e17b4558SAndroid Build Coastguard Worker Vogar runs given action in an app_process runtime on a device or emulator. 46*e17b4558SAndroid Build Coastguard Worker Used in conjunction with the `--benchmark` option for running Caliper benchmarks. 47*e17b4558SAndroid Build Coastguard Worker This is required to benchmark any code relying on the android framework. 48*e17b4558SAndroid Build Coastguard Worker 49*e17b4558SAndroid Build Coastguard Worker ```bash 50*e17b4558SAndroid Build Coastguard Worker Vogar --mode app_process --benchmark frameworks/base/core/tests/benchmarks/src/android/os/ParcelBenchmark.java 51*e17b4558SAndroid Build Coastguard Worker ``` 52*e17b4558SAndroid Build Coastguard Worker 53*e17b4558SAndroid Build Coastguard Worker3. Device (`--mode=device`) 54*e17b4558SAndroid Build Coastguard Worker 55*e17b4558SAndroid Build Coastguard Worker Vogar runs given action in an ART runtime on a device or emulator. 56*e17b4558SAndroid Build Coastguard Worker 57*e17b4558SAndroid Build Coastguard Worker4. Host (`--mode=host`) 58*e17b4558SAndroid Build Coastguard Worker 59*e17b4558SAndroid Build Coastguard Worker Vogar runs in an ART runtime on the local machine built with any lunch combo. 60*e17b4558SAndroid Build Coastguard Worker Similar to "Device" mode but running local ART. 61*e17b4558SAndroid Build Coastguard Worker 62*e17b4558SAndroid Build Coastguard Worker5. JVM (`--mode=jvm`) 63*e17b4558SAndroid Build Coastguard Worker 64*e17b4558SAndroid Build Coastguard Worker Vogar runs given action in a Java VM on the local machine. 65*e17b4558SAndroid Build Coastguard Worker 66*e17b4558SAndroid Build Coastguard WorkerMost frequently you will use either `--mode=device` or `--mode=host` mode. 67*e17b4558SAndroid Build Coastguard Worker 68*e17b4558SAndroid Build Coastguard Worker## Testing and debugging 69*e17b4558SAndroid Build Coastguard Worker 70*e17b4558SAndroid Build Coastguard WorkerVogar has unit test coverage around basic functionality. Most of the coverage 71*e17b4558SAndroid Build Coastguard Workeris for [JUnit](https://junit.org/) and [TestNG](https://testng.org/) integration. 72*e17b4558SAndroid Build Coastguard Worker 73*e17b4558SAndroid Build Coastguard Worker### Building and running 74*e17b4558SAndroid Build Coastguard Worker 75*e17b4558SAndroid Build Coastguard WorkerFirst, build tests with: 76*e17b4558SAndroid Build Coastguard Worker```bash 77*e17b4558SAndroid Build Coastguard Workerm vogar-tests 78*e17b4558SAndroid Build Coastguard Worker``` 79*e17b4558SAndroid Build Coastguard Worker 80*e17b4558SAndroid Build Coastguard WorkerRun all tests using phony make target with: 81*e17b4558SAndroid Build Coastguard Worker```bash 82*e17b4558SAndroid Build Coastguard Workerm run-vogar-tests 83*e17b4558SAndroid Build Coastguard Worker``` 84*e17b4558SAndroid Build Coastguard Worker 85*e17b4558SAndroid Build Coastguard WorkerOr run manually (if you want to specify a subset of all unit tests, for example): 86*e17b4558SAndroid Build Coastguard Worker```bash 87*e17b4558SAndroid Build Coastguard Workerjava -cp ${ANDROID_BUILD_TOP}/out/host/linux-x86/framework/vogar-tests.jar \ 88*e17b4558SAndroid Build Coastguard Worker org.junit.runner.JUnitCore vogar.AllTests 89*e17b4558SAndroid Build Coastguard Worker``` 90*e17b4558SAndroid Build Coastguard Worker 91*e17b4558SAndroid Build Coastguard Worker## Architecture and implementation 92*e17b4558SAndroid Build Coastguard Worker 93*e17b4558SAndroid Build Coastguard WorkerHigh level model of each Vogar run is: 94*e17b4558SAndroid Build Coastguard Worker 95*e17b4558SAndroid Build Coastguard Worker 1. Parsing input options. 96*e17b4558SAndroid Build Coastguard Worker 2. Creating a list of `Task` objects that encapsulate various steps required. 97*e17b4558SAndroid Build Coastguard Worker These `Task` objects can depend on each other, and get executed only if all 98*e17b4558SAndroid Build Coastguard Worker dependencies are already executed. 99*e17b4558SAndroid Build Coastguard Worker 3. Executing tasks. It include assembling the code, dexing it, packing in 100*e17b4558SAndroid Build Coastguard Worker an activity/runnable dex jar, preparing the environment (host or device), 101*e17b4558SAndroid Build Coastguard Worker pushing all artifacts, and running it. 102*e17b4558SAndroid Build Coastguard Worker 103*e17b4558SAndroid Build Coastguard Worker### Classes overview 104*e17b4558SAndroid Build Coastguard Worker 105*e17b4558SAndroid Build Coastguard WorkerThe basic building block of Vogar execution is the `Task` class. There are several 106*e17b4558SAndroid Build Coastguard Workersub classes of `Task`, for example: 107*e17b4558SAndroid Build Coastguard Worker 108*e17b4558SAndroid Build Coastguard Worker * `MkdirTask` 109*e17b4558SAndroid Build Coastguard Worker * `RmTask` 110*e17b4558SAndroid Build Coastguard Worker * `PrepareTarget` 111*e17b4558SAndroid Build Coastguard Worker 112*e17b4558SAndroid Build Coastguard WorkerThe `Target` class encapsulates the runtime environment, for example a 113*e17b4558SAndroid Build Coastguard Workerremote device or the local host. There are four available environments: 114*e17b4558SAndroid Build Coastguard Worker 115*e17b4558SAndroid Build Coastguard Worker * `AdbTarget` is used when `--mode=device` is set. 116*e17b4558SAndroid Build Coastguard Worker 117*e17b4558SAndroid Build Coastguard Worker It makes sure device is connected, required directories are mount 118*e17b4558SAndroid Build Coastguard Worker properly, and all required files are synced to the device. 119*e17b4558SAndroid Build Coastguard Worker 120*e17b4558SAndroid Build Coastguard Worker * `AdbChrootTarget` is used when `--mode=device --chroot=/data/chroot/` 121*e17b4558SAndroid Build Coastguard Worker are set. 122*e17b4558SAndroid Build Coastguard Worker 123*e17b4558SAndroid Build Coastguard Worker Same as `AdbTarget` but relatively to a specified chroot directory 124*e17b4558SAndroid Build Coastguard Worker (instead of the whole system under the root directory on the device). 125*e17b4558SAndroid Build Coastguard Worker 126*e17b4558SAndroid Build Coastguard Worker * `LocalTarget` is used when `--mode=host` or `--mode=jvm` are set. 127*e17b4558SAndroid Build Coastguard Worker 128*e17b4558SAndroid Build Coastguard Worker Same as `AdbTarget` but runs on the host machine. 129*e17b4558SAndroid Build Coastguard Worker 130*e17b4558SAndroid Build Coastguard Worker * `SshTarget` is used when `--ssh <host:port>` is set. 131*e17b4558SAndroid Build Coastguard Worker 132*e17b4558SAndroid Build Coastguard Worker Same as `LocalTarget` but on a remote machine at the given address. 133*e17b4558SAndroid Build Coastguard Worker 134*e17b4558SAndroid Build Coastguard WorkerAfter parsing command line options, Vogar builds a list of tasks which 135*e17b4558SAndroid Build Coastguard Workerare put in a `TaskQueue`. They are executed using all available cores 136*e17b4558SAndroid Build Coastguard Workerexcept when "Activity" mode is enabled -- in that case it is always one 137*e17b4558SAndroid Build Coastguard Workerthread. 138*e17b4558SAndroid Build Coastguard Worker 139