1 # Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; only version 2
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 from pathlib
import PureWindowsPath
, PurePosixPath
24 test_ctf_traces_path
= os
.environ
['BT_CTF_TRACES_PATH']
27 # Key to sort streams in a predictable order.
28 def sort_predictably(stream
):
29 return stream
['port-name']
32 class QueryTraceInfoClockOffsetTestCase(unittest
.TestCase
):
34 ctf
= bt2
.find_plugin('ctf')
35 self
._fs
= ctf
.source_component_classes
['fs']
38 os
.path
.join(test_ctf_traces_path
, 'intersection', '3eventsintersect')
41 def _check(self
, trace
, offset
):
43 trace
['intersection-range-ns']['begin'], 13515309000000070 + offset
46 trace
['intersection-range-ns']['end'], 13515309000000100 + offset
49 streams
= sorted(trace
['streams'], key
=sort_predictably
)
50 self
.assertEqual(streams
[0]['range-ns']['begin'], 13515309000000000 + offset
)
51 self
.assertEqual(streams
[0]['range-ns']['end'], 13515309000000100 + offset
)
52 self
.assertEqual(streams
[1]['range-ns']['begin'], 13515309000000070 + offset
)
53 self
.assertEqual(streams
[1]['range-ns']['end'], 13515309000000120 + offset
)
55 # Test various cominations of the clock-class-offset-s and
56 # clock-class-offset-ns parameters to babeltrace.trace-info queries.
58 # Without clock class offset
60 def test_no_clock_class_offset(self
):
61 res
= bt2
.QueryExecutor(
62 self
._fs
, 'babeltrace.trace-info', {'inputs': self
._inputs
}
67 # With clock-class-offset-s
69 def test_clock_class_offset_s(self
):
70 res
= bt2
.QueryExecutor(
72 'babeltrace.trace-info',
73 {'inputs': self
._inputs
, 'clock-class-offset-s': 2},
76 self
._check
(trace
, 2000000000)
78 # With clock-class-offset-ns
80 def test_clock_class_offset_ns(self
):
81 res
= bt2
.QueryExecutor(
83 'babeltrace.trace-info',
84 {'inputs': self
._inputs
, 'clock-class-offset-ns': 2},
91 def test_clock_class_offset_both(self
):
92 res
= bt2
.QueryExecutor(
94 'babeltrace.trace-info',
96 'inputs': self
._inputs
,
97 'clock-class-offset-s': -2,
98 'clock-class-offset-ns': -2,
102 self
._check
(trace
, -2000000002)
104 def test_clock_class_offset_s_wrong_type(self
):
105 with self
.assertRaises(bt2
._Error
):
108 'babeltrace.trace-info',
109 {'inputs': self
._inputs
, 'clock-class-offset-s': "2"},
112 def test_clock_class_offset_s_wrong_type_none(self
):
113 with self
.assertRaises(bt2
._Error
):
116 'babeltrace.trace-info',
117 {'inputs': self
._inputs
, 'clock-class-offset-s': None},
120 def test_clock_class_offset_ns_wrong_type(self
):
121 with self
.assertRaises(bt2
._Error
):
124 'babeltrace.trace-info',
125 {'inputs': self
._inputs
, 'clock-class-offset-ns': "2"},
128 def test_clock_class_offset_ns_wrong_type_none(self
):
129 with self
.assertRaises(bt2
._Error
):
132 'babeltrace.trace-info',
133 {'inputs': self
._inputs
, 'clock-class-offset-ns': None},
137 class QueryTraceInfoPortNameTestCase(unittest
.TestCase
):
139 ctf
= bt2
.find_plugin("ctf")
140 self
._fs
= ctf
.source_component_classes
["fs"]
142 def test_trace_uuid_stream_class_id_no_stream_id(self
):
143 res
= bt2
.QueryExecutor(
145 "babeltrace.trace-info",
149 test_ctf_traces_path
, "intersection", "3eventsintersect"
155 os_stream_path
= PurePosixPath(
156 '/tests/data/ctf-traces/intersection/3eventsintersect/'
158 if os
.environ
['BT_OS_TYPE'] == 'mingw':
159 os_stream_path
= PureWindowsPath(os_stream_path
)
161 self
.assertEqual(len(res
), 1)
163 streams
= sorted(trace
["streams"], key
=sort_predictably
)
164 self
.assertEqual(len(streams
), 2)
165 self
.assertRegexpMatches(
166 str(streams
[0]["port-name"]),
167 r
"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*"
168 + re
.escape(str(os_stream_path
/ "test_stream_0"))
171 self
.assertRegexpMatches(
172 str(streams
[1]["port-name"]),
173 r
"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*"
174 + re
.escape(str(os_stream_path
/ "test_stream_1"))
178 def test_trace_uuid_no_stream_class_id_no_stream_id(self
):
179 res
= bt2
.QueryExecutor(
181 "babeltrace.trace-info",
182 {"inputs": [os
.path
.join(test_ctf_traces_path
, "succeed", "succeed1")]},
185 os_stream_path
= PurePosixPath(
186 '/tests/data/ctf-traces/succeed/succeed1/dummystream'
188 if os
.environ
['BT_OS_TYPE'] == 'mingw':
189 os_stream_path
= PureWindowsPath(os_stream_path
)
191 self
.assertEqual(len(res
), 1)
193 streams
= sorted(trace
["streams"], key
=sort_predictably
)
194 self
.assertEqual(len(streams
), 1)
195 self
.assertRegexpMatches(
196 str(streams
[0]["port-name"]),
197 r
"^2a6422d0-6cee-11e0-8c08-cb07d7b3a564 \| .*"
198 + re
.escape(str(os_stream_path
))
203 class QueryTraceInfoRangeTestCase(unittest
.TestCase
):
205 ctf
= bt2
.find_plugin("ctf")
206 self
._fs
= ctf
.source_component_classes
["fs"]
208 def test_trace_no_range(self
):
209 # This trace has no `timestamp_begin` and `timestamp_end` in its
210 # packet context. The `babeltrace.trace-info` query should omit
211 # the `range-ns` fields in the `trace` and `stream` data
214 res
= bt2
.QueryExecutor(
216 "babeltrace.trace-info",
217 {"inputs": [os
.path
.join(test_ctf_traces_path
, "succeed", "succeed1")]},
220 self
.assertEqual(len(res
), 1)
222 streams
= trace
["streams"]
223 self
.assertEqual(len(streams
), 1)
225 self
.assertRaises(KeyError, lambda: trace
['range-ns'])
226 self
.assertRaises(KeyError, lambda: streams
[0]['range-ns'])
229 class QueryTraceInfoPacketTimestampQuirksTestCase(unittest
.TestCase
):
231 ctf
= bt2
.find_plugin('ctf')
232 self
._fs
= ctf
.source_component_classes
['fs']
233 self
._path
= os
.path
.join(test_ctf_traces_path
, 'succeed')
235 def _test_lttng_quirks(self
, trace_name
):
236 res
= bt2
.QueryExecutor(
238 "babeltrace.trace-info",
239 {"inputs": [os
.path
.join(self
._path
, trace_name
)]},
242 self
.assertEqual(len(res
), 1)
245 def test_event_after_packet(self
):
246 trace
= self
._test
_lttng
_quirks
("lttng-event-after-packet")
247 streams
= trace
["streams"]
248 self
.assertEqual(len(streams
), 1)
250 self
.assertEqual(streams
[0]['range-ns']['begin'], 1565957300948091100)
251 self
.assertEqual(streams
[0]['range-ns']['end'], 1565957302180016069)
253 def test_lttng_crash(self
):
254 trace
= self
._test
_lttng
_quirks
("lttng-crash")
255 streams
= trace
["streams"]
256 self
.assertEqual(len(streams
), 1)
258 self
.assertEqual(streams
[0]['range-ns']['begin'], 1565891729288866738)
259 self
.assertEqual(streams
[0]['range-ns']['end'], 1565891729293526525)
262 if __name__
== '__main__':
This page took 0.037339 seconds and 5 git commands to generate.