mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-16 06:45:16 +01:00
* Added a convenience derivation for running the test driver
interactively on a network specification. For instance: $ nix-build tests/ -A quake3.driver $ ./result/bin/nixos-test-driver > startAll; client1: starting vm client1: QEMU running (pid 14971) server: starting vm server: QEMU running (pid 14982) ... > $client1->execute("quake3 ..."); * Use the GNU readline library in interactive mode. svn path=/nixos/trunk/; revision=25156
This commit is contained in:
parent
8496dbf350
commit
445827ad45
3 changed files with 50 additions and 10 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue