mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 21:50:33 +03:00
* 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
5 changed files with 59 additions and 9 deletions
|
@ -16,15 +16,29 @@ print STDERR "using multicast address $mcastAddr\n";
|
||||||
|
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, $vmScript) = @_;
|
my ($class, $args) = @_;
|
||||||
|
|
||||||
$vmScript =~ /run-(.*)-vm$/ or die;
|
my $startCommand = $args->{startCommand};
|
||||||
my $name = $1;
|
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 $tmpDir = $ENV{'TMPDIR'} || "/tmp";
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
script => $vmScript,
|
startCommand => $startCommand,
|
||||||
name => $name,
|
name => $name,
|
||||||
booted => 0,
|
booted => 0,
|
||||||
pid => 0,
|
pid => 0,
|
||||||
|
@ -79,9 +93,9 @@ sub start {
|
||||||
dup2(fileno(NUL), fileno(STDIN));
|
dup2(fileno(NUL), fileno(STDIN));
|
||||||
$ENV{TMPDIR} = $self->{stateDir};
|
$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_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;
|
chdir $self->{stateDir} or die;
|
||||||
exec $self->{script};
|
exec $self->{startCommand};
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ my $context = "";
|
||||||
|
|
||||||
|
|
||||||
foreach my $vmScript (@ARGV) {
|
foreach my $vmScript (@ARGV) {
|
||||||
my $vm = Machine->new($vmScript);
|
my $vm = Machine->new({startCommand => $vmScript});
|
||||||
$vms{$vm->name} = $vm;
|
$vms{$vm->name} = $vm;
|
||||||
$context .= "my \$" . $vm->name . " = \$vms{'" . $vm->name . "'}; ";
|
$context .= "my \$" . $vm->name . " = \$vms{'" . $vm->name . "'}; ";
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,11 @@ rec {
|
||||||
stdenv.mkDerivation {
|
stdenv.mkDerivation {
|
||||||
name = "vm-test-run";
|
name = "vm-test-run";
|
||||||
inherit tests;
|
inherit tests;
|
||||||
|
|
||||||
scrot = "${pkgs.scrot}/bin/scrot";
|
scrot = "${pkgs.scrot}/bin/scrot";
|
||||||
|
|
||||||
|
buildInputs = [ pkgs.qemu_kvm ];
|
||||||
|
|
||||||
buildCommand =
|
buildCommand =
|
||||||
''
|
''
|
||||||
mkdir $out
|
mkdir $out
|
||||||
|
|
|
@ -12,9 +12,12 @@ let
|
||||||
apply = testFun:
|
apply = testFun:
|
||||||
with testLib;
|
with testLib;
|
||||||
let
|
let
|
||||||
t = testFun { inherit pkgs testLib; };
|
t = testFun { inherit pkgs nixpkgs system testLib; };
|
||||||
in t // rec {
|
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; };
|
vms = buildVirtualNetwork { inherit nodes; };
|
||||||
test = runTests vms t.testScript;
|
test = runTests vms t.testScript;
|
||||||
report = makeReport test;
|
report = makeReport test;
|
||||||
|
@ -24,6 +27,7 @@ in
|
||||||
|
|
||||||
{
|
{
|
||||||
firefox = apply (import ./firefox.nix);
|
firefox = apply (import ./firefox.nix);
|
||||||
|
installer = apply (import ./installer.nix);
|
||||||
kde4 = apply (import ./kde4.nix);
|
kde4 = apply (import ./kde4.nix);
|
||||||
quake3 = apply (import ./quake3.nix);
|
quake3 = apply (import ./quake3.nix);
|
||||||
subversion = apply (import ./subversion.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…
Add table
Add a link
Reference in a new issue