Welcome to Part 6 of Android System Verification. It's getting hard to trace back to the previous articles, so here is a complete list of links:
Part 1 Part 2 Part 3 Part 4 Part 5
Last time I showed how to create hardware stimulus and use coverage to keep track of the generated stimulus across multiple runs. Recall, that we were sending commands representing hardware stimulus to the Android device and the operations could be seen on the emulated device display, but there was no way to check the commands were being executed correctly. In order to close the loop we need a way to check that the operations are actually being performed and flag an error if they are not.
So far we have been doing everything with an unmodified Android emulator. To add the needed checking it's time to put some instrumentation into the emulator to help out. The instrumentation will communicate with Specman to close the loop. Step one is to build the emulator from source and run the new executable to make sure everything is OK. Once this is done we can work on instrumenting the emulator.
Recall from Part 1 that the emulator executable is creatively named "emulator" and is found in the tools/ directory of the Android SDK. This is the executable we want to learn how to build. Let's get started.
First, information about how to download the source code is at http://source.android.com/download
Today, I'm working on Ubuntu 9.04 so the instructions about the needed packages are easy to follow and I can get any needed packages using apt-get. We are not going to build the entire Android source tree, only the emulator, so the entire list of required tools is probably not needed. The main tool that is needed and not normally available on most Linux machines is git. Make sure you have git installed.
Android doesn't use git directly, but instead provides a script named repo to make it easier to work with git.
I installed my Android SDK at /home/jasona/android. The SDK install created the new directory /home/jasona/android/android-sdk-linux_86
To setup repo:
$ cd /home/jasona/android$ curl http://android.git.kernel.org/repo > repo ; chmod +x repo
Now create a directory to hold the source tree:
$ mkdir mydroid$ cd mydroid
The instructions from source.android.com show the -b donut option, but the eclair release is newer so let's download that one.
$ ../repo init -u git://android.git.kernel.org/platform/manifest.git -b eclair$ ../repo sync
When prompted I entered my gmail login, but I'm not sure it's needed if you are not going to submit any code, probably not.
Once the download is done we are ready to build the emulator. The main hurdle is usually the SDL library, but I found that there is a pre-built version that comes in the source tree that works well using the --sdl-config option to configure.
$ cd external/qemu$ android-configure.sh --sdl-config=../../prebuilt/linux-x86/sdl/bin/sdl-config$ make
If all of this succeeds you have a new emulator in the objs/ directory. Just to make sure we are running with the newly built emulator, I suggest putting a print statement into the emulator source code to confirm the modified emulator is actually running. To do this edit the file android/main.c. The main starts about line 1786. I added a print statement as the first line of code in main() just before the options are parsed.
printf("Warning: custom emulator\n");
Now rebuild again using make and the new emulator is ready. Save the original emulator to a new filename and copy the new emulator to the SDK tools/ directory and try it out.
$ emulator -avd verifyWarning: custom emulator
This confirms the warning appears when the emulator is run.
Next time we will start to instrument the emulator to provide the needed checking and start digging into the hardware model of the Goldfish platform to see what kind of interesting things are happening during the tests.
Thank you Jason your blog is really very helpful!