3
0
Fork 0
forked from mirrors/nixpkgs

* Add a method Machine::sleep to sleep N seconds in virtual (guest)

time rather than host real time.

svn path=/nixos/trunk/; revision=25491
This commit is contained in:
Eelco Dolstra 2011-01-10 14:41:16 +00:00
parent 8db3bdc4fc
commit 60b6eb7579
7 changed files with 32 additions and 21 deletions

View file

@ -467,10 +467,12 @@ sub screenshot {
# testing the existence of /tmp/.X11-unix/X0 is insufficient.
sub waitForX {
my ($self, $regexp) = @_;
retry sub {
my ($status, $out) = $self->execute("xwininfo -root > /dev/null 2>&1");
return 1 if $status == 0;
}
$self->nest("waiting for the X11 server", sub {
retry sub {
my ($status, $out) = $self->execute("xwininfo -root > /dev/null 2>&1");
return 1 if $status == 0;
}
});
}
@ -484,12 +486,14 @@ sub getWindowNames {
sub waitForWindow {
my ($self, $regexp) = @_;
retry sub {
my @names = $self->getWindowNames;
foreach my $n (@names) {
return 1 if $n =~ /$regexp/;
$self->nest("waiting for a window to appear", sub {
retry sub {
my @names = $self->getWindowNames;
foreach my $n (@names) {
return 1 if $n =~ /$regexp/;
}
}
}
});
}
@ -518,4 +522,11 @@ sub sendChars {
}
# Sleep N seconds (in virtual guest time, not real time).
sub sleep {
my ($self, $time) = @_;
$self->succeed("sleep $time");
}
1;

View file

@ -46,7 +46,7 @@ with pkgs;
# More DNS-SD.
$one->execute("avahi-publish -s \"This is a test\" _test._tcp 123 one=1 &");
sleep 5;
$one->sleep(5);
print STDERR
$two->mustSucceed("avahi-browse -r -t _test._tcp | tee out");
$two->mustSucceed("test `wc -l < out` -gt 0");

View file

@ -13,8 +13,8 @@
''
$machine->waitForX;
$machine->execute("firefox file://${pkgs.valgrind}/share/doc/valgrind/html/index.html &");
$machine->waitForWindow(/Valgrind.*Shiretoko/);
sleep 40; # wait until Firefox has finished loading the page
$machine->waitForWindow(qr/Valgrind/);
$machine->sleep(40); # wait until Firefox has finished loading the page
$machine->screenshot("screen");
'';

View file

@ -45,7 +45,7 @@
$machine->waitForWindow(qr/messages.*KWrite/);
$machine->waitForWindow(qr/Valgrind.*Konqueror/);
sleep 5;
$machine->sleep(5);
$machine->screenshot("screen");
'';

View file

@ -16,7 +16,7 @@
$machine->waitForJob("tty1");
$machine->sendChars("alice\n");
$machine->waitUntilSucceeds("pgrep login");
$machine->execute("sleep 2"); # urgh: wait for `Password:'
$machine->sleep(2); # urgh: wait for `Password:'
$machine->sendChars("foobar\n");
$machine->waitUntilSucceeds("pgrep -u alice bash");
$machine->sendChars("touch done\n");
@ -27,7 +27,7 @@
subtest "virtual console switching", sub {
$machine->sendKeys("alt-f10");
$machine->waitUntilSucceeds("[ \$(fgconsole) = 10 ]");
$machine->execute("sleep 2"); # allow fbcondecor to catch up (not important)
$machine->sleep(2); # allow fbcondecor to catch up (not important)
$machine->screenshot("syslog");
};
@ -35,10 +35,10 @@
# ownership as needed.
subtest "device permissions", sub {
$machine->succeed("chvt 1");
$machine->execute("sleep 1"); # urgh
$machine->sleep(1); # urgh
$machine->succeed("getfacl /dev/snd/timer | grep -q alice");
$machine->succeed("chvt 2");
$machine->execute("sleep 1"); # urgh
$machine->sleep(1); # urgh
$machine->fail("getfacl /dev/snd/timer | grep -q alice");
};

View file

@ -56,18 +56,18 @@ rec {
$server->waitUntilSucceeds("grep -q 'Foo.*entered the game' /tmp/log");
$server->waitUntilSucceeds("grep -q 'Bar.*entered the game' /tmp/log");
sleep 10; # wait for a while to get a nice screenshot
$server->sleep(10); # wait for a while to get a nice screenshot
$client1->block();
sleep 20;
$server->sleep(20);
$client1->screenshot("screen1");
$client2->screenshot("screen2");
$client1->unblock();
sleep 10;
$server->sleep(10);
$client1->screenshot("screen3");
$client2->screenshot("screen4");

View file

@ -69,7 +69,7 @@
$client->waitForX;
$client->execute("konqueror http://webserver/projects/test &");
$client->waitForWindow(qr/Test.*Konqueror/);
sleep 30; # loading takes a long time
$client->sleep(30); # loading takes a long time
$client->screenshot("screen");
'';