3 # Tests of the functions in util.py
11 from tests import util
13 helper = os.path.abspath(os.path.join(util.BASE_PATH, '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
31 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
33 with pytest.raises(subprocess.CalledProcessError):
34 util.run(helper, 'abort', check=True)
36 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
38 with pytest.raises(util.ValgrindFailedError):
39 util.run(helper, 'leak', valgrind=True)
41 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
43 with pytest.raises(util.ValgrindFailedError):
44 util.run(helper, 'undefined', valgrind=True)
46 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
47 def test_undefined_branch():
48 with pytest.raises(util.ValgrindFailedError):
49 util.run(helper, 'undefined_branch', valgrind=True)
51 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
52 def test_read_after_free():
53 with pytest.raises(util.ValgrindFailedError):
54 util.run(helper, 'read_after_free', valgrind=True)
56 @pytest.mark.skipif(not util.ENABLE_VALGRIND, reason="no valgrind")
57 def test_write_after_free():
58 with pytest.raises(util.ValgrindFailedError):
59 util.run(helper, 'write_after_free', valgrind=True)
61 def test_mountpoint(tmpdir):
62 path = util.mountpoint(tmpdir)
63 assert str(path)[-4:] == '/mnt'
67 t1 = time.clock_gettime(time.CLOCK_REALTIME)
68 with util.Timestamp() as ts:
69 t2 = time.clock_gettime(time.CLOCK_REALTIME)
70 t3 = time.clock_gettime(time.CLOCK_REALTIME)
72 assert not ts.contains(t1)
73 assert ts.contains(t2)
74 assert not ts.contains(t3)