Commit | Line | Data |
---|---|---|
4c3453a1 JG |
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 | ||
4c3453a1 JG |
25 | import tempfile |
26 | import babeltrace.writer as btw | |
27 | import babeltrace.reader as btr | |
28 | import shutil | |
29 | import uuid | |
295f4581 | 30 | import unittest |
4c3453a1 | 31 | |
295f4581 JG |
32 | class CtfWriterNoPacketContextTestCase(unittest.TestCase): |
33 | def setUp(self): | |
34 | self._expected_event_count = 100 | |
35 | self._trace_path = tempfile.mkdtemp() | |
4c3453a1 | 36 | |
295f4581 JG |
37 | def tearDown(self): |
38 | shutil.rmtree(self._trace_path) | |
4c3453a1 | 39 | |
295f4581 JG |
40 | def _write_trace(self): |
41 | trace = btw.Writer(self._trace_path) | |
4c3453a1 JG |
42 | clock = btw.Clock('test_clock') |
43 | trace.add_clock(clock) | |
44 | ||
45 | integer_field_type = btw.IntegerFieldDeclaration(32) | |
46 | ||
47 | event_class = btw.EventClass('simple_event') | |
48 | event_class.add_field(integer_field_type, 'int_field') | |
49 | ||
50 | stream_class = btw.StreamClass('test_stream') | |
51 | stream_class.add_event_class(event_class) | |
52 | stream_class.clock = clock | |
53 | ||
54 | stream_class.packet_context_type = None | |
4c3453a1 JG |
55 | stream = trace.create_stream(stream_class) |
56 | ||
295f4581 JG |
57 | for i in range(self._expected_event_count): |
58 | event = btw.Event(event_class) | |
59 | event.payload('int_field').value = i | |
60 | stream.append_event(event) | |
4c3453a1 | 61 | stream.flush() |
4c3453a1 JG |
62 | |
63 | # It is not valid for a stream to contain more than one packet | |
64 | # if it does not have content_size/packet_size info in its packet | |
65 | # context | |
66 | event = btw.Event(event_class) | |
67 | event.payload('int_field').value = 42 | |
68 | stream.append_event(event) | |
295f4581 JG |
69 | |
70 | flush_raises = False | |
4c3453a1 JG |
71 | try: |
72 | stream.flush() | |
4c3453a1 | 73 | except ValueError: |
295f4581 JG |
74 | flush_raises = True |
75 | self.assertTrue(flush_raises) | |
76 | trace.flush_metadata() | |
77 | ||
78 | def test_trace_no_packet_context(self): | |
79 | self._write_trace() | |
80 | traces = btr.TraceCollection() | |
81 | trace_handle = traces.add_trace(self._trace_path, 'ctf') | |
82 | self.assertIsNotNone(trace_handle) | |
83 | ||
84 | event_count = sum(1 for event in traces.events) | |
85 | self.assertEqual(self._expected_event_count, event_count) |