2011-01-05 16:27:21 +01:00
#! /somewhere/perl -w
2010-12-16 16:54:15 +01:00
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
use strict ;
use Machine ;
2010-12-16 16:54:15 +01:00
use Term::ReadLine ;
2011-01-05 15:04:38 +01:00
use IO::File ;
2011-01-14 17:01:47 +01:00
use IO::Pty ;
2011-01-06 18:28:35 +01:00
use Logger ;
2011-01-12 19:47:23 +01:00
use Cwd ;
2011-01-14 17:01:47 +01:00
use POSIX qw( _exit dup2 ) ;
2016-12-29 13:59:52 +01:00
use Time::HiRes qw( clock_gettime CLOCK_MONOTONIC ) ;
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
$ SIG { PIPE } = 'IGNORE' ; # because Unix domain sockets may die unexpectedly
2010-01-05 12:43:38 +01:00
STDERR - > autoflush ( 1 ) ;
2011-01-06 18:28:35 +01:00
my $ log = new Logger ;
2011-01-05 16:27:21 +01:00
2011-01-05 15:04:38 +01:00
2011-01-12 19:47:23 +01:00
# Start vde_switch for each network required by the test.
my % vlans ;
foreach my $ vlan ( split / / , $ ENV { VLANS } || "" ) {
next if defined $ vlans { $ vlan } ;
2011-01-14 17:01:47 +01:00
# Start vde_switch as a child process. We don't run it in daemon
# mode because we want the child process to be cleaned up when we
# die. Since we have to make sure that the control socket is
# ready, we send a dummy command to vde_switch (via stdin) and
# wait for a reply. Note that vde_switch requires stdin to be a
# TTY, so we create one.
2011-01-12 19:47:23 +01:00
$ log - > log ( "starting VDE switch for network $vlan" ) ;
my $ socket = Cwd:: abs_path "./vde$vlan.ctl" ;
2011-01-14 17:01:47 +01:00
my $ pty = new IO:: Pty ;
my ( $ stdoutR , $ stdoutW ) ; pipe $ stdoutR , $ stdoutW ;
my $ pid = fork ( ) ; die "cannot fork" unless defined $ pid ;
if ( $ pid == 0 ) {
dup2 ( fileno ( $ pty - > slave ) , 0 ) ;
dup2 ( fileno ( $ stdoutW ) , 1 ) ;
2017-06-07 11:57:36 +02:00
exec "vde_switch -s $socket --dirmode 0700" or _exit ( 1 ) ;
2011-01-14 17:01:47 +01:00
}
close $ stdoutW ;
print $ pty "version\n" ;
2011-02-22 11:41:11 +01:00
readline $ stdoutR or die "cannot start vde_switch" ;
2011-01-12 19:47:23 +01:00
$ ENV { "QEMU_VDE_SOCKET_$vlan" } = $ socket ;
2011-01-14 17:01:47 +01:00
$ vlans { $ vlan } = $ pty ;
2011-02-22 11:41:11 +01:00
die unless - e "$socket/ctl" ;
2011-01-12 19:47:23 +01:00
}
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
my % vms ;
my $ context = "" ;
2011-01-05 16:27:21 +01:00
sub createMachine {
my ( $ args ) = @ _ ;
2012-07-20 18:03:15 +02:00
my $ vm = Machine - > new ( { % { $ args } , log = > $ log , redirectSerial = > ( $ ENV { USE_SERIAL } // "0" ) ne "1" } ) ;
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
$ vms { $ vm - > name } = $ vm ;
2014-05-21 14:05:43 +02:00
$ context . = "my \$" . $ vm - > name . " = \$vms{'" . $ vm - > name . "'}; " ;
2011-01-05 16:27:21 +01:00
return $ vm ;
}
foreach my $ vmScript ( @ ARGV ) {
my $ vm = createMachine ( { startCommand = > $ vmScript } ) ;
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
}
sub startAll {
2011-01-06 18:28:35 +01:00
$ log - > nest ( "starting all VMs" , sub {
$ _ - > start foreach values % vms ;
} ) ;
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
}
2012-06-22 20:31:07 +02:00
# Wait until all VMs have terminated.
sub joinAll {
$ log - > nest ( "waiting for all VMs to finish" , sub {
$ _ - > waitForShutdown foreach values % vms ;
} ) ;
}
2011-01-05 15:04:38 +01:00
# In interactive tests, this allows the non-interactive test script to
# be executed conveniently.
sub testScript {
eval "$context $ENV{testScript};\n" ;
warn $@ if $@ ;
}
2011-01-06 18:28:35 +01:00
my $ nrTests = 0 ;
my $ nrSucceeded = 0 ;
sub subtest {
my ( $ name , $ coderef ) = @ _ ;
$ log - > nest ( "subtest: $name" , sub {
$ nrTests + + ;
2011-01-09 19:46:02 +01:00
eval { & $ coderef } ;
if ( $@ ) {
$ log - > log ( "error: $@" , { error = > 1 } ) ;
} else {
$ nrSucceeded + + ;
}
2011-01-06 18:28:35 +01:00
} ) ;
}
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
sub runTests {
2010-01-04 17:30:54 +01:00
if ( defined $ ENV { tests } ) {
2011-01-09 18:58:52 +01:00
$ log - > nest ( "running the VM test script" , sub {
eval "$context $ENV{tests}" ;
2011-01-09 23:52:27 +01:00
if ( $@ ) {
$ log - > log ( "error: $@" , { error = > 1 } ) ;
die $@ ;
}
2011-01-09 18:58:52 +01:00
} , { expanded = > 1 } ) ;
2010-01-04 17:30:54 +01:00
} else {
2010-12-16 16:54:15 +01:00
my $ term = Term::ReadLine - > new ( 'nixos-vm-test' ) ;
$ term - > ReadHistory ;
while ( defined ( $ _ = $ term - > readline ( "> " ) ) ) {
2010-01-04 17:30:54 +01:00
eval "$context $_\n" ;
warn $@ if $@ ;
}
2010-12-16 16:54:15 +01:00
$ term - > WriteHistory ;
2010-01-04 17:30:54 +01:00
}
2009-09-02 00:50:46 +02:00
# Copy the kernel coverage data for each machine, if the kernel
# has been compiled with coverage instrumentation.
2011-01-12 19:47:23 +01:00
$ log - > nest ( "collecting coverage data" , sub {
foreach my $ vm ( values % vms ) {
my $ gcovDir = "/sys/kernel/debug/gcov" ;
2010-01-04 14:22:43 +01:00
2011-01-12 19:47:23 +01:00
next unless $ vm - > isUp ( ) ;
2010-02-06 14:08:15 +01:00
2011-01-12 19:47:23 +01:00
my ( $ status , $ out ) = $ vm - > execute ( "test -e $gcovDir" ) ;
next if $ status != 0 ;
2009-09-02 00:50:46 +02:00
2011-01-12 19:47:23 +01:00
# Figure out where to put the *.gcda files so that the
# report generator can find the corresponding kernel
# sources.
2012-07-23 03:19:02 +02:00
my $ kernelDir = $ vm - > mustSucceed ( "echo \$(dirname \$(readlink -f /run/current-system/kernel))/.build/linux-*" ) ;
2011-01-12 19:47:23 +01:00
chomp $ kernelDir ;
2011-08-09 16:07:44 +02:00
my $ coverageDir = "/tmp/xchg/coverage-data/$kernelDir" ;
2009-09-02 00:50:46 +02:00
2011-01-12 19:47:23 +01:00
# Copy all the *.gcda files.
$ vm - > execute ( "for d in $gcovDir/nix/store/*/.build/linux-*; do for i in \$(cd \$d && find -name '*.gcda'); do echo \$i; mkdir -p $coverageDir/\$(dirname \$i); cp -v \$d/\$i $coverageDir/\$i; done; done" ) ;
}
} ) ;
2011-01-06 18:28:35 +01:00
2014-03-03 13:37:44 +01:00
$ log - > nest ( "syncing" , sub {
foreach my $ vm ( values % vms ) {
next unless $ vm - > isUp ( ) ;
2014-04-07 13:21:13 +02:00
$ vm - > execute ( "sync" ) ;
2014-03-03 13:37:44 +01:00
}
} ) ;
2011-01-06 18:28:35 +01:00
if ( $ nrTests != 0 ) {
2011-01-09 19:46:02 +01:00
$ log - > log ( "$nrSucceeded out of $nrTests tests succeeded" ,
2011-01-09 19:56:11 +01:00
( $ nrSucceeded < $ nrTests ? { error = > 1 } : { } ) ) ;
2011-01-06 18:28:35 +01:00
}
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
}
2012-04-11 12:05:29 +02:00
# Create an empty raw virtual disk with the given name and size (in
2010-01-06 15:37:23 +01:00
# MiB).
sub createDisk {
my ( $ name , $ size ) = @ _ ;
2012-04-11 12:05:29 +02:00
system ( "qemu-img create -f raw $name ${size}M" ) == 0
2010-01-06 15:37:23 +01:00
or die "cannot create image of size $size" ;
}
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
END {
2011-01-12 19:47:23 +01:00
$ log - > nest ( "cleaning up" , sub {
foreach my $ vm ( values % vms ) {
if ( $ vm - > { pid } ) {
$ log - > log ( "killing " . $ vm - > { name } . " (pid " . $ vm - > { pid } . ")" ) ;
kill 9 , $ vm - > { pid } ;
}
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
}
2011-01-12 19:47:23 +01:00
} ) ;
2011-01-06 18:28:35 +01:00
$ log - > close ( ) ;
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
}
2016-12-29 13:59:52 +01:00
my $ now1 = clock_gettime ( CLOCK_MONOTONIC ) ;
* Stuff for automatic and manual testing of NixOS VMs.
lib/build-vms.nix contains a function `buildVirtualNetwork' that
takes a specification of a network of machines (as an attribute set
of NixOS machine configurations) and builds a script that starts
each configuration in a separate QEMU/KVM VM and connects them
together in a virtual network. This script can be run manually to
test the VMs interactively. There is also a function `runTests'
that starts and runs the virtual network in a derivation, and
then executes a test specification that tells the VMs to do certain
things (i.e., letting one VM send an HTTP request to a webserver on
another VM). The tests are written in Perl (for now).
tests/subversion.nix shows a simple example, namely a network of two
machines: a webserver that runs the Subversion subservice, and a
client. Apache, Subversion and a few other packages are built with
coverage analysis instrumentation. For instance,
$ nix-build tests/subversion.nix -A vms
$ ./result/bin/run-vms
starts two QEMU/KVM instances. When they have finished booting, the
webserver can be accessed from the host through
http://localhost:8081/.
It also has a small test suite:
$ nix-build tests/subversion.nix -A report
This runs the VMs in a derivation, runs the tests, and then produces
a distributed code coverage analysis report (i.e. it shows the
combined coverage on both machines).
The Perl test driver program is in lib/test-driver. It executes
commands on the guest machines by connecting to a root shell running
on port 514 (provided by modules/testing/test-instrumentation.nix).
The VMs are connected together in a virtual network using QEMU's
multicast feature. This isn't very secure. At the very least,
other processes on the same machine can listen to or send packets on
the virtual network. On the plus side, we don't need to be root to
set up a multicast virtual network, so we can do it from a
derivation. Maybe we can use VDE instead.
(Moved from the vario repository.)
svn path=/nixos/trunk/; revision=16899
2009-08-31 16:25:12 +02:00
runTests ;
2011-01-09 19:56:11 +01:00
2016-12-29 13:59:52 +01:00
my $ now2 = clock_gettime ( CLOCK_MONOTONIC ) ;
printf STDERR "test script finished in %.2fs\n" , $ now2 - $ now1 ;
2011-01-09 19:56:11 +01:00
exit ( $ nrSucceeded < $ nrTests ? 1 : 0 ) ;