From 816f12da885b1ac8c961ac628c932297a9f5cd2f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Jan 2010 13:36:21 +0000 Subject: [PATCH] * Test driver: added support for running from an ISO image. The goal is to merge test-nixos-install-from-cd so that we have a single testing framework. svn path=/nixos/trunk/; revision=19259 --- lib/test-driver/Machine.pm | 26 ++++++++++++++++++++------ lib/test-driver/test-driver.pl | 2 +- lib/testing.nix | 4 ++++ tests/default.nix | 8 ++++++-- tests/installer.nix | 28 ++++++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 tests/installer.nix diff --git a/lib/test-driver/Machine.pm b/lib/test-driver/Machine.pm index 8f0bd0a88bc3..ad39ed62a01a 100644 --- a/lib/test-driver/Machine.pm +++ b/lib/test-driver/Machine.pm @@ -16,15 +16,29 @@ print STDERR "using multicast address $mcastAddr\n"; sub new { - my ($class, $vmScript) = @_; + my ($class, $args) = @_; - $vmScript =~ /run-(.*)-vm$/ or die; - my $name = $1; + my $startCommand = $args->{startCommand}; + if (!$startCommand) { + # !!! merge with qemu-vm.nix. + $startCommand = + "qemu-system-x86_64 -m 384 -no-kvm-irqchip " . + "-net nic,model=virtio -net user \$QEMU_OPTS "; + $startCommand .= "-cdrom $args->{cdrom} " + if defined $args->{cdrom}; + #-drive file=$NIX_DISK_IMAGE,if=virtio,boot=on + } + + my $name = $args->{name}; + if (!$name) { + $startCommand =~ /run-(.*)-vm$/; + $name = $1 || "machine"; + } my $tmpDir = $ENV{'TMPDIR'} || "/tmp"; my $self = { - script => $vmScript, + startCommand => $startCommand, name => $name, booted => 0, pid => 0, @@ -79,9 +93,9 @@ sub start { dup2(fileno(NUL), fileno(STDIN)); $ENV{TMPDIR} = $self->{stateDir}; $ENV{QEMU_OPTS} = "-nographic -no-reboot -redir tcp:65535::514 -net nic,vlan=1 -net socket,vlan=1,mcast=$mcastAddr"; - $ENV{QEMU_KERNEL_PARAMS} = "console=ttyS0 panic=1 hostTmpDir=$ENV{TMPDIR}"; + $ENV{QEMU_KERNEL_PARAMS} = "console=tty1 console=ttyS0 panic=1 hostTmpDir=$ENV{TMPDIR}"; chdir $self->{stateDir} or die; - exec $self->{script}; + exec $self->{startCommand}; die; } diff --git a/lib/test-driver/test-driver.pl b/lib/test-driver/test-driver.pl index 65d051eb1707..6bac1f1dd39c 100644 --- a/lib/test-driver/test-driver.pl +++ b/lib/test-driver/test-driver.pl @@ -10,7 +10,7 @@ my $context = ""; foreach my $vmScript (@ARGV) { - my $vm = Machine->new($vmScript); + my $vm = Machine->new({startCommand => $vmScript}); $vms{$vm->name} = $vm; $context .= "my \$" . $vm->name . " = \$vms{'" . $vm->name . "'}; "; } diff --git a/lib/testing.nix b/lib/testing.nix index 28ee564517e3..6df4cd397dde 100644 --- a/lib/testing.nix +++ b/lib/testing.nix @@ -14,7 +14,11 @@ rec { stdenv.mkDerivation { name = "vm-test-run"; inherit tests; + scrot = "${pkgs.scrot}/bin/scrot"; + + buildInputs = [ pkgs.qemu_kvm ]; + buildCommand = '' mkdir $out diff --git a/tests/default.nix b/tests/default.nix index 833d06b1f5df..735b8bbbd4ad 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -12,9 +12,12 @@ let apply = testFun: with testLib; let - t = testFun { inherit pkgs testLib; }; + t = testFun { inherit pkgs nixpkgs system testLib; }; in t // rec { - nodes = if t ? nodes then t.nodes else { machine = t.machine; }; + nodes = + if t ? nodes then t.nodes else + if t ? machine then { machine = t.machine; } + else { }; vms = buildVirtualNetwork { inherit nodes; }; test = runTests vms t.testScript; report = makeReport test; @@ -24,6 +27,7 @@ in { firefox = apply (import ./firefox.nix); + installer = apply (import ./installer.nix); kde4 = apply (import ./kde4.nix); quake3 = apply (import ./quake3.nix); subversion = apply (import ./subversion.nix); diff --git a/tests/installer.nix b/tests/installer.nix new file mode 100644 index 000000000000..f57f8e90a3e2 --- /dev/null +++ b/tests/installer.nix @@ -0,0 +1,28 @@ +{ pkgs, nixpkgs, system, ... }: + +rec { + + # Build the ISO. This is the regular installation CD but with test + # instrumentation. + iso = + (import ../lib/eval-config.nix { + inherit nixpkgs system; + modules = + [ ../modules/installer/cd-dvd/installation-cd-minimal.nix + ../modules/testing/test-instrumentation.nix + { key = "serial"; + boot.kernelParams = [ "console=tty1" "console=ttyS0" ]; + } + ]; + }).config.system.build.isoImage; + + testScript = + '' + #createDisk("harddisk", 2 * 1024); + + my $machine = Machine->new({ hda => "harddisk", cdrom => glob("${iso}/iso/*.iso") }); + $machine->start; + + $machine->mustSucceed("echo hello"); + ''; +}