How to add tests to CTSVerifier for AOSP

Jiri Richter
2 min readSep 27, 2021

As the authors of the Don’t kill my app project, we’ve been recently asked by Google to add some tests regarding foreground services to the CTS in AOSP. We’ve had some issues with that, so in this article I’ll describe the steps we took in order to be able to add the tests.

What is CTS?

CTS stands for “Compatibility Test Suite” and it’s a bunch of automated tests that are meant to be run on a real device by engineers who are building a new Android phone. So all the big guys like Samsung, HMD Global, Xiaomi, HTC, Sony etc. are using those tests in order to comply with Google’s quality rules.

There’s also a subset of tests in the CTS that are meant to be run manually by a manual tester. This subset is bundled in an app called CTSVerifier (you can see the source e.g. here).

What we were tasked with was to add a new test to the CTSVerifier. There’s quite some setup work involved.

Setup

I’ve been following steps from the Android source documentation. I was running this on Ubuntu 20.04, on other OS/distributions the steps may vary a little:

  1. Install repo, which is Google’s repository management tool running on top of git.

2. Create a project directory and enter it.

3. Initialize the repo tool as outlined here. This will download a manifest file for the given repository and also the latest repo version inside the project directory. This is usually done just by “repo init [url]” but there might be some issues with your local installation of Python.

Repo uses Python but strictly needs 3.x version and cannot run with 2.x. I have both installed on my system, but 2.x is the default which is being invoked whenever I type “python” in terminal. So I need some way to force repo to use Python version 3.

To init repo, you also need to know the URL of the repository that you want to download. In order to be able to build and run the CTSVerifier, we need the AOSP source branch corresponding to an Android version we have lying around on a real device. Since I have a phone with Android 10, I downloaded the Android 10 branch, latest tag.

List of all branches/tags can be found here.

Okay, so our repo is initialized. Now we need to checkout the actual files.

4. Checkout the files with “repo sync” command.

Open up a beer since this is going to download around 60 gigabytes of source code. We don’t actually need most of that but I didn’t find a more direct way.

We’re almost there!

Build

This one is surely easy enough. Go to the root of the repo and shoot!

This will build CtsVerifier.apk in projectDir/out/target/product/generic/data/app/CtsVerifier/

Go ahead and install it onto your phone.

Happy testing!

--

--

Jiri Richter

Dad of 2 boys, programmer. Experience: web (Angular, Ionic, NodeJS + FeathersJS), mobile (Android), wearable (Garmin, Fitbit, Samsung) and stuff here and there.