3 # Tests of the functions in util.py
10 from pathlib import Path
12 #helper = Path('.') / 'test_helper'
13 helper = './test_helper'
15 def test_sparse_file(tmpdir):
16 dev = util.sparse_file(tmpdir / '1k', 1024)
17 assert dev.stat().st_size == 1024
19 def test_device_1g(tmpdir):
20 dev = util.device_1g(tmpdir)
21 assert dev.stat().st_size == 1024**3
24 ret = util.run(helper, 'abort')
25 assert ret.returncode == -signal.SIGABRT
28 ret = util.run(helper, 'segfault')
29 assert ret.returncode == -signal.SIGSEGV
32 with pytest.raises(subprocess.CalledProcessError):
33 ret = util.run(helper, 'abort', check=True)
36 with pytest.raises(util.ValgrindFailedError):
37 ret = util.run(helper, 'leak', valgrind=True)
40 with pytest.raises(util.ValgrindFailedError):
41 ret = util.run(helper, 'undefined', valgrind=True)
43 def test_undefined_branch():
44 with pytest.raises(util.ValgrindFailedError):
45 ret = util.run(helper, 'undefined_branch', valgrind=True)
47 def test_read_after_free():
48 with pytest.raises(util.ValgrindFailedError):
49 ret = util.run(helper, 'read_after_free', valgrind=True)
51 def test_write_after_free():
52 with pytest.raises(util.ValgrindFailedError):
53 ret = util.run(helper, 'write_after_free', valgrind=True)