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