Canonical Voices

What The Quality Hour talks about

Automating tests is an essential goal of any QA Engineer. It saves precious human resources and allows to maintain a healthy continuous integration. Unit and integration tests are closest to the developer’s work: libraries, classes and functions. However, when a project is GUI-intensive or use software with poor introspection/accessibility capabilities, visual tests are very helpful. In this regard, we at Canonical are developing some good QA tools and one of them is Xpresser.

So, what is Xpresser? It’s a Python framework to do visual tests. It was originally developed by Gustavo Niemeyer. Xpresser’s main feature is to find saved images in the desktop. For example, if we want to check whether the Messaging Menu is active, we first save the blue icon and then command Xpresser to find it: Xpresser checks the whole visible desktop, as a regular person would do with its eyes. Xpresser is not only able to find images, but also to click on them. So in the previous case, will could open the Messaging Menu when active to then check whether Thunderbird is open. Xpresser even allows to simulate the keyboard.

To illustrate this, watch this useful screencast done by Chris Wayne, who works with us at Canonical as QA Engineer in OEM.

Plain easy, isn’t it?

Xpresser is currently available in this PPA ppa:xpresser-team/ppa for Ubuntu Precise and Oneiric.

This post will describe how we are using Jenkins and Launchpad together to achieve Continuous integration.

Right now we are running our tests right after the code is (manually) reviewed and just before pushing them to trunk. We refer to this part of the process as autolanding and there are tools (tarmac) which can automate the process. However the manual process of code review can take quite some and our jenkins jobs are not triggered until the review is ready.

We would like to run tests much sooner, though. Ideally the workflow would be as follow:

Once all the tests finished the merge proposal is updated with the test result and a link to the jenkins job

In our case we are using libvirt and VMs to achieve a clean and isolated test environment. Therefore we are doing some post-test clean-up actions (reverting the VM to a predefined snapshot).

Our jenkins setup looks roughly like this.

In this case there are jenkins jobs:

unity-ci – job which gets triggered as soon as a new merge proposal exists for lp:unity and does the testing

generic_update-mp – parametrized job which will take test result, merge proposal and few other parameters and updates the merge proposal in launchpad with the result.

Flowchart for the whole process:

The setup for autolanding is very similar:

The only difference is that

unity-autolanding job is triggered when a merge proposal is approved

generic-land job will also merge the branch from merge proposal to trunk and does the actual push to trunk

The flowchart is slightly more complicated as there are more possible failure points (e.g. the testing might pass but the autolanding will fail because we require non-empty commit message and the commit message was not specified):

Right now we have a prototype in Python using a ScriptTrigger plugin for jenkins which is implementing all of this. I will describe in the next post how use it in practice together with some examples.

In the 3D team, we have autopilot: Autopilot aims to make writing functional tests for Unity as easy as possible. Previously, features that were too hard to test with unit tests were written as a “manual test”. Manual tests are text documents stored in the Unity source tree. When we prepare a point release of Unity we iterate through all the manual tests and ensure they all pass. This is obviously less than ideal – running the entire suite of manual tests takes a lot of time, and stops a developer from writing more code. Most of these tests can be automated.
Here’s an example that was written after someone noticed a bug in the dash command lens:

Dash search
-----------
This test makes sure that the right command is run when you search
using the dash. (see lp:856205)
#. Press Alt+F2
#. Press 'g'. Make sure you see some command name (like gcc)
#. Quickly type 'edit<Enter>' - so you'd run 'gedit'.
Outcome
The dash disappears, and gedit is run. If nothing happens or the first
command is run (in this case gcc), this test failed.

This is a reasonable test specification, but does not need to be a manual test, we can automate this, and have autopilot perform the same actions as a user would. If we break down the test specification into smaller steps, we end up with the following:

Reveal the command lens.

Type “g”, and wait for the command lens to refresh and show us some results.

Quickly type “edit” and hit “Enter”.

Wait (with a timeout) for the gedit application to launch.

If gedit was launched, the test passed. If the timeout was reached, the test failed.

Autopilot tests are standard python unit tests, so the resulting test will look familiar to people used to reading python unit tests:

This test is part of a larger class that contains several similar tests – I have omitted the rest of the class for clarity. There’s a few things happening here:

On lines 9, 11, and 12 we’re generating X11 keyboard events (we can handle mouse events as well). This allows us to manipulate the various parts of the desktop shell just like a user would.

On lines 8 and 14 we’re querying various parts of the unity shell for information. When we reveal the command lens we check that it’s actually showing by asking Unity internal state information. When we check for running applications we’re talking with the Bamf daemon.

We generate the X events using python-xlib and the xtest extension. Of course, we don’t want programmers to have to deal with Xlib themselves, so we wrap all Xlib calls into two classes: “Keyboard” and “Mouse”. They work exactly as you’d expect.

Getting information is a bit more interesting: many classes within unity contain information we would like in autopilot. In order to expose this information, a class must:

Derive from the Introspectable class (defined in “Introspectable.h”)

Implement the “GetName” and “AddProperties” methods.

Browsing the unity C++ source files will reveal many instances of introspectable objects. Introspectable objects form a tree within unity, with the main shell instance at the top. To build the tree, an introspectable instance can call the “AddChild” and “RemoveChild” methods. In this manner, a tree of objects is built. The full tree is huge, but you can see a small part of it below:

