2 # Copyright (C) 2019 EfficiOS Inc.
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
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.
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.
20 from utils
import run_in_component_init
23 class StreamClassTestCase(unittest
.TestCase
):
26 tc
= comp_self
._create
_trace
_class
(assigns_automatic_stream_class_id
=True)
27 cc
= comp_self
._create
_clock
_class
()
30 self
._tc
, self
._cc
= run_in_component_init(f
)
31 self
._trace
= self
._tc
()
33 def test_create_default(self
):
34 sc
= self
._tc
.create_stream_class()
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
)
42 self
.assertFalse(sc
.supports_packets
)
43 self
.assertFalse(sc
.packets_have_beginning_default_clock_snapshot
)
44 self
.assertFalse(sc
.packets_have_end_default_clock_snapshot
)
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
)
50 def test_create_name(self
):
51 sc
= self
._tc
.create_stream_class(name
='bozo')
52 self
.assertEqual(sc
.name
, 'bozo')
54 def test_create_invalid_name(self
):
55 with self
.assertRaises(TypeError):
56 self
._tc
.create_stream_class(name
=17)
58 def test_create_packet_context_field_class(self
):
59 fc
= self
._tc
.create_structure_field_class()
60 sc
= self
._tc
.create_stream_class(
61 packet_context_field_class
=fc
, supports_packets
=True
63 self
.assertEqual(sc
.packet_context_field_class
, fc
)
65 def test_create_invalid_packet_context_field_class(self
):
66 with self
.assertRaises(TypeError):
67 self
._tc
.create_stream_class(packet_context_field_class
=22)
69 def test_create_invalid_packet_context_field_class_no_packets(self
):
70 fc
= self
._tc
.create_structure_field_class()
72 with self
.assertRaises(ValueError):
73 self
._tc
.create_stream_class(packet_context_field_class
=fc
)
75 def test_create_event_common_context_field_class(self
):
76 fc
= self
._tc
.create_structure_field_class()
77 sc
= self
._tc
.create_stream_class(event_common_context_field_class
=fc
)
78 self
.assertEqual(sc
.event_common_context_field_class
, fc
)
80 def test_create_invalid_event_common_context_field_class(self
):
81 with self
.assertRaises(TypeError):
82 self
._tc
.create_stream_class(event_common_context_field_class
=22)
84 def test_create_default_clock_class(self
):
85 sc
= self
._tc
.create_stream_class(default_clock_class
=self
._cc
)
86 self
.assertEqual(sc
.default_clock_class
.addr
, self
._cc
.addr
)
88 def test_create_invalid_default_clock_class(self
):
89 with self
.assertRaises(TypeError):
90 self
._tc
.create_stream_class(default_clock_class
=12)
92 def test_automatic_stream_ids(self
):
93 sc
= self
._tc
.create_stream_class(assigns_automatic_stream_id
=True)
94 self
.assertTrue(sc
.assigns_automatic_stream_id
)
96 stream
= self
._trace
.create_stream(sc
)
97 self
.assertIsNotNone(stream
.id)
99 def test_automatic_stream_ids_raises(self
):
100 sc
= self
._tc
.create_stream_class(assigns_automatic_stream_id
=True)
101 self
.assertTrue(sc
.assigns_automatic_stream_id
)
103 with self
.assertRaises(ValueError):
104 self
._trace
.create_stream(sc
, id=123)
106 def test_no_automatic_stream_ids(self
):
107 sc
= self
._tc
.create_stream_class(assigns_automatic_stream_id
=False)
108 self
.assertFalse(sc
.assigns_automatic_stream_id
)
110 stream
= self
._trace
.create_stream(sc
, id=333)
111 self
.assertEqual(stream
.id, 333)
113 def test_no_automatic_stream_ids_raises(self
):
114 sc
= self
._tc
.create_stream_class(assigns_automatic_stream_id
=False)
115 self
.assertFalse(sc
.assigns_automatic_stream_id
)
117 with self
.assertRaises(ValueError):
118 self
._trace
.create_stream(sc
)
120 def test_automatic_event_class_ids(self
):
121 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=True)
122 self
.assertTrue(sc
.assigns_automatic_event_class_id
)
124 ec
= sc
.create_event_class()
125 self
.assertIsNotNone(ec
.id)
127 def test_automatic_event_class_ids_raises(self
):
128 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=True)
129 self
.assertTrue(sc
.assigns_automatic_event_class_id
)
131 with self
.assertRaises(ValueError):
132 sc
.create_event_class(id=123)
134 def test_no_automatic_event_class_ids(self
):
135 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=False)
136 self
.assertFalse(sc
.assigns_automatic_event_class_id
)
138 ec
= sc
.create_event_class(id=333)
139 self
.assertEqual(ec
.id, 333)
141 def test_no_automatic_event_class_ids_raises(self
):
142 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=False)
143 self
.assertFalse(sc
.assigns_automatic_event_class_id
)
145 with self
.assertRaises(ValueError):
146 sc
.create_event_class()
148 def test_supports_packets_without_cs(self
):
149 sc
= self
._tc
.create_stream_class(
150 default_clock_class
=self
._cc
, supports_packets
=True
152 self
.assertTrue(sc
.supports_packets
)
153 self
.assertFalse(sc
.packets_have_beginning_default_clock_snapshot
)
154 self
.assertFalse(sc
.packets_have_end_default_clock_snapshot
)
156 def test_supports_packets_with_begin_cs(self
):
157 sc
= self
._tc
.create_stream_class(
158 default_clock_class
=self
._cc
,
159 supports_packets
=True,
160 packets_have_beginning_default_clock_snapshot
=True,
162 self
.assertTrue(sc
.supports_packets
)
163 self
.assertTrue(sc
.packets_have_beginning_default_clock_snapshot
)
164 self
.assertFalse(sc
.packets_have_end_default_clock_snapshot
)
166 def test_supports_packets_with_end_cs(self
):
167 sc
= self
._tc
.create_stream_class(
168 default_clock_class
=self
._cc
,
169 supports_packets
=True,
170 packets_have_end_default_clock_snapshot
=True,
172 self
.assertTrue(sc
.supports_packets
)
173 self
.assertFalse(sc
.packets_have_beginning_default_clock_snapshot
)
174 self
.assertTrue(sc
.packets_have_end_default_clock_snapshot
)
176 def test_supports_packets_raises_type_error(self
):
177 with self
.assertRaises(TypeError):
178 sc
= self
._tc
.create_stream_class(
179 default_clock_class
=self
._cc
, supports_packets
=23
182 def test_packets_have_begin_default_cs_raises_type_error(self
):
183 with self
.assertRaises(TypeError):
184 sc
= self
._tc
.create_stream_class(
185 default_clock_class
=self
._cc
,
186 packets_have_beginning_default_clock_snapshot
=23,
189 def test_packets_have_end_default_cs_raises_type_error(self
):
190 with self
.assertRaises(TypeError):
191 sc
= self
._tc
.create_stream_class(
192 default_clock_class
=self
._cc
, packets_have_end_default_clock_snapshot
=23
195 def test_does_not_support_packets_raises_with_begin_cs(self
):
196 with self
.assertRaises(ValueError):
197 sc
= self
._tc
.create_stream_class(
198 default_clock_class
=self
._cc
,
199 packets_have_beginning_default_clock_snapshot
=True,
202 def test_does_not_support_packets_raises_with_end_cs(self
):
203 with self
.assertRaises(ValueError):
204 sc
= self
._tc
.create_stream_class(
205 default_clock_class
=self
._cc
,
206 packets_have_end_default_clock_snapshot
=True,
209 def test_supports_discarded_events_without_cs(self
):
210 sc
= self
._tc
.create_stream_class(
211 default_clock_class
=self
._cc
, supports_discarded_events
=True
213 self
.assertTrue(sc
.supports_discarded_events
)
214 self
.assertFalse(sc
.discarded_events_have_default_clock_snapshots
)
216 def test_supports_discarded_events_with_cs(self
):
217 sc
= self
._tc
.create_stream_class(
218 default_clock_class
=self
._cc
,
219 supports_discarded_events
=True,
220 discarded_events_have_default_clock_snapshots
=True,
222 self
.assertTrue(sc
.supports_discarded_events
)
223 self
.assertTrue(sc
.discarded_events_have_default_clock_snapshots
)
225 def test_supports_discarded_events_raises_type_error(self
):
226 with self
.assertRaises(TypeError):
227 sc
= self
._tc
.create_stream_class(
228 default_clock_class
=self
._cc
, supports_discarded_events
=23
231 def test_discarded_events_have_default_cs_raises_type_error(self
):
232 with self
.assertRaises(TypeError):
233 sc
= self
._tc
.create_stream_class(
234 default_clock_class
=self
._cc
,
235 discarded_events_have_default_clock_snapshots
=23,
238 def test_does_not_support_discarded_events_raises_with_cs(self
):
239 with self
.assertRaises(ValueError):
240 sc
= self
._tc
.create_stream_class(
241 default_clock_class
=self
._cc
,
242 discarded_events_have_default_clock_snapshots
=True,
245 def test_supports_discarded_packets_without_cs(self
):
246 sc
= self
._tc
.create_stream_class(
247 default_clock_class
=self
._cc
,
248 supports_discarded_packets
=True,
249 supports_packets
=True,
251 self
.assertTrue(sc
.supports_discarded_packets
)
252 self
.assertFalse(sc
.discarded_packets_have_default_clock_snapshots
)
254 def test_supports_discarded_packets_with_cs(self
):
255 sc
= self
._tc
.create_stream_class(
256 default_clock_class
=self
._cc
,
257 supports_discarded_packets
=True,
258 discarded_packets_have_default_clock_snapshots
=True,
259 supports_packets
=True,
261 self
.assertTrue(sc
.supports_discarded_packets
)
262 self
.assertTrue(sc
.discarded_packets_have_default_clock_snapshots
)
264 def test_supports_discarded_packets_raises_without_packet_support(self
):
265 with self
.assertRaises(ValueError):
266 sc
= self
._tc
.create_stream_class(
267 default_clock_class
=self
._cc
, supports_discarded_packets
=True
270 def test_supports_discarded_packets_raises_type_error(self
):
271 with self
.assertRaises(TypeError):
272 sc
= self
._tc
.create_stream_class(
273 default_clock_class
=self
._cc
,
274 supports_discarded_packets
=23,
275 supports_packets
=True,
278 def test_discarded_packets_have_default_cs_raises_type_error(self
):
279 with self
.assertRaises(TypeError):
280 sc
= self
._tc
.create_stream_class(
281 default_clock_class
=self
._cc
,
282 discarded_packets_have_default_clock_snapshots
=23,
283 supports_packets
=True,
286 def test_does_not_support_discarded_packets_raises_with_cs(self
):
287 with self
.assertRaises(ValueError):
288 sc
= self
._tc
.create_stream_class(
289 default_clock_class
=self
._cc
,
290 discarded_packets_have_default_clock_snapshots
=True,
291 supports_packets
=True,
294 def test_trace_class(self
):
295 sc
= self
._tc
.create_stream_class()
296 self
.assertEqual(sc
.trace_class
.addr
, self
._tc
.addr
)
298 def _create_stream_class_with_event_classes(self
):
299 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=False)
300 ec1
= sc
.create_event_class(id=23)
301 ec2
= sc
.create_event_class(id=17)
304 def test_getitem(self
):
305 sc
, ec1
, ec2
= self
._create
_stream
_class
_with
_event
_classes
()
307 self
.assertEqual(sc
[23].addr
, ec1
.addr
)
308 self
.assertEqual(sc
[17].addr
, ec2
.addr
)
310 def test_getitem_wrong_key_type(self
):
311 sc
, _
, _
= self
._create
_stream
_class
_with
_event
_classes
()
313 with self
.assertRaises(TypeError):
316 def test_getitem_wrong_key(self
):
317 sc
, _
, _
= self
._create
_stream
_class
_with
_event
_classes
()
319 with self
.assertRaises(KeyError):
323 sc
, _
, _
= self
._create
_stream
_class
_with
_event
_classes
()
325 self
.assertEqual(len(sc
), 2)
328 sc
, _
, _
= self
._create
_stream
_class
_with
_event
_classes
()
331 self
.assertEqual(ec_ids
, [17, 23])