Commit | Line | Data |
---|---|---|
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 | 19 | import unittest |
3cdfbaea | 20 | from utils import run_in_component_init |
9cf643d1 PP |
21 | |
22 | ||
23 | class 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) | |
3cdfbaea SM |
49 | |
50 | def test_create_name(self): | |
51 | sc = self._tc.create_stream_class(name='bozo') | |
52 | self.assertEqual(sc.name, 'bozo') | |
53 | ||
54 | def test_create_invalid_name(self): | |
9cf643d1 | 55 | with self.assertRaises(TypeError): |
3cdfbaea | 56 | self._tc.create_stream_class(name=17) |
9cf643d1 | 57 | |
3cdfbaea SM |
58 | def test_create_packet_context_field_class(self): |
59 | fc = self._tc.create_structure_field_class() | |
cfbd7cf3 FD |
60 | sc = self._tc.create_stream_class( |
61 | packet_context_field_class=fc, supports_packets=True | |
62 | ) | |
3cdfbaea | 63 | self.assertEqual(sc.packet_context_field_class, fc) |
9cf643d1 | 64 | |
3cdfbaea | 65 | def test_create_invalid_packet_context_field_class(self): |
9cf643d1 | 66 | with self.assertRaises(TypeError): |
3cdfbaea | 67 | self._tc.create_stream_class(packet_context_field_class=22) |
9cf643d1 | 68 | |
26fc5aed PP |
69 | def test_create_invalid_packet_context_field_class_no_packets(self): |
70 | fc = self._tc.create_structure_field_class() | |
71 | ||
72 | with self.assertRaises(ValueError): | |
73 | self._tc.create_stream_class(packet_context_field_class=fc) | |
74 | ||
3cdfbaea SM |
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) | |
811644b8 | 79 | |
3cdfbaea SM |
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) | |
9cf643d1 | 83 | |
3cdfbaea SM |
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) | |
9cf643d1 | 87 | |
3cdfbaea | 88 | def test_create_invalid_default_clock_class(self): |
9cf643d1 | 89 | with self.assertRaises(TypeError): |
3cdfbaea | 90 | self._tc.create_stream_class(default_clock_class=12) |
9cf643d1 | 91 | |
3cdfbaea SM |
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) | |
9cf643d1 | 95 | |
3cdfbaea SM |
96 | stream = self._trace.create_stream(sc) |
97 | self.assertIsNotNone(stream.id) | |
9cf643d1 | 98 | |
3cdfbaea SM |
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) | |
102 | ||
4430bc80 | 103 | with self.assertRaises(ValueError): |
3cdfbaea SM |
104 | self._trace.create_stream(sc, id=123) |
105 | ||
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) | |
109 | ||
110 | stream = self._trace.create_stream(sc, id=333) | |
111 | self.assertEqual(stream.id, 333) | |
112 | ||
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) | |
116 | ||
4430bc80 | 117 | with self.assertRaises(ValueError): |
3cdfbaea SM |
118 | self._trace.create_stream(sc) |
119 | ||
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) | |
123 | ||
124 | ec = sc.create_event_class() | |
125 | self.assertIsNotNone(ec.id) | |
126 | ||
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) | |
130 | ||
4430bc80 | 131 | with self.assertRaises(ValueError): |
3cdfbaea SM |
132 | sc.create_event_class(id=123) |
133 | ||
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) | |
9cf643d1 | 137 | |
3cdfbaea SM |
138 | ec = sc.create_event_class(id=333) |
139 | self.assertEqual(ec.id, 333) | |
9cf643d1 | 140 | |
3cdfbaea SM |
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) | |
9cf643d1 | 144 | |
4430bc80 | 145 | with self.assertRaises(ValueError): |
3cdfbaea SM |
146 | sc.create_event_class() |
147 | ||
26fc5aed | 148 | def test_supports_packets_without_cs(self): |
cfbd7cf3 FD |
149 | sc = self._tc.create_stream_class( |
150 | default_clock_class=self._cc, supports_packets=True | |
151 | ) | |
26fc5aed PP |
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) | |
155 | ||
156 | def test_supports_packets_with_begin_cs(self): | |
cfbd7cf3 FD |
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, | |
161 | ) | |
26fc5aed | 162 | self.assertTrue(sc.supports_packets) |
9b24b6aa | 163 | self.assertTrue(sc.packets_have_beginning_default_clock_snapshot) |
26fc5aed | 164 | self.assertFalse(sc.packets_have_end_default_clock_snapshot) |
3cdfbaea | 165 | |
26fc5aed | 166 | def test_supports_packets_with_end_cs(self): |
cfbd7cf3 FD |
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, | |
171 | ) | |
26fc5aed PP |
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) | |
175 | ||
176 | def test_supports_packets_raises_type_error(self): | |
3cdfbaea | 177 | with self.assertRaises(TypeError): |
cfbd7cf3 FD |
178 | sc = self._tc.create_stream_class( |
179 | default_clock_class=self._cc, supports_packets=23 | |
180 | ) | |
3cdfbaea | 181 | |
26fc5aed PP |
182 | def test_packets_have_begin_default_cs_raises_type_error(self): |
183 | with self.assertRaises(TypeError): | |
cfbd7cf3 FD |
184 | sc = self._tc.create_stream_class( |
185 | default_clock_class=self._cc, | |
186 | packets_have_beginning_default_clock_snapshot=23, | |
187 | ) | |
3cdfbaea | 188 | |
26fc5aed | 189 | def test_packets_have_end_default_cs_raises_type_error(self): |
9cf643d1 | 190 | with self.assertRaises(TypeError): |
cfbd7cf3 FD |
191 | sc = self._tc.create_stream_class( |
192 | default_clock_class=self._cc, packets_have_end_default_clock_snapshot=23 | |
193 | ) | |
26fc5aed PP |
194 | |
195 | def test_does_not_support_packets_raises_with_begin_cs(self): | |
196 | with self.assertRaises(ValueError): | |
cfbd7cf3 FD |
197 | sc = self._tc.create_stream_class( |
198 | default_clock_class=self._cc, | |
199 | packets_have_beginning_default_clock_snapshot=True, | |
200 | ) | |
26fc5aed PP |
201 | |
202 | def test_does_not_support_packets_raises_with_end_cs(self): | |
203 | with self.assertRaises(ValueError): | |
cfbd7cf3 FD |
204 | sc = self._tc.create_stream_class( |
205 | default_clock_class=self._cc, | |
206 | packets_have_end_default_clock_snapshot=True, | |
207 | ) | |
3cdfbaea | 208 | |
2e90378a | 209 | def test_supports_discarded_events_without_cs(self): |
cfbd7cf3 FD |
210 | sc = self._tc.create_stream_class( |
211 | default_clock_class=self._cc, supports_discarded_events=True | |
212 | ) | |
2e90378a PP |
213 | self.assertTrue(sc.supports_discarded_events) |
214 | self.assertFalse(sc.discarded_events_have_default_clock_snapshots) | |
215 | ||
216 | def test_supports_discarded_events_with_cs(self): | |
cfbd7cf3 FD |
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, | |
221 | ) | |
2e90378a PP |
222 | self.assertTrue(sc.supports_discarded_events) |
223 | self.assertTrue(sc.discarded_events_have_default_clock_snapshots) | |
224 | ||
225 | def test_supports_discarded_events_raises_type_error(self): | |
226 | with self.assertRaises(TypeError): | |
cfbd7cf3 FD |
227 | sc = self._tc.create_stream_class( |
228 | default_clock_class=self._cc, supports_discarded_events=23 | |
229 | ) | |
2e90378a PP |
230 | |
231 | def test_discarded_events_have_default_cs_raises_type_error(self): | |
232 | with self.assertRaises(TypeError): | |
cfbd7cf3 FD |
233 | sc = self._tc.create_stream_class( |
234 | default_clock_class=self._cc, | |
235 | discarded_events_have_default_clock_snapshots=23, | |
236 | ) | |
2e90378a PP |
237 | |
238 | def test_does_not_support_discarded_events_raises_with_cs(self): | |
239 | with self.assertRaises(ValueError): | |
cfbd7cf3 FD |
240 | sc = self._tc.create_stream_class( |
241 | default_clock_class=self._cc, | |
242 | discarded_events_have_default_clock_snapshots=True, | |
243 | ) | |
2e90378a PP |
244 | |
245 | def test_supports_discarded_packets_without_cs(self): | |
cfbd7cf3 FD |
246 | sc = self._tc.create_stream_class( |
247 | default_clock_class=self._cc, | |
248 | supports_discarded_packets=True, | |
249 | supports_packets=True, | |
250 | ) | |
2e90378a PP |
251 | self.assertTrue(sc.supports_discarded_packets) |
252 | self.assertFalse(sc.discarded_packets_have_default_clock_snapshots) | |
253 | ||
254 | def test_supports_discarded_packets_with_cs(self): | |
cfbd7cf3 FD |
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, | |
260 | ) | |
2e90378a PP |
261 | self.assertTrue(sc.supports_discarded_packets) |
262 | self.assertTrue(sc.discarded_packets_have_default_clock_snapshots) | |
263 | ||
26fc5aed PP |
264 | def test_supports_discarded_packets_raises_without_packet_support(self): |
265 | with self.assertRaises(ValueError): | |
cfbd7cf3 FD |
266 | sc = self._tc.create_stream_class( |
267 | default_clock_class=self._cc, supports_discarded_packets=True | |
268 | ) | |
26fc5aed | 269 | |
2e90378a PP |
270 | def test_supports_discarded_packets_raises_type_error(self): |
271 | with self.assertRaises(TypeError): | |
cfbd7cf3 FD |
272 | sc = self._tc.create_stream_class( |
273 | default_clock_class=self._cc, | |
274 | supports_discarded_packets=23, | |
275 | supports_packets=True, | |
276 | ) | |
2e90378a PP |
277 | |
278 | def test_discarded_packets_have_default_cs_raises_type_error(self): | |
279 | with self.assertRaises(TypeError): | |
cfbd7cf3 FD |
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, | |
284 | ) | |
2e90378a PP |
285 | |
286 | def test_does_not_support_discarded_packets_raises_with_cs(self): | |
287 | with self.assertRaises(ValueError): | |
cfbd7cf3 FD |
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, | |
292 | ) | |
2e90378a | 293 | |
3cdfbaea SM |
294 | def test_trace_class(self): |
295 | sc = self._tc.create_stream_class() | |
296 | self.assertEqual(sc.trace_class.addr, self._tc.addr) | |
297 | ||
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) | |
302 | return sc, ec1, ec2 | |
9cf643d1 PP |
303 | |
304 | def test_getitem(self): | |
3cdfbaea SM |
305 | sc, ec1, ec2 = self._create_stream_class_with_event_classes() |
306 | ||
307 | self.assertEqual(sc[23].addr, ec1.addr) | |
308 | self.assertEqual(sc[17].addr, ec2.addr) | |
9cf643d1 PP |
309 | |
310 | def test_getitem_wrong_key_type(self): | |
3cdfbaea SM |
311 | sc, _, _ = self._create_stream_class_with_event_classes() |
312 | ||
9cf643d1 | 313 | with self.assertRaises(TypeError): |
3cdfbaea | 314 | sc['event23'] |
9cf643d1 PP |
315 | |
316 | def test_getitem_wrong_key(self): | |
3cdfbaea SM |
317 | sc, _, _ = self._create_stream_class_with_event_classes() |
318 | ||
9cf643d1 | 319 | with self.assertRaises(KeyError): |
3cdfbaea | 320 | sc[19] |
9cf643d1 PP |
321 | |
322 | def test_len(self): | |
3cdfbaea SM |
323 | sc, _, _ = self._create_stream_class_with_event_classes() |
324 | ||
325 | self.assertEqual(len(sc), 2) | |
9cf643d1 PP |
326 | |
327 | def test_iter(self): | |
3cdfbaea SM |
328 | sc, _, _ = self._create_stream_class_with_event_classes() |
329 | ||
330 | ec_ids = sorted(sc) | |
331 | self.assertEqual(ec_ids, [17, 23]) |