OS-autoinst: Test module development HowTo
Test Modules are contained in .pm files and contain perl code.
Best is to copy and modify an existing module.
Example
x11test.d/500_banshee.pm :
use base "basetest";
use bmwqemu;
sub is_applicable()
{
return $ENV{DESKTOP
} eq "gnome" && !$ENV{LIVECD
};
}
sub run()
{
x11_start_program("banshee-1");
$self->take_screenshot;
sendkey "ctrl-q"; # really quit (alt-f4 just backgrounds)
sendkey "alt-f4";
waitidle;
}
sub checklist()
{
# return hashref:
055ef0f7abcff0ebf91f545ce290ef9a OK
9b0ed4c97220f047a16252aad1aca253 OK
b178bcd5587d55b8fc5aadfd1e18bad0 OK
)}
}
1;
Explanation
Filename matters - the number(500 in this case) determines the order of execution and the name will be used for screenshots and result summary in the log
Line 1: Code is object-oriented, so individual tests are derived from the basetest class.
Line 2: Test code also calls utility functions exported from bmwqemu.pm, so this line imports it.
Line 4: some tests only make sense under certain circumstances, so the is_applicable() method is overridden here. The default basetest::is_applicable always returns 1 so that the test is always run.
Line 6: only return 1 for gnome testruns - and LiveCD also does not contain banshee, so that is skipped as well.
Line 9: Overriding the run method is mandatory
Line 12: x11_start_program uses Alt-F2 keycombo available on KDE/GNOME/XFCE/LXDE to start the given program
Line 13: capture and write a screenshot of the VM to testresults/.../banshee-1.ppm using the test module's filename and a counter
Line 14: sendkey sends one single key(-combination) to the test VM
Line 16: waitidle waits until CPU usage of kvm goes below the IDLETHRESHOLD value defined in env.sh
Line 19: override checklist method. default is to return {} (an empty hash reference).
Line 23: define which screenshot-section md5sums occur with good ("OK") or bad ("fail") results - md5sums can be taken from logfile or computed with tools/inststagedetect2.pl SomeOfYour.ppm
Line 29: all perl modules must return a true value
Function reference
basetest.pm only has the take_screenshot method to be called by child-classes.
bmwqemu.pm exports these functions for use in test modules:
- waitinststage("splashscreen|booted"[, timeout]) - wait until a stage name matching this pattern occurs. The underlying inststagedetect function currently uses md5sums from goodimage.pm
- waitidle([timeout]) - waits until CPU usage of kvm goes below the IDLETHRESHOLD value defined in env.sh
- waitstillimage([stilltime][, timeout]) waits for the VGA output to remain constant for stilltime seconds but at most timeout seconds. returns 0 on timeout
- waitserial(regexp[, timeout]) - wait for a message to appear on serial output
- waitimage(glob[, timeout]) - wait for one of the image files appearing in VM screenshot
- sendkey - sends one single key(-combination) to the test VM
- sendkeyw - as above, but with waitidle at the end
- sendautotype - type a string using sendkey. The \n \t \e and \b control codes are understood.
- mouse_set - move mouse cursor - input between 0 and 800/600
- mouse_hide - move mouse cursor to the bottom right corner to less disturb tests
Further information
If you want to know more, you can check the basetest.pm and bmwqemu.pm code or have a look at other examples in consoletest.d/ or x11test.d/ directory.