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 |
9cf643d1 | 20 | import bt2 |
3cdfbaea | 21 | from utils import run_in_component_init |
9cf643d1 PP |
22 | |
23 | ||
24 | class StreamClassTestCase(unittest.TestCase): | |
25 | def setUp(self): | |
3cdfbaea SM |
26 | def f(comp_self): |
27 | tc = comp_self._create_trace_class(assigns_automatic_stream_class_id=True) | |
28 | cc = comp_self._create_clock_class() | |
29 | return tc, cc | |
30 | ||
31 | self._tc, self._cc = run_in_component_init(f) | |
32 | self._trace = self._tc() | |
33 | ||
34 | def test_create_default(self): | |
35 | sc = self._tc.create_stream_class() | |
36 | ||
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) | |
26fc5aed | 43 | self.assertFalse(sc.supports_packets) |
9b24b6aa PP |
44 | self.assertFalse(sc.packets_have_beginning_default_clock_snapshot) |
45 | self.assertFalse(sc.packets_have_end_default_clock_snapshot) | |
2e90378a PP |
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) | |
3cdfbaea SM |
50 | |
51 | def test_create_name(self): | |
52 | sc = self._tc.create_stream_class(name='bozo') | |
53 | self.assertEqual(sc.name, 'bozo') | |
54 | ||
55 | def test_create_invalid_name(self): | |
9cf643d1 | 56 | with self.assertRaises(TypeError): |
3cdfbaea | 57 | self._tc.create_stream_class(name=17) |
9cf643d1 | 58 | |
3cdfbaea SM |
59 | def test_create_packet_context_field_class(self): |
60 | fc = self._tc.create_structure_field_class() | |
26fc5aed PP |
61 | sc = self._tc.create_stream_class(packet_context_field_class=fc, |
62 | supports_packets=True) | |
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 PP |
148 | def test_supports_packets_without_cs(self): |
149 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
150 | supports_packets=True) | |
151 | self.assertTrue(sc.supports_packets) | |
152 | self.assertFalse(sc.packets_have_beginning_default_clock_snapshot) | |
153 | self.assertFalse(sc.packets_have_end_default_clock_snapshot) | |
154 | ||
155 | def test_supports_packets_with_begin_cs(self): | |
156 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
157 | supports_packets=True, | |
158 | packets_have_beginning_default_clock_snapshot=True) | |
159 | self.assertTrue(sc.supports_packets) | |
9b24b6aa | 160 | self.assertTrue(sc.packets_have_beginning_default_clock_snapshot) |
26fc5aed | 161 | self.assertFalse(sc.packets_have_end_default_clock_snapshot) |
3cdfbaea | 162 | |
26fc5aed PP |
163 | def test_supports_packets_with_end_cs(self): |
164 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
165 | supports_packets=True, | |
166 | packets_have_end_default_clock_snapshot=True) | |
167 | self.assertTrue(sc.supports_packets) | |
168 | self.assertFalse(sc.packets_have_beginning_default_clock_snapshot) | |
169 | self.assertTrue(sc.packets_have_end_default_clock_snapshot) | |
170 | ||
171 | def test_supports_packets_raises_type_error(self): | |
3cdfbaea | 172 | with self.assertRaises(TypeError): |
26fc5aed PP |
173 | sc = self._tc.create_stream_class(default_clock_class=self._cc, |
174 | supports_packets=23) | |
3cdfbaea | 175 | |
26fc5aed PP |
176 | def test_packets_have_begin_default_cs_raises_type_error(self): |
177 | with self.assertRaises(TypeError): | |
178 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
179 | packets_have_beginning_default_clock_snapshot=23) | |
3cdfbaea | 180 | |
26fc5aed | 181 | def test_packets_have_end_default_cs_raises_type_error(self): |
9cf643d1 | 182 | with self.assertRaises(TypeError): |
26fc5aed PP |
183 | sc = self._tc.create_stream_class(default_clock_class=self._cc, |
184 | packets_have_end_default_clock_snapshot=23) | |
185 | ||
186 | def test_does_not_support_packets_raises_with_begin_cs(self): | |
187 | with self.assertRaises(ValueError): | |
188 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
189 | packets_have_beginning_default_clock_snapshot=True) | |
190 | ||
191 | def test_does_not_support_packets_raises_with_end_cs(self): | |
192 | with self.assertRaises(ValueError): | |
193 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
194 | packets_have_end_default_clock_snapshot=True) | |
3cdfbaea | 195 | |
2e90378a PP |
196 | def test_supports_discarded_events_without_cs(self): |
197 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
198 | supports_discarded_events=True) | |
199 | self.assertTrue(sc.supports_discarded_events) | |
200 | self.assertFalse(sc.discarded_events_have_default_clock_snapshots) | |
201 | ||
202 | def test_supports_discarded_events_with_cs(self): | |
203 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
204 | supports_discarded_events=True, | |
205 | discarded_events_have_default_clock_snapshots=True) | |
206 | self.assertTrue(sc.supports_discarded_events) | |
207 | self.assertTrue(sc.discarded_events_have_default_clock_snapshots) | |
208 | ||
209 | def test_supports_discarded_events_raises_type_error(self): | |
210 | with self.assertRaises(TypeError): | |
211 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
212 | supports_discarded_events=23) | |
213 | ||
214 | def test_discarded_events_have_default_cs_raises_type_error(self): | |
215 | with self.assertRaises(TypeError): | |
216 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
217 | discarded_events_have_default_clock_snapshots=23) | |
218 | ||
219 | def test_does_not_support_discarded_events_raises_with_cs(self): | |
220 | with self.assertRaises(ValueError): | |
221 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
222 | discarded_events_have_default_clock_snapshots=True) | |
223 | ||
224 | def test_supports_discarded_packets_without_cs(self): | |
225 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
26fc5aed PP |
226 | supports_discarded_packets=True, |
227 | supports_packets=True) | |
2e90378a PP |
228 | self.assertTrue(sc.supports_discarded_packets) |
229 | self.assertFalse(sc.discarded_packets_have_default_clock_snapshots) | |
230 | ||
231 | def test_supports_discarded_packets_with_cs(self): | |
232 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
233 | supports_discarded_packets=True, | |
26fc5aed PP |
234 | discarded_packets_have_default_clock_snapshots=True, |
235 | supports_packets=True) | |
2e90378a PP |
236 | self.assertTrue(sc.supports_discarded_packets) |
237 | self.assertTrue(sc.discarded_packets_have_default_clock_snapshots) | |
238 | ||
26fc5aed PP |
239 | def test_supports_discarded_packets_raises_without_packet_support(self): |
240 | with self.assertRaises(ValueError): | |
241 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
242 | supports_discarded_packets=True) | |
243 | ||
2e90378a PP |
244 | def test_supports_discarded_packets_raises_type_error(self): |
245 | with self.assertRaises(TypeError): | |
246 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
26fc5aed PP |
247 | supports_discarded_packets=23, |
248 | supports_packets=True) | |
2e90378a PP |
249 | |
250 | def test_discarded_packets_have_default_cs_raises_type_error(self): | |
251 | with self.assertRaises(TypeError): | |
252 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
26fc5aed PP |
253 | discarded_packets_have_default_clock_snapshots=23, |
254 | supports_packets=True) | |
2e90378a PP |
255 | |
256 | def test_does_not_support_discarded_packets_raises_with_cs(self): | |
257 | with self.assertRaises(ValueError): | |
258 | sc = self._tc.create_stream_class(default_clock_class=self._cc, | |
26fc5aed PP |
259 | discarded_packets_have_default_clock_snapshots=True, |
260 | supports_packets=True) | |
2e90378a | 261 | |
3cdfbaea SM |
262 | def test_trace_class(self): |
263 | sc = self._tc.create_stream_class() | |
264 | self.assertEqual(sc.trace_class.addr, self._tc.addr) | |
265 | ||
266 | def _create_stream_class_with_event_classes(self): | |
267 | sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False) | |
268 | ec1 = sc.create_event_class(id=23) | |
269 | ec2 = sc.create_event_class(id=17) | |
270 | return sc, ec1, ec2 | |
9cf643d1 PP |
271 | |
272 | def test_getitem(self): | |
3cdfbaea SM |
273 | sc, ec1, ec2 = self._create_stream_class_with_event_classes() |
274 | ||
275 | self.assertEqual(sc[23].addr, ec1.addr) | |
276 | self.assertEqual(sc[17].addr, ec2.addr) | |
9cf643d1 PP |
277 | |
278 | def test_getitem_wrong_key_type(self): | |
3cdfbaea SM |
279 | sc, _, _ = self._create_stream_class_with_event_classes() |
280 | ||
9cf643d1 | 281 | with self.assertRaises(TypeError): |
3cdfbaea | 282 | sc['event23'] |
9cf643d1 PP |
283 | |
284 | def test_getitem_wrong_key(self): | |
3cdfbaea SM |
285 | sc, _, _ = self._create_stream_class_with_event_classes() |
286 | ||
9cf643d1 | 287 | with self.assertRaises(KeyError): |
3cdfbaea | 288 | sc[19] |
9cf643d1 PP |
289 | |
290 | def test_len(self): | |
3cdfbaea SM |
291 | sc, _, _ = self._create_stream_class_with_event_classes() |
292 | ||
293 | self.assertEqual(len(sc), 2) | |
9cf643d1 PP |
294 | |
295 | def test_iter(self): | |
3cdfbaea SM |
296 | sc, _, _ = self._create_stream_class_with_event_classes() |
297 | ||
298 | ec_ids = sorted(sc) | |
299 | self.assertEqual(ec_ids, [17, 23]) |