Run Android CTS within LXC

21 Apr 2016
Posted by stylesen

This is a continuation to "Access Android devices from LXC" which explains how to access an Android device from within an LXC container. Android Compatibility Test Suite (CTS) represents the "mechanism" of compatibility for Android devices. It is a suite of tests that are run on an Android device to check compatibility of the device under test. We shall see how we can run CTS within LXC so that we have an option of running CTS from different operating systems and different JAVA versions.

In this post, I would like to explain running CTS from a LXC container that runs Ubuntu Wily ie., Ubuntu 15.10 and the device under test is a Nexus 4 with factory image loaded. The factory image in Nexus 4 is Lollipop ie., 5.1.1 as available here. We will run Android 5.1 R6 Compatibility Test Suite (CTS) - ARM on this Nexus 4 device.

To create a Ubuntu Wily LXC follow the steps below:

stylesen@harshu:~$ sudo lxc-create -n ubuntu-wily -t download
Setting up the GPG keyring
Downloading the image index

centos    6    amd64    default    20160421_02:16
centos    6    i386    default    20160421_02:16
... truncated output ...
ubuntu    wily    amd64    default    20160421_03:49
ubuntu    wily    armhf    default    20160421_03:49
ubuntu    wily    i386    default    20160421_03:49
ubuntu    wily    powerpc    default    20160421_03:49
ubuntu    wily    ppc64el    default    20160421_03:49
ubuntu    xenial    amd64    default    20160421_03:49
ubuntu    xenial    armhf    default    20160421_03:49
ubuntu    xenial    i386    default    20160421_03:49
ubuntu    xenial    powerpc    default    20160421_03:49
ubuntu    xenial    ppc64el    default    20160421_03:49
ubuntu    xenial    s390x    default    20160421_03:49

Distribution: ubuntu
Release: wily
Architecture: amd64

Using image from local cache
Unpacking the rootfs

You just created an Ubuntu container (release=wily, arch=amd64, variant=default)

To enable sshd, run: apt-get install openssh-server

For security reason, container images ship without user accounts
and without a root password.

Use lxc-attach or chroot directly into the rootfs to set a root password
or create user accounts.
stylesen@harshu:~$ sudo lxc-start -n ubuntu-wily -d
stylesen@harshu:~$ sudo lxc-attach -n ubuntu-wily
root@ubuntu-wily:/# cd
root@ubuntu-wily:/# apt-get update
... truncated output ...
root@ubuntu-wily:~# apt-get install openjdk-7-jdk aapt android-tools-adb android-tools-fastboot wget unzip usbutils
... truncated output ...
root@ubuntu-wily:~# wget -c
... truncated output ...
root@ubuntu-wily:~# unzip
... truncated output ...

On the Host which holds the LXC container ie., ubuntu-wily, follow the steps as given in Access Android devices from LXC to get the device show up in `adb devices` within the LXC container.

Follow the steps given in Android device configuration to setup the Nexus 4 device for running CTS.

root@ubuntu-wily:~# adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
04f228d1d9c76f39    device

Once the above setup are done use the following command within the container ie., ubuntu-wily as follows in order to run specific test plans of CTS or entire CTS.

root@ubuntu-wily:~# ./android-cts/tools/cts-tradefed run cts --plan Android --disable-reboot
Android CTS 5.1_r6
Using commandline arguments as starting command: [run, cts, --plan, Android, --disable-reboot]
04-21 15:04:41 I/DeviceManager: Detected new device 04f228d1d9c76f39
04-21 15:04:41 I/TestInvocation: Starting invocation for 'cts' on build '5.1_r6' on device 04f228d1d9c76f39
04-21 15:04:41 I/04f228d1d9c76f39: Created result dir 2016.04.21_15.04.41
04-21 15:04:41 I/CtsTest: ABIs: [armeabi-v7a]
04-21 15:04:52 I/04f228d1d9c76f39: Collecting device info
04-21 15:04:53 I/CtsTest: Start test run of 84 packages, containing 65,097 tests
04-21 15:04:53 I/CtsTest: Installing prerequisites
04-21 15:05:06 I/04f228d1d9c76f39: -----------------------------------------
04-21 15:05:06 I/04f228d1d9c76f39: Test package armeabi-v7a android.JobScheduler started
04-21 15:05:06 I/04f228d1d9c76f39: -----------------------------------------
04-21 15:05:40 I/04f228d1d9c76f39: android.jobscheduler.cts.TimingConstraintsTest#testCancel PASS
04-21 15:05:45 I/04f228d1d9c76f39: android.jobscheduler.cts.TimingConstraintsTest#testScheduleOnce PASS
04-21 15:06:00 I/04f228d1d9c76f39: android.jobscheduler.cts.TimingConstraintsTest#testSchedulePeriodic PASS
... truncated output ...

For more information on CTS see