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