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
33 with pytest.raises(subprocess.CalledProcessError):
34 ret = util.run(helper, 'abort', check=True)
37 with pytest.raises(util.ValgrindFailedError):
38 ret = util.run(helper, 'leak', valgrind=True)
41 with pytest.raises(util.ValgrindFailedError):
42 ret = util.run(helper, 'undefined', valgrind=True)
44 def test_undefined_branch():
45 with pytest.raises(util.ValgrindFailedError):
46 ret = util.run(helper, 'undefined_branch', valgrind=True)
48 def test_read_after_free():
49 with pytest.raises(util.ValgrindFailedError):
50 ret = util.run(helper, 'read_after_free', valgrind=True)
52 def test_write_after_free():
53 with pytest.raises(util.ValgrindFailedError):
54 ret = util.run(helper, 'write_after_free', valgrind=True)
56 def test_mountpoint(tmpdir):
57 path = util.mountpoint(tmpdir)
58 assert str(path)[-4:] == '/mnt'
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)
67 assert not ts.contains(t1)
68 assert ts.contains(t2)
69 assert not ts.contains(t3)