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.
21 from utils
import run_in_component_init
24 class StreamClassTestCase(unittest
.TestCase
):
27 tc
= comp_self
._create
_trace
_class
(assigns_automatic_stream_class_id
=True)
28 cc
= comp_self
._create
_clock
_class
()
31 self
._tc
, self
._cc
= run_in_component_init(f
)
32 self
._trace
= self
._tc
()
34 def test_create_default(self
):
35 sc
= self
._tc
.create_stream_class()
37 self
.assertIsNone(sc
.name
)
38 self
.assertIsNone(sc
.packet_context_field_class
)
39 self
.assertIsNone(sc
.event_common_context_field_class
)
40 self
.assertIsNone(sc
.default_clock_class
)
41 self
.assertTrue(sc
.assigns_automatic_event_class_id
)
42 self
.assertTrue(sc
.assigns_automatic_stream_id
)
43 self
.assertFalse(sc
.supports_packets
)
44 self
.assertFalse(sc
.packets_have_beginning_default_clock_snapshot
)
45 self
.assertFalse(sc
.packets_have_end_default_clock_snapshot
)
46 self
.assertFalse(sc
.supports_discarded_events
)
47 self
.assertFalse(sc
.discarded_events_have_default_clock_snapshots
)
48 self
.assertFalse(sc
.supports_discarded_packets
)
49 self
.assertFalse(sc
.discarded_packets_have_default_clock_snapshots
)
51 def test_create_name(self
):
52 sc
= self
._tc
.create_stream_class(name
='bozo')
53 self
.assertEqual(sc
.name
, 'bozo')
55 def test_create_invalid_name(self
):
56 with self
.assertRaises(TypeError):
57 self
._tc
.create_stream_class(name
=17)
59 def test_create_packet_context_field_class(self
):
60 fc
= self
._tc
.create_structure_field_class()
61 sc
= self
._tc
.create_stream_class(
62 packet_context_field_class
=fc
, supports_packets
=True
64 self
.assertEqual(sc
.packet_context_field_class
, fc
)
66 def test_create_invalid_packet_context_field_class(self
):
67 with self
.assertRaises(TypeError):
68 self
._tc
.create_stream_class(packet_context_field_class
=22)
70 def test_create_invalid_packet_context_field_class_no_packets(self
):
71 fc
= self
._tc
.create_structure_field_class()
73 with self
.assertRaises(ValueError):
74 self
._tc
.create_stream_class(packet_context_field_class
=fc
)
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
)
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)
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
)
89 def test_create_invalid_default_clock_class(self
):
90 with self
.assertRaises(TypeError):
91 self
._tc
.create_stream_class(default_clock_class
=12)
93 def test_automatic_stream_ids(self
):
94 sc
= self
._tc
.create_stream_class(assigns_automatic_stream_id
=True)
95 self
.assertTrue(sc
.assigns_automatic_stream_id
)
97 stream
= self
._trace
.create_stream(sc
)
98 self
.assertIsNotNone(stream
.id)
100 def test_automatic_stream_ids_raises(self
):
101 sc
= self
._tc
.create_stream_class(assigns_automatic_stream_id
=True)
102 self
.assertTrue(sc
.assigns_automatic_stream_id
)
104 with self
.assertRaises(ValueError):
105 self
._trace
.create_stream(sc
, id=123)
107 def test_no_automatic_stream_ids(self
):
108 sc
= self
._tc
.create_stream_class(assigns_automatic_stream_id
=False)
109 self
.assertFalse(sc
.assigns_automatic_stream_id
)
111 stream
= self
._trace
.create_stream(sc
, id=333)
112 self
.assertEqual(stream
.id, 333)
114 def test_no_automatic_stream_ids_raises(self
):
115 sc
= self
._tc
.create_stream_class(assigns_automatic_stream_id
=False)
116 self
.assertFalse(sc
.assigns_automatic_stream_id
)
118 with self
.assertRaises(ValueError):
119 self
._trace
.create_stream(sc
)
121 def test_automatic_event_class_ids(self
):
122 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=True)
123 self
.assertTrue(sc
.assigns_automatic_event_class_id
)
125 ec
= sc
.create_event_class()
126 self
.assertIsNotNone(ec
.id)
128 def test_automatic_event_class_ids_raises(self
):
129 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=True)
130 self
.assertTrue(sc
.assigns_automatic_event_class_id
)
132 with self
.assertRaises(ValueError):
133 sc
.create_event_class(id=123)
135 def test_no_automatic_event_class_ids(self
):
136 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=False)
137 self
.assertFalse(sc
.assigns_automatic_event_class_id
)
139 ec
= sc
.create_event_class(id=333)
140 self
.assertEqual(ec
.id, 333)
142 def test_no_automatic_event_class_ids_raises(self
):
143 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=False)
144 self
.assertFalse(sc
.assigns_automatic_event_class_id
)
146 with self
.assertRaises(ValueError):
147 sc
.create_event_class()
149 def test_supports_packets_without_cs(self
):
150 sc
= self
._tc
.create_stream_class(
151 default_clock_class
=self
._cc
, supports_packets
=True
153 self
.assertTrue(sc
.supports_packets
)
154 self
.assertFalse(sc
.packets_have_beginning_default_clock_snapshot
)
155 self
.assertFalse(sc
.packets_have_end_default_clock_snapshot
)
157 def test_supports_packets_with_begin_cs(self
):
158 sc
= self
._tc
.create_stream_class(
159 default_clock_class
=self
._cc
,
160 supports_packets
=True,
161 packets_have_beginning_default_clock_snapshot
=True,
163 self
.assertTrue(sc
.supports_packets
)
164 self
.assertTrue(sc
.packets_have_beginning_default_clock_snapshot
)
165 self
.assertFalse(sc
.packets_have_end_default_clock_snapshot
)
167 def test_supports_packets_with_end_cs(self
):
168 sc
= self
._tc
.create_stream_class(
169 default_clock_class
=self
._cc
,
170 supports_packets
=True,
171 packets_have_end_default_clock_snapshot
=True,
173 self
.assertTrue(sc
.supports_packets
)
174 self
.assertFalse(sc
.packets_have_beginning_default_clock_snapshot
)
175 self
.assertTrue(sc
.packets_have_end_default_clock_snapshot
)
177 def test_supports_packets_raises_type_error(self
):
178 with self
.assertRaises(TypeError):
179 sc
= self
._tc
.create_stream_class(
180 default_clock_class
=self
._cc
, supports_packets
=23
183 def test_packets_have_begin_default_cs_raises_type_error(self
):
184 with self
.assertRaises(TypeError):
185 sc
= self
._tc
.create_stream_class(
186 default_clock_class
=self
._cc
,
187 packets_have_beginning_default_clock_snapshot
=23,
190 def test_packets_have_end_default_cs_raises_type_error(self
):
191 with self
.assertRaises(TypeError):
192 sc
= self
._tc
.create_stream_class(
193 default_clock_class
=self
._cc
, packets_have_end_default_clock_snapshot
=23
196 def test_does_not_support_packets_raises_with_begin_cs(self
):
197 with self
.assertRaises(ValueError):
198 sc
= self
._tc
.create_stream_class(
199 default_clock_class
=self
._cc
,
200 packets_have_beginning_default_clock_snapshot
=True,
203 def test_does_not_support_packets_raises_with_end_cs(self
):
204 with self
.assertRaises(ValueError):
205 sc
= self
._tc
.create_stream_class(
206 default_clock_class
=self
._cc
,
207 packets_have_end_default_clock_snapshot
=True,
210 def test_supports_discarded_events_without_cs(self
):
211 sc
= self
._tc
.create_stream_class(
212 default_clock_class
=self
._cc
, supports_discarded_events
=True
214 self
.assertTrue(sc
.supports_discarded_events
)
215 self
.assertFalse(sc
.discarded_events_have_default_clock_snapshots
)
217 def test_supports_discarded_events_with_cs(self
):
218 sc
= self
._tc
.create_stream_class(
219 default_clock_class
=self
._cc
,
220 supports_discarded_events
=True,
221 discarded_events_have_default_clock_snapshots
=True,
223 self
.assertTrue(sc
.supports_discarded_events
)
224 self
.assertTrue(sc
.discarded_events_have_default_clock_snapshots
)
226 def test_supports_discarded_events_raises_type_error(self
):
227 with self
.assertRaises(TypeError):
228 sc
= self
._tc
.create_stream_class(
229 default_clock_class
=self
._cc
, supports_discarded_events
=23
232 def test_discarded_events_have_default_cs_raises_type_error(self
):
233 with self
.assertRaises(TypeError):
234 sc
= self
._tc
.create_stream_class(
235 default_clock_class
=self
._cc
,
236 discarded_events_have_default_clock_snapshots
=23,
239 def test_does_not_support_discarded_events_raises_with_cs(self
):
240 with self
.assertRaises(ValueError):
241 sc
= self
._tc
.create_stream_class(
242 default_clock_class
=self
._cc
,
243 discarded_events_have_default_clock_snapshots
=True,
246 def test_supports_discarded_packets_without_cs(self
):
247 sc
= self
._tc
.create_stream_class(
248 default_clock_class
=self
._cc
,
249 supports_discarded_packets
=True,
250 supports_packets
=True,
252 self
.assertTrue(sc
.supports_discarded_packets
)
253 self
.assertFalse(sc
.discarded_packets_have_default_clock_snapshots
)
255 def test_supports_discarded_packets_with_cs(self
):
256 sc
= self
._tc
.create_stream_class(
257 default_clock_class
=self
._cc
,
258 supports_discarded_packets
=True,
259 discarded_packets_have_default_clock_snapshots
=True,
260 supports_packets
=True,
262 self
.assertTrue(sc
.supports_discarded_packets
)
263 self
.assertTrue(sc
.discarded_packets_have_default_clock_snapshots
)
265 def test_supports_discarded_packets_raises_without_packet_support(self
):
266 with self
.assertRaises(ValueError):
267 sc
= self
._tc
.create_stream_class(
268 default_clock_class
=self
._cc
, supports_discarded_packets
=True
271 def test_supports_discarded_packets_raises_type_error(self
):
272 with self
.assertRaises(TypeError):
273 sc
= self
._tc
.create_stream_class(
274 default_clock_class
=self
._cc
,
275 supports_discarded_packets
=23,
276 supports_packets
=True,
279 def test_discarded_packets_have_default_cs_raises_type_error(self
):
280 with self
.assertRaises(TypeError):
281 sc
= self
._tc
.create_stream_class(
282 default_clock_class
=self
._cc
,
283 discarded_packets_have_default_clock_snapshots
=23,
284 supports_packets
=True,
287 def test_does_not_support_discarded_packets_raises_with_cs(self
):
288 with self
.assertRaises(ValueError):
289 sc
= self
._tc
.create_stream_class(
290 default_clock_class
=self
._cc
,
291 discarded_packets_have_default_clock_snapshots
=True,
292 supports_packets
=True,
295 def test_trace_class(self
):
296 sc
= self
._tc
.create_stream_class()
297 self
.assertEqual(sc
.trace_class
.addr
, self
._tc
.addr
)
299 def _create_stream_class_with_event_classes(self
):
300 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=False)
301 ec1
= sc
.create_event_class(id=23)
302 ec2
= sc
.create_event_class(id=17)
305 def test_getitem(self
):
306 sc
, ec1
, ec2
= self
._create
_stream
_class
_with
_event
_classes
()
308 self
.assertEqual(sc
[23].addr
, ec1
.addr
)
309 self
.assertEqual(sc
[17].addr
, ec2
.addr
)
311 def test_getitem_wrong_key_type(self
):
312 sc
, _
, _
= self
._create
_stream
_class
_with
_event
_classes
()
314 with self
.assertRaises(TypeError):
317 def test_getitem_wrong_key(self
):
318 sc
, _
, _
= self
._create
_stream
_class
_with
_event
_classes
()
320 with self
.assertRaises(KeyError):
324 sc
, _
, _
= self
._create
_stream
_class
_with
_event
_classes
()
326 self
.assertEqual(len(sc
), 2)
329 sc
, _
, _
= self
._create
_stream
_class
_with
_event
_classes
()
332 self
.assertEqual(ec_ids
, [17, 23])