Commit | Line | Data |
---|---|---|
ab973b67 PP |
1 | #!/usr/bin/env python3 |
2 | # | |
3 | # The MIT License (MIT) | |
4 | # | |
5 | # Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
6 | # | |
7 | # Permission is hereby granted, free of charge, to any person obtaining a copy | |
8 | # of this software and associated documentation files (the "Software"), to deal | |
9 | # in the Software without restriction, including without limitation the rights | |
10 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
11 | # copies of the Software, and to permit persons to whom the Software is | |
12 | # furnished to do so, subject to the following conditions: | |
13 | # | |
14 | # The above copyright notice and this permission notice shall be included in | |
15 | # all copies or substantial portions of the Software. | |
16 | # | |
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
18 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
19 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
20 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
21 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
22 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
23 | # SOFTWARE. | |
24 | ||
25 | import tempfile | |
90cfc012 SM |
26 | #import babeltrace.writer as btw |
27 | #import babeltrace.reader as btr | |
ab973b67 PP |
28 | import shutil |
29 | import uuid | |
30 | import unittest | |
31 | ||
90cfc012 | 32 | @unittest.skip("this is broken") |
ab973b67 PP |
33 | class CtfWriterTestCase(unittest.TestCase): |
34 | def setUp(self): | |
35 | self._expected_event_count = 100 | |
36 | self._trace_path = tempfile.mkdtemp() | |
37 | ||
38 | def tearDown(self): | |
39 | shutil.rmtree(self._trace_path) | |
40 | ||
41 | def _create_trace(self): | |
42 | trace = btw.Writer(self._trace_path) | |
43 | clock = btw.Clock('test_clock') | |
44 | trace.add_clock(clock) | |
45 | ||
46 | integer_field_type = btw.IntegerFieldDeclaration(32) | |
47 | ||
48 | event_class = btw.EventClass('simple_event') | |
49 | event_class.add_field(integer_field_type, 'int_field') | |
50 | ||
51 | stream_class = btw.StreamClass('empty_packet_stream') | |
52 | stream_class.add_event_class(event_class) | |
53 | stream_class.clock = clock | |
54 | ||
55 | stream = trace.create_stream(stream_class) | |
56 | ||
57 | for j in range(2): | |
58 | for i in range(self._expected_event_count // 2): | |
59 | val = i * (j + 1) | |
60 | clock.time = val * 200 | |
61 | event = btw.Event(event_class) | |
62 | event.payload('int_field').value = val | |
63 | stream.append_event(event) | |
64 | ||
65 | stream.flush() | |
66 | ||
67 | def test_writer(self): | |
68 | self._create_trace() | |
69 | ||
70 | traces = btr.TraceCollection() | |
71 | trace_handle = traces.add_trace(self._trace_path, 'ctf') | |
72 | self.assertIsNotNone(trace_handle) | |
73 | ||
74 | event_count = sum(1 for event in traces.events) | |
75 | self.assertEqual(self._expected_event_count, event_count) | |
76 | ||
77 | self.assertEqual(traces.timestamp_begin, 0) | |
78 | self.assertEqual(traces.timestamp_end, 19600) |