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 if 'range-ns' in stream
:
30 return stream
['range-ns']['begin']
32 return stream
['paths'][0]
35 class QueryTraceInfoClockOffsetTestCase(unittest
.TestCase
):
37 ctf
= bt2
.find_plugin('ctf')
38 self
._fs
= ctf
.source_component_classes
['fs']
41 os
.path
.join(test_ctf_traces_path
, 'intersection', '3eventsintersect')
44 def _check(self
, trace
, offset
):
45 self
.assertEqual(trace
['range-ns']['begin'], 13515309000000000 + offset
)
46 self
.assertEqual(trace
['range-ns']['end'], 13515309000000120 + offset
)
48 trace
['intersection-range-ns']['begin'], 13515309000000070 + offset
51 trace
['intersection-range-ns']['end'], 13515309000000100 + offset
54 streams
= sorted(trace
['streams'], key
=sort_predictably
)
55 self
.assertEqual(streams
[0]['range-ns']['begin'], 13515309000000000 + offset
)
56 self
.assertEqual(streams
[0]['range-ns']['end'], 13515309000000100 + offset
)
57 self
.assertEqual(streams
[1]['range-ns']['begin'], 13515309000000070 + offset
)
58 self
.assertEqual(streams
[1]['range-ns']['end'], 13515309000000120 + offset
)
60 # Test various cominations of the clock-class-offset-s and
61 # clock-class-offset-ns parameters to babeltrace.trace-info queries.
63 # Without clock class offset
65 def test_no_clock_class_offset(self
):
66 res
= bt2
.QueryExecutor(
67 self
._fs
, 'babeltrace.trace-info', {'inputs': self
._inputs
}
72 # With clock-class-offset-s
74 def test_clock_class_offset_s(self
):
75 res
= bt2
.QueryExecutor(
77 'babeltrace.trace-info',
78 {'inputs': self
._inputs
, 'clock-class-offset-s': 2},
81 self
._check
(trace
, 2000000000)
83 # With clock-class-offset-ns
85 def test_clock_class_offset_ns(self
):
86 res
= bt2
.QueryExecutor(
88 'babeltrace.trace-info',
89 {'inputs': self
._inputs
, 'clock-class-offset-ns': 2},
96 def test_clock_class_offset_both(self
):
97 res
= bt2
.QueryExecutor(
99 'babeltrace.trace-info',
101 'inputs': self
._inputs
,
102 'clock-class-offset-s': -2,
103 'clock-class-offset-ns': -2,
107 self
._check
(trace
, -2000000002)
109 def test_clock_class_offset_s_wrong_type(self
):
110 with self
.assertRaises(bt2
._Error
):
113 'babeltrace.trace-info',
114 {'inputs': self
._inputs
, 'clock-class-offset-s': "2"},
117 def test_clock_class_offset_s_wrong_type_none(self
):
118 with self
.assertRaises(bt2
._Error
):
121 'babeltrace.trace-info',
122 {'inputs': self
._inputs
, 'clock-class-offset-s': None},
125 def test_clock_class_offset_ns_wrong_type(self
):
126 with self
.assertRaises(bt2
._Error
):
129 'babeltrace.trace-info',
130 {'inputs': self
._inputs
, 'clock-class-offset-ns': "2"},
133 def test_clock_class_offset_ns_wrong_type_none(self
):
134 with self
.assertRaises(bt2
._Error
):
137 'babeltrace.trace-info',
138 {'inputs': self
._inputs
, 'clock-class-offset-ns': None},
142 class QueryTraceInfoPortNameTestCase(unittest
.TestCase
):
144 ctf
= bt2
.find_plugin("ctf")
145 self
._fs
= ctf
.source_component_classes
["fs"]
147 def test_trace_uuid_stream_class_id_no_stream_id(self
):
148 res
= bt2
.QueryExecutor(
150 "babeltrace.trace-info",
154 test_ctf_traces_path
, "intersection", "3eventsintersect"
160 os_stream_path
= PurePosixPath(
161 '/tests/data/ctf-traces/intersection/3eventsintersect/'
163 if os
.environ
['BT_OS_TYPE'] == 'mingw':
164 os_stream_path
= PureWindowsPath(os_stream_path
)
166 self
.assertEqual(len(res
), 1)
168 streams
= sorted(trace
["streams"], key
=sort_predictably
)
169 self
.assertEqual(len(streams
), 2)
170 self
.assertRegexpMatches(
171 str(streams
[0]["port-name"]),
172 r
"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*"
173 + re
.escape(str(os_stream_path
/ "test_stream_0"))
176 self
.assertRegexpMatches(
177 str(streams
[1]["port-name"]),
178 r
"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*"
179 + re
.escape(str(os_stream_path
/ "test_stream_1"))
183 def test_trace_uuid_no_stream_class_id_no_stream_id(self
):
184 res
= bt2
.QueryExecutor(
186 "babeltrace.trace-info",
187 {"inputs": [os
.path
.join(test_ctf_traces_path
, "succeed", "succeed1")]},
190 os_stream_path
= PurePosixPath(
191 '/tests/data/ctf-traces/succeed/succeed1/dummystream'
193 if os
.environ
['BT_OS_TYPE'] == 'mingw':
194 os_stream_path
= PureWindowsPath(os_stream_path
)
196 self
.assertEqual(len(res
), 1)
198 streams
= sorted(trace
["streams"], key
=sort_predictably
)
199 self
.assertEqual(len(streams
), 1)
200 self
.assertRegexpMatches(
201 str(streams
[0]["port-name"]),
202 r
"^2a6422d0-6cee-11e0-8c08-cb07d7b3a564 \| .*"
203 + re
.escape(str(os_stream_path
))
208 class QueryTraceInfoRangeTestCase(unittest
.TestCase
):
210 ctf
= bt2
.find_plugin("ctf")
211 self
._fs
= ctf
.source_component_classes
["fs"]
213 def test_trace_no_range(self
):
214 # This trace has no `timestamp_begin` and `timestamp_end` in its
215 # packet context. The `babeltrace.trace-info` query should omit
216 # the `range-ns` fields in the `trace` and `stream` data
219 res
= bt2
.QueryExecutor(
221 "babeltrace.trace-info",
222 {"inputs": [os
.path
.join(test_ctf_traces_path
, "succeed", "succeed1")]},
225 self
.assertEqual(len(res
), 1)
227 streams
= trace
["streams"]
228 self
.assertEqual(len(streams
), 1)
230 self
.assertRaises(KeyError, lambda: trace
['range-ns'])
231 self
.assertRaises(KeyError, lambda: streams
[0]['range-ns'])
234 if __name__
== '__main__':
This page took 0.034339 seconds and 4 git commands to generate.