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')
43 self
._executor
= bt2
.QueryExecutor()
45 def _check(self
, trace
, offset
):
46 self
.assertEqual(trace
['range-ns']['begin'], 13515309000000000 + offset
)
47 self
.assertEqual(trace
['range-ns']['end'], 13515309000000120 + offset
)
49 trace
['intersection-range-ns']['begin'], 13515309000000070 + offset
52 trace
['intersection-range-ns']['end'], 13515309000000100 + offset
55 streams
= sorted(trace
['streams'], key
=sort_predictably
)
56 self
.assertEqual(streams
[0]['range-ns']['begin'], 13515309000000000 + offset
)
57 self
.assertEqual(streams
[0]['range-ns']['end'], 13515309000000100 + offset
)
58 self
.assertEqual(streams
[1]['range-ns']['begin'], 13515309000000070 + offset
)
59 self
.assertEqual(streams
[1]['range-ns']['end'], 13515309000000120 + offset
)
61 # Test various cominations of the clock-class-offset-s and
62 # clock-class-offset-ns parameters to trace-info queries.
64 # Without clock class offset
66 def test_no_clock_class_offset(self
):
67 res
= self
._executor
.query(self
._fs
, 'trace-info', {'paths': self
._paths
})
71 # With clock-class-offset-s
73 def test_clock_class_offset_s(self
):
74 res
= self
._executor
.query(
75 self
._fs
, 'trace-info', {'paths': self
._paths
, 'clock-class-offset-s': 2}
78 self
._check
(trace
, 2000000000)
80 # With clock-class-offset-ns
82 def test_clock_class_offset_ns(self
):
83 res
= self
._executor
.query(
84 self
._fs
, 'trace-info', {'paths': self
._paths
, 'clock-class-offset-ns': 2}
91 def test_clock_class_offset_both(self
):
92 res
= self
._executor
.query(
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
.InvalidParams
):
106 self
._executor
.query(
109 {'paths': self
._paths
, 'clock-class-offset-s': "2"},
112 def test_clock_class_offset_s_wrong_type_none(self
):
113 with self
.assertRaises(bt2
.InvalidParams
):
114 self
._executor
.query(
117 {'paths': self
._paths
, 'clock-class-offset-s': None},
120 def test_clock_class_offset_ns_wrong_type(self
):
121 with self
.assertRaises(bt2
.InvalidParams
):
122 self
._executor
.query(
125 {'paths': self
._paths
, 'clock-class-offset-ns': "2"},
128 def test_clock_class_offset_ns_wrong_type_none(self
):
129 with self
.assertRaises(bt2
.InvalidParams
):
130 self
._executor
.query(
133 {'paths': self
._paths
, '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 self
._executor
= bt2
.QueryExecutor()
144 def test_trace_uuid_stream_class_id_no_stream_id(self
):
145 res
= self
._executor
.query(
151 test_ctf_traces_path
, "intersection", "3eventsintersect"
157 os_stream_path
= PurePosixPath(
158 '/tests/data/ctf-traces/intersection/3eventsintersect/'
160 if os
.environ
['BT_OS_TYPE'] == 'mingw':
161 os_stream_path
= PureWindowsPath(os_stream_path
)
163 self
.assertEqual(len(res
), 1)
165 streams
= sorted(trace
["streams"], key
=sort_predictably
)
166 self
.assertEqual(len(streams
), 2)
167 self
.assertRegexpMatches(
168 str(streams
[0]["port-name"]),
169 r
"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*"
170 + re
.escape(str(os_stream_path
/ "test_stream_0"))
173 self
.assertRegexpMatches(
174 str(streams
[1]["port-name"]),
175 r
"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*"
176 + re
.escape(str(os_stream_path
/ "test_stream_1"))
180 def test_trace_uuid_no_stream_class_id_no_stream_id(self
):
181 res
= self
._executor
.query(
184 {"paths": [os
.path
.join(test_ctf_traces_path
, "succeed", "succeed1")]},
187 os_stream_path
= PurePosixPath(
188 '/tests/data/ctf-traces/succeed/succeed1/dummystream'
190 if os
.environ
['BT_OS_TYPE'] == 'mingw':
191 os_stream_path
= PureWindowsPath(os_stream_path
)
193 self
.assertEqual(len(res
), 1)
195 streams
= sorted(trace
["streams"], key
=sort_predictably
)
196 self
.assertEqual(len(streams
), 1)
197 self
.assertRegexpMatches(
198 str(streams
[0]["port-name"]),
199 r
"^2a6422d0-6cee-11e0-8c08-cb07d7b3a564 \| .*"
200 + re
.escape(str(os_stream_path
))
205 class QueryTraceInfoRangeTestCase(unittest
.TestCase
):
207 ctf
= bt2
.find_plugin("ctf")
208 self
._fs
= ctf
.source_component_classes
["fs"]
210 self
._executor
= bt2
.QueryExecutor()
212 def test_trace_no_range(self
):
213 # This trace has no `timestamp_begin` and `timestamp_end` in its packet
214 # context. The `trace-info` query should omit the `range-ns` fields in
215 # the `trace` and `stream` data structures.
217 res
= self
._executor
.query(
220 {"paths": [os
.path
.join(test_ctf_traces_path
, "succeed", "succeed1")]},
223 self
.assertEqual(len(res
), 1)
225 streams
= trace
["streams"]
226 self
.assertEqual(len(streams
), 1)
228 self
.assertRaises(KeyError, lambda: trace
['range-ns'])
229 self
.assertRaises(KeyError, lambda: streams
[0]['range-ns'])
232 if __name__
== '__main__':
This page took 0.034213 seconds and 4 git commands to generate.