* 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 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;
}

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 {
foreach my $vm (values %vms) {
if ($vm->{pid}) {

View file

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

View file

@ -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;
'';
}