Debian Codegraph @

pypy/module/__pypy__/test/test_debug.py

raw symbols SCIP
1 import py
2
3 from pypy.interpreter.gateway import interp2app
4 from rpython.rlib import debug
5
6
7 class AppTestDebug:
8 spaceconfig = dict(usemodules=['__pypy__'])
9
10 def setup_class(cls):
11 if cls.runappdirect:
12 py.test.skip("not meant to be run with -A")
13 cls.w_check_log = cls.space.wrap(interp2app(cls.check_log))
14
15 def setup_method(self, meth):
16 debug._log = debug.DebugLog()
17
18 def teardown_method(self, meth):
19 debug._log = None
20
21 @staticmethod
22 def check_log(space, w_expected):
23 assert list(debug._log) == space.unwrap(w_expected)
24
25 def test_debug_print(self):
26 from __pypy__ import debug_start, debug_stop, debug_print
27 debug_start('my-category')
28 debug_print('one')
29 debug_print('two', 3, [])
30 debug_stop('my-category')
31 self.check_log([
32 ('my-category', [
33 ('debug_print', 'one'),
34 ('debug_print', 'two 3 []'),
35 ])
36 ])
37
38 def test_debug_print_once(self):
39 from __pypy__ import debug_print_once
40 debug_print_once('foobar', 'hello world')
41 self.check_log([
42 ('foobar', [
43 ('debug_print', 'hello world'),
44 ])
45 ])
46
47 def test_debug_flush(self):
48 from __pypy__ import debug_flush
49 debug_flush()
50 # assert did not crash
51
52 def test_debug_read_timestamp(self):
53 from __pypy__ import debug_read_timestamp
54 a = debug_read_timestamp()
55 b = debug_read_timestamp()
56 assert b > a
57
58 def test_debug_get_timestamp_unit(self):
59 from __pypy__ import debug_get_timestamp_unit
60 unit = debug_get_timestamp_unit()
61 assert unit in ('tsc', 'ns', 'QueryPerformanceCounter')
62
63 def test_debug_start_stop_timestamp(self):
64 import time
65 from __pypy__ import debug_start, debug_stop, debug_read_timestamp
66 assert debug_start('foo') is None
67 assert debug_stop('foo') is None
68 ts1 = debug_start('foo', timestamp=True)
69 t = time.process_time()
70 while time.process_time() - t < 0.02:
71 pass
72 ts2 = debug_stop('foo', timestamp=True)
73 assert ts2 > ts1
74
75 def test_remote_exec_exists(self):
76 import __pypy__
77 assert hasattr(__pypy__, 'remote_exec')
78 # real test in test_pypy_remote_debug.py