autodisc: don't accept NULL values for `support-info` query `group` key
[babeltrace.git] / tests / bindings / python / bt2 / test_stream_class.py
CommitLineData
d2d857a8
MJ
1#
2# Copyright (C) 2019 EfficiOS Inc.
3#
4# This program is free software; you can redistribute it and/or
5# modify it under the terms of the GNU General Public License
6# as published by the Free Software Foundation; only version 2
7# of the License.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17#
18
9cf643d1 19import unittest
3cdfbaea 20from utils import run_in_component_init
9cf643d1
PP
21
22
23class StreamClassTestCase(unittest.TestCase):
24 def setUp(self):
3cdfbaea
SM
25 def f(comp_self):
26 tc = comp_self._create_trace_class(assigns_automatic_stream_class_id=True)
27 cc = comp_self._create_clock_class()
28 return tc, cc
29
30 self._tc, self._cc = run_in_component_init(f)
31 self._trace = self._tc()
32
33 def test_create_default(self):
34 sc = self._tc.create_stream_class()
35
36 self.assertIsNone(sc.name)
37 self.assertIsNone(sc.packet_context_field_class)
38 self.assertIsNone(sc.event_common_context_field_class)
39 self.assertIsNone(sc.default_clock_class)
40 self.assertTrue(sc.assigns_automatic_event_class_id)
41 self.assertTrue(sc.assigns_automatic_stream_id)
26fc5aed 42 self.assertFalse(sc.supports_packets)
9b24b6aa
PP
43 self.assertFalse(sc.packets_have_beginning_default_clock_snapshot)
44 self.assertFalse(sc.packets_have_end_default_clock_snapshot)
2e90378a
PP
45 self.assertFalse(sc.supports_discarded_events)
46 self.assertFalse(sc.discarded_events_have_default_clock_snapshots)
47 self.assertFalse(sc.supports_discarded_packets)
48 self.assertFalse(sc.discarded_packets_have_default_clock_snapshots)
5783664e 49 self.assertEqual(len(sc.user_attributes), 0)
3cdfbaea
SM
50
51 def test_create_name(self):
52 sc = self._tc.create_stream_class(name='bozo')
53 self.assertEqual(sc.name, 'bozo')
54
55 def test_create_invalid_name(self):
9cf643d1 56 with self.assertRaises(TypeError):
3cdfbaea 57 self._tc.create_stream_class(name=17)
9cf643d1 58
3cdfbaea
SM
59 def test_create_packet_context_field_class(self):
60 fc = self._tc.create_structure_field_class()
cfbd7cf3
FD
61 sc = self._tc.create_stream_class(
62 packet_context_field_class=fc, supports_packets=True
63 )
3cdfbaea 64 self.assertEqual(sc.packet_context_field_class, fc)
9cf643d1 65
3cdfbaea 66 def test_create_invalid_packet_context_field_class(self):
9cf643d1 67 with self.assertRaises(TypeError):
3cdfbaea 68 self._tc.create_stream_class(packet_context_field_class=22)
9cf643d1 69
26fc5aed
PP
70 def test_create_invalid_packet_context_field_class_no_packets(self):
71 fc = self._tc.create_structure_field_class()
72
73 with self.assertRaises(ValueError):
74 self._tc.create_stream_class(packet_context_field_class=fc)
75
3cdfbaea
SM
76 def test_create_event_common_context_field_class(self):
77 fc = self._tc.create_structure_field_class()
78 sc = self._tc.create_stream_class(event_common_context_field_class=fc)
79 self.assertEqual(sc.event_common_context_field_class, fc)
811644b8 80
3cdfbaea
SM
81 def test_create_invalid_event_common_context_field_class(self):
82 with self.assertRaises(TypeError):
83 self._tc.create_stream_class(event_common_context_field_class=22)
9cf643d1 84
3cdfbaea
SM
85 def test_create_default_clock_class(self):
86 sc = self._tc.create_stream_class(default_clock_class=self._cc)
87 self.assertEqual(sc.default_clock_class.addr, self._cc.addr)
9cf643d1 88
3cdfbaea 89 def test_create_invalid_default_clock_class(self):
9cf643d1 90 with self.assertRaises(TypeError):
3cdfbaea 91 self._tc.create_stream_class(default_clock_class=12)
9cf643d1 92
5783664e
PP
93 def test_create_user_attributes(self):
94 sc = self._tc.create_stream_class(user_attributes={'salut': 23})
95 self.assertEqual(sc.user_attributes, {'salut': 23})
96
97 def test_create_invalid_user_attributes(self):
98 with self.assertRaises(TypeError):
99 self._tc.create_stream_class(user_attributes=object())
100
101 def test_create_invalid_user_attributes_value_type(self):
102 with self.assertRaises(TypeError):
103 self._tc.create_stream_class(user_attributes=23)
104
3cdfbaea
SM
105 def test_automatic_stream_ids(self):
106 sc = self._tc.create_stream_class(assigns_automatic_stream_id=True)
107 self.assertTrue(sc.assigns_automatic_stream_id)
9cf643d1 108
3cdfbaea
SM
109 stream = self._trace.create_stream(sc)
110 self.assertIsNotNone(stream.id)
9cf643d1 111
3cdfbaea
SM
112 def test_automatic_stream_ids_raises(self):
113 sc = self._tc.create_stream_class(assigns_automatic_stream_id=True)
114 self.assertTrue(sc.assigns_automatic_stream_id)
115
4430bc80 116 with self.assertRaises(ValueError):
3cdfbaea
SM
117 self._trace.create_stream(sc, id=123)
118
119 def test_no_automatic_stream_ids(self):
120 sc = self._tc.create_stream_class(assigns_automatic_stream_id=False)
121 self.assertFalse(sc.assigns_automatic_stream_id)
122
123 stream = self._trace.create_stream(sc, id=333)
124 self.assertEqual(stream.id, 333)
125
126 def test_no_automatic_stream_ids_raises(self):
127 sc = self._tc.create_stream_class(assigns_automatic_stream_id=False)
128 self.assertFalse(sc.assigns_automatic_stream_id)
129
4430bc80 130 with self.assertRaises(ValueError):
3cdfbaea
SM
131 self._trace.create_stream(sc)
132
133 def test_automatic_event_class_ids(self):
134 sc = self._tc.create_stream_class(assigns_automatic_event_class_id=True)
135 self.assertTrue(sc.assigns_automatic_event_class_id)
136
137 ec = sc.create_event_class()
138 self.assertIsNotNone(ec.id)
139
140 def test_automatic_event_class_ids_raises(self):
141 sc = self._tc.create_stream_class(assigns_automatic_event_class_id=True)
142 self.assertTrue(sc.assigns_automatic_event_class_id)
143
4430bc80 144 with self.assertRaises(ValueError):
3cdfbaea
SM
145 sc.create_event_class(id=123)
146
147 def test_no_automatic_event_class_ids(self):
148 sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False)
149 self.assertFalse(sc.assigns_automatic_event_class_id)
9cf643d1 150
3cdfbaea
SM
151 ec = sc.create_event_class(id=333)
152 self.assertEqual(ec.id, 333)
9cf643d1 153
3cdfbaea
SM
154 def test_no_automatic_event_class_ids_raises(self):
155 sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False)
156 self.assertFalse(sc.assigns_automatic_event_class_id)
9cf643d1 157
4430bc80 158 with self.assertRaises(ValueError):
3cdfbaea
SM
159 sc.create_event_class()
160
26fc5aed 161 def test_supports_packets_without_cs(self):
cfbd7cf3
FD
162 sc = self._tc.create_stream_class(
163 default_clock_class=self._cc, supports_packets=True
164 )
26fc5aed
PP
165 self.assertTrue(sc.supports_packets)
166 self.assertFalse(sc.packets_have_beginning_default_clock_snapshot)
167 self.assertFalse(sc.packets_have_end_default_clock_snapshot)
168
169 def test_supports_packets_with_begin_cs(self):
cfbd7cf3
FD
170 sc = self._tc.create_stream_class(
171 default_clock_class=self._cc,
172 supports_packets=True,
173 packets_have_beginning_default_clock_snapshot=True,
174 )
26fc5aed 175 self.assertTrue(sc.supports_packets)
9b24b6aa 176 self.assertTrue(sc.packets_have_beginning_default_clock_snapshot)
26fc5aed 177 self.assertFalse(sc.packets_have_end_default_clock_snapshot)
3cdfbaea 178
26fc5aed 179 def test_supports_packets_with_end_cs(self):
cfbd7cf3
FD
180 sc = self._tc.create_stream_class(
181 default_clock_class=self._cc,
182 supports_packets=True,
183 packets_have_end_default_clock_snapshot=True,
184 )
26fc5aed
PP
185 self.assertTrue(sc.supports_packets)
186 self.assertFalse(sc.packets_have_beginning_default_clock_snapshot)
187 self.assertTrue(sc.packets_have_end_default_clock_snapshot)
188
189 def test_supports_packets_raises_type_error(self):
3cdfbaea 190 with self.assertRaises(TypeError):
cfbd7cf3
FD
191 sc = self._tc.create_stream_class(
192 default_clock_class=self._cc, supports_packets=23
193 )
3cdfbaea 194
26fc5aed
PP
195 def test_packets_have_begin_default_cs_raises_type_error(self):
196 with self.assertRaises(TypeError):
cfbd7cf3
FD
197 sc = self._tc.create_stream_class(
198 default_clock_class=self._cc,
199 packets_have_beginning_default_clock_snapshot=23,
200 )
3cdfbaea 201
26fc5aed 202 def test_packets_have_end_default_cs_raises_type_error(self):
9cf643d1 203 with self.assertRaises(TypeError):
cfbd7cf3
FD
204 sc = self._tc.create_stream_class(
205 default_clock_class=self._cc, packets_have_end_default_clock_snapshot=23
206 )
26fc5aed
PP
207
208 def test_does_not_support_packets_raises_with_begin_cs(self):
209 with self.assertRaises(ValueError):
cfbd7cf3
FD
210 sc = self._tc.create_stream_class(
211 default_clock_class=self._cc,
212 packets_have_beginning_default_clock_snapshot=True,
213 )
26fc5aed
PP
214
215 def test_does_not_support_packets_raises_with_end_cs(self):
216 with self.assertRaises(ValueError):
cfbd7cf3
FD
217 sc = self._tc.create_stream_class(
218 default_clock_class=self._cc,
219 packets_have_end_default_clock_snapshot=True,
220 )
3cdfbaea 221
2e90378a 222 def test_supports_discarded_events_without_cs(self):
cfbd7cf3
FD
223 sc = self._tc.create_stream_class(
224 default_clock_class=self._cc, supports_discarded_events=True
225 )
2e90378a
PP
226 self.assertTrue(sc.supports_discarded_events)
227 self.assertFalse(sc.discarded_events_have_default_clock_snapshots)
228
229 def test_supports_discarded_events_with_cs(self):
cfbd7cf3
FD
230 sc = self._tc.create_stream_class(
231 default_clock_class=self._cc,
232 supports_discarded_events=True,
233 discarded_events_have_default_clock_snapshots=True,
234 )
2e90378a
PP
235 self.assertTrue(sc.supports_discarded_events)
236 self.assertTrue(sc.discarded_events_have_default_clock_snapshots)
237
238 def test_supports_discarded_events_raises_type_error(self):
239 with self.assertRaises(TypeError):
cfbd7cf3
FD
240 sc = self._tc.create_stream_class(
241 default_clock_class=self._cc, supports_discarded_events=23
242 )
2e90378a
PP
243
244 def test_discarded_events_have_default_cs_raises_type_error(self):
245 with self.assertRaises(TypeError):
cfbd7cf3
FD
246 sc = self._tc.create_stream_class(
247 default_clock_class=self._cc,
248 discarded_events_have_default_clock_snapshots=23,
249 )
2e90378a
PP
250
251 def test_does_not_support_discarded_events_raises_with_cs(self):
252 with self.assertRaises(ValueError):
cfbd7cf3
FD
253 sc = self._tc.create_stream_class(
254 default_clock_class=self._cc,
255 discarded_events_have_default_clock_snapshots=True,
256 )
2e90378a
PP
257
258 def test_supports_discarded_packets_without_cs(self):
cfbd7cf3
FD
259 sc = self._tc.create_stream_class(
260 default_clock_class=self._cc,
261 supports_discarded_packets=True,
262 supports_packets=True,
263 )
2e90378a
PP
264 self.assertTrue(sc.supports_discarded_packets)
265 self.assertFalse(sc.discarded_packets_have_default_clock_snapshots)
266
267 def test_supports_discarded_packets_with_cs(self):
cfbd7cf3
FD
268 sc = self._tc.create_stream_class(
269 default_clock_class=self._cc,
270 supports_discarded_packets=True,
271 discarded_packets_have_default_clock_snapshots=True,
272 supports_packets=True,
273 )
2e90378a
PP
274 self.assertTrue(sc.supports_discarded_packets)
275 self.assertTrue(sc.discarded_packets_have_default_clock_snapshots)
276
26fc5aed
PP
277 def test_supports_discarded_packets_raises_without_packet_support(self):
278 with self.assertRaises(ValueError):
cfbd7cf3
FD
279 sc = self._tc.create_stream_class(
280 default_clock_class=self._cc, supports_discarded_packets=True
281 )
26fc5aed 282
2e90378a
PP
283 def test_supports_discarded_packets_raises_type_error(self):
284 with self.assertRaises(TypeError):
cfbd7cf3
FD
285 sc = self._tc.create_stream_class(
286 default_clock_class=self._cc,
287 supports_discarded_packets=23,
288 supports_packets=True,
289 )
2e90378a
PP
290
291 def test_discarded_packets_have_default_cs_raises_type_error(self):
292 with self.assertRaises(TypeError):
cfbd7cf3
FD
293 sc = self._tc.create_stream_class(
294 default_clock_class=self._cc,
295 discarded_packets_have_default_clock_snapshots=23,
296 supports_packets=True,
297 )
2e90378a
PP
298
299 def test_does_not_support_discarded_packets_raises_with_cs(self):
300 with self.assertRaises(ValueError):
cfbd7cf3
FD
301 sc = self._tc.create_stream_class(
302 default_clock_class=self._cc,
303 discarded_packets_have_default_clock_snapshots=True,
304 supports_packets=True,
305 )
2e90378a 306
3cdfbaea
SM
307 def test_trace_class(self):
308 sc = self._tc.create_stream_class()
309 self.assertEqual(sc.trace_class.addr, self._tc.addr)
310
311 def _create_stream_class_with_event_classes(self):
312 sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False)
313 ec1 = sc.create_event_class(id=23)
314 ec2 = sc.create_event_class(id=17)
315 return sc, ec1, ec2
9cf643d1
PP
316
317 def test_getitem(self):
3cdfbaea
SM
318 sc, ec1, ec2 = self._create_stream_class_with_event_classes()
319
320 self.assertEqual(sc[23].addr, ec1.addr)
321 self.assertEqual(sc[17].addr, ec2.addr)
9cf643d1
PP
322
323 def test_getitem_wrong_key_type(self):
3cdfbaea
SM
324 sc, _, _ = self._create_stream_class_with_event_classes()
325
9cf643d1 326 with self.assertRaises(TypeError):
3cdfbaea 327 sc['event23']
9cf643d1
PP
328
329 def test_getitem_wrong_key(self):
3cdfbaea
SM
330 sc, _, _ = self._create_stream_class_with_event_classes()
331
9cf643d1 332 with self.assertRaises(KeyError):
3cdfbaea 333 sc[19]
9cf643d1
PP
334
335 def test_len(self):
3cdfbaea
SM
336 sc, _, _ = self._create_stream_class_with_event_classes()
337
338 self.assertEqual(len(sc), 2)
9cf643d1
PP
339
340 def test_iter(self):
3cdfbaea
SM
341 sc, _, _ = self._create_stream_class_with_event_classes()
342
343 ec_ids = sorted(sc)
344 self.assertEqual(ec_ids, [17, 23])
This page took 0.064016 seconds and 4 git commands to generate.