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