From 1b21115f61c668c8ca3cd47cda3840f2be3b0032 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Jan 2010 14:37:23 +0000 Subject: [PATCH] * Support creating a virtual disk in the test driver. svn path=/nixos/trunk/; revision=19263 --- lib/test-driver/Machine.pm | 21 ++++++++++++++------- lib/test-driver/test-driver.pl | 9 +++++++++ modules/installer/cd-dvd/iso-image.nix | 1 + tests/installer.nix | 24 ++++++++++++++++++++++-- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/lib/test-driver/Machine.pm b/lib/test-driver/Machine.pm index ad39ed62a01a..92d390b15c03 100644 --- a/lib/test-driver/Machine.pm +++ b/lib/test-driver/Machine.pm @@ -7,6 +7,7 @@ use Socket; use IO::Handle; use POSIX qw(dup2); use FileHandle; +use Cwd; # Stuff our PID in the multicast address/port to prevent collissions @@ -24,6 +25,8 @@ sub new { $startCommand = "qemu-system-x86_64 -m 384 -no-kvm-irqchip " . "-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} " if defined $args->{cdrom}; #-drive file=$NIX_DISK_IMAGE,if=virtio,boot=on @@ -186,13 +189,17 @@ sub execute { sub mustSucceed { - my ($self, $command) = @_; - my ($status, $out) = $self->execute($command); - if ($status != 0) { - $self->log("output: $out"); - die "command `$command' did not succeed (exit code $status)"; + my ($self, @commands) = @_; + my $res; + foreach my $command (@commands) { + my ($status, $out) = $self->execute($command); + 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) = @_; return unless $self->{booted}; - $self->execute("poweroff -f &"); + $self->execute("poweroff"); $self->waitForShutdown; } diff --git a/lib/test-driver/test-driver.pl b/lib/test-driver/test-driver.pl index 6bac1f1dd39c..2ccc6bd4b9a9 100644 --- a/lib/test-driver/test-driver.pl +++ b/lib/test-driver/test-driver.pl @@ -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 { foreach my $vm (values %vms) { if ($vm->{pid}) { diff --git a/modules/installer/cd-dvd/iso-image.nix b/modules/installer/cd-dvd/iso-image.nix index ea9709a99255..e97b3a51cdca 100644 --- a/modules/installer/cd-dvd/iso-image.nix +++ b/modules/installer/cd-dvd/iso-image.nix @@ -204,6 +204,7 @@ in chainloader +1 } ''; + boot.loader.grub.timeout = 10; # Create the ISO image. diff --git a/tests/installer.nix b/tests/installer.nix index f57f8e90a3e2..ca712b9fc4d9 100644 --- a/tests/installer.nix +++ b/tests/installer.nix @@ -12,17 +12,37 @@ rec { ../modules/testing/test-instrumentation.nix { key = "serial"; boot.kernelParams = [ "console=tty1" "console=ttyS0" ]; + boot.loader.grub.timeout = pkgs.lib.mkOverride 0 {} 0; } ]; }).config.system.build.isoImage; testScript = '' - #createDisk("harddisk", 2 * 1024); + createDisk("harddisk", 4 * 1024); my $machine = Machine->new({ hda => "harddisk", cdrom => glob("${iso}/iso/*.iso") }); - $machine->start; $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; ''; }