c263d20396060017deb108d68e85d0bbee8bb406
[babeltrace.git] / tests / data / plugins / flt.utils.muxer / bt_plugin_muxer_test.py
1 import bt2
2
3
4 class TheIteratorOfConfusion(bt2._UserMessageIterator):
5 def __init__(self, config, port):
6 self._at = 0
7 test_name = port.user_data[0]
8 TEST_CASES[test_name].create_msgs(self, port.user_data[1:])
9
10 def __next__(self):
11 if self._at < len(self._msgs):
12 msg = self._msgs[self._at]
13 self._at += 1
14 return msg
15 raise StopIteration
16
17
18 @bt2.plugin_component_class
19 class TheSourceOfConfusion(
20 bt2._UserSourceComponent, message_iterator_class=TheIteratorOfConfusion
21 ):
22 def __init__(self, config, params, obj):
23 test_name = str(params['test-name'])
24
25 TEST_CASES[test_name].source_setup(self, test_name)
26
27
28 class DiffTraceName:
29 def source_setup(src, test_name):
30 tc1 = src._create_trace_class()
31 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
32 tc2 = src._create_trace_class()
33 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
34
35 trace_name1 = 'rouyn'
36 trace_name2 = 'noranda'
37
38 src._add_output_port('out1', (test_name, 1, tc1, cc1, trace_name1))
39 src._add_output_port('out2', (test_name, 2, tc2, cc2, trace_name2))
40
41 def create_msgs(msg_iter, params):
42 iter_id, tc, cc, trace_name = params
43 trace = tc(name=trace_name)
44 sc = tc.create_stream_class(
45 default_clock_class=cc, assigns_automatic_stream_id=False
46 )
47 stream = trace.create_stream(sc, 0)
48
49 sb_msg = msg_iter._create_stream_beginning_message(stream, 0)
50 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
51
52 msg_iter._msgs = [sb_msg, se_msg]
53
54
55 class DiffStreamName:
56 def source_setup(src, test_name):
57 tc1 = src._create_trace_class()
58 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
59 tc2 = src._create_trace_class()
60 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
61
62 stream_name1 = 'port-daniel'
63 stream_name2 = 'gascon'
64
65 src._add_output_port('out1', (test_name, 1, tc1, cc1, stream_name1))
66 src._add_output_port('out2', (test_name, 2, tc2, cc2, stream_name2))
67
68 def create_msgs(msg_iter, params):
69 iter_id, tc, cc, stream_name = params
70 trace = tc()
71 sc = tc.create_stream_class(
72 default_clock_class=cc, assigns_automatic_stream_id=False
73 )
74 stream = trace.create_stream(sc, 0, stream_name)
75
76 sb_msg = msg_iter._create_stream_beginning_message(stream, 0)
77 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
78
79 msg_iter._msgs = [sb_msg, se_msg]
80
81
82 class DiffStreamId:
83 def source_setup(src, test_name):
84 tc1 = src._create_trace_class()
85 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
86 tc2 = src._create_trace_class()
87 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
88
89 stream_id1 = 18
90 stream_id2 = 23
91
92 src._add_output_port('out1', (test_name, 1, tc1, cc1, stream_id1))
93 src._add_output_port('out2', (test_name, 2, tc2, cc2, stream_id2))
94
95 def create_msgs(msg_iter, params):
96 iter_id, tc, cc, stream_id = params
97 trace = tc()
98 sc = tc.create_stream_class(
99 default_clock_class=cc, assigns_automatic_stream_id=False
100 )
101 stream = trace.create_stream(sc, stream_id)
102
103 sb_msg = msg_iter._create_stream_beginning_message(stream, 0)
104 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
105
106 msg_iter._msgs = [sb_msg, se_msg]
107
108
109 class DiffStreamNoName:
110 def source_setup(src, test_name):
111 tc1 = src._create_trace_class()
112 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
113 tc2 = src._create_trace_class()
114 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
115
116 stream_name1 = "one"
117 stream_name2 = None
118
119 src._add_output_port('out1', (test_name, 1, tc1, cc1, stream_name1))
120 src._add_output_port('out2', (test_name, 2, tc2, cc2, stream_name2))
121
122 def create_msgs(msg_iter, params):
123 iter_id, tc, cc, stream_no_name = params
124 trace = tc()
125 sc = tc.create_stream_class(
126 default_clock_class=cc, assigns_automatic_stream_id=False
127 )
128 stream = trace.create_stream(sc, 0, name=stream_no_name)
129
130 sb_msg = msg_iter._create_stream_beginning_message(stream, 0)
131 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
132
133 msg_iter._msgs = [sb_msg, se_msg]
134
135
136 class DiffStreamClassId:
137 def source_setup(src, test_name):
138 tc1 = src._create_trace_class(assigns_automatic_stream_class_id=False)
139 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
140 tc2 = src._create_trace_class(assigns_automatic_stream_class_id=False)
141 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
142
143 stream_class_id1 = 18
144 stream_class_id2 = 23
145
146 src._add_output_port('out1', (test_name, 1, tc1, cc1, stream_class_id1))
147 src._add_output_port('out2', (test_name, 2, tc2, cc2, stream_class_id2))
148
149 def create_msgs(msg_iter, params):
150 iter_id, tc, cc, stream_class_id = params
151 trace = tc()
152 sc = tc.create_stream_class(
153 default_clock_class=cc,
154 id=stream_class_id,
155 assigns_automatic_stream_id=False,
156 )
157 stream = trace.create_stream(sc, 0)
158
159 sb_msg = msg_iter._create_stream_beginning_message(stream, 0)
160 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
161
162 msg_iter._msgs = [sb_msg, se_msg]
163
164
165 class DiffStreamClassName:
166 def source_setup(src, test_name):
167 tc1 = src._create_trace_class(assigns_automatic_stream_class_id=False)
168 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
169 tc2 = src._create_trace_class(assigns_automatic_stream_class_id=False)
170 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
171
172 stream_class_name1 = 'one'
173 stream_class_name2 = 'two'
174
175 src._add_output_port('out1', (test_name, 1, tc1, cc1, stream_class_name1))
176 src._add_output_port('out2', (test_name, 2, tc2, cc2, stream_class_name2))
177
178 def create_msgs(msg_iter, params):
179 iter_id, tc, cc, stream_class_name = params
180 trace = tc()
181 sc = tc.create_stream_class(
182 default_clock_class=cc,
183 id=0,
184 name=stream_class_name,
185 assigns_automatic_stream_id=False,
186 )
187 stream = trace.create_stream(sc, 0)
188
189 sb_msg = msg_iter._create_stream_beginning_message(stream, 0)
190 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
191
192 msg_iter._msgs = [sb_msg, se_msg]
193
194
195 class DiffStreamClassNoName:
196 def source_setup(src, test_name):
197 tc1 = src._create_trace_class(assigns_automatic_stream_class_id=False)
198 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
199 tc2 = src._create_trace_class(assigns_automatic_stream_class_id=False)
200 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
201
202 stream_class_name1 = 'one'
203 stream_class_name2 = None
204
205 src._add_output_port('out1', (test_name, 1, tc1, cc1, stream_class_name1))
206 src._add_output_port('out2', (test_name, 2, tc2, cc2, stream_class_name2))
207
208 def create_msgs(msg_iter, params):
209 iter_id, tc, cc, stream_class_name = params
210 trace = tc()
211 sc = tc.create_stream_class(
212 default_clock_class=cc,
213 id=0,
214 name=stream_class_name,
215 assigns_automatic_stream_id=False,
216 )
217 stream = trace.create_stream(sc, 0)
218
219 sb_msg = msg_iter._create_stream_beginning_message(stream, 0)
220 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
221
222 msg_iter._msgs = [sb_msg, se_msg]
223
224
225 class BasicTimestampOrdering:
226 def source_setup(src, test_name):
227 tc = src._create_trace_class()
228 cc = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
229
230 timestamp1 = 0
231 timestamp2 = 120
232 timestamp3 = 4
233
234 src._add_output_port('out1', (test_name, 1, tc, cc, timestamp1))
235 src._add_output_port('out2', (test_name, 2, tc, cc, timestamp2))
236 src._add_output_port('out3', (test_name, 3, tc, cc, timestamp3))
237
238 def create_msgs(msg_iter, params):
239 iter_id, tc, cc, timestamp = params
240 trace = tc()
241 sc = tc.create_stream_class(default_clock_class=cc)
242 stream = trace.create_stream(sc)
243
244 sb_msg = msg_iter._create_stream_beginning_message(stream, timestamp)
245 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
246
247 msg_iter._msgs = [sb_msg, se_msg]
248
249
250 class MultiIterOrdering:
251 def source_setup(src, test_name):
252 tc1 = src._create_trace_class(assigns_automatic_stream_class_id=False)
253 tc2 = src._create_trace_class(assigns_automatic_stream_class_id=False)
254 tc3 = src._create_trace_class(assigns_automatic_stream_class_id=False)
255 tc4 = src._create_trace_class(assigns_automatic_stream_class_id=False)
256 cc = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
257
258 src._add_output_port('out1', (test_name, 1, tc1, cc))
259 src._add_output_port('out2', (test_name, 2, tc2, cc))
260 src._add_output_port('out3', (test_name, 3, tc3, cc))
261 src._add_output_port('out4', (test_name, 4, tc4, cc))
262
263 def create_msgs(msg_iter, params):
264 iter_id, tc, cc = params
265 trace_hello = tc(name='hello')
266 trace_meow = tc(name='meow')
267
268 # Craft list of messages for each iterator so that the last messages of
269 # each iterator are all sharing the same timestamp.
270 clock_snapshot_value = 25
271
272 if iter_id == 1:
273 # Event, 2500 ns, trace "hello", stream class 0, stream 1
274 stream_class0 = tc.create_stream_class(
275 id=0, default_clock_class=cc, assigns_automatic_stream_id=False
276 )
277 sc_0_stream_1 = trace_hello.create_stream(stream_class0, id=1)
278 event_class = stream_class0.create_event_class(name='saumon atlantique')
279
280 msg_iter._msgs = [
281 msg_iter._create_stream_beginning_message(sc_0_stream_1, 0),
282 msg_iter._create_event_message(
283 event_class, sc_0_stream_1, clock_snapshot_value
284 ),
285 msg_iter._create_stream_end_message(sc_0_stream_1, iter_id * 193),
286 ]
287 elif iter_id == 2:
288 # Packet beginning, 2500 ns, trace "meow", stream class 0, stream 1
289 stream_class0 = tc.create_stream_class(
290 id=0,
291 default_clock_class=cc,
292 supports_packets=True,
293 packets_have_beginning_default_clock_snapshot=True,
294 packets_have_end_default_clock_snapshot=True,
295 assigns_automatic_stream_id=False,
296 )
297
298 sc_0_stream_1 = trace_meow.create_stream(stream_class0, id=1)
299 packet = sc_0_stream_1.create_packet()
300
301 msg_iter._msgs = [
302 msg_iter._create_stream_beginning_message(sc_0_stream_1, 1),
303 msg_iter._create_packet_beginning_message(packet, clock_snapshot_value),
304 msg_iter._create_packet_end_message(packet, iter_id * 79),
305 msg_iter._create_stream_end_message(sc_0_stream_1, iter_id * 193),
306 ]
307 elif iter_id == 3:
308 # Stream beginning, 2500 ns, trace "hello", stream class 0, stream 0
309 stream_class0 = tc.create_stream_class(
310 id=0, default_clock_class=cc, assigns_automatic_stream_id=False
311 )
312
313 sc_0_stream_0 = trace_hello.create_stream(stream_class0, id=0)
314
315 msg_iter._msgs = [
316 msg_iter._create_stream_beginning_message(
317 sc_0_stream_0, clock_snapshot_value
318 ),
319 msg_iter._create_stream_end_message(sc_0_stream_0, iter_id * 193),
320 ]
321 elif iter_id == 4:
322 # Event, 2500 ns, trace "meow", stream class 1, stream 1
323 stream_class1 = tc.create_stream_class(
324 id=1, default_clock_class=cc, assigns_automatic_stream_id=False
325 )
326
327 sc_1_stream_1 = trace_meow.create_stream(stream_class1, id=1)
328
329 event_class = stream_class1.create_event_class(name='bar rayƩ')
330 msg_iter._msgs = [
331 msg_iter._create_stream_beginning_message(sc_1_stream_1, 3),
332 msg_iter._create_event_message(
333 event_class, sc_1_stream_1, clock_snapshot_value
334 ),
335 msg_iter._create_stream_end_message(sc_1_stream_1, iter_id * 193),
336 ]
337
338
339 class DiffEventClassName:
340 def source_setup(src, test_name):
341 tc1 = src._create_trace_class(assigns_automatic_stream_class_id=False)
342 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
343 tc2 = src._create_trace_class(assigns_automatic_stream_class_id=False)
344 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
345
346 event_class_name1 = 'Hull'
347 event_class_name2 = 'Gatineau'
348
349 src._add_output_port('out1', (test_name, 1, tc1, cc1, event_class_name1))
350 src._add_output_port('out2', (test_name, 2, tc2, cc2, event_class_name2))
351
352 def create_msgs(msg_iter, params):
353 iter_id, tc, cc, event_class_name = params
354 trace = tc()
355 sc = tc.create_stream_class(
356 default_clock_class=cc,
357 id=0,
358 assigns_automatic_stream_id=False,
359 supports_packets=False,
360 )
361 ec = sc.create_event_class(name=event_class_name)
362
363 stream = trace.create_stream(sc, 0)
364
365 # Use event class name length as timestamp so that both stream
366 # beginning message are not at the same time. This test is targetting
367 # event message.
368 sb_msg = msg_iter._create_stream_beginning_message(stream, len(ec.name))
369 ev_msg = msg_iter._create_event_message(ec, stream, 50)
370 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
371
372 msg_iter._msgs = [sb_msg, ev_msg, se_msg]
373
374
375 class DiffEventClassId:
376 def source_setup(src, test_name):
377 tc1 = src._create_trace_class(assigns_automatic_stream_class_id=False)
378 cc1 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
379 tc2 = src._create_trace_class(assigns_automatic_stream_class_id=False)
380 cc2 = src._create_clock_class(frequency=1, offset=bt2.ClockClassOffset(0))
381
382 event_class_id1 = 1
383 event_class_id2 = 2
384
385 src._add_output_port('out1', (test_name, 1, tc1, cc1, event_class_id1))
386 src._add_output_port('out2', (test_name, 2, tc2, cc2, event_class_id2))
387
388 def create_msgs(msg_iter, params):
389 iter_id, tc, cc, event_class_id = params
390 trace = tc()
391 sc = tc.create_stream_class(
392 default_clock_class=cc,
393 id=0,
394 assigns_automatic_stream_id=False,
395 assigns_automatic_event_class_id=False,
396 supports_packets=False,
397 )
398 ec = sc.create_event_class(id=event_class_id)
399
400 stream = trace.create_stream(sc, 0)
401
402 # Use event class id as timestamp so that both stream beginning message
403 # are not at the same time. This test is targetting event message.
404 sb_msg = msg_iter._create_stream_beginning_message(stream, ec.id)
405 ev_msg = msg_iter._create_event_message(ec, stream, 50)
406 se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193)
407
408 msg_iter._msgs = [sb_msg, ev_msg, se_msg]
409
410
411 class DiffInactivityMsgCs:
412 def source_setup(src, test_name):
413 cc1 = src._create_clock_class(
414 frequency=1, name='La Baie', offset=bt2.ClockClassOffset(0)
415 )
416 cc2 = src._create_clock_class(
417 frequency=1, name='Chicoutimi', offset=bt2.ClockClassOffset(0)
418 )
419
420 src._add_output_port('out1', (test_name, cc1))
421 src._add_output_port('out2', (test_name, cc2))
422
423 def create_msgs(msg_iter, params):
424 cc, = params
425 sb_msg = msg_iter._create_message_iterator_inactivity_message(cc, 0)
426 msg_iter._msgs = [sb_msg]
427
428
429 TEST_CASES = {
430 'diff_trace_name': DiffTraceName,
431 'diff_event_class_name': DiffEventClassName,
432 'diff_event_class_id': DiffEventClassId,
433 'diff_stream_name': DiffStreamName,
434 'diff_stream_no_name': DiffStreamNoName,
435 'diff_stream_id': DiffStreamId,
436 'diff_stream_class_id': DiffStreamClassId,
437 'diff_stream_class_name': DiffStreamClassName,
438 'diff_stream_class_no_name': DiffStreamClassNoName,
439 'diff_inactivity_msg_cs': DiffInactivityMsgCs,
440 'basic_timestamp_ordering': BasicTimestampOrdering,
441 'multi_iter_ordering': MultiIterOrdering,
442 }
443
444 bt2.register_plugin(__name__, 'test-muxer')
This page took 0.040988 seconds and 4 git commands to generate.