]> git.sesse.net Git - bcachefs-tools-debian/blob - tests/test_fixture.py
Initial version of bcachefs 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
9 import util
10 from pathlib import Path
11
12 #helper = Path('.') / 'test_helper'
13 helper = './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 def test_check():
32     with pytest.raises(subprocess.CalledProcessError):
33         ret = util.run(helper, 'abort', check=True)
34
35 def test_leak():
36     with pytest.raises(util.ValgrindFailedError):
37         ret = util.run(helper, 'leak', valgrind=True)
38
39 def test_undefined():
40     with pytest.raises(util.ValgrindFailedError):
41         ret = util.run(helper, 'undefined', valgrind=True)
42
43 def test_undefined_branch():
44     with pytest.raises(util.ValgrindFailedError):
45         ret = util.run(helper, 'undefined_branch', valgrind=True)
46
47 def test_read_after_free():
48     with pytest.raises(util.ValgrindFailedError):
49         ret = util.run(helper, 'read_after_free', valgrind=True)
50
51 def test_write_after_free():
52     with pytest.raises(util.ValgrindFailedError):
53         ret = util.run(helper, 'write_after_free', valgrind=True)