3 # The MIT License (MIT)
5 # Copyright (C) 2017 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
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
25 import bt_python_helper
27 import babeltrace
.writer
as btw
28 import babeltrace
.reader
as btr
33 EXPECTED_EVENT_COUNT
= 10
34 trace_path
= tempfile
.mkdtemp()
37 def print_test_result(test_number
, result
, description
):
38 result_string
= 'ok' if result
else 'not ok'
39 result_string
+= ' {} - {}'.format(test_number
, description
)
42 def create_trace(path
):
43 trace
= btw
.Writer(path
)
44 clock
= btw
.Clock('test_clock')
45 trace
.add_clock(clock
)
47 integer_field_type
= btw
.IntegerFieldDeclaration(32)
49 event_class
= btw
.EventClass('simple_event')
50 event_class
.add_field(integer_field_type
, 'int_field')
52 stream_class
= btw
.StreamClass('test_stream')
53 stream_class
.add_event_class(event_class
)
54 stream_class
.clock
= clock
56 stream_class
.packet_context_type
= None
57 print_test_result(1, stream_class
.packet_context_type
is None,
58 'Set stream class packet context type to None')
60 stream
= trace
.create_stream(stream_class
)
62 for i
in range(EXPECTED_EVENT_COUNT
):
63 event
= btw
.Event(event_class
)
64 event
.payload('int_field').value
= i
65 stream
.append_event(event
)
67 print_test_result(2, True,
70 # It is not valid for a stream to contain more than one packet
71 # if it does not have content_size/packet_size info in its packet
73 event
= btw
.Event(event_class
)
74 event
.payload('int_field').value
= 42
75 stream
.append_event(event
)
78 second_flush_succeeded
= True
80 second_flush_succeeded
= False
82 print_test_result(3, not second_flush_succeeded
,
83 'Flushing a second packet in a stream without a defined packet context fails')
87 print('1..{}'.format(TEST_COUNT
))
88 print('# Creating trace at {}'.format(trace_path
))
89 create_trace(trace_path
)
91 traces
= btr
.TraceCollection()
92 trace_handle
= traces
.add_trace(trace_path
, 'ctf')
93 if trace_handle
is None:
94 print('Failed to open trace at {}'.format(trace_path
))
97 for event
in traces
.events
:
100 print_test_result(4, EXPECTED_EVENT_COUNT
== event_count
,
101 'Trace was found to contain {} events, expected {}'.format(
102 event_count
, EXPECTED_EVENT_COUNT
))
104 shutil
.rmtree(trace_path
)
This page took 0.033176 seconds and 4 git commands to generate.