diff --git a/lib/test-driver/Machine.pm b/lib/test-driver/Machine.pm index 28596a5d634..b9dae819b49 100644 --- a/lib/test-driver/Machine.pm +++ b/lib/test-driver/Machine.pm @@ -251,7 +251,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; @@ -270,7 +271,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; } @@ -407,7 +408,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 diff --git a/lib/test-driver/test-driver.pl b/lib/test-driver/test-driver.pl index ad1af5a6fbf..6735b52dd69 100644 --- a/lib/test-driver/test-driver.pl +++ b/lib/test-driver/test-driver.pl @@ -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 () { + 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 diff --git a/lib/testing.nix b/lib/testing.nix index 02c011c5bc8..f7c25d938a8 100644 --- a/lib/testing.nix +++ b/lib/testing.nix @@ -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 @@ -103,6 +122,17 @@ rec { # Call the test script with the computed nodes. (if builtins.isFunction t.testScript then t.testScript { inherit (vms) nodes; } else t.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]; } + '' + 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" + ''; # " }; runInMachine = @@ -140,7 +170,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