* 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 15:25:12 +01:00
|
|
|
|
package Machine;
|
|
|
|
|
|
|
|
|
|
use strict;
|
2010-01-04 18:04:57 +00:00
|
|
|
|
use threads;
|
* 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 15:25:12 +01:00
|
|
|
|
use Socket;
|
|
|
|
|
use IO::Handle;
|
|
|
|
|
use POSIX qw(dup2);
|
2010-01-04 18:04:57 +00:00
|
|
|
|
use FileHandle;
|
2010-01-06 14:37:23 +00:00
|
|
|
|
use Cwd;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
use File::Basename;
|
2012-08-16 15:47:33 +01:00
|
|
|
|
use File::Path qw(make_path);
|
2015-05-21 18:06:09 +01:00
|
|
|
|
use File::Slurp;
|
* 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 15:25:12 +01:00
|
|
|
|
|
|
|
|
|
|
2010-12-16 16:58:06 +00:00
|
|
|
|
my $showGraphics = defined $ENV{'DISPLAY'};
|
|
|
|
|
|
2012-08-16 15:47:33 +01:00
|
|
|
|
my $sharedDir;
|
|
|
|
|
|
* 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 15:25:12 +01:00
|
|
|
|
|
|
|
|
|
sub new {
|
2010-01-06 13:36:21 +00:00
|
|
|
|
my ($class, $args) = @_;
|
|
|
|
|
|
|
|
|
|
my $startCommand = $args->{startCommand};
|
2015-06-10 11:02:48 +01:00
|
|
|
|
|
2010-12-16 13:53:17 +00:00
|
|
|
|
my $name = $args->{name};
|
|
|
|
|
if (!$name) {
|
2011-02-16 10:07:28 +00:00
|
|
|
|
$startCommand =~ /run-(.*)-vm$/ if defined $startCommand;
|
2010-12-16 13:53:17 +00:00
|
|
|
|
$name = $1 || "machine";
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 13:36:21 +00:00
|
|
|
|
if (!$startCommand) {
|
|
|
|
|
# !!! merge with qemu-vm.nix.
|
|
|
|
|
$startCommand =
|
2013-07-31 13:53:27 +01:00
|
|
|
|
"qemu-kvm -m 384 " .
|
2011-03-19 08:58:56 +00:00
|
|
|
|
"-net nic,model=virtio \$QEMU_OPTS ";
|
2018-04-30 00:43:17 +01:00
|
|
|
|
|
|
|
|
|
if (defined $args->{hda}) {
|
|
|
|
|
if ($args->{hdaInterface} eq "scsi") {
|
|
|
|
|
$startCommand .= "-drive id=hda,file="
|
|
|
|
|
. Cwd::abs_path($args->{hda})
|
|
|
|
|
. ",werror=report,if=none "
|
|
|
|
|
. "-device scsi-hd,drive=hda ";
|
|
|
|
|
} else {
|
|
|
|
|
$startCommand .= "-drive file=" . Cwd::abs_path($args->{hda})
|
|
|
|
|
. ",if=" . $args->{hdaInterface}
|
|
|
|
|
. ",werror=report ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 13:36:21 +00:00
|
|
|
|
$startCommand .= "-cdrom $args->{cdrom} "
|
|
|
|
|
if defined $args->{cdrom};
|
2014-11-19 22:18:44 +00:00
|
|
|
|
$startCommand .= "-device piix3-usb-uhci -drive id=usbdisk,file=$args->{usb},if=none,readonly -device usb-storage,drive=usbdisk "
|
|
|
|
|
if defined $args->{usb};
|
|
|
|
|
$startCommand .= "-bios $args->{bios} "
|
|
|
|
|
if defined $args->{bios};
|
2010-05-27 13:20:37 +01:00
|
|
|
|
$startCommand .= $args->{qemuFlags} || "";
|
2010-01-06 13:36:21 +00: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 15:25:12 +01:00
|
|
|
|
|
|
|
|
|
my $tmpDir = $ENV{'TMPDIR'} || "/tmp";
|
2012-08-16 15:47:33 +01:00
|
|
|
|
unless (defined $sharedDir) {
|
|
|
|
|
$sharedDir = $tmpDir . "/xchg-shared";
|
|
|
|
|
make_path($sharedDir, { mode => 0700, owner => $< });
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-31 18:31:18 +01:00
|
|
|
|
my $allowReboot = 0;
|
|
|
|
|
$allowReboot = $args->{allowReboot} if defined $args->{allowReboot};
|
|
|
|
|
|
* 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 15:25:12 +01:00
|
|
|
|
my $self = {
|
2010-01-06 13:36:21 +00:00
|
|
|
|
startCommand => $startCommand,
|
* 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 15:25:12 +01:00
|
|
|
|
name => $name,
|
2013-07-31 18:31:18 +01:00
|
|
|
|
allowReboot => $allowReboot,
|
* 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 15:25:12 +01:00
|
|
|
|
booted => 0,
|
|
|
|
|
pid => 0,
|
|
|
|
|
connected => 0,
|
|
|
|
|
socket => undef,
|
2010-12-16 16:58:06 +00:00
|
|
|
|
stateDir => "$tmpDir/vm-state-$name",
|
2010-02-05 16:51:37 +00:00
|
|
|
|
monitor => undef,
|
2011-01-06 17:28:35 +00:00
|
|
|
|
log => $args->{log},
|
2012-07-20 17:03:15 +01:00
|
|
|
|
redirectSerial => $args->{redirectSerial} // 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 15:25:12 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mkdir $self->{stateDir}, 0700;
|
|
|
|
|
|
|
|
|
|
bless $self, $class;
|
|
|
|
|
return $self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub log {
|
|
|
|
|
my ($self, $msg) = @_;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->{log}->log($msg, { machine => $self->{name} });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub nest {
|
|
|
|
|
my ($self, $msg, $coderef, $attrs) = @_;
|
|
|
|
|
$self->{log}->nest($msg, $coderef, { %{$attrs || {}}, machine => $self->{name} });
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub name {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return $self->{name};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-09-01 23:22:45 +01:00
|
|
|
|
sub stateDir {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return $self->{stateDir};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
* 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 15:25:12 +01:00
|
|
|
|
sub start {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return if $self->{booted};
|
|
|
|
|
|
|
|
|
|
$self->log("starting vm");
|
|
|
|
|
|
2010-02-05 16:51:37 +00:00
|
|
|
|
# Create a socket pair for the serial line input/output of the VM.
|
|
|
|
|
my ($serialP, $serialC);
|
|
|
|
|
socketpair($serialP, $serialC, PF_UNIX, SOCK_STREAM, 0) or die;
|
2010-01-04 18:04:57 +00:00
|
|
|
|
|
2010-02-05 16:51:37 +00:00
|
|
|
|
# Create a Unix domain socket to which QEMU's monitor will connect.
|
|
|
|
|
my $monitorPath = $self->{stateDir} . "/monitor";
|
|
|
|
|
unlink $monitorPath;
|
|
|
|
|
my $monitorS;
|
|
|
|
|
socket($monitorS, PF_UNIX, SOCK_STREAM, 0) or die;
|
|
|
|
|
bind($monitorS, sockaddr_un($monitorPath)) or die "cannot bind monitor socket: $!";
|
|
|
|
|
listen($monitorS, 1) or die;
|
|
|
|
|
|
2010-06-18 20:31:02 +01:00
|
|
|
|
# Create a Unix domain socket to which the root shell in the guest will connect.
|
|
|
|
|
my $shellPath = $self->{stateDir} . "/shell";
|
|
|
|
|
unlink $shellPath;
|
|
|
|
|
my $shellS;
|
|
|
|
|
socket($shellS, PF_UNIX, SOCK_STREAM, 0) or die;
|
|
|
|
|
bind($shellS, sockaddr_un($shellPath)) or die "cannot bind shell socket: $!";
|
|
|
|
|
listen($shellS, 1) or die;
|
|
|
|
|
|
2010-02-05 16:51:37 +00:00
|
|
|
|
# Start the VM.
|
* 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 15:25:12 +01:00
|
|
|
|
my $pid = fork();
|
|
|
|
|
die if $pid == -1;
|
|
|
|
|
|
|
|
|
|
if ($pid == 0) {
|
2010-02-05 16:51:37 +00:00
|
|
|
|
close $serialP;
|
|
|
|
|
close $monitorS;
|
2010-06-18 20:31:02 +01:00
|
|
|
|
close $shellS;
|
2012-07-20 17:03:15 +01:00
|
|
|
|
if ($self->{redirectSerial}) {
|
|
|
|
|
open NUL, "</dev/null" or die;
|
|
|
|
|
dup2(fileno(NUL), fileno(STDIN));
|
|
|
|
|
dup2(fileno($serialC), fileno(STDOUT));
|
|
|
|
|
dup2(fileno($serialC), fileno(STDERR));
|
|
|
|
|
}
|
* 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 15:25:12 +01:00
|
|
|
|
$ENV{TMPDIR} = $self->{stateDir};
|
2012-08-16 15:47:33 +01:00
|
|
|
|
$ENV{SHARED_DIR} = $sharedDir;
|
2010-06-15 17:15:17 +01:00
|
|
|
|
$ENV{USE_TMPDIR} = 1;
|
2010-12-16 16:58:06 +00:00
|
|
|
|
$ENV{QEMU_OPTS} =
|
2013-07-31 18:31:18 +01:00
|
|
|
|
($self->{allowReboot} ? "" : "-no-reboot ") .
|
|
|
|
|
"-monitor unix:./monitor -chardev socket,id=shell,path=./shell " .
|
2011-03-18 12:38:22 +00:00
|
|
|
|
"-device virtio-serial -device virtconsole,chardev=shell " .
|
2017-11-24 12:45:24 +00:00
|
|
|
|
"-device virtio-rng-pci " .
|
2011-07-28 10:41:07 +01:00
|
|
|
|
($showGraphics ? "-serial stdio" : "-nographic") . " " . ($ENV{QEMU_OPTS} || "");
|
* 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 15:25:12 +01:00
|
|
|
|
chdir $self->{stateDir} or die;
|
2010-01-06 13:36:21 +00:00
|
|
|
|
exec $self->{startCommand};
|
2010-12-16 13:53:17 +00:00
|
|
|
|
die "running VM script: $!";
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
2010-01-04 18:04:57 +00:00
|
|
|
|
|
2010-02-05 16:51:37 +00:00
|
|
|
|
# Process serial line output.
|
|
|
|
|
close $serialC;
|
2010-01-04 18:04:57 +00:00
|
|
|
|
|
2010-02-05 16:51:37 +00:00
|
|
|
|
threads->create(\&processSerialOutput, $self, $serialP)->detach;
|
2010-01-04 18:04:57 +00:00
|
|
|
|
|
2010-02-05 16:51:37 +00:00
|
|
|
|
sub processSerialOutput {
|
|
|
|
|
my ($self, $serialP) = @_;
|
|
|
|
|
while (<$serialP>) {
|
2010-01-04 18:04:57 +00:00
|
|
|
|
chomp;
|
2010-06-18 16:30:36 +01:00
|
|
|
|
s/\r$//;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
print STDERR $self->{name}, "# $_\n";
|
|
|
|
|
$self->{log}->{logQueue}->enqueue({msg => $_, machine => $self->{name}}); # !!!
|
2010-01-04 18:04:57 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-18 16:30:36 +01:00
|
|
|
|
eval {
|
|
|
|
|
local $SIG{CHLD} = sub { die "QEMU died prematurely\n"; };
|
2015-06-10 11:02:48 +01:00
|
|
|
|
|
2010-06-18 20:31:02 +01:00
|
|
|
|
# Wait until QEMU connects to the monitor.
|
2010-06-18 16:30:36 +01:00
|
|
|
|
accept($self->{monitor}, $monitorS) or die;
|
2010-06-18 20:31:02 +01:00
|
|
|
|
|
|
|
|
|
# Wait until QEMU connects to the root shell socket. QEMU
|
|
|
|
|
# does so immediately; this doesn't mean that the root shell
|
|
|
|
|
# has connected yet inside the guest.
|
|
|
|
|
accept($self->{socket}, $shellS) or die;
|
|
|
|
|
$self->{socket}->autoflush(1);
|
2010-06-18 16:30:36 +01:00
|
|
|
|
};
|
|
|
|
|
die "$@" if $@;
|
2015-06-10 11:02:48 +01:00
|
|
|
|
|
2010-06-18 16:30:36 +01:00
|
|
|
|
$self->waitForMonitorPrompt;
|
|
|
|
|
|
|
|
|
|
$self->log("QEMU running (pid $pid)");
|
2015-06-10 11:02:48 +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 15:25:12 +01:00
|
|
|
|
$self->{pid} = $pid;
|
|
|
|
|
$self->{booted} = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-05 16:51:37 +00:00
|
|
|
|
# Send a command to the monitor and wait for it to finish. TODO: QEMU
|
|
|
|
|
# also has a JSON-based monitor interface now, but it doesn't support
|
|
|
|
|
# all commands yet. We should use it once it does.
|
|
|
|
|
sub sendMonitorCommand {
|
|
|
|
|
my ($self, $command) = @_;
|
2010-02-06 13:08:15 +00:00
|
|
|
|
$self->log("sending monitor command: $command");
|
2010-02-05 16:51:37 +00:00
|
|
|
|
syswrite $self->{monitor}, "$command\n";
|
|
|
|
|
return $self->waitForMonitorPrompt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Wait until the monitor sends "(qemu) ".
|
|
|
|
|
sub waitForMonitorPrompt {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
my $res = "";
|
|
|
|
|
my $s;
|
|
|
|
|
while (sysread($self->{monitor}, $s, 1024)) {
|
|
|
|
|
$res .= $s;
|
|
|
|
|
last if $res =~ s/\(qemu\) $//;
|
|
|
|
|
}
|
|
|
|
|
return $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-06 15:14:26 +00:00
|
|
|
|
# Call the given code reference repeatedly, with 1 second intervals,
|
|
|
|
|
# until it returns 1 or a timeout is reached.
|
|
|
|
|
sub retry {
|
|
|
|
|
my ($coderef) = @_;
|
|
|
|
|
my $n;
|
2017-06-21 00:53:25 +01:00
|
|
|
|
for ($n = 899; $n >=0; $n--) {
|
|
|
|
|
return if &$coderef($n);
|
2010-01-06 15:14:26 +00:00
|
|
|
|
sleep 1;
|
|
|
|
|
}
|
|
|
|
|
die "action timed out after $n seconds";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
* 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 15:25:12 +01:00
|
|
|
|
sub connect {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return if $self->{connected};
|
|
|
|
|
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->nest("waiting for the VM to finish booting", sub {
|
* 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 15:25:12 +01:00
|
|
|
|
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->start;
|
|
|
|
|
|
2013-09-16 16:15:42 +01:00
|
|
|
|
local $SIG{ALRM} = sub { die "timed out waiting for the VM to connect\n"; };
|
2011-01-06 17:28:35 +00:00
|
|
|
|
alarm 300;
|
2013-09-16 16:15:42 +01:00
|
|
|
|
readline $self->{socket} or die "the VM quit before connecting\n";
|
2011-01-06 17:28:35 +00:00
|
|
|
|
alarm 0;
|
2015-06-10 11:02:48 +01:00
|
|
|
|
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->log("connected to guest root shell");
|
|
|
|
|
$self->{connected} = 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub waitForShutdown {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return unless $self->{booted};
|
2011-01-06 17:28:35 +00:00
|
|
|
|
|
|
|
|
|
$self->nest("waiting for the VM to power off", sub {
|
|
|
|
|
waitpid $self->{pid}, 0;
|
|
|
|
|
$self->{pid} = 0;
|
|
|
|
|
$self->{booted} = 0;
|
|
|
|
|
$self->{connected} = 0;
|
|
|
|
|
});
|
2010-02-06 13:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub isUp {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return $self->{booted} && $self->{connected};
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-01-06 17:28:35 +00:00
|
|
|
|
sub execute_ {
|
* 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 15:25:12 +01:00
|
|
|
|
my ($self, $command) = @_;
|
2015-06-10 11:02:48 +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 15:25:12 +01:00
|
|
|
|
$self->connect;
|
|
|
|
|
|
2009-09-01 23:22:45 +01:00
|
|
|
|
print { $self->{socket} } ("( $command ); echo '|!=EOF' \$?\n");
|
* 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 15:25:12 +01:00
|
|
|
|
|
|
|
|
|
my $out = "";
|
|
|
|
|
|
|
|
|
|
while (1) {
|
2010-12-16 15:54:15 +00:00
|
|
|
|
my $line = readline($self->{socket});
|
|
|
|
|
die "connection to VM lost unexpectedly" unless defined $line;
|
* 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 15:25:12 +01:00
|
|
|
|
#$self->log("got line: $line");
|
|
|
|
|
if ($line =~ /^(.*)\|\!\=EOF\s+(\d+)$/) {
|
|
|
|
|
$out .= $1;
|
|
|
|
|
$self->log("exit status $2");
|
|
|
|
|
return ($2, $out);
|
|
|
|
|
}
|
|
|
|
|
$out .= $line;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-01-06 17:28:35 +00:00
|
|
|
|
sub execute {
|
|
|
|
|
my ($self, $command) = @_;
|
|
|
|
|
my @res;
|
|
|
|
|
$self->nest("running command: $command", sub {
|
|
|
|
|
@res = $self->execute_($command);
|
|
|
|
|
});
|
|
|
|
|
return @res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-05-22 22:27:38 +01:00
|
|
|
|
sub succeed {
|
2010-01-06 14:37:23 +00:00
|
|
|
|
my ($self, @commands) = @_;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
|
2010-01-06 14:37:23 +00:00
|
|
|
|
my $res;
|
|
|
|
|
foreach my $command (@commands) {
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->nest("must succeed: $command", sub {
|
|
|
|
|
my ($status, $out) = $self->execute_($command);
|
|
|
|
|
if ($status != 0) {
|
|
|
|
|
$self->log("output: $out");
|
|
|
|
|
die "command `$command' did not succeed (exit code $status)\n";
|
|
|
|
|
}
|
|
|
|
|
$res .= $out;
|
|
|
|
|
});
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
2011-01-06 17:28:35 +00:00
|
|
|
|
|
2010-01-06 14:37:23 +00:00
|
|
|
|
return $res;
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-05-22 22:27:38 +01:00
|
|
|
|
sub mustSucceed {
|
|
|
|
|
succeed @_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-04 13:59:31 +00:00
|
|
|
|
sub waitUntilSucceeds {
|
|
|
|
|
my ($self, $command) = @_;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->nest("waiting for success: $command", sub {
|
|
|
|
|
retry sub {
|
|
|
|
|
my ($status, $out) = $self->execute($command);
|
|
|
|
|
return 1 if $status == 0;
|
|
|
|
|
};
|
|
|
|
|
});
|
2010-02-04 13:59:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-02-06 13:08:15 +00:00
|
|
|
|
sub waitUntilFails {
|
|
|
|
|
my ($self, $command) = @_;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->nest("waiting for failure: $command", sub {
|
|
|
|
|
retry sub {
|
|
|
|
|
my ($status, $out) = $self->execute($command);
|
|
|
|
|
return 1 if $status != 0;
|
|
|
|
|
};
|
|
|
|
|
});
|
2010-02-06 13:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-09 14:46:52 +01:00
|
|
|
|
sub fail {
|
* 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 15:25:12 +01:00
|
|
|
|
my ($self, $command) = @_;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->nest("must fail: $command", sub {
|
|
|
|
|
my ($status, $out) = $self->execute_($command);
|
|
|
|
|
die "command `$command' unexpectedly succeeded"
|
|
|
|
|
if $status == 0;
|
|
|
|
|
});
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-09 14:46:52 +01:00
|
|
|
|
sub mustFail {
|
|
|
|
|
fail @_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-10-04 17:34:44 +01:00
|
|
|
|
sub getUnitInfo {
|
2017-12-19 14:19:38 +00:00
|
|
|
|
my ($self, $unit, $user) = @_;
|
|
|
|
|
my ($status, $lines) = $self->systemctl("--no-pager show \"$unit\"", $user);
|
2012-10-04 17:34:44 +01:00
|
|
|
|
return undef if $status != 0;
|
|
|
|
|
my $info = {};
|
|
|
|
|
foreach my $line (split '\n', $lines) {
|
|
|
|
|
$line =~ /^([^=]+)=(.*)$/ or next;
|
|
|
|
|
$info->{$1} = $2;
|
|
|
|
|
}
|
|
|
|
|
return $info;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-19 14:19:38 +00:00
|
|
|
|
sub systemctl {
|
|
|
|
|
my ($self, $q, $user) = @_;
|
|
|
|
|
if ($user) {
|
|
|
|
|
$q =~ s/'/\\'/g;
|
|
|
|
|
return $self->execute("su -l $user -c \$'XDG_RUNTIME_DIR=/run/user/`id -u` systemctl --user $q'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $self->execute("systemctl $q");
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-30 20:12:24 +01:00
|
|
|
|
# Fail if the given systemd unit is not in the "active" state.
|
|
|
|
|
sub requireActiveUnit {
|
|
|
|
|
my ($self, $unit) = @_;
|
|
|
|
|
$self->nest("checking if unit ‘$unit’ has reached state 'active'", sub {
|
|
|
|
|
my $info = $self->getUnitInfo($unit);
|
|
|
|
|
my $state = $info->{ActiveState};
|
|
|
|
|
if ($state ne "active") {
|
|
|
|
|
die "Expected unit ‘$unit’ to to be in state 'active' but it is in state ‘$state’\n";
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
2012-10-04 17:34:44 +01:00
|
|
|
|
|
|
|
|
|
# Wait for a systemd unit to reach the "active" state.
|
|
|
|
|
sub waitForUnit {
|
2017-12-19 14:19:38 +00:00
|
|
|
|
my ($self, $unit, $user) = @_;
|
2012-10-04 17:34:44 +01:00
|
|
|
|
$self->nest("waiting for unit ‘$unit’", sub {
|
2011-01-06 17:28:35 +00:00
|
|
|
|
retry sub {
|
2017-12-19 14:19:38 +00:00
|
|
|
|
my $info = $self->getUnitInfo($unit, $user);
|
2012-10-04 17:34:44 +01:00
|
|
|
|
my $state = $info->{ActiveState};
|
|
|
|
|
die "unit ‘$unit’ reached state ‘$state’\n" if $state eq "failed";
|
2015-12-30 11:40:29 +00:00
|
|
|
|
if ($state eq "inactive") {
|
2016-05-24 15:33:14 +01:00
|
|
|
|
# If there are no pending jobs, then assume this unit
|
|
|
|
|
# will never reach active state.
|
2017-12-19 14:19:38 +00:00
|
|
|
|
my ($status, $jobs) = $self->systemctl("list-jobs --full 2>&1", $user);
|
2016-05-24 15:33:14 +01:00
|
|
|
|
if ($jobs =~ /No jobs/) { # FIXME: fragile
|
|
|
|
|
# Handle the case where the unit may have started
|
|
|
|
|
# between the previous getUnitInfo() and
|
|
|
|
|
# list-jobs.
|
|
|
|
|
my $info2 = $self->getUnitInfo($unit);
|
|
|
|
|
die "unit ‘$unit’ is inactive and there are no pending jobs\n"
|
|
|
|
|
if $info2->{ActiveState} eq $state;
|
|
|
|
|
}
|
2015-12-30 11:40:29 +00:00
|
|
|
|
}
|
2012-10-04 17:34:44 +01:00
|
|
|
|
return 1 if $state eq "active";
|
2011-01-06 17:28:35 +00: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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-10-04 17:34:44 +01:00
|
|
|
|
sub waitForJob {
|
|
|
|
|
my ($self, $jobName) = @_;
|
2012-10-19 15:32:09 +01:00
|
|
|
|
return $self->waitForUnit($jobName);
|
2012-10-04 17:34:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-09-02 15:48:28 +01:00
|
|
|
|
# Wait until the specified file exists.
|
|
|
|
|
sub waitForFile {
|
|
|
|
|
my ($self, $fileName) = @_;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->nest("waiting for file ‘$fileName’", sub {
|
|
|
|
|
retry sub {
|
|
|
|
|
my ($status, $out) = $self->execute("test -e $fileName");
|
|
|
|
|
return 1 if $status == 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
2009-09-02 15:48:28 +01:00
|
|
|
|
}
|
|
|
|
|
|
2010-10-10 23:37:45 +01:00
|
|
|
|
sub startJob {
|
2017-12-19 14:19:38 +00:00
|
|
|
|
my ($self, $jobName, $user) = @_;
|
|
|
|
|
$self->systemctl("start $jobName", $user);
|
2012-10-04 17:34:44 +01:00
|
|
|
|
# FIXME: check result
|
2010-10-10 23:37:45 +01:00
|
|
|
|
}
|
2009-09-02 15:48:28 +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 15:25:12 +01:00
|
|
|
|
sub stopJob {
|
2017-12-19 14:19:38 +00:00
|
|
|
|
my ($self, $jobName, $user) = @_;
|
|
|
|
|
$self->systemctl("stop $jobName", $user);
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Wait until the machine is listening on the given TCP port.
|
|
|
|
|
sub waitForOpenPort {
|
|
|
|
|
my ($self, $port) = @_;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->nest("waiting for TCP port $port", sub {
|
|
|
|
|
retry sub {
|
|
|
|
|
my ($status, $out) = $self->execute("nc -z localhost $port");
|
|
|
|
|
return 1 if $status == 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Wait until the machine is not listening on the given TCP port.
|
|
|
|
|
sub waitForClosedPort {
|
|
|
|
|
my ($self, $port) = @_;
|
2010-01-06 15:14:26 +00:00
|
|
|
|
retry sub {
|
* 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 15:25:12 +01:00
|
|
|
|
my ($status, $out) = $self->execute("nc -z localhost $port");
|
2010-01-06 15:14:26 +00:00
|
|
|
|
return 1 if $status != 0;
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub shutdown {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return unless $self->{booted};
|
|
|
|
|
|
2012-10-30 16:01:21 +00:00
|
|
|
|
print { $self->{socket} } ("poweroff\n");
|
* 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 15:25:12 +01:00
|
|
|
|
|
|
|
|
|
$self->waitForShutdown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-06-09 14:46:52 +01:00
|
|
|
|
sub crash {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
return unless $self->{booted};
|
2015-06-10 11:02:48 +01:00
|
|
|
|
|
2012-03-16 20:10:14 +00:00
|
|
|
|
$self->log("forced crash");
|
2010-06-09 14:46:52 +01:00
|
|
|
|
|
|
|
|
|
$self->sendMonitorCommand("quit");
|
|
|
|
|
|
|
|
|
|
$self->waitForShutdown;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
* 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 15:25:12 +01:00
|
|
|
|
# Make the machine unreachable by shutting down eth1 (the multicast
|
|
|
|
|
# interface used to talk to the other VMs). We keep eth0 up so that
|
|
|
|
|
# the test driver can continue to talk to the machine.
|
|
|
|
|
sub block {
|
|
|
|
|
my ($self) = @_;
|
2011-01-09 15:44:48 +00:00
|
|
|
|
$self->sendMonitorCommand("set_link virtio-net-pci.1 off");
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Make the machine reachable.
|
|
|
|
|
sub unblock {
|
|
|
|
|
my ($self) = @_;
|
2011-01-09 15:44:48 +00:00
|
|
|
|
$self->sendMonitorCommand("set_link virtio-net-pci.1 on");
|
* 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 15:25:12 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-05 11:35:59 +00:00
|
|
|
|
# Take a screenshot of the X server on :0.0.
|
|
|
|
|
sub screenshot {
|
|
|
|
|
my ($self, $filename) = @_;
|
2010-12-16 15:54:15 +00:00
|
|
|
|
my $dir = $ENV{'out'} || Cwd::abs_path(".");
|
|
|
|
|
$filename = "$dir/${filename}.png" if $filename =~ /^\w+$/;
|
2010-02-05 16:51:37 +00:00
|
|
|
|
my $tmp = "${filename}.ppm";
|
2011-01-06 17:28:35 +00:00
|
|
|
|
my $name = basename($filename);
|
|
|
|
|
$self->nest("making screenshot ‘$name’", sub {
|
|
|
|
|
$self->sendMonitorCommand("screendump $tmp");
|
2014-09-24 22:48:31 +01:00
|
|
|
|
system("pnmtopng $tmp > ${filename}") == 0
|
2011-01-06 17:28:35 +00:00
|
|
|
|
or die "cannot convert screenshot";
|
|
|
|
|
unlink $tmp;
|
|
|
|
|
}, { image => $name } );
|
2010-01-05 11:35:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 04:58:21 +00:00
|
|
|
|
# Get the text of TTY<n>
|
|
|
|
|
sub getTTYText {
|
|
|
|
|
my ($self, $tty) = @_;
|
|
|
|
|
|
2017-02-12 23:16:18 +00:00
|
|
|
|
my ($status, $out) = $self->execute("fold -w\$(stty -F /dev/tty${tty} size | awk '{print \$2}') /dev/vcs${tty}");
|
2016-11-30 04:58:21 +00:00
|
|
|
|
return $out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Wait until TTY<n>'s text matches a particular regular expression
|
|
|
|
|
sub waitUntilTTYMatches {
|
|
|
|
|
my ($self, $tty, $regexp) = @_;
|
|
|
|
|
|
|
|
|
|
$self->nest("waiting for $regexp to appear on tty $tty", sub {
|
|
|
|
|
retry sub {
|
2017-06-21 01:55:52 +01:00
|
|
|
|
my ($retries_remaining) = @_;
|
|
|
|
|
if ($retries_remaining == 0) {
|
|
|
|
|
$self->log("Last chance to match /$regexp/ on TTY$tty, which currently contains:");
|
|
|
|
|
$self->log($self->getTTYText($tty));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-30 04:58:21 +00:00
|
|
|
|
return 1 if $self->getTTYText($tty) =~ /$regexp/;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Debugging: Dump the contents of the TTY<n>
|
|
|
|
|
sub dumpTTYContents {
|
|
|
|
|
my ($self, $tty) = @_;
|
|
|
|
|
|
|
|
|
|
$self->execute("fold -w 80 /dev/vcs${tty} | systemd-cat");
|
|
|
|
|
}
|
2010-01-05 11:35:59 +00:00
|
|
|
|
|
2015-05-21 18:06:09 +01:00
|
|
|
|
# Take a screenshot and return the result as text using optical character
|
|
|
|
|
# recognition.
|
|
|
|
|
sub getScreenText {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
2015-05-22 07:10:17 +01:00
|
|
|
|
system("command -v tesseract &> /dev/null") == 0
|
2015-05-22 06:14:00 +01:00
|
|
|
|
or die "getScreenText used but enableOCR is false";
|
|
|
|
|
|
2015-05-21 18:06:09 +01:00
|
|
|
|
my $text;
|
|
|
|
|
$self->nest("performing optical character recognition", sub {
|
|
|
|
|
my $tmpbase = Cwd::abs_path(".")."/ocr";
|
|
|
|
|
my $tmpin = $tmpbase."in.ppm";
|
|
|
|
|
|
|
|
|
|
$self->sendMonitorCommand("screendump $tmpin");
|
2017-04-09 22:34:26 +01:00
|
|
|
|
|
|
|
|
|
my $magickArgs = "-filter Catrom -density 72 -resample 300 "
|
|
|
|
|
. "-contrast -normalize -despeckle -type grayscale "
|
|
|
|
|
. "-sharpen 1 -posterize 3 -negate -gamma 100 "
|
|
|
|
|
. "-blur 1x65535";
|
|
|
|
|
my $tessArgs = "-c debug_file=/dev/null --psm 11 --oem 2";
|
|
|
|
|
|
|
|
|
|
$text = `convert $magickArgs $tmpin tiff:- | tesseract - - $tessArgs`;
|
|
|
|
|
my $status = $? >> 8;
|
2015-05-21 18:06:09 +01:00
|
|
|
|
unlink $tmpin;
|
2017-04-09 22:34:26 +01:00
|
|
|
|
|
|
|
|
|
die "OCR failed with exit code $status" if $status != 0;
|
2015-05-21 18:06:09 +01:00
|
|
|
|
});
|
|
|
|
|
return $text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-05-21 18:49:08 +01:00
|
|
|
|
# Wait until a specific regexp matches the textual contents of the screen.
|
|
|
|
|
sub waitForText {
|
|
|
|
|
my ($self, $regexp) = @_;
|
|
|
|
|
$self->nest("waiting for $regexp to appear on the screen", sub {
|
|
|
|
|
retry sub {
|
2017-06-21 02:10:34 +01:00
|
|
|
|
my ($retries_remaining) = @_;
|
|
|
|
|
if ($retries_remaining == 0) {
|
|
|
|
|
$self->log("Last chance to match /$regexp/ on the screen, which currently contains:");
|
|
|
|
|
$self->log($self->getScreenText);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-21 18:49:08 +01:00
|
|
|
|
return 1 if $self->getScreenText =~ /$regexp/;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2010-01-05 23:59:29 +00:00
|
|
|
|
# Wait until it is possible to connect to the X server. Note that
|
|
|
|
|
# testing the existence of /tmp/.X11-unix/X0 is insufficient.
|
|
|
|
|
sub waitForX {
|
|
|
|
|
my ($self, $regexp) = @_;
|
2011-01-10 14:41:16 +00:00
|
|
|
|
$self->nest("waiting for the X11 server", sub {
|
|
|
|
|
retry sub {
|
2018-03-29 15:27:38 +01:00
|
|
|
|
my ($status, $out) = $self->execute("journalctl -b SYSLOG_IDENTIFIER=systemd | grep 'Reached target Current graphical'");
|
2014-01-22 19:23:56 +00:00
|
|
|
|
return 0 if $status != 0;
|
2017-11-08 17:03:59 +00:00
|
|
|
|
($status, $out) = $self->execute("[ -e /tmp/.X11-unix/X0 ]");
|
2011-01-10 14:41:16 +00:00
|
|
|
|
return 1 if $status == 0;
|
|
|
|
|
}
|
|
|
|
|
});
|
2010-02-06 13:08:15 +00:00
|
|
|
|
}
|
2010-01-05 23:59:29 +00:00
|
|
|
|
|
|
|
|
|
|
2010-01-05 23:38:13 +00:00
|
|
|
|
sub getWindowNames {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
my $res = $self->mustSucceed(
|
2010-01-05 23:59:29 +00:00
|
|
|
|
q{xwininfo -root -tree | sed 's/.*0x[0-9a-f]* \"\([^\"]*\)\".*/\1/; t; d'});
|
2010-01-05 23:38:13 +00:00
|
|
|
|
return split /\n/, $res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub waitForWindow {
|
|
|
|
|
my ($self, $regexp) = @_;
|
2011-01-10 14:41:16 +00:00
|
|
|
|
$self->nest("waiting for a window to appear", sub {
|
|
|
|
|
retry sub {
|
|
|
|
|
my @names = $self->getWindowNames;
|
nixos tests: waitForWindow: output a list of windows we see prior to the final check
machine: must succeed: xwininfo -root -tree | sed 's/.*0x[0-9a-f]* \"\([^\"]*\)\".*/\1/; t; d'
machine: exit status 0
machine: Last chance to match /(?^:dfiirst configuration)/ on the the window list, which currently contains:
machine: [i3 con] container around 0xf8a5f0, i3: first configuration, [i3 con] floatingcon around 0xf8c260, [i3 con] container around 0xf8a380, i3bar for output Virtual-1, [i3 con] bottom dockarea Virtual-1, [i3 con] workspace 1, [i3 con] content Virtual-1, [i3 con] top dockarea Virtual-1, [i3 con] output Virtual-1, [i3 con] workspace __i3_scratch, [i3 con] content __i3, [i3 con] pseudo-output __i3, i3
2017-06-21 02:16:35 +01:00
|
|
|
|
|
|
|
|
|
my ($retries_remaining) = @_;
|
|
|
|
|
if ($retries_remaining == 0) {
|
|
|
|
|
$self->log("Last chance to match /$regexp/ on the the window list, which currently contains:");
|
|
|
|
|
$self->log(join(", ", @names));
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-10 14:41:16 +00:00
|
|
|
|
foreach my $n (@names) {
|
|
|
|
|
return 1 if $n =~ /$regexp/;
|
|
|
|
|
}
|
2010-01-05 23:38:13 +00:00
|
|
|
|
}
|
2011-01-10 14:41:16 +00:00
|
|
|
|
});
|
2010-02-06 13:08:15 +00:00
|
|
|
|
}
|
2010-01-05 23:38:13 +00:00
|
|
|
|
|
|
|
|
|
|
2010-01-06 20:52:05 +00:00
|
|
|
|
sub copyFileFromHost {
|
|
|
|
|
my ($self, $from, $to) = @_;
|
|
|
|
|
my $s = `cat $from` or die;
|
2017-02-17 17:18:16 +00:00
|
|
|
|
$s =~ s/'/'\\''/g;
|
|
|
|
|
$self->mustSucceed("echo '$s' > $to");
|
2010-01-06 20:52:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-01-05 23:18:49 +00:00
|
|
|
|
my %charToKey = (
|
2017-05-19 14:56:10 +01:00
|
|
|
|
'A' => "shift-a", 'N' => "shift-n", '-' => "0x0C", '_' => "shift-0x0C", '!' => "shift-0x02",
|
|
|
|
|
'B' => "shift-b", 'O' => "shift-o", '=' => "0x0D", '+' => "shift-0x0D", '@' => "shift-0x03",
|
|
|
|
|
'C' => "shift-c", 'P' => "shift-p", '[' => "0x1A", '{' => "shift-0x1A", '#' => "shift-0x04",
|
|
|
|
|
'D' => "shift-d", 'Q' => "shift-q", ']' => "0x1B", '}' => "shift-0x1B", '$' => "shift-0x05",
|
|
|
|
|
'E' => "shift-e", 'R' => "shift-r", ';' => "0x27", ':' => "shift-0x27", '%' => "shift-0x06",
|
|
|
|
|
'F' => "shift-f", 'S' => "shift-s", '\'' => "0x28", '"' => "shift-0x28", '^' => "shift-0x07",
|
|
|
|
|
'G' => "shift-g", 'T' => "shift-t", '`' => "0x29", '~' => "shift-0x29", '&' => "shift-0x08",
|
|
|
|
|
'H' => "shift-h", 'U' => "shift-u", '\\' => "0x2B", '|' => "shift-0x2B", '*' => "shift-0x09",
|
|
|
|
|
'I' => "shift-i", 'V' => "shift-v", ',' => "0x33", '<' => "shift-0x33", '(' => "shift-0x0A",
|
|
|
|
|
'J' => "shift-j", 'W' => "shift-w", '.' => "0x34", '>' => "shift-0x34", ')' => "shift-0x0B",
|
|
|
|
|
'K' => "shift-k", 'X' => "shift-x", '/' => "0x35", '?' => "shift-0x35",
|
|
|
|
|
'L' => "shift-l", 'Y' => "shift-y", ' ' => "spc",
|
|
|
|
|
'M' => "shift-m", 'Z' => "shift-z", "\n" => "ret",
|
2017-01-05 23:18:49 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
2010-02-06 13:08:15 +00:00
|
|
|
|
sub sendKeys {
|
|
|
|
|
my ($self, @keys) = @_;
|
|
|
|
|
foreach my $key (@keys) {
|
2017-01-05 23:18:49 +00:00
|
|
|
|
$key = $charToKey{$key} if exists $charToKey{$key};
|
2010-02-06 13:08:15 +00:00
|
|
|
|
$self->sendMonitorCommand("sendkey $key");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sub sendChars {
|
|
|
|
|
my ($self, $chars) = @_;
|
2011-01-06 17:28:35 +00:00
|
|
|
|
$self->nest("sending keys ‘$chars’", sub {
|
|
|
|
|
$self->sendKeys(split //, $chars);
|
|
|
|
|
});
|
2010-02-06 13:08:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-01-10 14:41:16 +00:00
|
|
|
|
# Sleep N seconds (in virtual guest time, not real time).
|
|
|
|
|
sub sleep {
|
|
|
|
|
my ($self, $time) = @_;
|
|
|
|
|
$self->succeed("sleep $time");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-04-27 10:54:17 +01:00
|
|
|
|
# Forward a TCP port on the host to a TCP port on the guest. Useful
|
|
|
|
|
# during interactive testing.
|
|
|
|
|
sub forwardPort {
|
|
|
|
|
my ($self, $hostPort, $guestPort) = @_;
|
|
|
|
|
$hostPort = 8080 unless defined $hostPort;
|
|
|
|
|
$guestPort = 80 unless defined $guestPort;
|
|
|
|
|
$self->sendMonitorCommand("hostfwd_add tcp::$hostPort-:$guestPort");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
* 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 15:25:12 +01:00
|
|
|
|
1;
|