tests: Move data files to a common directory
[babeltrace.git] / tests / bindings / python / bt2 / test_trace_collection_message_iterator.py
CommitLineData
704c2307
PP
1import unittest
2import datetime
704c2307
PP
3import bt2
4import os
5import os.path
6
7
bbff0ab4
MJ
8_BT_CTF_TRACES_PATH = os.environ['BT_CTF_TRACES_PATH']
9_3EVENTS_INTERSECT_TRACE_PATH = os.path.join(_BT_CTF_TRACES_PATH,
704c2307
PP
10 'intersection',
11 '3eventsintersect')
12
13
3d60267b 14class ComponentSpecTestCase(unittest.TestCase):
704c2307 15 def test_create_good_no_params(self):
907f2b70 16 bt2.ComponentSpec('plugin', 'compcls')
704c2307
PP
17
18 def test_create_good_with_params(self):
907f2b70 19 bt2.ComponentSpec('plugin', 'compcls', {'salut': 23})
704c2307
PP
20
21 def test_create_good_with_path_params(self):
3d60267b 22 spec = bt2.ComponentSpec('plugin', 'compcls', 'a path')
907f2b70 23 self.assertEqual(spec.params['paths'], ['a path'])
704c2307
PP
24
25 def test_create_wrong_plugin_name_type(self):
26 with self.assertRaises(TypeError):
907f2b70 27 bt2.ComponentSpec(23, 'compcls')
704c2307
PP
28
29 def test_create_wrong_component_class_name_type(self):
30 with self.assertRaises(TypeError):
907f2b70 31 bt2.ComponentSpec('plugin', 190)
704c2307
PP
32
33 def test_create_wrong_params_type(self):
34 with self.assertRaises(TypeError):
907f2b70
SM
35 bt2.ComponentSpec('dwdw', 'compcls', datetime.datetime.now())
36
37
38# Return a map, msg type -> number of messages of this type.
39
40def _count_msgs_by_type(msgs):
41 res = {}
42
43 for msg in msgs:
44 t = type(msg)
45 n = res.get(t, 0)
46 res[t] = n + 1
47
48 return res
704c2307
PP
49
50
5602ef81 51class TraceCollectionMessageIteratorTestCase(unittest.TestCase):
704c2307 52 def test_create_wrong_stream_intersection_mode_type(self):
3d60267b 53 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
704c2307
PP
54
55 with self.assertRaises(TypeError):
907f2b70 56 bt2.TraceCollectionMessageIterator(specs, stream_intersection_mode=23)
704c2307
PP
57
58 def test_create_wrong_begin_type(self):
3d60267b 59 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
704c2307
PP
60
61 with self.assertRaises(TypeError):
907f2b70 62 bt2.TraceCollectionMessageIterator(specs, begin='hi')
704c2307
PP
63
64 def test_create_wrong_end_type(self):
3d60267b 65 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
704c2307
PP
66
67 with self.assertRaises(TypeError):
907f2b70 68 bt2.TraceCollectionMessageIterator(specs, begin='lel')
704c2307
PP
69
70 def test_create_no_such_plugin(self):
3d60267b 71 specs = [bt2.ComponentSpec('77', '101', _3EVENTS_INTERSECT_TRACE_PATH)]
704c2307
PP
72
73 with self.assertRaises(bt2.Error):
907f2b70 74 bt2.TraceCollectionMessageIterator(specs)
704c2307
PP
75
76 def test_create_begin_s(self):
3d60267b 77 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
907f2b70 78 bt2.TraceCollectionMessageIterator(specs, begin=19457.918232)
704c2307
PP
79
80 def test_create_end_s(self):
3d60267b 81 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
907f2b70 82 bt2.TraceCollectionMessageIterator(specs, end=123.12312)
704c2307
PP
83
84 def test_create_begin_datetime(self):
3d60267b 85 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
907f2b70 86 bt2.TraceCollectionMessageIterator(specs, begin=datetime.datetime.now())
704c2307
PP
87
88 def test_create_end_datetime(self):
3d60267b 89 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
907f2b70 90 bt2.TraceCollectionMessageIterator(specs, end=datetime.datetime.now())
704c2307
PP
91
92 def test_iter_no_intersection(self):
3d60267b 93 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
5602ef81 94 msg_iter = bt2.TraceCollectionMessageIterator(specs)
907f2b70
SM
95 msgs = list(msg_iter)
96 self.assertEqual(len(msgs), 32)
97 hist = _count_msgs_by_type(msgs)
98 self.assertEqual(hist[bt2.message._EventMessage], 8)
704c2307 99
907f2b70 100 # Same as the above, but we pass a single spec instead of a spec list.
3d60267b
PP
101 def test_iter_specs_not_list(self):
102 spec = bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)
907f2b70
SM
103 msg_iter = bt2.TraceCollectionMessageIterator(spec)
104 msgs = list(msg_iter)
105 self.assertEqual(len(msgs), 32)
106 hist = _count_msgs_by_type(msgs)
107 self.assertEqual(hist[bt2.message._EventMessage], 8)
3d60267b
PP
108
109 def test_iter_custom_filter(self):
110 src_spec = bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)
111 flt_spec = bt2.ComponentSpec('utils', 'trimmer', {
907f2b70 112 'end': '13515309.000000075',
3d60267b 113 })
907f2b70
SM
114 msg_iter = bt2.TraceCollectionMessageIterator(src_spec, flt_spec)
115 hist = _count_msgs_by_type(msg_iter)
116 self.assertEqual(hist[bt2.message._EventMessage], 5)
3d60267b 117
704c2307 118 def test_iter_intersection(self):
3d60267b 119 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
5602ef81 120 msg_iter = bt2.TraceCollectionMessageIterator(specs, stream_intersection_mode=True)
907f2b70
SM
121 msgs = list(msg_iter)
122 self.assertEqual(len(msgs), 19)
123 hist = _count_msgs_by_type(msgs)
124 self.assertEqual(hist[bt2.message._EventMessage], 3)
704c2307
PP
125
126 def test_iter_intersection_no_path_param(self):
3d60267b 127 specs = [bt2.ComponentSpec('text', 'dmesg', {'read-from-stdin': True})]
704c2307
PP
128
129 with self.assertRaises(bt2.Error):
907f2b70 130 bt2.TraceCollectionMessageIterator(specs, stream_intersection_mode=True)
704c2307
PP
131
132 def test_iter_no_intersection_two_traces(self):
3d60267b 133 spec = bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)
704c2307 134 specs = [spec, spec]
5602ef81 135 msg_iter = bt2.TraceCollectionMessageIterator(specs)
907f2b70
SM
136 msgs = list(msg_iter)
137 self.assertEqual(len(msgs), 64)
138 hist = _count_msgs_by_type(msgs)
139 self.assertEqual(hist[bt2.message._EventMessage], 16)
704c2307
PP
140
141 def test_iter_no_intersection_begin(self):
3d60267b 142 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
907f2b70
SM
143 msg_iter = bt2.TraceCollectionMessageIterator(specs, begin=13515309.000000023)
144 hist = _count_msgs_by_type(msg_iter)
145 self.assertEqual(hist[bt2.message._EventMessage], 6)
704c2307
PP
146
147 def test_iter_no_intersection_end(self):
3d60267b 148 specs = [bt2.ComponentSpec('ctf', 'fs', _3EVENTS_INTERSECT_TRACE_PATH)]
907f2b70
SM
149 msg_iter = bt2.TraceCollectionMessageIterator(specs, end=13515309.000000075)
150 hist = _count_msgs_by_type(msg_iter)
151 self.assertEqual(hist[bt2.message._EventMessage], 5)
This page took 0.038175 seconds and 4 git commands to generate.