1import ./make-test.nix ({ pkgs, ... }: with pkgs.pythonPackages; rec {
2 name = "blivet";
3 meta = with pkgs.stdenv.lib.maintainers; {
4 maintainers = [ aszlig ];
5 };
6
7 machine = {
8 environment.systemPackages = [ pkgs.python blivet mock ];
9 boot.supportedFilesystems = [ "btrfs" "jfs" "reiserfs" "xfs" ];
10 virtualisation.memorySize = 768;
11 };
12
13 debugBlivet = false;
14 debugProgramCalls = false;
15
16 pythonTestRunner = pkgs.writeText "run-blivet-tests.py" ''
17 import sys
18 import logging
19
20 from unittest import TestLoader
21 from unittest.runner import TextTestRunner
22
23 ${pkgs.lib.optionalString debugProgramCalls ''
24 blivet_program_log = logging.getLogger("program")
25 blivet_program_log.setLevel(logging.DEBUG)
26 blivet_program_log.addHandler(logging.StreamHandler(sys.stderr))
27 ''}
28
29 ${pkgs.lib.optionalString debugBlivet ''
30 blivet_log = logging.getLogger("blivet")
31 blivet_log.setLevel(logging.DEBUG)
32 blivet_log.addHandler(logging.StreamHandler(sys.stderr))
33 ''}
34
35 runner = TextTestRunner(verbosity=2, failfast=False, buffer=False)
36 result = runner.run(TestLoader().discover('tests/', pattern='*_test.py'))
37 sys.exit(not result.wasSuccessful())
38 '';
39
40 blivetTest = pkgs.writeScript "blivet-test.sh" ''
41 #!${pkgs.stdenv.shell} -e
42
43 # Use the hosts temporary directory, because we have a tmpfs within the VM
44 # and we don't want to increase the memory size of the VM for no reason.
45 mkdir -p /tmp/xchg/bigtmp
46 TMPDIR=/tmp/xchg/bigtmp
47 export TMPDIR
48
49 cp -Rd "${blivet.src}/tests" .
50
51 # Skip SELinux tests
52 rm -f tests/formats_test/selinux_test.py
53
54 # Race conditions in growing/shrinking during resync
55 rm -f tests/devicelibs_test/mdraid_*
56
57 # Deactivate small BTRFS device test, because it fails with newer btrfsprogs
58 sed -i -e '/^class *BTRFSAsRootTestCase3(/,/^[^ ]/ {
59 /^class *BTRFSAsRootTestCase3(/d
60 /^$/d
61 /^ /d
62 }' tests/devicelibs_test/btrfs_test.py
63
64 # How on earth can these tests ever work even upstream? O_o
65 sed -i -e '/def testDiskChunk[12]/,/^ *[^ ]/{n; s/^ */&return # /}' \
66 tests/partitioning_test.py
67
68 # fix hardcoded temporary directory
69 sed -i \
70 -e '1i import tempfile' \
71 -e 's|_STORE_FILE_PATH = .*|_STORE_FILE_PATH = tempfile.gettempdir()|' \
72 tests/loopbackedtestcase.py
73
74 PYTHONPATH=".:$(< "${pkgs.stdenv.mkDerivation {
75 name = "blivet-pythonpath";
76 buildInputs = [ blivet mock ];
77 buildCommand = "echo \"$PYTHONPATH\" > \"$out\"";
78 }}")" python "${pythonTestRunner}"
79 '';
80
81 testScript = ''
82 $machine->waitForUnit("multi-user.target");
83 $machine->succeed("${blivetTest}");
84 $machine->execute("rm -rf /tmp/xchg/bigtmp");
85 '';
86})