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.


x11test.d/500_banshee.pm :
  1. use base "basetest";
  2. use bmwqemu;
  4. sub is_applicable()
  5. {
  6.         return $ENV{DESKTOP} eq "gnome" && !$ENV{LIVECD};
  7. }
  9. sub run()
  10. {
  11.         my $self=shift;
  12.         x11_start_program("banshee-1");
  13.         $self->take_screenshot;
  14.         sendkey "ctrl-q"; # really quit (alt-f4 just backgrounds)
  15.         sendkey "alt-f4";
  16.         waitidle;
  17. }
  19. sub checklist()
  20. {
  21.         # return hashref:
  22.         return {qw(
  23.                 055ef0f7abcff0ebf91f545ce290ef9a OK
  24.                 9b0ed4c97220f047a16252aad1aca253 OK
  25.                 b178bcd5587d55b8fc5aadfd1e18bad0 OK
  26.         )}
  27. }
  29. 1;


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:

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.

Valid XHTML 1.0! IPv6 logo