Even from this small part of the tree you can tell a lot about the state of my desktop shell: I have only one launcher (on monitor 0). Launcher keyboard navigation (as initiated by pressing Alt+F1 or Super+Tab) is not active, I have at least three launcher icons (actually many more, but they’re cut out of the image), including D-feet, gnome-terminal and the Quassel IRC client.

All this information (and more) is available to autopilot tests. The combination of a vast amount of information, and the fact that Python is incredibly fast to work in makes it trivially easy to write autopilot tests. This is one of the key ways in which we’re testing unity for the precise release cycle.

Running the Tests

Running the tests is simple. From the root of the unity source tree, you can list all the autopilot tests like this:

$ ./tools/autopilot list

You can run the entire autopilot suite like this:

$ ./tools/autopilot run

…or you can specify one or more tests you want to run (the entire suite takes a long time) like this:

Currently we have around 100 tests, and many of these are parameterized to expand in certain conditions. For example, if the test machine has multiple monitors configured, almost all the launcher tests are configured to run once on each monitor. We use a similar technique to ensure that we support multiple international languages in the dash.

On Jenkins

The entire autopilot test suite runs on jenkins as well. We’ve recently started recording failing autopilot tests, which helps us diagnose failing tests. This is especially important, as the test machine may have different hardware or software configuration from a developer’s machine: being able to see the test failing makes diagnosing errors a lot easier.

You can help!

We’re always happy to have people writing autopilot tests. If you know a bit of Python, and are willing to learn about testing Unity, please find me (“thomi”) in the #ubuntu-unity channel on irc.freenode.net – I’m happy to guide anyone who would like to get involved through writing, testing, and submitting your first autopilot test.

Testing is hugely important to us at Canonical. We all strive to have Ubuntu reliable, consistent and fast. But we’re human, and we make mistakes. Sometimes a bugfix will break something else, and for something as complex as a desktop shell, it’s easy to miss these breakages. While manual tests can help reduce these regressions, realistically we need an automated system to emulate the users inputs and verify our software works as it should – and scream bloody murder if it doesn’t!

In Unity 2D (my project!), we have just introduced an automated User Experience testing system, based on a test framework called Testability Driver (I’ll just call it ‘Testability’ from now on). First off, a clarification:

Testability is for Qt-based applications only!

A limitation: yes, but this requirement comes with a great reward: Testability allows inspection of the tree of QObjects in a Qt application while it is running!

It can read and write object properties, call methods and slots, verify signals are emitted, as well as fake mouse/keyboard/gesture inputs, grab visual outputs, and measure performance.

And best of all, Testability is open source and maintained by Nokia! That means everyone can run and contribute tests! Read more

This tutorial describes how to produce test-coverage metrics for C/C++ projects. We start by instrumenting an autotools build to produce gcov output with gcc; we then generate test coverage artifacts by running our test suite, and finally we explore our results using lcov.

Introduction

We’d like to assess the quality of the existing test suite for each Product Strategy project. A measurement of test coverage will tell us what part of the project’s code is “covered” or exercised by its tests. 50% is a start; 80% would be a good goal for a neglected project; one rarely encounters 100% test coverage, but we’d like to get as close as we can. Initially we’ll use these findings to gain an overview of the test-quality of each project; ultimately these metrics will guide the improvement of our codebase, and enable us to monitor our progress using Jenkins and associated open-source tools.

A Three-Part Process in Several Steps

We’ll enable test-coverage of a particular C/C++ project in a three-part process:

enabling a special build

running the tests

studying the output

Our first step will be to enable a special build. Ultimately this just means adding a few flags to our gcc invocation, but it never seems so straightforward with autotools projects Read more

Last week was my first one at Canonical and I spent it in Budapest where Ubuntu Engineering and Product Strategy teams had their rally. This is the first company where I was asked to travel on my first day and it did feel strange at the beginning Read more

With Canonical’s growing engagement with test driven development (TDD), we recently started introducing Google Test to a number of our upstream projects. Google Test is a unit testing framework targeted towards C & C++. It is lightweight and offers a load of features that ease unit testing tremendously. Most importantly, it supports automatic test case registration and the notions of test suite environments and fixtures. Here, a developer’s efficiency is our main focus. We acknowledge that providing a decent test coverage requires time and effort and we would like to free a developer from writing boiler plate code for test case setup, teardown and for acutally assembling his test cases.

Recently, we started working on an extension to Google test that introduces a dummy (read:headless) X server environment by means of a custom Google test environment and custom Google test fixtures. In summary, the extension starts and stops a dummy xserver and makes sure that a connection to the server is established correctly as part of the test setup procedure. On tear down, the connection to the X server is terminated before the server instance is stopped. Jump over to launchpad for the actual project and take a look at utouch-frame for a real-world application of the extension.

Test Case Result Integration with Jenkins CI

Continuous integration is a hot topic at Canonical and automatic execution of unit test suites is an integral part of our development model. For this reason, we store all unit test results in Google test’s XML dialect and export it to Jenkins to provide user, developers and QA with a summary of a project’s build status.

Conclusions & Outlook

With the introduction of Google test & Jenkins CI to Canonical’s testing landscape we want to provide the plumbing layer for a TDD environment that is loved by developers. It is the first step towards supporting engineers with meaningful metrics to further understand our software ecosystem and identify blank spots on our software map. Thus, stay tuned for Allan Lesage‘s work on code coverage calculation going to land in the not too distant future Read more