3 # Tests of the functions in util.py
11 from pathlib import Path
13 #helper = Path('.') / 'test_helper'
14 helper = './test_helper'
16 def test_sparse_file(tmpdir):
17 dev = util.sparse_file(tmpdir / '1k', 1024)
18 assert dev.stat().st_size == 1024
20 def test_device_1g(tmpdir):
21 dev = util.device_1g(tmpdir)
22 assert dev.stat().st_size == 1024**3
25 ret = util.run(helper, 'abort')
26 assert ret.returncode == -signal.SIGABRT
29 ret = util.run(helper, 'segfault')
30 assert ret.returncode == -signal.SIGSEGV
32 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
34 with pytest.raises(subprocess.CalledProcessError):
35 ret = util.run(helper, 'abort', check=True)
37 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
39 with pytest.raises(util.ValgrindFailedError):
40 ret = util.run(helper, 'leak', valgrind=True)
42 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
44 with pytest.raises(util.ValgrindFailedError):
45 ret = util.run(helper, 'undefined', valgrind=True)
47 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
48 def test_undefined_branch():
49 with pytest.raises(util.ValgrindFailedError):
50 ret = util.run(helper, 'undefined_branch', valgrind=True)
52 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
53 def test_read_after_free():
54 with pytest.raises(util.ValgrindFailedError):
55 ret = util.run(helper, 'read_after_free', valgrind=True)
57 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
58 def test_write_after_free():
59 with pytest.raises(util.ValgrindFailedError):
60 ret = util.run(helper, 'write_after_free', valgrind=True)
62 def test_mountpoint(tmpdir):
63 path = util.mountpoint(tmpdir)
64 assert str(path)[-4:] == '/mnt'
68 t1 = time.clock_gettime(time.CLOCK_REALTIME)
69 with util.Timestamp() as ts:
70 t2 = time.clock_gettime(time.CLOCK_REALTIME)
71 t3 = time.clock_gettime(time.CLOCK_REALTIME)
73 assert not ts.contains(t1)
74 assert ts.contains(t2)
75 assert not ts.contains(t3)