]> git.sesse.net Git - bcachefs-tools-debian/blob - tests/test_fixture.py
Disable pristine-tar option in gbp.conf, since there is no pristine-tar branch.
[bcachefs-tools-debian] / tests / test_fixture.py
1 #!/usr/bin/python3
2 #
3 # Tests of the functions in util.py
4
5 import signal
6 import subprocess
7 import time
8 import os
9 import pytest
10
11 from tests import util
12
13 helper = os.path.abspath(os.path.join(util.BASE_PATH, 'test_helper'))
14
15 def test_sparse_file(tmpdir):
16     dev = util.sparse_file(tmpdir / '1k', 1024)
17     assert dev.stat().st_size == 1024
18
19 def test_device_1g(tmpdir):
20     dev = util.device_1g(tmpdir)
21     assert dev.stat().st_size == 1024**3
22
23 def test_abort():
24     ret = util.run(helper, 'abort')
25     assert ret.returncode == -signal.SIGABRT
26
27 def test_segfault():
28     ret = util.run(helper, 'segfault')
29     assert ret.returncode == -signal.SIGSEGV
30
31 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
32 def test_check():
33     with pytest.raises(subprocess.CalledProcessError):
34         util.run(helper, 'abort', check=True)
35
36 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
37 def test_leak():
38     with pytest.raises(util.ValgrindFailedError):
39         util.run(helper, 'leak', valgrind=True)
40
41 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
42 def test_undefined():
43     with pytest.raises(util.ValgrindFailedError):
44         util.run(helper, 'undefined', valgrind=True)
45
46 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
47 def test_undefined_branch():
48     with pytest.raises(util.ValgrindFailedError):
49         util.run(helper, 'undefined_branch', valgrind=True)
50
51 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
52 def test_read_after_free():
53     with pytest.raises(util.ValgrindFailedError):
54         util.run(helper, 'read_after_free', valgrind=True)
55
56 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
57 def test_write_after_free():
58     with pytest.raises(util.ValgrindFailedError):
59         util.run(helper, 'write_after_free', valgrind=True)
60
61 def test_mountpoint(tmpdir):
62     path = util.mountpoint(tmpdir)
63     assert str(path)[-4:] == '/mnt'
64     assert path.is_dir()
65
66 def test_timestamp():
67     t1 = time.clock_gettime(time.CLOCK_REALTIME)
68     with util.Timestamp() as ts:
69         t2 = time.clock_gettime(time.CLOCK_REALTIME)
70     t3 = time.clock_gettime(time.CLOCK_REALTIME)
71
72     assert not ts.contains(t1)
73     assert ts.contains(t2)
74     assert not ts.contains(t3)