diff --git a/lib/test-driver/Machine.pm b/lib/test-driver/Machine.pm index 34ea4e5e65ce..a3c714b3a86a 100644 --- a/lib/test-driver/Machine.pm +++ b/lib/test-driver/Machine.pm @@ -287,4 +287,24 @@ sub screenshot { } +sub getWindowNames { + my ($self) = @_; + my $res = $self->mustSucceed( + q{DISPLAY=:0.0 xwininfo -root -tree | sed 's/.*0x[0-9a-f]* \"\([^\"]*\)\".*/\1/; t; d'}); + return split /\n/, $res; +} + + +sub waitForWindow { + my ($self, $regexp) = @_; + while (1) { + my @names = $self->getWindowNames; + foreach my $n (@names) { + return if $n =~ /$regexp/; + } + sleep 2; + } +}; + + 1; diff --git a/modules/testing/test-instrumentation.nix b/modules/testing/test-instrumentation.nix index 2dd1a90b966e..a563852e22c0 100644 --- a/modules/testing/test-instrumentation.nix +++ b/modules/testing/test-instrumentation.nix @@ -48,6 +48,9 @@ with pkgs.lib; # Panic if an error occurs in stage 1 (rather than waiting for # user intervention). boot.kernelParams = [ "stage1panic" ]; + + # `xwininfo' is used by the test driver to query open windows. + environment.systemPackages = [ pkgs.xorg.xwininfo ]; }; diff --git a/tests/kde4.nix b/tests/kde4.nix index f13b87b07633..3b91b738cb7f 100644 --- a/tests/kde4.nix +++ b/tests/kde4.nix @@ -36,18 +36,16 @@ testScript = '' - $machine->waitForFile("/tmp/.X11-unix/X0"); - - sleep 70; + $machine->waitForWindow(qr/plasma-desktop/); $machine->execute("su - alice -c 'DISPLAY=:0.0 kwrite /var/log/messages &'"); - - sleep 10; - $machine->execute("su - alice -c 'DISPLAY=:0.0 konqueror http://localhost/ &'"); - sleep 10; + $machine->waitForWindow(qr/messages.*KWrite/); + $machine->waitForWindow(qr/Valgrind.*Konqueror/); + sleep 5; + $machine->screenshot("screen"); '';