3
0
Fork 0
forked from mirrors/nixpkgs

* Support creating a virtual disk in the test driver.

svn path=/nixos/trunk/; revision=19263
This commit is contained in:
Eelco Dolstra 2010-01-06 14:37:23 +00:00
parent 816f12da88
commit 1b21115f61
4 changed files with 46 additions and 9 deletions

View file

@ -7,6 +7,7 @@ use Socket;
use IO::Handle; use IO::Handle;
use POSIX qw(dup2); use POSIX qw(dup2);
use FileHandle; use FileHandle;
use Cwd;
# Stuff our PID in the multicast address/port to prevent collissions # Stuff our PID in the multicast address/port to prevent collissions
@ -24,6 +25,8 @@ sub new {
$startCommand = $startCommand =
"qemu-system-x86_64 -m 384 -no-kvm-irqchip " . "qemu-system-x86_64 -m 384 -no-kvm-irqchip " .
"-net nic,model=virtio -net user \$QEMU_OPTS "; "-net nic,model=virtio -net user \$QEMU_OPTS ";
$startCommand .= "-drive file=" . Cwd::abs_path($args->{hda}) . ",if=virtio,boot=on "
if defined $args->{hda};
$startCommand .= "-cdrom $args->{cdrom} " $startCommand .= "-cdrom $args->{cdrom} "
if defined $args->{cdrom}; if defined $args->{cdrom};
#-drive file=$NIX_DISK_IMAGE,if=virtio,boot=on #-drive file=$NIX_DISK_IMAGE,if=virtio,boot=on
@ -186,13 +189,17 @@ sub execute {
sub mustSucceed { sub mustSucceed {
my ($self, $command) = @_; my ($self, @commands) = @_;
my ($status, $out) = $self->execute($command); my $res;
if ($status != 0) { foreach my $command (@commands) {
$self->log("output: $out"); my ($status, $out) = $self->execute($command);
die "command `$command' did not succeed (exit code $status)"; if ($status != 0) {
$self->log("output: $out");
die "command `$command' did not succeed (exit code $status)";
}
$res .= $out;
} }
return $out; return $res;
} }
@ -266,7 +273,7 @@ sub shutdown {
my ($self) = @_; my ($self) = @_;
return unless $self->{booted}; return unless $self->{booted};
$self->execute("poweroff -f &"); $self->execute("poweroff");
$self->waitForShutdown; $self->waitForShutdown;
} }

View file

@ -52,6 +52,15 @@ sub runTests {
} }
# Create an empty qcow2 virtual disk with the given name and size (in
# MiB).
sub createDisk {
my ($name, $size) = @_;
system("qemu-img create -f qcow2 $name ${size}M") == 0
or die "cannot create image of size $size";
}
END { END {
foreach my $vm (values %vms) { foreach my $vm (values %vms) {
if ($vm->{pid}) { if ($vm->{pid}) {

View file

@ -204,6 +204,7 @@ in
chainloader +1 chainloader +1
} }
''; '';
boot.loader.grub.timeout = 10; boot.loader.grub.timeout = 10;
# Create the ISO image. # Create the ISO image.

View file

@ -12,17 +12,37 @@ rec {
../modules/testing/test-instrumentation.nix ../modules/testing/test-instrumentation.nix
{ key = "serial"; { key = "serial";
boot.kernelParams = [ "console=tty1" "console=ttyS0" ]; boot.kernelParams = [ "console=tty1" "console=ttyS0" ];
boot.loader.grub.timeout = pkgs.lib.mkOverride 0 {} 0;
} }
]; ];
}).config.system.build.isoImage; }).config.system.build.isoImage;
testScript = testScript =
'' ''
#createDisk("harddisk", 2 * 1024); createDisk("harddisk", 4 * 1024);
my $machine = Machine->new({ hda => "harddisk", cdrom => glob("${iso}/iso/*.iso") }); my $machine = Machine->new({ hda => "harddisk", cdrom => glob("${iso}/iso/*.iso") });
$machine->start;
$machine->mustSucceed("echo hello"); $machine->mustSucceed("echo hello");
# Make sure that we get a login prompt etc.
$machine->waitForJob("tty1");
$machine->waitForJob("rogue");
$machine->waitForJob("nixos-manual");
# Partition the disk.
$machine->mustSucceed(
"parted /dev/vda mklabel msdos",
"parted /dev/vda mkpart primary linux-swap 0 1G",
"parted /dev/vda mkpart primary ext2 1G 3G",
# It can take udev a moment to create /dev/vda*.
"udevadm settle",
"mkswap /dev/vda1 -L swap",
"swapon -L swap",
"mkfs.ext3 -L nixos /dev/vda2",
"mount LABEL=nixos /mnt",
);
$machine->shutdown;
''; '';
} }