Simulating 2G/3G/4G modem behavior in ModemManager tests

Unit testing is a very powerful approach to quickly find issues that may have been introduced in your software. I have always been very interested in unit testing, even more since my first professional job at Panda Security was implementing a whole new unit testing system for a desktop antivirus.

In ModemManager we had some unit testing support, but it was really only focused on making sure that our AT response parsers worked correctly. These tests are of course very important, not saying they aren’t, but they only cover a very small subset of the implementation.

Supporting completely different devices from multiple vendors with completely different behaviors, while still providing a unified interface for all of them is a very challenging task. In particular, making changes to fix the behavior of one device may lead to broken behavior with others, and the AT response parser unit tests really are not up to the task of finding those issues. So, in order to improve that, we have now included a nice black box system testing environment along with the common unit tests, which can not only simulate AT-based modems, but also let us play with the ModemManager DBus interface directly. And all this by just running make check!

Keep on reading if you want to know how all this was setup :)

simulator-step-1-bus

Every test using the new black box system testing will run a common test setup method before the actual test (and a common teardown method after having run it). This setup method will take care of launching a private DBus session using the excellent GTestDBus implementation in GLib/GIO. Once the new bus is ready to use, the test setup will also request a Ping() to the standard org.freedesktop.DBus.Peer interface in ModemManager, which in turn will make the daemon get started by DBus. Once the test fixture is setup, the test itself will be able to make use of the ModemManager process running in the private session, without any interference with the ModemManager that may already be running in the standard system-level bus.

simulator-step-2-thread

Each test will then setup the simulation of the modem, by launching a separate thread running a Unix-domain socket service. This socket will have an abstract address, and will allow other processes to get connected to send/receive data. In addition to the socket service, the simulator will also read a dictionary of AT requests and responses from a text file included in the test context. This pair of socket and AT chat build together the simulation of an AT port of a modem: AT requests will arrive through the socket, and the simulator will reply the corresponding AT response gathered from the AT chat dictionary. If the dictionary doesn’t have the response expected for a given request, it will just reply “ERROR”.

simulator-step-3-test-modem

But the private ModemManager instance doesn’t know anything about the new modem simulator being available, as there is no real physical port being created that ModemManager could get notified about via udev. So, once the simulator is in place, the test will report the abstract address of the socket via the SetProfile() method in the new org.freedesktop.ModemManager.Test interface. This method will just tell ModemManager that a given new virtual AT port is available in a given abstract socket address, and ModemManager will go on creating a new AT virtual port object internally and treat it as if it were a new TTY reported by udev.

simulator-step-4-detect-modem

As soon as ModemManager knows about the new virtual AT port, it will start probing it and creating a whole Modem object internally. Of course, for this to work well, the simulated modem needs to be able to reply correctly to most AT requests sent by ModemManager. The current implementation provides a generic AT chat dictionary for 3GPP (GSM, UMTS, HSPA, LTE…) devices, and the overall idea is that tests can load first the generic one to get a basic subset of responses, and then load a vendor-specific one with vendor-specific responses (overriding the generic ones if needed).

simulator-step-5-unit-test

And of course, the last step is the test itself. Once every previous step has been successfully executed, the tester can now play with the standard ModemManager interfaces in DBus, querying for modems, requesting PIN unlock, enabling or disabling the device, and so on.

The currently available setup is not fully featured yet, it just provides some basic building blocks to be able to extend the black box system tests further more. The real work comes now, adding new behavior tests and writing new AT chat dictionaries to simulate different devices. If you want to play yourself with this setup, get the latest code from git master!

About these ads

Posted on February 14, 2014, in FreeDesktop Planet, GNOME Planet, GNU Planet, ModemManager, Planets, Uncategorized and tagged , , . Bookmark the permalink. 2 Comments.

  1. Awesome work Aleksander. Thanks!

  2. Yeah, thanks for taking time to describe all this abstract stuff.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 57 other followers

%d bloggers like this: