Commit | Line | Data |
---|---|---|
32d2d479 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 | ||
32656995 | 19 | import unittest |
32656995 | 20 | import bt2 |
9cbe0c59 FD |
21 | from utils import get_default_trace_class, TestOutputPortMessageIterator |
22 | from bt2 import value as bt2_value | |
23 | from bt2 import field_class as bt2_field_class | |
24 | ||
25 | ||
26 | def _create_stream(tc, ctx_field_classes): | |
27 | packet_context_fc = tc.create_structure_field_class() | |
28 | for name, fc in ctx_field_classes: | |
29 | packet_context_fc.append_member(name, fc) | |
30 | ||
31 | trace = tc() | |
32 | stream_class = tc.create_stream_class( | |
33 | packet_context_field_class=packet_context_fc, supports_packets=True | |
34 | ) | |
35 | ||
36 | stream = trace.create_stream(stream_class) | |
37 | return stream | |
38 | ||
39 | ||
40 | def _create_const_field_class(tc, field_class, value_setter_fn): | |
41 | field_name = 'const field' | |
42 | ||
43 | class MyIter(bt2._UserMessageIterator): | |
9415de1c | 44 | def __init__(self, config, self_port_output): |
9cbe0c59 FD |
45 | nonlocal field_class |
46 | nonlocal value_setter_fn | |
47 | stream = _create_stream(tc, [(field_name, field_class)]) | |
48 | packet = stream.create_packet() | |
49 | ||
50 | value_setter_fn(packet.context_field[field_name]) | |
51 | ||
52 | self._msgs = [ | |
53 | self._create_stream_beginning_message(stream), | |
54 | self._create_packet_beginning_message(packet), | |
55 | ] | |
56 | ||
57 | def __next__(self): | |
58 | if len(self._msgs) == 0: | |
59 | raise StopIteration | |
60 | ||
61 | return self._msgs.pop(0) | |
62 | ||
63 | class MySrc(bt2._UserSourceComponent, message_iterator_class=MyIter): | |
e3250e61 | 64 | def __init__(self, config, params, obj): |
9cbe0c59 FD |
65 | self._add_output_port('out', params) |
66 | ||
67 | graph = bt2.Graph() | |
68 | src_comp = graph.add_component(MySrc, 'my_source', None) | |
69 | msg_iter = TestOutputPortMessageIterator(graph, src_comp.output_ports['out']) | |
70 | ||
71 | # Ignore first message, stream beginning | |
72 | _ = next(msg_iter) | |
73 | packet_beg_msg = next(msg_iter) | |
74 | ||
75 | return packet_beg_msg.packet.context_field[field_name].cls | |
32656995 SM |
76 | |
77 | ||
b2df5780 PP |
78 | class _TestFieldClass: |
79 | def test_create_user_attributes(self): | |
80 | fc = self._create_default_field_class(user_attributes={'salut': 23}) | |
81 | self.assertEqual(fc.user_attributes, {'salut': 23}) | |
9cbe0c59 FD |
82 | self.assertIs(type(fc.user_attributes), bt2_value.MapValue) |
83 | ||
84 | def test_const_create_user_attributes(self): | |
85 | fc = self._create_default_const_field_class(user_attributes={'salut': 23}) | |
86 | self.assertEqual(fc.user_attributes, {'salut': 23}) | |
87 | self.assertIs(type(fc.user_attributes), bt2_value._MapValueConst) | |
b2df5780 PP |
88 | |
89 | def test_create_invalid_user_attributes(self): | |
90 | with self.assertRaises(TypeError): | |
91 | self._create_default_field_class(user_attributes=object()) | |
92 | ||
93 | def test_create_invalid_user_attributes_value_type(self): | |
94 | with self.assertRaises(TypeError): | |
95 | self._create_default_field_class(user_attributes=23) | |
96 | ||
97 | ||
98 | class BoolFieldClassTestCase(_TestFieldClass, unittest.TestCase): | |
9cbe0c59 FD |
99 | @staticmethod |
100 | def _const_value_setter(field): | |
c82e5122 | 101 | field.value = False |
9cbe0c59 | 102 | |
b2df5780 | 103 | def _create_default_field_class(self, **kwargs): |
a07f15cb | 104 | tc = get_default_trace_class() |
b2df5780 PP |
105 | return tc.create_bool_field_class(**kwargs) |
106 | ||
9cbe0c59 FD |
107 | def _create_default_const_field_class(self, *args, **kwargs): |
108 | tc = get_default_trace_class() | |
109 | fc = tc.create_bool_field_class(*args, **kwargs) | |
110 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
111 | ||
b2df5780 PP |
112 | def setUp(self): |
113 | self._fc = self._create_default_field_class() | |
9cbe0c59 | 114 | self._fc_const = self._create_default_const_field_class() |
a07f15cb PP |
115 | |
116 | def test_create_default(self): | |
117 | self.assertIsNotNone(self._fc) | |
b2df5780 | 118 | self.assertEqual(len(self._fc.user_attributes), 0) |
a07f15cb PP |
119 | |
120 | ||
b2df5780 | 121 | class BitArrayFieldClassTestCase(_TestFieldClass, unittest.TestCase): |
9cbe0c59 FD |
122 | @staticmethod |
123 | def _const_value_setter(field): | |
c82e5122 | 124 | field.value = [] |
9cbe0c59 | 125 | |
b2df5780 PP |
126 | def _create_field_class(self, *args, **kwargs): |
127 | tc = get_default_trace_class() | |
128 | return tc.create_bit_array_field_class(*args, **kwargs) | |
129 | ||
130 | def _create_default_field_class(self, **kwargs): | |
131 | return self._create_field_class(17, **kwargs) | |
132 | ||
9cbe0c59 FD |
133 | def _create_default_const_field_class(self, *args, **kwargs): |
134 | tc = get_default_trace_class() | |
135 | fc = tc.create_bit_array_field_class(17, **kwargs) | |
136 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
137 | ||
6b29f2d4 | 138 | def setUp(self): |
b2df5780 | 139 | self._fc = self._create_default_field_class() |
6b29f2d4 PP |
140 | |
141 | def test_create_default(self): | |
142 | self.assertIsNotNone(self._fc) | |
b2df5780 | 143 | self.assertEqual(len(self._fc.user_attributes), 0) |
6b29f2d4 PP |
144 | |
145 | def test_create_length_out_of_range(self): | |
146 | with self.assertRaises(ValueError): | |
b2df5780 | 147 | self._create_field_class(65) |
6b29f2d4 PP |
148 | |
149 | def test_create_length_zero(self): | |
150 | with self.assertRaises(ValueError): | |
b2df5780 | 151 | self._create_field_class(0) |
6b29f2d4 PP |
152 | |
153 | def test_create_length_invalid_type(self): | |
154 | with self.assertRaises(TypeError): | |
b2df5780 | 155 | self._create_field_class('lel') |
6b29f2d4 PP |
156 | |
157 | def test_length_prop(self): | |
158 | self.assertEqual(self._fc.length, 17) | |
159 | ||
160 | ||
c8820b76 SM |
161 | class _TestIntegerFieldClassProps: |
162 | def test_create_default(self): | |
b2df5780 | 163 | fc = self._create_default_field_class() |
c8820b76 SM |
164 | self.assertEqual(fc.field_value_range, 64) |
165 | self.assertEqual(fc.preferred_display_base, bt2.IntegerDisplayBase.DECIMAL) | |
b2df5780 | 166 | self.assertEqual(len(fc.user_attributes), 0) |
32656995 | 167 | |
c8820b76 | 168 | def test_create_range(self): |
b2df5780 | 169 | fc = self._create_field_class(field_value_range=35) |
c8820b76 | 170 | self.assertEqual(fc.field_value_range, 35) |
32656995 | 171 | |
b2df5780 | 172 | fc = self._create_field_class(36) |
c8820b76 | 173 | self.assertEqual(fc.field_value_range, 36) |
32656995 | 174 | |
c8820b76 SM |
175 | def test_create_invalid_range(self): |
176 | with self.assertRaises(TypeError): | |
b2df5780 | 177 | self._create_field_class('yes') |
32656995 | 178 | |
c8820b76 | 179 | with self.assertRaises(TypeError): |
b2df5780 | 180 | self._create_field_class(field_value_range='yes') |
32656995 | 181 | |
32656995 | 182 | with self.assertRaises(ValueError): |
b2df5780 | 183 | self._create_field_class(field_value_range=-2) |
32656995 | 184 | |
c8820b76 | 185 | with self.assertRaises(ValueError): |
b2df5780 | 186 | self._create_field_class(field_value_range=0) |
32656995 | 187 | |
c8820b76 | 188 | def test_create_base(self): |
b2df5780 | 189 | fc = self._create_field_class( |
61d96b89 FD |
190 | preferred_display_base=bt2.IntegerDisplayBase.HEXADECIMAL |
191 | ) | |
c8820b76 | 192 | self.assertEqual(fc.preferred_display_base, bt2.IntegerDisplayBase.HEXADECIMAL) |
32656995 | 193 | |
c8820b76 | 194 | def test_create_invalid_base_type(self): |
32656995 | 195 | with self.assertRaises(TypeError): |
b2df5780 | 196 | self._create_field_class(preferred_display_base='yes') |
32656995 | 197 | |
c8820b76 SM |
198 | def test_create_invalid_base_value(self): |
199 | with self.assertRaises(ValueError): | |
b2df5780 | 200 | self._create_field_class(preferred_display_base=444) |
32656995 | 201 | |
c8820b76 | 202 | def test_create_full(self): |
b2df5780 PP |
203 | fc = self._create_field_class( |
204 | 24, preferred_display_base=bt2.IntegerDisplayBase.OCTAL | |
205 | ) | |
c8820b76 SM |
206 | self.assertEqual(fc.field_value_range, 24) |
207 | self.assertEqual(fc.preferred_display_base, bt2.IntegerDisplayBase.OCTAL) | |
32656995 SM |
208 | |
209 | ||
b2df5780 PP |
210 | class SignedIntegerFieldClassTestCase( |
211 | _TestIntegerFieldClassProps, _TestFieldClass, unittest.TestCase | |
212 | ): | |
9cbe0c59 FD |
213 | @staticmethod |
214 | def _const_value_setter(field): | |
c82e5122 | 215 | field.value = -18 |
9cbe0c59 | 216 | |
b2df5780 PP |
217 | def _create_field_class(self, *args, **kwargs): |
218 | tc = get_default_trace_class() | |
219 | return tc.create_signed_integer_field_class(*args, **kwargs) | |
32656995 | 220 | |
9cbe0c59 FD |
221 | def _create_default_const_field_class(self, *args, **kwargs): |
222 | tc = get_default_trace_class() | |
223 | fc = tc.create_signed_integer_field_class(*args, **kwargs) | |
224 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
225 | ||
b2df5780 PP |
226 | _create_default_field_class = _create_field_class |
227 | ||
228 | ||
229 | class UnsignedIntegerFieldClassTestCase( | |
230 | _TestIntegerFieldClassProps, _TestFieldClass, unittest.TestCase | |
231 | ): | |
9cbe0c59 FD |
232 | @staticmethod |
233 | def _const_value_setter(field): | |
c82e5122 | 234 | field.value = 18 |
9cbe0c59 | 235 | |
b2df5780 PP |
236 | def _create_field_class(self, *args, **kwargs): |
237 | tc = get_default_trace_class() | |
238 | return tc.create_unsigned_integer_field_class(*args, **kwargs) | |
239 | ||
9cbe0c59 FD |
240 | def _create_default_const_field_class(self, *args, **kwargs): |
241 | tc = get_default_trace_class() | |
242 | fc = tc.create_signed_integer_field_class(*args, **kwargs) | |
243 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
244 | ||
b2df5780 | 245 | _create_default_field_class = _create_field_class |
32656995 | 246 | |
b2df5780 | 247 | |
76276a81 | 248 | class SingleRealFieldClassTestCase(_TestFieldClass, unittest.TestCase): |
9cbe0c59 FD |
249 | @staticmethod |
250 | def _const_value_setter(field): | |
76276a81 | 251 | field.value = -18.0 |
9cbe0c59 | 252 | |
b2df5780 PP |
253 | def _create_field_class(self, *args, **kwargs): |
254 | tc = get_default_trace_class() | |
76276a81 | 255 | return tc.create_single_precision_real_field_class(*args, **kwargs) |
b2df5780 | 256 | |
9cbe0c59 FD |
257 | def _create_default_const_field_class(self, *args, **kwargs): |
258 | tc = get_default_trace_class() | |
76276a81 | 259 | fc = tc.create_single_precision_real_field_class(*args, **kwargs) |
9cbe0c59 FD |
260 | return _create_const_field_class(tc, fc, self._const_value_setter) |
261 | ||
b2df5780 | 262 | _create_default_field_class = _create_field_class |
32656995 | 263 | |
c8820b76 | 264 | def test_create_default(self): |
b2df5780 | 265 | fc = self._create_field_class() |
b2df5780 | 266 | self.assertEqual(len(fc.user_attributes), 0) |
32656995 | 267 | |
c8820b76 | 268 | |
76276a81 FD |
269 | class DoubleRealFieldClassTestCase(_TestFieldClass, unittest.TestCase): |
270 | @staticmethod | |
271 | def _const_value_setter(field): | |
272 | field.value = -18.0 | |
273 | ||
274 | def _create_field_class(self, *args, **kwargs): | |
275 | tc = get_default_trace_class() | |
276 | return tc.create_double_precision_real_field_class(*args, **kwargs) | |
277 | ||
278 | def _create_default_const_field_class(self, *args, **kwargs): | |
279 | tc = get_default_trace_class() | |
280 | fc = tc.create_double_precision_real_field_class(*args, **kwargs) | |
281 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
282 | ||
283 | _create_default_field_class = _create_field_class | |
284 | ||
285 | def test_create_default(self): | |
286 | fc = self._create_field_class() | |
287 | self.assertEqual(len(fc.user_attributes), 0) | |
32656995 | 288 | |
32656995 | 289 | |
c8820b76 SM |
290 | # Converts an _EnumerationFieldClassMapping to a list of ranges: |
291 | # | |
292 | # [(lower0, upper0), (lower1, upper1), ...] | |
293 | ||
61d96b89 | 294 | |
02b61fe0 PP |
295 | def enum_mapping_to_set(mapping): |
296 | return {(x.lower, x.upper) for x in mapping.ranges} | |
32656995 | 297 | |
32656995 | 298 | |
02b61fe0 | 299 | class _EnumerationFieldClassTestCase(_TestIntegerFieldClassProps): |
c8820b76 | 300 | def setUp(self): |
02b61fe0 | 301 | self._spec_set_up() |
b2df5780 | 302 | self._fc = self._create_default_field_class() |
9cbe0c59 | 303 | self._fc_const = self._create_default_const_field_class() |
c8820b76 SM |
304 | |
305 | def test_create_from_invalid_type(self): | |
32656995 | 306 | with self.assertRaises(TypeError): |
b2df5780 | 307 | self._create_field_class('coucou') |
32656995 | 308 | |
c8820b76 | 309 | def test_add_mapping_simple(self): |
02b61fe0 | 310 | self._fc.add_mapping('hello', self._ranges1) |
c8820b76 SM |
311 | mapping = self._fc['hello'] |
312 | self.assertEqual(mapping.label, 'hello') | |
02b61fe0 | 313 | self.assertEqual(mapping.ranges, self._ranges1) |
32656995 | 314 | |
9cbe0c59 FD |
315 | def test_const_add_mapping(self): |
316 | with self.assertRaises(AttributeError): | |
317 | self._fc_const.add_mapping('hello', self._ranges1) | |
318 | ||
c8820b76 | 319 | def test_add_mapping_simple_kwargs(self): |
02b61fe0 | 320 | self._fc.add_mapping(label='hello', ranges=self._ranges1) |
c8820b76 SM |
321 | mapping = self._fc['hello'] |
322 | self.assertEqual(mapping.label, 'hello') | |
02b61fe0 | 323 | self.assertEqual(mapping.ranges, self._ranges1) |
32656995 | 324 | |
02b61fe0 PP |
325 | def test_add_mapping_invalid_name(self): |
326 | with self.assertRaises(TypeError): | |
327 | self._fc.add_mapping(17, self._ranges1) | |
32656995 | 328 | |
02b61fe0 PP |
329 | def test_add_mapping_invalid_range(self): |
330 | with self.assertRaises(TypeError): | |
331 | self._fc.add_mapping('allo', 'meow') | |
c8820b76 | 332 | |
02b61fe0 | 333 | def test_add_mapping_dup_label(self): |
3b2be708 | 334 | with self.assertRaises(ValueError): |
02b61fe0 PP |
335 | self._fc.add_mapping('a', self._ranges1) |
336 | self._fc.add_mapping('a', self._ranges2) | |
c8820b76 | 337 | |
02b61fe0 | 338 | def test_add_mapping_invalid_ranges_signedness(self): |
32656995 | 339 | with self.assertRaises(TypeError): |
02b61fe0 | 340 | self._fc.add_mapping('allo', self._inval_ranges) |
32656995 | 341 | |
c8820b76 | 342 | def test_iadd(self): |
02b61fe0 | 343 | self._fc.add_mapping('c', self._ranges1) |
32656995 | 344 | |
61d96b89 | 345 | self._fc += [('d', self._ranges2), ('e', self._ranges3)] |
32656995 | 346 | |
02b61fe0 | 347 | self.assertEqual(len(self._fc), 3) |
c8820b76 | 348 | self.assertEqual(self._fc['c'].label, 'c') |
02b61fe0 | 349 | self.assertEqual(self._fc['c'].ranges, self._ranges1) |
c8820b76 | 350 | self.assertEqual(self._fc['d'].label, 'd') |
02b61fe0 | 351 | self.assertEqual(self._fc['d'].ranges, self._ranges2) |
c8820b76 | 352 | self.assertEqual(self._fc['e'].label, 'e') |
02b61fe0 | 353 | self.assertEqual(self._fc['e'].ranges, self._ranges3) |
32656995 | 354 | |
9cbe0c59 FD |
355 | def test_const_iadd(self): |
356 | with self.assertRaises(TypeError): | |
357 | self._fc_const += [('d', self._ranges2), ('e', self._ranges3)] | |
358 | ||
c8820b76 SM |
359 | def test_bool_op(self): |
360 | self.assertFalse(self._fc) | |
02b61fe0 | 361 | self._fc.add_mapping('a', self._ranges1) |
c8820b76 | 362 | self.assertTrue(self._fc) |
32656995 | 363 | |
c8820b76 | 364 | def test_len(self): |
02b61fe0 PP |
365 | self._fc.add_mapping('a', self._ranges1) |
366 | self._fc.add_mapping('b', self._ranges2) | |
367 | self._fc.add_mapping('c', self._ranges3) | |
c8820b76 | 368 | self.assertEqual(len(self._fc), 3) |
32656995 | 369 | |
c8820b76 | 370 | def test_getitem(self): |
02b61fe0 PP |
371 | self._fc.add_mapping('a', self._ranges1) |
372 | self._fc.add_mapping('b', self._ranges2) | |
373 | self._fc.add_mapping('c', self._ranges3) | |
c8820b76 | 374 | mapping = self._fc['a'] |
c8820b76 | 375 | self.assertEqual(mapping.label, 'a') |
02b61fe0 | 376 | self.assertEqual(mapping.ranges, self._ranges1) |
8d99efe6 FD |
377 | self.assertIs(type(mapping), self._MAPPING_CLASS) |
378 | self.assertIs(type(mapping.ranges), self._CONST_RANGE_SET_CLASS) | |
32656995 | 379 | |
02b61fe0 | 380 | def test_getitem_nonexistent(self): |
c8820b76 SM |
381 | with self.assertRaises(KeyError): |
382 | self._fc['doesnotexist'] | |
32656995 | 383 | |
c8820b76 | 384 | def test_iter(self): |
02b61fe0 PP |
385 | self._fc.add_mapping('a', self._ranges1) |
386 | self._fc.add_mapping('b', self._ranges2) | |
387 | self._fc.add_mapping('c', self._ranges3) | |
32656995 | 388 | |
c8820b76 SM |
389 | # This exercises iteration. |
390 | labels = sorted(self._fc) | |
32656995 | 391 | |
02b61fe0 | 392 | self.assertEqual(labels, ['a', 'b', 'c']) |
32656995 | 393 | |
c8820b76 | 394 | def test_find_by_value(self): |
02b61fe0 PP |
395 | self._fc.add_mapping('a', self._ranges1) |
396 | self._fc.add_mapping('b', self._ranges2) | |
397 | self._fc.add_mapping('c', self._ranges3) | |
398 | mappings = self._fc.mappings_for_value(self._value_in_range_1_and_3) | |
399 | labels = set([mapping.label for mapping in mappings]) | |
400 | expected_labels = set(['a', 'c']) | |
401 | self.assertEqual(labels, expected_labels) | |
402 | ||
403 | ||
61d96b89 | 404 | class UnsignedEnumerationFieldClassTestCase( |
b2df5780 | 405 | _EnumerationFieldClassTestCase, _TestFieldClass, unittest.TestCase |
61d96b89 | 406 | ): |
8d99efe6 FD |
407 | _MAPPING_CLASS = bt2_field_class._UnsignedEnumerationFieldClassMappingConst |
408 | _RANGE_SET_CLASS = bt2.UnsignedIntegerRangeSet | |
409 | _CONST_RANGE_SET_CLASS = bt2._UnsignedIntegerRangeSetConst | |
410 | ||
02b61fe0 PP |
411 | def _spec_set_up(self): |
412 | self._ranges1 = bt2.UnsignedIntegerRangeSet([(1, 4), (18, 47)]) | |
413 | self._ranges2 = bt2.UnsignedIntegerRangeSet([(5, 5)]) | |
414 | self._ranges3 = bt2.UnsignedIntegerRangeSet([(8, 22), (48, 99)]) | |
415 | self._inval_ranges = bt2.SignedIntegerRangeSet([(-8, -5), (48, 1928)]) | |
416 | self._value_in_range_1_and_3 = 20 | |
b2df5780 | 417 | |
9cbe0c59 FD |
418 | @staticmethod |
419 | def _const_value_setter(field): | |
c82e5122 | 420 | field.value = 0 |
9cbe0c59 | 421 | |
b2df5780 PP |
422 | def _create_field_class(self, *args, **kwargs): |
423 | tc = get_default_trace_class() | |
424 | return tc.create_unsigned_enumeration_field_class(*args, **kwargs) | |
425 | ||
9cbe0c59 FD |
426 | def _create_default_const_field_class(self, *args, **kwargs): |
427 | tc = get_default_trace_class() | |
428 | fc = tc.create_unsigned_enumeration_field_class(*args, **kwargs) | |
429 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
430 | ||
b2df5780 | 431 | _create_default_field_class = _create_field_class |
32656995 | 432 | |
32656995 | 433 | |
61d96b89 | 434 | class SignedEnumerationFieldClassTestCase( |
b2df5780 | 435 | _EnumerationFieldClassTestCase, _TestFieldClass, unittest.TestCase |
61d96b89 | 436 | ): |
8d99efe6 FD |
437 | _MAPPING_CLASS = bt2_field_class._SignedEnumerationFieldClassMappingConst |
438 | _RANGE_SET_CLASS = bt2.SignedIntegerRangeSet | |
439 | _CONST_RANGE_SET_CLASS = bt2._SignedIntegerRangeSetConst | |
440 | ||
02b61fe0 PP |
441 | def _spec_set_up(self): |
442 | self._ranges1 = bt2.SignedIntegerRangeSet([(-10, -4), (18, 47)]) | |
443 | self._ranges2 = bt2.SignedIntegerRangeSet([(-3, -3)]) | |
444 | self._ranges3 = bt2.SignedIntegerRangeSet([(-100, -1), (8, 16), (48, 99)]) | |
445 | self._inval_ranges = bt2.UnsignedIntegerRangeSet([(8, 16), (48, 99)]) | |
446 | self._value_in_range_1_and_3 = -7 | |
32656995 | 447 | |
9cbe0c59 FD |
448 | @staticmethod |
449 | def _const_value_setter(field): | |
c82e5122 | 450 | field.value = 0 |
9cbe0c59 | 451 | |
b2df5780 PP |
452 | def _create_field_class(self, *args, **kwargs): |
453 | tc = get_default_trace_class() | |
454 | return tc.create_signed_enumeration_field_class(*args, **kwargs) | |
455 | ||
9cbe0c59 FD |
456 | def _create_default_const_field_class(self, *args, **kwargs): |
457 | tc = get_default_trace_class() | |
458 | fc = tc.create_signed_enumeration_field_class(*args, **kwargs) | |
459 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
460 | ||
b2df5780 | 461 | _create_default_field_class = _create_field_class |
32656995 | 462 | |
b2df5780 PP |
463 | |
464 | class StringFieldClassTestCase(_TestFieldClass, unittest.TestCase): | |
9cbe0c59 FD |
465 | @staticmethod |
466 | def _const_value_setter(field): | |
c82e5122 | 467 | field.value = 'chaine' |
9cbe0c59 | 468 | |
b2df5780 | 469 | def _create_field_class(self, *args, **kwargs): |
c8820b76 | 470 | tc = get_default_trace_class() |
b2df5780 PP |
471 | return tc.create_string_field_class(*args, **kwargs) |
472 | ||
9cbe0c59 FD |
473 | def _create_default_const_field_class(self, *args, **kwargs): |
474 | tc = get_default_trace_class() | |
475 | fc = tc.create_string_field_class(*args, **kwargs) | |
476 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
477 | ||
b2df5780 PP |
478 | _create_default_field_class = _create_field_class |
479 | ||
480 | def setUp(self): | |
481 | self._fc = self._create_default_field_class() | |
32656995 SM |
482 | |
483 | def test_create_default(self): | |
c8820b76 | 484 | self.assertIsNotNone(self._fc) |
b2df5780 | 485 | self.assertEqual(len(self._fc.user_attributes), 0) |
32656995 | 486 | |
32656995 | 487 | |
61d96b89 | 488 | class _TestElementContainer: |
02b61fe0 PP |
489 | def setUp(self): |
490 | self._tc = get_default_trace_class() | |
b2df5780 | 491 | self._fc = self._create_default_field_class() |
9cbe0c59 | 492 | self._fc_const = self._create_default_const_field_class() |
02b61fe0 PP |
493 | |
494 | def test_create_default(self): | |
495 | self.assertIsNotNone(self._fc) | |
b2df5780 | 496 | self.assertEqual(len(self._fc.user_attributes), 0) |
02b61fe0 | 497 | |
c8820b76 SM |
498 | def test_append_element(self): |
499 | int_field_class = self._tc.create_signed_integer_field_class(32) | |
500 | self._append_element_method(self._fc, 'int32', int_field_class) | |
02b61fe0 | 501 | field_class = self._fc['int32'].field_class |
c8820b76 | 502 | self.assertEqual(field_class.addr, int_field_class.addr) |
32656995 | 503 | |
02b61fe0 | 504 | def test_append_element_kwargs(self): |
c8820b76 SM |
505 | int_field_class = self._tc.create_signed_integer_field_class(32) |
506 | self._append_element_method(self._fc, name='int32', field_class=int_field_class) | |
02b61fe0 | 507 | field_class = self._fc['int32'].field_class |
c8820b76 SM |
508 | self.assertEqual(field_class.addr, int_field_class.addr) |
509 | ||
510 | def test_append_element_invalid_name(self): | |
511 | sub_fc = self._tc.create_string_field_class() | |
32656995 | 512 | |
32656995 | 513 | with self.assertRaises(TypeError): |
c8820b76 | 514 | self._append_element_method(self._fc, 23, sub_fc) |
32656995 | 515 | |
c8820b76 | 516 | def test_append_element_invalid_field_class(self): |
32656995 | 517 | with self.assertRaises(TypeError): |
c8820b76 | 518 | self._append_element_method(self._fc, 'yes', object()) |
32656995 | 519 | |
02b61fe0 PP |
520 | def test_append_element_dup_name(self): |
521 | sub_fc1 = self._tc.create_string_field_class() | |
522 | sub_fc2 = self._tc.create_string_field_class() | |
523 | ||
3b2be708 | 524 | with self.assertRaises(ValueError): |
02b61fe0 PP |
525 | self._append_element_method(self._fc, 'yes', sub_fc1) |
526 | self._append_element_method(self._fc, 'yes', sub_fc2) | |
527 | ||
9cbe0c59 FD |
528 | def test_attr_field_class(self): |
529 | int_field_class = self._tc.create_signed_integer_field_class(32) | |
530 | self._append_element_method(self._fc, 'int32', int_field_class) | |
531 | field_class = self._fc['int32'].field_class | |
532 | ||
533 | self.assertIs(type(field_class), bt2_field_class._SignedIntegerFieldClass) | |
534 | ||
535 | def test_const_attr_field_class(self): | |
536 | int_field_class = self._tc.create_signed_integer_field_class(32) | |
537 | self._append_element_method(self._fc, 'int32', int_field_class) | |
538 | field_class = self._fc['int32'].field_class | |
539 | const_fc = _create_const_field_class( | |
540 | self._tc, self._fc, self._const_value_setter | |
541 | ) | |
542 | field_class = const_fc['int32'].field_class | |
543 | ||
544 | self.assertIs(type(field_class), bt2_field_class._SignedIntegerFieldClassConst) | |
545 | ||
32656995 | 546 | def test_iadd(self): |
76276a81 | 547 | a_field_class = self._tc.create_single_precision_real_field_class() |
c8820b76 SM |
548 | b_field_class = self._tc.create_signed_integer_field_class(17) |
549 | self._append_element_method(self._fc, 'a_float', a_field_class) | |
550 | self._append_element_method(self._fc, 'b_int', b_field_class) | |
02b61fe0 | 551 | c_field_class = self._tc.create_string_field_class() |
61d96b89 FD |
552 | d_field_class = self._tc.create_signed_enumeration_field_class( |
553 | field_value_range=32 | |
554 | ) | |
02b61fe0 PP |
555 | e_field_class = self._tc.create_structure_field_class() |
556 | self._fc += [ | |
557 | ('c_string', c_field_class), | |
558 | ('d_enum', d_field_class), | |
559 | ('e_struct', e_field_class), | |
560 | ] | |
561 | self.assertEqual(self._fc['a_float'].field_class.addr, a_field_class.addr) | |
562 | self.assertEqual(self._fc['a_float'].name, 'a_float') | |
563 | self.assertEqual(self._fc['b_int'].field_class.addr, b_field_class.addr) | |
564 | self.assertEqual(self._fc['b_int'].name, 'b_int') | |
565 | self.assertEqual(self._fc['c_string'].field_class.addr, c_field_class.addr) | |
566 | self.assertEqual(self._fc['c_string'].name, 'c_string') | |
567 | self.assertEqual(self._fc['d_enum'].field_class.addr, d_field_class.addr) | |
568 | self.assertEqual(self._fc['d_enum'].name, 'd_enum') | |
569 | self.assertEqual(self._fc['e_struct'].field_class.addr, e_field_class.addr) | |
570 | self.assertEqual(self._fc['e_struct'].name, 'e_struct') | |
32656995 | 571 | |
9cbe0c59 | 572 | def test_const_iadd(self): |
76276a81 | 573 | a_field_class = self._tc.create_single_precision_real_field_class() |
9cbe0c59 FD |
574 | with self.assertRaises(TypeError): |
575 | self._fc_const += a_field_class | |
576 | ||
32656995 SM |
577 | def test_bool_op(self): |
578 | self.assertFalse(self._fc) | |
c8820b76 | 579 | self._append_element_method(self._fc, 'a', self._tc.create_string_field_class()) |
32656995 SM |
580 | self.assertTrue(self._fc) |
581 | ||
582 | def test_len(self): | |
02b61fe0 PP |
583 | self._append_element_method(self._fc, 'a', self._tc.create_string_field_class()) |
584 | self._append_element_method(self._fc, 'b', self._tc.create_string_field_class()) | |
585 | self._append_element_method(self._fc, 'c', self._tc.create_string_field_class()) | |
32656995 SM |
586 | self.assertEqual(len(self._fc), 3) |
587 | ||
588 | def test_getitem(self): | |
c8820b76 SM |
589 | a_fc = self._tc.create_signed_integer_field_class(32) |
590 | b_fc = self._tc.create_string_field_class() | |
76276a81 | 591 | c_fc = self._tc.create_single_precision_real_field_class() |
c8820b76 SM |
592 | self._append_element_method(self._fc, 'a', a_fc) |
593 | self._append_element_method(self._fc, 'b', b_fc) | |
594 | self._append_element_method(self._fc, 'c', c_fc) | |
02b61fe0 PP |
595 | self.assertEqual(self._fc['b'].field_class.addr, b_fc.addr) |
596 | self.assertEqual(self._fc['b'].name, 'b') | |
32656995 SM |
597 | |
598 | def test_getitem_invalid_key_type(self): | |
599 | with self.assertRaises(TypeError): | |
600 | self._fc[0] | |
601 | ||
602 | def test_getitem_invalid_key(self): | |
603 | with self.assertRaises(KeyError): | |
604 | self._fc['no way'] | |
605 | ||
606 | def test_contains(self): | |
607 | self.assertFalse('a' in self._fc) | |
c8820b76 | 608 | self._append_element_method(self._fc, 'a', self._tc.create_string_field_class()) |
32656995 SM |
609 | self.assertTrue('a' in self._fc) |
610 | ||
611 | def test_iter(self): | |
c8820b76 SM |
612 | a_fc = self._tc.create_signed_integer_field_class(32) |
613 | b_fc = self._tc.create_string_field_class() | |
76276a81 | 614 | c_fc = self._tc.create_single_precision_real_field_class() |
61d96b89 | 615 | elements = (('a', a_fc), ('b', b_fc), ('c', c_fc)) |
32656995 | 616 | |
02b61fe0 PP |
617 | for elem in elements: |
618 | self._append_element_method(self._fc, *elem) | |
32656995 | 619 | |
02b61fe0 PP |
620 | for (name, element), test_elem in zip(self._fc.items(), elements): |
621 | self.assertEqual(element.name, test_elem[0]) | |
622 | self.assertEqual(name, element.name) | |
623 | self.assertEqual(element.field_class.addr, test_elem[1].addr) | |
b2df5780 | 624 | self.assertEqual(len(element.user_attributes), 0) |
32656995 SM |
625 | |
626 | def test_at_index(self): | |
c8820b76 SM |
627 | a_fc = self._tc.create_signed_integer_field_class(32) |
628 | b_fc = self._tc.create_string_field_class() | |
76276a81 | 629 | c_fc = self._tc.create_single_precision_real_field_class() |
c8820b76 SM |
630 | self._append_element_method(self._fc, 'c', c_fc) |
631 | self._append_element_method(self._fc, 'a', a_fc) | |
632 | self._append_element_method(self._fc, 'b', b_fc) | |
02b61fe0 PP |
633 | elem = self._at_index_method(self._fc, 1) |
634 | self.assertEqual(elem.field_class.addr, a_fc.addr) | |
635 | self.assertEqual(elem.name, 'a') | |
32656995 SM |
636 | |
637 | def test_at_index_invalid(self): | |
61d96b89 FD |
638 | self._append_element_method( |
639 | self._fc, 'c', self._tc.create_signed_integer_field_class(32) | |
640 | ) | |
32656995 SM |
641 | |
642 | with self.assertRaises(TypeError): | |
c8820b76 | 643 | self._at_index_method(self._fc, 'yes') |
32656995 SM |
644 | |
645 | def test_at_index_out_of_bounds_after(self): | |
61d96b89 FD |
646 | self._append_element_method( |
647 | self._fc, 'c', self._tc.create_signed_integer_field_class(32) | |
648 | ) | |
32656995 SM |
649 | |
650 | with self.assertRaises(IndexError): | |
c8820b76 | 651 | self._at_index_method(self._fc, len(self._fc)) |
32656995 | 652 | |
b2df5780 PP |
653 | def test_user_attributes(self): |
654 | self._append_element_method( | |
655 | self._fc, | |
656 | 'c', | |
657 | self._tc.create_string_field_class(), | |
658 | user_attributes={'salut': 23}, | |
659 | ) | |
660 | self.assertEqual(self._fc['c'].user_attributes, {'salut': 23}) | |
9cbe0c59 FD |
661 | self.assertIs(type(self._fc.user_attributes), bt2_value.MapValue) |
662 | self.assertIs(type(self._fc['c'].user_attributes), bt2_value.MapValue) | |
32656995 | 663 | |
b2df5780 PP |
664 | def test_invalid_user_attributes(self): |
665 | with self.assertRaises(TypeError): | |
666 | self._append_element_method( | |
667 | self._fc, | |
668 | 'c', | |
669 | self._tc.create_string_field_class(), | |
670 | user_attributes=object(), | |
671 | ) | |
672 | ||
673 | def test_invalid_user_attributes_value_type(self): | |
674 | with self.assertRaises(TypeError): | |
675 | self._append_element_method( | |
676 | self._fc, 'c', self._tc.create_string_field_class(), user_attributes=23 | |
677 | ) | |
678 | ||
679 | ||
680 | class StructureFieldClassTestCase( | |
681 | _TestFieldClass, _TestElementContainer, unittest.TestCase | |
682 | ): | |
c946c9de PP |
683 | _append_element_method = staticmethod(bt2._StructureFieldClass.append_member) |
684 | _at_index_method = staticmethod(bt2._StructureFieldClass.member_at_index) | |
02b61fe0 | 685 | |
9cbe0c59 FD |
686 | @staticmethod |
687 | def _const_value_setter(field): | |
688 | field.value = {} | |
689 | ||
b2df5780 PP |
690 | def _create_field_class(self, *args, **kwargs): |
691 | tc = get_default_trace_class() | |
692 | return tc.create_structure_field_class(*args, **kwargs) | |
02b61fe0 | 693 | |
9cbe0c59 FD |
694 | def _create_default_const_field_class(self, *args, **kwargs): |
695 | tc = get_default_trace_class() | |
696 | fc = tc.create_structure_field_class(*args, **kwargs) | |
697 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
698 | ||
b2df5780 PP |
699 | _create_default_field_class = _create_field_class |
700 | ||
9cbe0c59 FD |
701 | def test_const_member_field_class(self): |
702 | def _real_value_setter(field): | |
703 | field.value = {'real': 0} | |
704 | ||
705 | tc = get_default_trace_class() | |
706 | fc = tc.create_structure_field_class() | |
76276a81 | 707 | member_fc = self._tc.create_single_precision_real_field_class() |
9cbe0c59 FD |
708 | fc.append_member('real', member_fc) |
709 | const_fc = _create_const_field_class(tc, fc, _real_value_setter) | |
710 | ||
711 | self.assertIs( | |
76276a81 FD |
712 | type(const_fc['real'].field_class), |
713 | bt2_field_class._SinglePrecisionRealFieldClassConst, | |
9cbe0c59 FD |
714 | ) |
715 | ||
716 | def test_member_field_class(self): | |
717 | tc = get_default_trace_class() | |
718 | fc = tc.create_structure_field_class() | |
76276a81 | 719 | member_fc = self._tc.create_single_precision_real_field_class() |
9cbe0c59 FD |
720 | fc.append_member('real', member_fc) |
721 | ||
76276a81 FD |
722 | self.assertIs( |
723 | type(fc['real'].field_class), bt2_field_class._SinglePrecisionRealFieldClass | |
724 | ) | |
9cbe0c59 | 725 | |
b2df5780 PP |
726 | |
727 | class OptionFieldClassTestCase(_TestFieldClass, unittest.TestCase): | |
9cbe0c59 FD |
728 | @staticmethod |
729 | def _const_value_setter(field): | |
730 | field.has_field = True | |
731 | field.value = 12 | |
732 | ||
b2df5780 PP |
733 | def _create_default_field_class(self, *args, **kwargs): |
734 | return self._tc.create_option_field_class(self._content_fc, **kwargs) | |
02b61fe0 | 735 | |
9cbe0c59 FD |
736 | def _create_default_const_field_class(self, *args, **kwargs): |
737 | fc = self._tc.create_option_field_class(self._content_fc, **kwargs) | |
738 | return _create_const_field_class(self._tc, fc, self._const_value_setter) | |
739 | ||
84eba0d9 PP |
740 | def setUp(self): |
741 | self._tc = get_default_trace_class() | |
742 | self._content_fc = self._tc.create_signed_integer_field_class(23) | |
743 | self._tag_fc = self._tc.create_bool_field_class() | |
744 | ||
745 | def test_create_default(self): | |
b2df5780 | 746 | fc = self._create_default_field_class() |
84eba0d9 PP |
747 | self.assertEqual(fc.field_class.addr, self._content_fc.addr) |
748 | self.assertIsNone(fc.selector_field_path, None) | |
b2df5780 | 749 | self.assertEqual(len(fc.user_attributes), 0) |
84eba0d9 | 750 | |
9cbe0c59 FD |
751 | def test_attr_field_class(self): |
752 | fc = self._create_default_field_class() | |
753 | self.assertIs(type(fc.field_class), bt2_field_class._SignedIntegerFieldClass) | |
754 | ||
755 | def test_const_attr_field_class(self): | |
756 | fc = self._create_default_const_field_class() | |
757 | self.assertIs( | |
758 | type(fc.field_class), bt2_field_class._SignedIntegerFieldClassConst | |
759 | ) | |
760 | ||
84eba0d9 | 761 | def _create_field_class_for_field_path_test(self): |
b2df5780 | 762 | fc = self._create_default_field_class(selector_fc=self._tag_fc) |
84eba0d9 | 763 | |
76276a81 | 764 | foo_fc = self._tc.create_single_precision_real_field_class() |
84eba0d9 PP |
765 | bar_fc = self._tc.create_string_field_class() |
766 | baz_fc = self._tc.create_string_field_class() | |
767 | ||
768 | inner_struct_fc = self._tc.create_structure_field_class() | |
769 | inner_struct_fc.append_member('bar', bar_fc) | |
770 | inner_struct_fc.append_member('baz', baz_fc) | |
771 | inner_struct_fc.append_member('tag', self._tag_fc) | |
772 | inner_struct_fc.append_member('opt', fc) | |
773 | ||
774 | opt_struct_array_fc = self._tc.create_option_field_class(inner_struct_fc) | |
775 | ||
776 | outer_struct_fc = self._tc.create_structure_field_class() | |
777 | outer_struct_fc.append_member('foo', foo_fc) | |
778 | outer_struct_fc.append_member('inner_opt', opt_struct_array_fc) | |
779 | ||
780 | # The path to the selector field class is resolved when the | |
781 | # option field class is actually used, for example in a packet | |
782 | # context. | |
783 | self._tc.create_stream_class( | |
784 | packet_context_field_class=outer_struct_fc, supports_packets=True | |
785 | ) | |
786 | ||
787 | return fc | |
788 | ||
789 | def test_field_path_len(self): | |
790 | fc = self._create_field_class_for_field_path_test() | |
791 | self.assertEqual(len(fc.selector_field_path), 3) | |
792 | ||
793 | def test_field_path_iter(self): | |
794 | fc = self._create_field_class_for_field_path_test() | |
795 | path_items = list(fc.selector_field_path) | |
796 | ||
797 | self.assertEqual(len(path_items), 3) | |
798 | ||
799 | self.assertIsInstance(path_items[0], bt2._IndexFieldPathItem) | |
800 | self.assertEqual(path_items[0].index, 1) | |
801 | ||
802 | self.assertIsInstance(path_items[1], bt2._CurrentOptionContentFieldPathItem) | |
803 | ||
804 | self.assertIsInstance(path_items[2], bt2._IndexFieldPathItem) | |
805 | self.assertEqual(path_items[2].index, 2) | |
806 | ||
807 | def test_field_path_root_scope(self): | |
808 | fc = self._create_field_class_for_field_path_test() | |
809 | self.assertEqual( | |
810 | fc.selector_field_path.root_scope, bt2.FieldPathScope.PACKET_CONTEXT | |
811 | ) | |
812 | ||
813 | def test_create_invalid_field_class(self): | |
814 | with self.assertRaises(TypeError): | |
815 | self._tc.create_option_field_class(object()) | |
816 | ||
817 | def test_create_invalid_selector_type(self): | |
818 | with self.assertRaises(TypeError): | |
819 | self._tc.create_option_field_class(self._content_fc, 17) | |
820 | ||
821 | ||
61d96b89 | 822 | class VariantFieldClassWithoutSelectorTestCase( |
b2df5780 | 823 | _TestFieldClass, _TestElementContainer, unittest.TestCase |
61d96b89 FD |
824 | ): |
825 | _append_element_method = staticmethod( | |
c946c9de | 826 | bt2._VariantFieldClassWithoutSelector.append_option |
61d96b89 FD |
827 | ) |
828 | _at_index_method = staticmethod( | |
c946c9de | 829 | bt2._VariantFieldClassWithoutSelector.option_at_index |
61d96b89 | 830 | ) |
02b61fe0 | 831 | |
9cbe0c59 FD |
832 | @staticmethod |
833 | def _const_value_setter(variant_field): | |
834 | variant_field.selected_option_index = 0 | |
835 | variant_field.value = 12 | |
836 | ||
b2df5780 PP |
837 | def _create_field_class(self, *args, **kwargs): |
838 | tc = get_default_trace_class() | |
839 | return tc.create_variant_field_class(*args, **kwargs) | |
840 | ||
9cbe0c59 FD |
841 | def _create_default_const_field_class(self, *args, **kwargs): |
842 | tc = get_default_trace_class() | |
843 | fc = tc.create_variant_field_class(*args, **kwargs) | |
844 | int_field_class = self._tc.create_signed_integer_field_class(32) | |
845 | fc.append_option('int32', int_field_class) | |
846 | ||
847 | return _create_const_field_class(tc, fc, self._const_value_setter) | |
848 | ||
b2df5780 | 849 | _create_default_field_class = _create_field_class |
02b61fe0 PP |
850 | |
851 | ||
852 | class _VariantFieldClassWithSelectorTestCase: | |
9cbe0c59 FD |
853 | @staticmethod |
854 | def _const_value_setter(field): | |
855 | field['variant'].selected_option_index = 0 | |
856 | field['variant'] = 12 | |
857 | ||
b2df5780 PP |
858 | def _create_default_field_class(self, *args, **kwargs): |
859 | return self._tc.create_variant_field_class( | |
860 | *args, selector_fc=self._selector_fc, **kwargs | |
861 | ) | |
862 | ||
9cbe0c59 FD |
863 | def _create_default_const_field_class(self, *args, **kwargs): |
864 | # Create a struct to contain the variant and its selector else we can't | |
865 | # create the non-const field necessary to get the the const field_class | |
866 | struct_fc = self._tc.create_structure_field_class() | |
867 | struct_fc.append_member('selecteux', self._selector_fc) | |
868 | variant_fc = self._tc.create_variant_field_class( | |
869 | *args, selector_fc=self._selector_fc | |
870 | ) | |
871 | variant_fc.append_option( | |
872 | 'a', self._tc.create_signed_integer_field_class(32), self._ranges1 | |
873 | ) | |
874 | struct_fc.append_member('variant', variant_fc, **kwargs) | |
875 | ||
876 | return _create_const_field_class(self._tc, struct_fc, self._const_value_setter)[ | |
877 | 'variant' | |
878 | ].field_class | |
879 | ||
32656995 | 880 | def setUp(self): |
c8820b76 | 881 | self._tc = get_default_trace_class() |
02b61fe0 | 882 | self._spec_set_up() |
b2df5780 | 883 | self._fc = self._create_default_field_class() |
c8820b76 SM |
884 | |
885 | def test_create_default(self): | |
886 | self.assertIsNotNone(self._fc) | |
b2df5780 | 887 | self.assertEqual(len(self._fc.user_attributes), 0) |
32656995 | 888 | |
02b61fe0 PP |
889 | def test_append_element(self): |
890 | str_field_class = self._tc.create_string_field_class() | |
891 | self._fc.append_option('str', str_field_class, self._ranges1) | |
892 | opt = self._fc['str'] | |
893 | self.assertEqual(opt.field_class.addr, str_field_class.addr) | |
894 | self.assertEqual(opt.name, 'str') | |
895 | self.assertEqual(opt.ranges.addr, self._ranges1.addr) | |
896 | ||
9cbe0c59 FD |
897 | def test_const_append(self): |
898 | fc_const = self._create_default_const_field_class() | |
dda7ee0a | 899 | str_field_class = self._tc.create_string_field_class() |
9cbe0c59 FD |
900 | with self.assertRaises(AttributeError): |
901 | fc_const.append_option('str', str_field_class, self._ranges1) | |
902 | ||
02b61fe0 PP |
903 | def test_append_element_kwargs(self): |
904 | int_field_class = self._tc.create_signed_integer_field_class(32) | |
61d96b89 FD |
905 | self._fc.append_option( |
906 | name='int32', field_class=int_field_class, ranges=self._ranges1 | |
907 | ) | |
02b61fe0 PP |
908 | opt = self._fc['int32'] |
909 | self.assertEqual(opt.field_class.addr, int_field_class.addr) | |
910 | self.assertEqual(opt.name, 'int32') | |
911 | self.assertEqual(opt.ranges.addr, self._ranges1.addr) | |
c8820b76 | 912 | |
02b61fe0 PP |
913 | def test_append_element_invalid_name(self): |
914 | sub_fc = self._tc.create_string_field_class() | |
32656995 | 915 | |
02b61fe0 PP |
916 | with self.assertRaises(TypeError): |
917 | self._fc.append_option(self._fc, 23, sub_fc) | |
32656995 | 918 | |
02b61fe0 PP |
919 | def test_append_element_invalid_field_class(self): |
920 | with self.assertRaises(TypeError): | |
921 | self._fc.append_option(self._fc, 'yes', object()) | |
922 | ||
923 | def test_append_element_invalid_ranges(self): | |
924 | sub_fc = self._tc.create_string_field_class() | |
925 | ||
926 | with self.assertRaises(TypeError): | |
927 | self._fc.append_option(self._fc, sub_fc, 'lel') | |
928 | ||
929 | def test_append_element_dup_name(self): | |
930 | sub_fc1 = self._tc.create_string_field_class() | |
931 | sub_fc2 = self._tc.create_string_field_class() | |
932 | ||
3b2be708 | 933 | with self.assertRaises(ValueError): |
02b61fe0 PP |
934 | self._fc.append_option('yes', sub_fc1, self._ranges1) |
935 | self._fc.append_option('yes', sub_fc2, self._ranges2) | |
936 | ||
937 | def test_append_element_invalid_ranges_signedness(self): | |
938 | sub_fc = self._tc.create_string_field_class() | |
939 | ||
940 | with self.assertRaises(TypeError): | |
941 | self._fc.append_option(self._fc, sub_fc, self._inval_ranges) | |
942 | ||
b2df5780 PP |
943 | def test_user_attributes(self): |
944 | self._fc.append_option( | |
945 | 'c', | |
946 | self._tc.create_string_field_class(), | |
947 | self._ranges1, | |
948 | user_attributes={'salut': 23}, | |
949 | ) | |
950 | self.assertEqual(self._fc['c'].user_attributes, {'salut': 23}) | |
9cbe0c59 FD |
951 | self.assertIs(type(self._fc.user_attributes), bt2_value.MapValue) |
952 | ||
953 | def test_const_user_attributes(self): | |
954 | fc_const = self._create_default_const_field_class() | |
955 | self.assertIs(type(fc_const.user_attributes), bt2_value._MapValueConst) | |
b2df5780 PP |
956 | |
957 | def test_invalid_user_attributes(self): | |
958 | with self.assertRaises(TypeError): | |
959 | self._fc.append_option( | |
960 | 'c', | |
961 | self._tc.create_string_field_class(), | |
962 | self._ranges1, | |
963 | user_attributes=object(), | |
964 | ) | |
965 | ||
966 | def test_invalid_user_attributes_value_type(self): | |
967 | with self.assertRaises(TypeError): | |
968 | self._fc.append_option( | |
969 | 'c', | |
970 | self._tc.create_string_field_class(), | |
971 | self._ranges1, | |
972 | user_attributes=23, | |
973 | ) | |
974 | ||
02b61fe0 | 975 | def test_iadd(self): |
76276a81 | 976 | a_field_class = self._tc.create_single_precision_real_field_class() |
02b61fe0 PP |
977 | self._fc.append_option('a_float', a_field_class, self._ranges1) |
978 | c_field_class = self._tc.create_string_field_class() | |
61d96b89 FD |
979 | d_field_class = self._tc.create_signed_enumeration_field_class( |
980 | field_value_range=32 | |
981 | ) | |
02b61fe0 PP |
982 | self._fc += [ |
983 | ('c_string', c_field_class, self._ranges2), | |
984 | ('d_enum', d_field_class, self._ranges3), | |
985 | ] | |
986 | self.assertEqual(self._fc['a_float'].field_class.addr, a_field_class.addr) | |
987 | self.assertEqual(self._fc['a_float'].name, 'a_float') | |
988 | self.assertEqual(self._fc['a_float'].ranges, self._ranges1) | |
989 | self.assertEqual(self._fc['c_string'].field_class.addr, c_field_class.addr) | |
990 | self.assertEqual(self._fc['c_string'].name, 'c_string') | |
991 | self.assertEqual(self._fc['c_string'].ranges, self._ranges2) | |
992 | self.assertEqual(self._fc['d_enum'].field_class.addr, d_field_class.addr) | |
993 | self.assertEqual(self._fc['d_enum'].name, 'd_enum') | |
994 | self.assertEqual(self._fc['d_enum'].ranges, self._ranges3) | |
995 | ||
9cbe0c59 FD |
996 | def test_const_iadd(self): |
997 | fc_const = self._create_default_const_field_class() | |
76276a81 | 998 | a_field_class = self._tc.create_single_precision_real_field_class() |
9cbe0c59 FD |
999 | with self.assertRaises(TypeError): |
1000 | fc_const += [('a_float', a_field_class, self._ranges1)] | |
1001 | ||
02b61fe0 PP |
1002 | def test_bool_op(self): |
1003 | self.assertFalse(self._fc) | |
1004 | self._fc.append_option('a', self._tc.create_string_field_class(), self._ranges1) | |
1005 | self.assertTrue(self._fc) | |
1006 | ||
1007 | def test_len(self): | |
1008 | self._fc.append_option('a', self._tc.create_string_field_class(), self._ranges1) | |
1009 | self._fc.append_option('b', self._tc.create_string_field_class(), self._ranges2) | |
1010 | self._fc.append_option('c', self._tc.create_string_field_class(), self._ranges3) | |
1011 | self.assertEqual(len(self._fc), 3) | |
1012 | ||
1013 | def test_getitem(self): | |
1014 | a_fc = self._tc.create_signed_integer_field_class(32) | |
1015 | b_fc = self._tc.create_string_field_class() | |
76276a81 | 1016 | c_fc = self._tc.create_single_precision_real_field_class() |
02b61fe0 PP |
1017 | self._fc.append_option('a', a_fc, self._ranges1) |
1018 | self._fc.append_option('b', b_fc, self._ranges2) | |
1019 | self._fc.append_option('c', c_fc, self._ranges3) | |
1020 | self.assertEqual(self._fc['b'].field_class.addr, b_fc.addr) | |
1021 | self.assertEqual(self._fc['b'].name, 'b') | |
1022 | self.assertEqual(self._fc['b'].ranges.addr, self._ranges2.addr) | |
1023 | ||
9cbe0c59 FD |
1024 | def test_option_field_class(self): |
1025 | a_fc = self._tc.create_signed_integer_field_class(32) | |
1026 | self._fc.append_option('a', a_fc, self._ranges1) | |
1027 | self.assertIs( | |
1028 | type(self._fc['a'].field_class), bt2_field_class._SignedIntegerFieldClass | |
1029 | ) | |
1030 | ||
1031 | def test_const_option_field_class(self): | |
1032 | fc_const = self._create_default_const_field_class() | |
1033 | self.assertIs( | |
1034 | type(fc_const['a'].field_class), | |
1035 | bt2_field_class._SignedIntegerFieldClassConst, | |
1036 | ) | |
1037 | ||
02b61fe0 PP |
1038 | def test_getitem_invalid_key_type(self): |
1039 | with self.assertRaises(TypeError): | |
1040 | self._fc[0] | |
1041 | ||
1042 | def test_getitem_invalid_key(self): | |
1043 | with self.assertRaises(KeyError): | |
1044 | self._fc['no way'] | |
1045 | ||
1046 | def test_contains(self): | |
1047 | self.assertFalse('a' in self._fc) | |
1048 | self._fc.append_option('a', self._tc.create_string_field_class(), self._ranges1) | |
1049 | self.assertTrue('a' in self._fc) | |
1050 | ||
1051 | def test_iter(self): | |
1052 | a_fc = self._tc.create_signed_integer_field_class(32) | |
1053 | b_fc = self._tc.create_string_field_class() | |
76276a81 | 1054 | c_fc = self._tc.create_single_precision_real_field_class() |
02b61fe0 PP |
1055 | opts = ( |
1056 | ('a', a_fc, self._ranges1), | |
1057 | ('b', b_fc, self._ranges2), | |
1058 | ('c', c_fc, self._ranges3), | |
1059 | ) | |
1060 | ||
1061 | for opt in opts: | |
1062 | self._fc.append_option(*opt) | |
32656995 | 1063 | |
02b61fe0 PP |
1064 | for (name, opt), test_opt in zip(self._fc.items(), opts): |
1065 | self.assertEqual(opt.name, test_opt[0]) | |
1066 | self.assertEqual(name, opt.name) | |
1067 | self.assertEqual(opt.field_class.addr, test_opt[1].addr) | |
1068 | self.assertEqual(opt.ranges.addr, test_opt[2].addr) | |
1069 | ||
1070 | def test_at_index(self): | |
1071 | a_fc = self._tc.create_signed_integer_field_class(32) | |
1072 | b_fc = self._tc.create_string_field_class() | |
76276a81 | 1073 | c_fc = self._tc.create_single_precision_real_field_class() |
02b61fe0 PP |
1074 | self._fc.append_option('c', c_fc, self._ranges1) |
1075 | self._fc.append_option('a', a_fc, self._ranges2) | |
1076 | self._fc.append_option('b', b_fc, self._ranges3) | |
1077 | self.assertEqual(self._fc.option_at_index(1).field_class.addr, a_fc.addr) | |
1078 | self.assertEqual(self._fc.option_at_index(1).name, 'a') | |
1079 | self.assertEqual(self._fc.option_at_index(1).ranges.addr, self._ranges2.addr) | |
1080 | ||
1081 | def test_at_index_invalid(self): | |
61d96b89 FD |
1082 | self._fc.append_option( |
1083 | 'c', self._tc.create_signed_integer_field_class(32), self._ranges3 | |
1084 | ) | |
02b61fe0 PP |
1085 | |
1086 | with self.assertRaises(TypeError): | |
1087 | self._fc.option_at_index('yes') | |
1088 | ||
1089 | def test_at_index_out_of_bounds_after(self): | |
61d96b89 FD |
1090 | self._fc.append_option( |
1091 | 'c', self._tc.create_signed_integer_field_class(32), self._ranges3 | |
1092 | ) | |
02b61fe0 PP |
1093 | |
1094 | with self.assertRaises(IndexError): | |
1095 | self._fc.option_at_index(len(self._fc)) | |
1096 | ||
1097 | def _fill_default_fc_for_field_path_test(self): | |
c8820b76 SM |
1098 | # Create something equivalent to: |
1099 | # | |
1100 | # struct outer_struct_fc { | |
1101 | # real foo; | |
1102 | # struct inner_struct_fc { | |
02b61fe0 | 1103 | # [u]int64_t selector; |
c8820b76 SM |
1104 | # string bar; |
1105 | # string baz; | |
02b61fe0 PP |
1106 | # variant <selector> { |
1107 | # real a; // selected with self._ranges1 | |
1108 | # int21_t b; // selected with self._ranges2 | |
1109 | # uint34_t c; // selected with self._ranges3 | |
c8820b76 SM |
1110 | # } variant; |
1111 | # } inner_struct[2]; | |
1112 | # }; | |
76276a81 FD |
1113 | self._fc.append_option( |
1114 | 'a', self._tc.create_single_precision_real_field_class(), self._ranges1 | |
1115 | ) | |
61d96b89 FD |
1116 | self._fc.append_option( |
1117 | 'b', self._tc.create_signed_integer_field_class(21), self._ranges2 | |
1118 | ) | |
1119 | self._fc.append_option( | |
1120 | 'c', self._tc.create_unsigned_integer_field_class(34), self._ranges3 | |
1121 | ) | |
32656995 | 1122 | |
76276a81 | 1123 | foo_fc = self._tc.create_single_precision_real_field_class() |
c8820b76 SM |
1124 | bar_fc = self._tc.create_string_field_class() |
1125 | baz_fc = self._tc.create_string_field_class() | |
32656995 | 1126 | |
c8820b76 | 1127 | inner_struct_fc = self._tc.create_structure_field_class() |
02b61fe0 | 1128 | inner_struct_fc.append_member('selector', self._selector_fc) |
c8820b76 SM |
1129 | inner_struct_fc.append_member('bar', bar_fc) |
1130 | inner_struct_fc.append_member('baz', baz_fc) | |
02b61fe0 | 1131 | inner_struct_fc.append_member('variant', self._fc) |
32656995 | 1132 | |
61d96b89 FD |
1133 | inner_struct_array_fc = self._tc.create_static_array_field_class( |
1134 | inner_struct_fc, 2 | |
1135 | ) | |
32656995 | 1136 | |
c8820b76 SM |
1137 | outer_struct_fc = self._tc.create_structure_field_class() |
1138 | outer_struct_fc.append_member('foo', foo_fc) | |
1139 | outer_struct_fc.append_member('inner_struct', inner_struct_array_fc) | |
32656995 | 1140 | |
c8820b76 SM |
1141 | # The path to the selector field is resolved when the sequence is |
1142 | # actually used, for example in a packet context. | |
61d96b89 FD |
1143 | self._tc.create_stream_class( |
1144 | supports_packets=True, packet_context_field_class=outer_struct_fc | |
1145 | ) | |
32656995 | 1146 | |
c8820b76 | 1147 | def test_selector_field_path_length(self): |
02b61fe0 PP |
1148 | self._fill_default_fc_for_field_path_test() |
1149 | self.assertEqual(len(self._fc.selector_field_path), 3) | |
32656995 | 1150 | |
c8820b76 | 1151 | def test_selector_field_path_iter(self): |
02b61fe0 PP |
1152 | self._fill_default_fc_for_field_path_test() |
1153 | path_items = list(self._fc.selector_field_path) | |
32656995 | 1154 | |
c8820b76 | 1155 | self.assertEqual(len(path_items), 3) |
32656995 | 1156 | |
c946c9de | 1157 | self.assertIsInstance(path_items[0], bt2._IndexFieldPathItem) |
c8820b76 | 1158 | self.assertEqual(path_items[0].index, 1) |
32656995 | 1159 | |
c946c9de | 1160 | self.assertIsInstance(path_items[1], bt2._CurrentArrayElementFieldPathItem) |
32656995 | 1161 | |
c946c9de | 1162 | self.assertIsInstance(path_items[2], bt2._IndexFieldPathItem) |
c8820b76 | 1163 | self.assertEqual(path_items[2].index, 0) |
32656995 | 1164 | |
c8820b76 | 1165 | def test_selector_field_path_root_scope(self): |
02b61fe0 | 1166 | self._fill_default_fc_for_field_path_test() |
61d96b89 | 1167 | self.assertEqual( |
056995e5 | 1168 | self._fc.selector_field_path.root_scope, bt2.FieldPathScope.PACKET_CONTEXT |
61d96b89 | 1169 | ) |
02b61fe0 PP |
1170 | |
1171 | ||
61d96b89 FD |
1172 | class VariantFieldClassWithUnsignedSelectorTestCase( |
1173 | _VariantFieldClassWithSelectorTestCase, unittest.TestCase | |
1174 | ): | |
02b61fe0 PP |
1175 | def _spec_set_up(self): |
1176 | self._ranges1 = bt2.UnsignedIntegerRangeSet([(1, 4), (18, 47)]) | |
1177 | self._ranges2 = bt2.UnsignedIntegerRangeSet([(5, 5)]) | |
1178 | self._ranges3 = bt2.UnsignedIntegerRangeSet([(8, 16), (48, 99)]) | |
1179 | self._inval_ranges = bt2.SignedIntegerRangeSet([(-8, 16), (48, 99)]) | |
1180 | self._selector_fc = self._tc.create_unsigned_integer_field_class() | |
1181 | ||
1182 | ||
61d96b89 FD |
1183 | class VariantFieldClassWithSignedSelectorTestCase( |
1184 | _VariantFieldClassWithSelectorTestCase, unittest.TestCase | |
1185 | ): | |
02b61fe0 PP |
1186 | def _spec_set_up(self): |
1187 | self._ranges1 = bt2.SignedIntegerRangeSet([(-10, -4), (18, 47)]) | |
1188 | self._ranges2 = bt2.SignedIntegerRangeSet([(-3, -3)]) | |
1189 | self._ranges3 = bt2.SignedIntegerRangeSet([(8, 16), (48, 99)]) | |
1190 | self._inval_ranges = bt2.UnsignedIntegerRangeSet([(8, 16), (48, 99)]) | |
1191 | self._selector_fc = self._tc.create_signed_integer_field_class() | |
32656995 | 1192 | |
c8820b76 | 1193 | |
9cbe0c59 FD |
1194 | class _ArrayFieldClassTestCase: |
1195 | def test_attr_element_field_class(self): | |
1196 | fc = self._create_array() | |
1197 | self.assertIs( | |
1198 | type(fc.element_field_class), bt2_field_class._SignedIntegerFieldClass | |
1199 | ) | |
1200 | ||
1201 | def test_const_attr_element_field_class(self): | |
1202 | fc = self._create_const_array() | |
1203 | self.assertIs( | |
1204 | type(fc.element_field_class), bt2_field_class._SignedIntegerFieldClassConst | |
1205 | ) | |
1206 | ||
1207 | ||
1208 | class StaticArrayFieldClassTestCase(_ArrayFieldClassTestCase, unittest.TestCase): | |
1209 | @staticmethod | |
1210 | def _const_value_setter(field): | |
c82e5122 | 1211 | field.value = [9] * 45 |
9cbe0c59 FD |
1212 | |
1213 | def _create_array(self): | |
1214 | return self._tc.create_static_array_field_class(self._elem_fc, 45) | |
1215 | ||
1216 | def _create_const_array(self): | |
1217 | fc = self._tc.create_static_array_field_class(self._elem_fc, 45) | |
1218 | return _create_const_field_class(self._tc, fc, self._const_value_setter) | |
1219 | ||
c8820b76 SM |
1220 | def setUp(self): |
1221 | self._tc = get_default_trace_class() | |
1222 | self._elem_fc = self._tc.create_signed_integer_field_class(23) | |
32656995 SM |
1223 | |
1224 | def test_create_default(self): | |
c8820b76 SM |
1225 | fc = self._tc.create_static_array_field_class(self._elem_fc, 45) |
1226 | self.assertEqual(fc.element_field_class.addr, self._elem_fc.addr) | |
1227 | self.assertEqual(fc.length, 45) | |
b2df5780 | 1228 | self.assertEqual(len(fc.user_attributes), 0) |
32656995 | 1229 | |
c8820b76 | 1230 | def test_create_invalid_elem_field_class(self): |
32656995 | 1231 | with self.assertRaises(TypeError): |
c8820b76 | 1232 | self._tc.create_static_array_field_class(object(), 45) |
32656995 SM |
1233 | |
1234 | def test_create_invalid_length(self): | |
1235 | with self.assertRaises(ValueError): | |
61d96b89 FD |
1236 | self._tc.create_static_array_field_class( |
1237 | self._tc.create_string_field_class(), -17 | |
1238 | ) | |
32656995 SM |
1239 | |
1240 | def test_create_invalid_length_type(self): | |
1241 | with self.assertRaises(TypeError): | |
61d96b89 FD |
1242 | self._tc.create_static_array_field_class( |
1243 | self._tc.create_string_field_class(), 'the length' | |
1244 | ) | |
c8820b76 SM |
1245 | |
1246 | ||
9cbe0c59 FD |
1247 | class DynamicArrayFieldClassTestCase(_ArrayFieldClassTestCase, unittest.TestCase): |
1248 | @staticmethod | |
1249 | def _const_value_setter(field): | |
c82e5122 | 1250 | field.value = [] |
9cbe0c59 FD |
1251 | |
1252 | def _create_array(self): | |
1253 | return self._tc.create_dynamic_array_field_class(self._elem_fc) | |
1254 | ||
1255 | def _create_const_array(self): | |
1256 | fc = self._tc.create_dynamic_array_field_class(self._elem_fc) | |
1257 | return _create_const_field_class(self._tc, fc, self._const_value_setter) | |
1258 | ||
c8820b76 SM |
1259 | def setUp(self): |
1260 | self._tc = get_default_trace_class() | |
1261 | self._elem_fc = self._tc.create_signed_integer_field_class(23) | |
1262 | self._len_fc = self._tc.create_unsigned_integer_field_class(12) | |
32656995 | 1263 | |
c8820b76 SM |
1264 | def test_create_default(self): |
1265 | fc = self._tc.create_dynamic_array_field_class(self._elem_fc) | |
1266 | self.assertEqual(fc.element_field_class.addr, self._elem_fc.addr) | |
1267 | self.assertIsNone(fc.length_field_path, None) | |
b2df5780 | 1268 | self.assertEqual(len(fc.user_attributes), 0) |
32656995 | 1269 | |
c8820b76 SM |
1270 | def _create_field_class_for_field_path_test(self): |
1271 | # Create something a field class that is equivalent to: | |
1272 | # | |
1273 | # struct outer_struct_fc { | |
1274 | # real foo; | |
1275 | # struct inner_struct_fc { | |
1276 | # string bar; | |
1277 | # string baz; | |
1278 | # uint12_t len; | |
1279 | # uint23_t dyn_array[len]; | |
1280 | # } inner_struct[2]; | |
1281 | # }; | |
32656995 | 1282 | |
c8820b76 | 1283 | fc = self._tc.create_dynamic_array_field_class(self._elem_fc, self._len_fc) |
32656995 | 1284 | |
76276a81 | 1285 | foo_fc = self._tc.create_single_precision_real_field_class() |
c8820b76 SM |
1286 | bar_fc = self._tc.create_string_field_class() |
1287 | baz_fc = self._tc.create_string_field_class() | |
32656995 | 1288 | |
c8820b76 SM |
1289 | inner_struct_fc = self._tc.create_structure_field_class() |
1290 | inner_struct_fc.append_member('bar', bar_fc) | |
1291 | inner_struct_fc.append_member('baz', baz_fc) | |
1292 | inner_struct_fc.append_member('len', self._len_fc) | |
1293 | inner_struct_fc.append_member('dyn_array', fc) | |
32656995 | 1294 | |
61d96b89 FD |
1295 | inner_struct_array_fc = self._tc.create_static_array_field_class( |
1296 | inner_struct_fc, 2 | |
1297 | ) | |
c8820b76 SM |
1298 | |
1299 | outer_struct_fc = self._tc.create_structure_field_class() | |
1300 | outer_struct_fc.append_member('foo', foo_fc) | |
1301 | outer_struct_fc.append_member('inner_struct', inner_struct_array_fc) | |
1302 | ||
1303 | # The path to the length field is resolved when the sequence is | |
1304 | # actually used, for example in a packet context. | |
61d96b89 FD |
1305 | self._tc.create_stream_class( |
1306 | packet_context_field_class=outer_struct_fc, supports_packets=True | |
1307 | ) | |
c8820b76 SM |
1308 | |
1309 | return fc | |
1310 | ||
1311 | def test_field_path_len(self): | |
1312 | fc = self._create_field_class_for_field_path_test() | |
1313 | self.assertEqual(len(fc.length_field_path), 3) | |
1314 | ||
1315 | def test_field_path_iter(self): | |
1316 | fc = self._create_field_class_for_field_path_test() | |
1317 | path_items = list(fc.length_field_path) | |
1318 | ||
1319 | self.assertEqual(len(path_items), 3) | |
1320 | ||
c946c9de | 1321 | self.assertIsInstance(path_items[0], bt2._IndexFieldPathItem) |
c8820b76 SM |
1322 | self.assertEqual(path_items[0].index, 1) |
1323 | ||
c946c9de | 1324 | self.assertIsInstance(path_items[1], bt2._CurrentArrayElementFieldPathItem) |
c8820b76 | 1325 | |
c946c9de | 1326 | self.assertIsInstance(path_items[2], bt2._IndexFieldPathItem) |
c8820b76 SM |
1327 | self.assertEqual(path_items[2].index, 2) |
1328 | ||
1329 | def test_field_path_root_scope(self): | |
1330 | fc = self._create_field_class_for_field_path_test() | |
056995e5 PP |
1331 | self.assertEqual( |
1332 | fc.length_field_path.root_scope, bt2.FieldPathScope.PACKET_CONTEXT | |
1333 | ) | |
32656995 SM |
1334 | |
1335 | def test_create_invalid_field_class(self): | |
1336 | with self.assertRaises(TypeError): | |
c8820b76 | 1337 | self._tc.create_dynamic_array_field_class(object()) |
32656995 SM |
1338 | |
1339 | def test_create_invalid_length_type(self): | |
1340 | with self.assertRaises(TypeError): | |
61d96b89 FD |
1341 | self._tc.create_dynamic_array_field_class( |
1342 | self._tc.create_string_field_class(), 17 | |
1343 | ) | |
32656995 | 1344 | |
32656995 | 1345 | |
c8820b76 SM |
1346 | if __name__ == "__main__": |
1347 | unittest.main() |