forked from mirrors/nixpkgs
* 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
This commit is contained in:
parent
1da72333d9
commit
816f12da88
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 . "'}; ";
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
28
tests/installer.nix
Normal file
28
tests/installer.nix
Normal file
|
@ -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");
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue