Remove `skip-string-normalization` in Python formatter config
[babeltrace.git] / tests / data / plugins / sink.text.pretty / bt_plugin_pretty_test.py
CommitLineData
ed30eb8d
GB
1# SPDX-License-Identifier: GPL-2.0-only
2# Copyright (C) 2020 Geneviève Bastien <gbastien@versatic.net>
3
4import bt2
5
6
7class TheIteratorOfProblems(bt2._UserMessageIterator):
8 def __init__(self, config, port):
9 tc, sc, ec1, params = port.user_data
10 trace = tc()
11 stream = trace.create_stream(sc)
f5567ea8 12 event_value = params["value"]
ed30eb8d
GB
13 self._msgs = []
14
15 self._msgs.append(self._create_stream_beginning_message(stream))
16
17 ev_msg1 = self._create_event_message(ec1, stream)
18 ev_msg1.event.payload_field["enum_field"] = event_value
19
20 self._msgs.append(ev_msg1)
21
22 self._msgs.append(self._create_stream_end_message(stream))
23
24 self._at = 0
25 config.can_seek_forward = True
26
27 def _user_seek_beginning(self):
28 self._at = 0
29
30 def __next__(self):
31 if self._at < len(self._msgs):
32 msg = self._msgs[self._at]
33 self._at += 1
34 return msg
35 else:
36 raise StopIteration
37
38
39@bt2.plugin_component_class
40class TheSourceOfProblems(
41 bt2._UserSourceComponent, message_iterator_class=TheIteratorOfProblems
42):
43 def __init__(self, config, params, obj):
44 tc = self._create_trace_class()
45
f5567ea8 46 enum_values_str = params["enum-values"]
ed30eb8d
GB
47
48 sc = tc.create_stream_class()
49
50 # Create the enumeration field with the values in parameter
f5567ea8 51 if params["enum-signed"]:
ed30eb8d
GB
52 enumfc = tc.create_signed_enumeration_field_class()
53 else:
54 enumfc = tc.create_unsigned_enumeration_field_class()
55
f5567ea8 56 groups = str(enum_values_str).split(" ")
ed30eb8d
GB
57 mappings = {}
58 range_set_type = (
59 bt2.SignedIntegerRangeSet
f5567ea8 60 if params["enum-signed"]
ed30eb8d
GB
61 else bt2.UnsignedIntegerRangeSet
62 )
63 for group in groups:
f5567ea8 64 label, low, high = group.split(",")
ed30eb8d
GB
65
66 if label not in mappings.keys():
67 mappings[label] = range_set_type()
68
69 mappings[label].add((int(low), int(high)))
70
71 for x, y in mappings.items():
72 enumfc.add_mapping(x, y)
73
74 # Create the struct field to contain the enum field class
75 struct_fc = tc.create_structure_field_class()
f5567ea8 76 struct_fc.append_member("enum_field", enumfc)
ed30eb8d
GB
77
78 # Create an event class on this stream with the struct field
f5567ea8
FD
79 ec1 = sc.create_event_class(name="with_enum", payload_field_class=struct_fc)
80 self._add_output_port("out", (tc, sc, ec1, params))
ed30eb8d
GB
81
82
f5567ea8 83bt2.register_plugin(__name__, "test-pretty")
This page took 0.030661 seconds and 4 git commands to generate.