4.3 KiB
Vogar
Vogar is a generic code/test/benchmark runner tool for Android. It is primarily used to run libcore and art tests and benchmarks, however this tool can also run arbitrary Java files either on host or target device.
Vogar supports multiple testing frameworks and configurations:
-
Allows running JUnit tests, TestNG tests, jtreg tests, Caliper benchmarks or executable Java classes. It supports running fine-grained tests that can be specified with hash symbol, e.g. "com.android.Test#test".
-
Allows running tests and benchmarks using five available runtime modes:
activity,app_process,device,hostorjvm.
Building and running
First build it:
- With a minimal
aosp/master-arttree:
export SOONG_ALLOW_MISSING_DEPENDENCIES=true
${ANDROID_BUILD_TOP}/art/tools/buildbot-build.sh --target
- With a full Android (AOSP)
aosp/mastertree:
m vogar
Features
Vogar supports running tests and/or benchmarks (called "actions" below in the document)
in five different modes (specified with --mode option). An "action" is a .java file,
directory or class names:
-
Activity (
--mode=activity)Vogar runs given action in the context of an
android.app.Activityon a device. -
App (
--mode=app_process)Vogar runs given action in an app_process runtime on a device or emulator. Used in conjunction with the
--benchmarkoption for running Caliper benchmarks. This is required to benchmark any code relying on the android framework.Vogar --mode app_process --benchmark frameworks/base/core/tests/benchmarks/src/android/os/ParcelBenchmark.java -
Device (
--mode=device)Vogar runs given action in an ART runtime on a device or emulator.
-
Host (
--mode=host)Vogar runs in an ART runtime on the local machine built with any lunch combo. Similar to "Device" mode but running local ART.
-
JVM (
--mode=jvm)Vogar runs given action in a Java VM on the local machine.
Most frequently you will use either --mode=device or --mode=host mode.
Testing and debugging
Vogar has unit test coverage around basic functionality. Most of the coverage is for JUnit and TestNG integration.
Building and running
First, build tests with:
m vogar-tests
Run all tests using phony make target with:
m run-vogar-tests
Or run manually (if you want to specify a subset of all unit tests, for example):
java -cp ${ANDROID_BUILD_TOP}/out/host/linux-x86/framework/vogar-tests.jar \
org.junit.runner.JUnitCore vogar.AllTests
Architecture and implementation
High level model of each Vogar run is:
- Parsing input options.
- Creating a list of
Taskobjects that encapsulate various steps required. TheseTaskobjects can depend on each other, and get executed only if all dependencies are already executed. - Executing tasks. It include assembling the code, dexing it, packing in an activity/runnable dex jar, preparing the environment (host or device), pushing all artifacts, and running it.
Classes overview
The basic building block of Vogar execution is the Task class. There are several
sub classes of Task, for example:
MkdirTaskRmTaskPrepareTarget
The Target class encapsulates the runtime environment, for example a
remote device or the local host. There are four available environments:
-
AdbTargetis used when--mode=deviceis set.It makes sure device is connected, required directories are mount properly, and all required files are synced to the device.
-
AdbChrootTargetis used when--mode=device --chroot=/data/chroot/are set.Same as
AdbTargetbut relatively to a specified chroot directory (instead of the whole system under the root directory on the device). -
LocalTargetis used when--mode=hostor--mode=jvmare set.Same as
AdbTargetbut runs on the host machine. -
SshTargetis used when--ssh <host:port>is set.Same as
LocalTargetbut on a remote machine at the given address.
After parsing command line options, Vogar builds a list of tasks which
are put in a TaskQueue. They are executed using all available cores
except when "Activity" mode is enabled -- in that case it is always one
thread.