My current project I'm working on is based on embedded systems and QT platform. Of course the very first task in the project is to implement some kind of testing method to get feedback on software quality. The test system is composed from few components:
- Automatic crash reports collected on central server
- Automatic random test runners connected to always-running (24/7) devices to catch crashes
First channel collects all crashes (from human and automated tests), second channel is performed fully automatically. Second channel allows to measure MMTF (mean time between failures) and analyse changes in time, probably helping with estimating current software quality state.
Second testing channel requires automatic test driver to inject random UI events (key presses, remote in my case). I used QT message queue for that purpose:
void TestScript::sendKey(int keyCode) {
QWSServer::sendKeyEvent(0, keyCode, Qt::NoModifier, 1, false);
msleep(PRESS_DELAY_MS);
QWSServer::sendKeyEvent(0, keyCode, Qt::NoModifier, 0, false);
msleep(WAIT_DELAY_MS);
}
Because QWSServer::sendKeyEvent() must be called in the same process like main application I decided to implement named pipe that will accept key names and render sequence of key events, pseudo-code below:
while (true) {
FILE* f = fopen("/tmp/events.pipe", "rt");
(...)
while (getline(&buf, &size, f) >= 0) {
QString line(buf);
(...)
if (mapNameToKey.contains(line)) {
sendKey(mapNameToKey.value(line));
QCoreApplication::processEvents();
}
(...)
}
fclose(f);
}
And usage:
echo "RCU_RIGHT" > /tmp/events.pipe
echo "RCU_OK" > /tmp/events.pipe
That's way I'm able to remotely control application (need just SSH access to the device). And the last (easiest) part is to generate random sequence of events - that can be done by any scripting langugae.
Happy automation!