diff --git a/doc/manual/development.xml b/doc/manual/development.xml index 5ddf5d935d1c..44edc54f8147 100644 --- a/doc/manual/development.xml +++ b/doc/manual/development.xml @@ -341,5 +341,109 @@ $ qemu-system-x86_64 -kernel ./kernel/bzImage -initrd ./initrd/initrd -hda /dev/ +
+ + Whole-system testing using virtual machines + + + Complete NixOS GNU/Linux systems can be tested in virtual machines + (VMs). This makes it possible to test a system upgrade or + configuration change before rebooting into it, using the + nixos-rebuild build-vm or + nixos-rebuild build-vm-with-bootloader command. + + + + + + The tests/ directory in the NixOS source tree + contains several whole-system unit tests. + These tests can be runNixOS tests can be run both from + NixOS and from a non-NixOS GNU/Linux distribution, provided the + Nix package manager is installed. from the NixOS + source tree as follows: + + + $ nix-build tests/ -A nfs.test + + + This performs an automated test of the NFS client and server + functionality in the Linux kernel, including file locking + semantics (e.g., whether locks are maintained across server + crashes). It will first build or download all the dependencies of + the test (e.g., all packages needed to run a NixOS VM). The test + is defined in + tests/nfs.nix. If the test succeeds, + nix-build will place a symlink + ./result in the current directory pointing at + the location in the Nix store of the test results (e.g., + screenshots, test reports, and so on). In particular, a + pretty-printed log of the test is written to + log.html, which can be viewed using something + like: + + + $ icecat result/log.html + + + + + It is also possible to run the test environment interactively, + allowing you to experiment with the VMs. For example: + + + $ nix-build tests/ -A nfs.driver + $ ./result/bin/nixos-run-vms + + + The script nixos-run-vms starts the three + virtual machines defined in the NFS test using QEMU/KVM. The root + file system of the VMs is created on the fly and kept across VM + restarts in + ./hostname.qcow2. + + + + Finally, the test itself can be run interactively. This is + particularly useful when developing or debugging a test: + + + $ nix-build tests/ -A nfs.driver + $ ./result/bin/nixos-test-driver + starting VDE switch for network 1 + > + + + Perl statements can now be typed in to start or manipulate the + VMs: + + + > startAll; + (the VMs start booting) + > $server->waitForJob("nfs-kernel-nfsd"); + > $client1->succeed("flock -x /data/lock -c 'sleep 100000' &"); + > $client2->fail("flock -n -s /data/lock true"); + > $client1->shutdown; + (this releases client1's lock) + > $client2->succeed("flock -n -s /data/lock true"); + + + The function testScript executes the entire + test script and drops you back into the test driver command line + upon its completion. This allows you to inspect the state of the + VMs after the test (e.g. to debug the test script). + + + + This and other tests are continuously run on the + Hydra instance at nixos.org, which + allows developers to be notified of any regressions introduced by + a NixOS or Nixpkgs change. + + +