Merging from trunk

svn path=/nixos/branches/stdenv-updates/; revision=25176
This commit is contained in:
Lluís Batlle i Rossell
2010-12-17 14:59:04 +00:00
31 changed files with 911 additions and 166 deletions

View File

@@ -108,7 +108,7 @@ rec {
virtualisation.qemu.options =
lib.flip lib.concatMapStrings interfacesNumbered
({ first, second }: qemuNICFlags second first );
({ first, second }: qemuNICFlags second first m.second);
};
}
)

View File

@@ -2,8 +2,8 @@
{
qemuNICFlags = nic: net:
"-net nic,vlan=${toString nic},model=virtio " +
qemuNICFlags = nic: net: machine:
"-net nic,vlan=${toString nic},macaddr=52:54:00:12:${toString net}:${toString machine},model=virtio " +
# Use 232.0.1.<vlan> as the multicast address to connect VMs on
# the same vlan, but allow it to be overriden using the
# $QEMU_MCAST_ADDR_<vlan> environment variable. The test driver

View File

@@ -19,11 +19,20 @@ for (my $n = 0; $n < 256; $n++) {
$ENV{"QEMU_MCAST_ADDR_$n"} = "$mcastPrefix.$n.$mcastSuffix";
}
my $showGraphics = defined $ENV{'DISPLAY'};
sub new {
my ($class, $args) = @_;
my $startCommand = $args->{startCommand};
my $name = $args->{name};
if (!$name) {
$startCommand =~ /run-(.*)-vm$/;
$name = $1 || "machine";
}
if (!$startCommand) {
# !!! merge with qemu-vm.nix.
$startCommand =
@@ -34,12 +43,8 @@ sub new {
$startCommand .= "-cdrom $args->{cdrom} "
if defined $args->{cdrom};
$startCommand .= $args->{qemuFlags} || "";
}
my $name = $args->{name};
if (!$name) {
$startCommand =~ /run-(.*)-vm$/;
$name = $1 || "machine";
} else {
$startCommand = Cwd::abs_path $startCommand;
}
my $tmpDir = $ENV{'TMPDIR'} || "/tmp";
@@ -51,7 +56,7 @@ sub new {
pid => 0,
connected => 0,
socket => undef,
stateDir => "$tmpDir/$name",
stateDir => "$tmpDir/vm-state-$name",
monitor => undef,
};
@@ -121,12 +126,14 @@ sub start {
dup2(fileno($serialC), fileno(STDERR));
$ENV{TMPDIR} = $self->{stateDir};
$ENV{USE_TMPDIR} = 1;
$ENV{QEMU_OPTS} = "-nographic -no-reboot -monitor unix:./monitor -chardev socket,id=shell,path=./shell";
$ENV{QEMU_OPTS} =
"-no-reboot -monitor unix:./monitor -chardev socket,id=shell,path=./shell " .
($showGraphics ? "-serial stdio" : "-nographic");
$ENV{QEMU_NET_OPTS} = "guestfwd=tcp:10.0.2.6:23-chardev:shell";
$ENV{QEMU_KERNEL_PARAMS} = "hostTmpDir=$ENV{TMPDIR}";
chdir $self->{stateDir} or die;
exec $self->{startCommand};
die;
die "running VM script: $!";
}
# Process serial line output.
@@ -248,7 +255,8 @@ sub execute {
my $out = "";
while (1) {
my $line = readline($self->{socket}) or die "connection to VM lost unexpectedly";
my $line = readline($self->{socket});
die "connection to VM lost unexpectedly" unless defined $line;
#$self->log("got line: $line");
if ($line =~ /^(.*)\|\!\=EOF\s+(\d+)$/) {
$out .= $1;
@@ -267,7 +275,7 @@ sub succeed {
my ($status, $out) = $self->execute($command);
if ($status != 0) {
$self->log("output: $out");
die "command `$command' did not succeed (exit code $status)";
die "command `$command' did not succeed (exit code $status)\n";
}
$res .= $out;
}
@@ -404,7 +412,8 @@ sub unblock {
# Take a screenshot of the X server on :0.0.
sub screenshot {
my ($self, $filename) = @_;
$filename = "$ENV{'out'}/${filename}.png" if $filename =~ /^\w+$/;
my $dir = $ENV{'out'} || Cwd::abs_path(".");
$filename = "$dir/${filename}.png" if $filename =~ /^\w+$/;
my $tmp = "${filename}.ppm";
$self->sendMonitorCommand("screendump $tmp");
system("convert $tmp ${filename}") == 0

View File

@@ -1,8 +1,13 @@
#! @perl@ -w -I@libDir@ -I@readline@
use strict;
use Machine;
use Term::ReadLine;
$SIG{PIPE} = 'IGNORE'; # because Unix domain sockets may die unexpectedly
$ENV{PATH} = "@extraPath@:$ENV{PATH}";
STDERR->autoflush(1);
my %vms;
@@ -26,10 +31,13 @@ sub runTests {
eval "$context $ENV{tests}";
die $@ if $@;
} else {
while (<STDIN>) {
my $term = Term::ReadLine->new('nixos-vm-test');
$term->ReadHistory;
while (defined ($_ = $term->readline("> "))) {
eval "$context $_\n";
warn $@ if $@;
}
$term->WriteHistory;
}
# Copy the kernel coverage data for each machine, if the kernel

View File

@@ -8,6 +8,27 @@ rec {
inherit pkgs;
testDriver = stdenv.mkDerivation {
name = "nixos-test-driver";
buildCommand =
''
mkdir -p $out/bin
cp ${./test-driver/test-driver.pl} $out/bin/nixos-test-driver
chmod u+x $out/bin/nixos-test-driver
libDir=$out/lib/perl5/site_perl
mkdir -p $libDir
cp ${./test-driver/Machine.pm} $libDir/Machine.pm
substituteInPlace $out/bin/nixos-test-driver \
--subst-var-by perl "${perl}/bin/perl" \
--subst-var-by readline "${perlPackages.TermReadLineGnu}/lib/perl5/site_perl" \
--subst-var-by extraPath "${imagemagick}/bin" \
--subst-var libDir
'';
};
# Run an automated test suite in the given virtual network.
# `network' must be the result of a call to the
# `buildVirtualNetwork' function. `tests' is a Perl fragment
@@ -20,15 +41,13 @@ rec {
inherit tests;
buildInputs = [ pkgs.qemu_kvm pkgs.imagemagick ];
buildInputs = [ pkgs.qemu_kvm ];
buildCommand =
''
mkdir $out
cp ${./test-driver/Machine.pm} Machine.pm
ensureDir $out/nix-support
${perl}/bin/perl ${./test-driver/test-driver.pl} ${network}/vms/*/bin/run-*-vm
${testDriver}/bin/nixos-test-driver ${network}/vms/*/bin/run-*-vm
for i in */coverage-data; do
ensureDir $out/coverage-data
@@ -98,13 +117,38 @@ rec {
if t ? nodes then t.nodes else
if t ? machine then { machine = t.machine; }
else { };
vms = buildVirtualNetwork { inherit nodes; };
test = runTests vms
testScript =
# Call the test script with the computed nodes.
(if builtins.isFunction t.testScript then t.testScript { inherit (vms) nodes; } else t.testScript);
if builtins.isFunction t.testScript
then t.testScript { inherit (vms) nodes; }
else t.testScript;
test = runTests vms testScript;
report = makeReport test;
# Generate a convenience wrapper for running the test driver
# interactively with the specified network.
driver = runCommand "nixos-test-driver"
{ buildInputs = [ makeWrapper];
inherit testScript;
}
''
mkdir -p $out/bin
ln -s ${vms}/bin/* $out/bin/
ln -s ${testDriver}/bin/* $out/bin/
wrapProgram $out/bin/nixos-test-driver \
--add-flags "${vms}/vms/*/bin/run-*-vm" \
--run "testScript=\"\$(cat $out/test-script)\"" \
--set testScript '"$testScript"'
echo "$testScript" > $out/test-script
''; # "
};
runInMachine =
{ drv
, machine
@@ -140,7 +184,7 @@ rec {
export PATH=${qemu_kvm}/bin:${coreutils}/bin
cp ${./test-driver/Machine.pm} Machine.pm
export tests='${testscript}'
${perl}/bin/perl ${./test-driver/test-driver.pl} ${vms}/vms/*/bin/run-*-vm
${testDriver}/bin/nixos-test-driver ${vms}/vms/*/bin/run-*-vm
''; # */
in
@@ -152,6 +196,7 @@ rec {
origBuilder = attrs.builder;
});
runInMachineWithX = { require ? [], ...}@args :
let
client =
@@ -174,6 +219,7 @@ rec {
'' ;
} // args );
simpleTest = as: (makeTest ({ ... }: as)).test;
}