summary refs log tree commit diff
path: root/lib/test-driver/Machine.pm
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2010-02-06 13:08:15 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2010-02-06 13:08:15 +0000
commit55c349fe201a6dd09364afc846517c87eb9cf767 (patch)
tree4673a00dbea9195f7404f3bd3fb27cc1c63c9ed9 /lib/test-driver/Machine.pm
parentfc805fe541c5844064a33f24c3dd709452ff1af0 (diff)
downloadnixpkgs-55c349fe201a6dd09364afc846517c87eb9cf767.tar
nixpkgs-55c349fe201a6dd09364afc846517c87eb9cf767.tar.gz
nixpkgs-55c349fe201a6dd09364afc846517c87eb9cf767.tar.bz2
nixpkgs-55c349fe201a6dd09364afc846517c87eb9cf767.tar.lz
nixpkgs-55c349fe201a6dd09364afc846517c87eb9cf767.tar.xz
nixpkgs-55c349fe201a6dd09364afc846517c87eb9cf767.tar.zst
nixpkgs-55c349fe201a6dd09364afc846517c87eb9cf767.zip
* Added a test that checks whether users can log in on a virtual
  console.  This uses the `sendkey' command in the QEMU monitor.
* For the block/unblock primitives, use the `set_link' command in the
  QEMU monitor.

svn path=/nixos/trunk/; revision=19854
Diffstat (limited to 'lib/test-driver/Machine.pm')
-rw-r--r--lib/test-driver/Machine.pm43
1 files changed, 38 insertions, 5 deletions
diff --git a/lib/test-driver/Machine.pm b/lib/test-driver/Machine.pm
index 6840f4e2af0..634f566bd1a 100644
--- a/lib/test-driver/Machine.pm
+++ b/lib/test-driver/Machine.pm
@@ -107,7 +107,7 @@ sub start {
         dup2(fileno($serialC), fileno(STDOUT));
         dup2(fileno($serialC), fileno(STDERR));
         $ENV{TMPDIR} = $self->{stateDir};
-        $ENV{QEMU_OPTS} = "-nographic -no-reboot -redir tcp:65535::514 -net nic,vlan=1 -net socket,vlan=1,mcast=$mcastAddr -monitor unix:./monitor";
+        $ENV{QEMU_OPTS} = "-nographic -no-reboot -redir tcp:65535::514 -net nic,vlan=1,model=virtio -net socket,vlan=1,mcast=$mcastAddr -monitor unix:./monitor";
         $ENV{QEMU_KERNEL_PARAMS} = "hostTmpDir=$ENV{TMPDIR}";
         chdir $self->{stateDir} or die;
         exec $self->{startCommand};
@@ -146,6 +146,7 @@ sub start {
 # all commands yet.  We should use it once it does.
 sub sendMonitorCommand {
     my ($self, $command) = @_;
+    $self->log("sending monitor command: $command");
     syswrite $self->{monitor}, "$command\n";
     return $self->waitForMonitorPrompt;
 }
@@ -215,6 +216,13 @@ sub waitForShutdown {
     waitpid $self->{pid}, 0;
     $self->{pid} = 0;
     $self->{booted} = 0;
+    $self->{connected} = 0;
+}
+
+
+sub isUp {
+    my ($self) = @_;
+    return $self->{booted} && $self->{connected};
 }
 
 
@@ -266,6 +274,15 @@ sub waitUntilSucceeds {
 }
 
 
+sub waitUntilFails {
+    my ($self, $command) = @_;
+    retry sub {
+        my ($status, $out) = $self->execute($command);
+        return 1 if $status != 0;
+    };
+}
+
+
 sub mustFail {
     my ($self, $command) = @_;
     my ($status, $out) = $self->execute($command);
@@ -337,14 +354,14 @@ sub shutdown {
 # the test driver can continue to talk to the machine.
 sub block {
     my ($self) = @_;
-    $self->mustSucceed("ifconfig eth1 down");
+    $self->sendMonitorCommand("set_link virtio-net-pci.1 down");
 }
 
 
 # Make the machine reachable.
 sub unblock {
     my ($self) = @_;
-    $self->mustSucceed("ifconfig eth1 up");
+    $self->sendMonitorCommand("set_link virtio-net-pci.1 up");
 }
 
 
@@ -368,7 +385,7 @@ sub waitForX {
         my ($status, $out) = $self->execute("xwininfo -root > /dev/null 2>&1");
         return 1 if $status == 0;
     }
-};
+}
 
 
 sub getWindowNames {
@@ -387,7 +404,7 @@ sub waitForWindow {
             return 1 if $n =~ /$regexp/;
         }
     }
-};
+}
 
 
 sub copyFileFromHost {
@@ -397,4 +414,20 @@ sub copyFileFromHost {
 }
 
 
+sub sendKeys {
+    my ($self, @keys) = @_;
+    foreach my $key (@keys) {
+        $key = "spc" if $key eq " ";
+        $key = "ret" if $key eq "\n";
+        $self->sendMonitorCommand("sendkey $key");
+    }
+}
+
+
+sub sendChars {
+    my ($self, $chars) = @_;
+    $self->sendKeys(split //, $chars);
+}
+
+
 1;