Commit | Line | Data |
---|---|---|
0235b0db MJ |
1 | # SPDX-License-Identifier: GPL-2.0-only |
2 | # | |
3 | # Copyright (C) 2019 EfficiOS Inc. | |
4 | # | |
5 | ||
38403bf5 FD |
6 | import bt2 |
7 | ||
8 | ||
9 | class TheIteratorOfConfusion(bt2._UserMessageIterator): | |
8d8b141d | 10 | def __init__(self, config, port): |
38403bf5 FD |
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 | ): | |
59225a3e | 27 | def __init__(self, config, params, obj): |
f5567ea8 | 28 | test_name = str(params["test-name"]) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
40 | trace_name1 = "rouyn" |
41 | trace_name2 = "noranda" | |
38403bf5 | 42 | |
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 55 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
67 | stream_name1 = "port-daniel" |
68 | stream_name2 = "gascon" | |
38403bf5 | 69 | |
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 82 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 109 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 136 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 165 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
177 | stream_class_name1 = "one" |
178 | stream_class_name2 = "two" | |
38403bf5 | 179 | |
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 195 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 | 207 | stream_class_name1 = "one" |
38403bf5 FD |
208 | stream_class_name2 = None |
209 | ||
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 225 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 250 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
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)) | |
38403bf5 FD |
267 | |
268 | def create_msgs(msg_iter, params): | |
269 | iter_id, tc, cc = params | |
f5567ea8 FD |
270 | trace_hello = tc(name="hello") |
271 | trace_meow = tc(name="meow") | |
38403bf5 FD |
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) | |
f5567ea8 | 283 | event_class = stream_class0.create_event_class(name="saumon atlantique") |
38403bf5 FD |
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 | ), | |
2b950395 | 290 | msg_iter._create_stream_end_message(sc_0_stream_1, iter_id * 193), |
38403bf5 FD |
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), | |
2b950395 FD |
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), | |
38403bf5 FD |
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 | ), | |
2b950395 | 324 | msg_iter._create_stream_end_message(sc_0_stream_0, iter_id * 193), |
38403bf5 FD |
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 | ||
f5567ea8 | 334 | event_class = stream_class1.create_event_class(name="bar rayƩ") |
38403bf5 FD |
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 | ), | |
2b950395 | 340 | msg_iter._create_stream_end_message(sc_1_stream_1, iter_id * 193), |
38403bf5 FD |
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 | ||
f5567ea8 FD |
351 | event_class_name1 = "Hull" |
352 | event_class_name2 = "Gatineau" | |
38403bf5 | 353 | |
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 375 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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 | ||
f5567ea8 FD |
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)) | |
38403bf5 FD |
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) | |
2b950395 | 411 | se_msg = msg_iter._create_stream_end_message(stream, iter_id * 193) |
38403bf5 FD |
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( | |
f5567ea8 | 419 | frequency=1, name="La Baie", offset=bt2.ClockClassOffset(0) |
38403bf5 FD |
420 | ) |
421 | cc2 = src._create_clock_class( | |
f5567ea8 | 422 | frequency=1, name="Chicoutimi", offset=bt2.ClockClassOffset(0) |
38403bf5 FD |
423 | ) |
424 | ||
f5567ea8 FD |
425 | src._add_output_port("out1", (test_name, cc1)) |
426 | src._add_output_port("out2", (test_name, cc2)) | |
38403bf5 FD |
427 | |
428 | def create_msgs(msg_iter, params): | |
75882e97 | 429 | (cc,) = params |
38403bf5 FD |
430 | sb_msg = msg_iter._create_message_iterator_inactivity_message(cc, 0) |
431 | msg_iter._msgs = [sb_msg] | |
432 | ||
433 | ||
434 | TEST_CASES = { | |
7132b838 PP |
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, | |
38403bf5 FD |
447 | } |
448 | ||
f5567ea8 | 449 | bt2.register_plugin(__name__, "test-muxer") |