forked from nico/ninjatracing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathninjatracing_test
61 lines (53 loc) · 2.16 KB
/
ninjatracing_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import ninjatracing
import unittest
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
class TestNinjaTracing(unittest.TestCase):
def test_simple(self):
log = StringIO("# ninja log v5\n"
"100\t200\t0\tmy_output\tdeadbeef\n"
"50\t120\t0\tmy_first_output\t0afef\n")
dicts = list(ninjatracing.log_to_dicts(log, 42, True))
expected = [{
'name': 'my_first_output', 'cat': 'targets', 'ph': 'X',
'ts': '50000', 'dur': '70000', 'pid': '42', 'tid': '0',
'args': {}
}, {
'name': 'my_output', 'cat': 'targets', 'ph': 'X',
'ts': '100000', 'dur': '100000', 'pid': '42', 'tid': '1',
'args': {}
},
]
self.assertEqual(expected, dicts)
def test_last_only(self):
# Test the behavior without --showall.
log = StringIO("# ninja log v5\n"
"100\t200\t0\tmy_output\tdeadbeef\n"
"50\t120\t0\tmy_first_output\t0afef\n")
dicts = list(ninjatracing.log_to_dicts(log, 42, False))
expected = [{
'name': 'my_first_output', 'cat': 'targets', 'ph': 'X',
'ts': '50000', 'dur': '70000', 'pid': '42', 'tid': '0',
'args': {}
},
]
self.assertEqual(expected, dicts)
def test_multiple_outputs(self):
# Both lines here have the same command hash and the same start
# and end times, meaning they were produced by the same command.
log = StringIO("# ninja log v5\n"
"100\t200\t0\toutput\tdeadbeef\n"
"100\t200\t0\tother_output\tdeadbeef\n")
dicts = list(ninjatracing.log_to_dicts(log, 42, True))
expected = [{
'name': 'output, other_output', 'cat': 'targets', 'ph': 'X',
'ts': '100000', 'dur': '100000', 'pid': '42', 'tid': '0',
'args': {}
},
]
self.assertEqual(expected, dicts)
if __name__ == '__main__':
unittest.main()