bt2: honor self component or query log level when logging
[babeltrace.git] / tests / plugins / src.ctf.fs / query / test_query_trace_info.py
CommitLineData
d907165c
SM
1# Copyright (C) 2019 Simon Marchi <simon.marchi@efficios.com>
2#
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
6# of the License.
7#
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.
12#
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.
16
17import unittest
18import bt2
19import os
a38d7650 20import re
f2bad367 21from pathlib import PureWindowsPath, PurePosixPath
d907165c
SM
22
23
bbff0ab4 24test_ctf_traces_path = os.environ['BT_CTF_TRACES_PATH']
d907165c
SM
25
26
1d4ac4b6
FD
27# Key to sort streams in a predictable order.
28def sort_predictably(stream):
29 if 'range-ns' in stream:
30 return stream['range-ns']['begin']
31 else:
32 return stream['paths'][0]
d907165c
SM
33
34
35class QueryTraceInfoClockOffsetTestCase(unittest.TestCase):
d907165c
SM
36 def setUp(self):
37 ctf = bt2.find_plugin('ctf')
38 self._fs = ctf.source_component_classes['fs']
39
73760435 40 self._inputs = [
cfbd7cf3
FD
41 os.path.join(test_ctf_traces_path, 'intersection', '3eventsintersect')
42 ]
d907165c
SM
43 self._executor = bt2.QueryExecutor()
44
45 def _check(self, trace, offset):
46 self.assertEqual(trace['range-ns']['begin'], 13515309000000000 + offset)
47 self.assertEqual(trace['range-ns']['end'], 13515309000000120 + offset)
cfbd7cf3
FD
48 self.assertEqual(
49 trace['intersection-range-ns']['begin'], 13515309000000070 + offset
50 )
51 self.assertEqual(
52 trace['intersection-range-ns']['end'], 13515309000000100 + offset
53 )
d907165c 54
1d4ac4b6 55 streams = sorted(trace['streams'], key=sort_predictably)
d907165c
SM
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)
60
61 # Test various cominations of the clock-class-offset-s and
1a29b831 62 # clock-class-offset-ns parameters to babeltrace.trace-info queries.
d907165c
SM
63
64 # Without clock class offset
65
66 def test_no_clock_class_offset(self):
1a29b831
PP
67 res = self._executor.query(
68 self._fs, 'babeltrace.trace-info', {'inputs': self._inputs}
69 )
d907165c
SM
70 trace = res[0]
71 self._check(trace, 0)
72
73 # With clock-class-offset-s
74
75 def test_clock_class_offset_s(self):
cfbd7cf3 76 res = self._executor.query(
1a29b831
PP
77 self._fs,
78 'babeltrace.trace-info',
79 {'inputs': self._inputs, 'clock-class-offset-s': 2},
cfbd7cf3 80 )
d907165c
SM
81 trace = res[0]
82 self._check(trace, 2000000000)
83
84 # With clock-class-offset-ns
85
86 def test_clock_class_offset_ns(self):
cfbd7cf3 87 res = self._executor.query(
1a29b831
PP
88 self._fs,
89 'babeltrace.trace-info',
90 {'inputs': self._inputs, 'clock-class-offset-ns': 2},
cfbd7cf3 91 )
d907165c
SM
92 trace = res[0]
93 self._check(trace, 2)
94
95 # With both, negative
96
97 def test_clock_class_offset_both(self):
cfbd7cf3
FD
98 res = self._executor.query(
99 self._fs,
1a29b831 100 'babeltrace.trace-info',
cfbd7cf3 101 {
73760435 102 'inputs': self._inputs,
cfbd7cf3
FD
103 'clock-class-offset-s': -2,
104 'clock-class-offset-ns': -2,
105 },
106 )
d907165c
SM
107 trace = res[0]
108 self._check(trace, -2000000002)
109
110 def test_clock_class_offset_s_wrong_type(self):
a635e507 111 with self.assertRaises(bt2._Error):
cfbd7cf3
FD
112 self._executor.query(
113 self._fs,
1a29b831 114 'babeltrace.trace-info',
73760435 115 {'inputs': self._inputs, 'clock-class-offset-s': "2"},
cfbd7cf3 116 )
d907165c
SM
117
118 def test_clock_class_offset_s_wrong_type_none(self):
a635e507 119 with self.assertRaises(bt2._Error):
cfbd7cf3
FD
120 self._executor.query(
121 self._fs,
1a29b831 122 'babeltrace.trace-info',
73760435 123 {'inputs': self._inputs, 'clock-class-offset-s': None},
cfbd7cf3 124 )
d907165c
SM
125
126 def test_clock_class_offset_ns_wrong_type(self):
a635e507 127 with self.assertRaises(bt2._Error):
cfbd7cf3
FD
128 self._executor.query(
129 self._fs,
1a29b831 130 'babeltrace.trace-info',
73760435 131 {'inputs': self._inputs, 'clock-class-offset-ns': "2"},
cfbd7cf3 132 )
d907165c
SM
133
134 def test_clock_class_offset_ns_wrong_type_none(self):
a635e507 135 with self.assertRaises(bt2._Error):
cfbd7cf3
FD
136 self._executor.query(
137 self._fs,
1a29b831 138 'babeltrace.trace-info',
73760435 139 {'inputs': self._inputs, 'clock-class-offset-ns': None},
cfbd7cf3 140 )
d907165c 141
a38d7650
SM
142
143class QueryTraceInfoPortNameTestCase(unittest.TestCase):
144 def setUp(self):
145 ctf = bt2.find_plugin("ctf")
146 self._fs = ctf.source_component_classes["fs"]
147
148 self._executor = bt2.QueryExecutor()
149
150 def test_trace_uuid_stream_class_id_no_stream_id(self):
151 res = self._executor.query(
152 self._fs,
1a29b831 153 "babeltrace.trace-info",
a38d7650 154 {
73760435 155 "inputs": [
a38d7650
SM
156 os.path.join(
157 test_ctf_traces_path, "intersection", "3eventsintersect"
158 )
159 ]
160 },
161 )
f2bad367
JR
162
163 os_stream_path = PurePosixPath(
164 '/tests/data/ctf-traces/intersection/3eventsintersect/'
165 )
166 if os.environ['BT_OS_TYPE'] == 'mingw':
167 os_stream_path = PureWindowsPath(os_stream_path)
168
a38d7650
SM
169 self.assertEqual(len(res), 1)
170 trace = res[0]
1d4ac4b6 171 streams = sorted(trace["streams"], key=sort_predictably)
a38d7650
SM
172 self.assertEqual(len(streams), 2)
173 self.assertRegexpMatches(
174 str(streams[0]["port-name"]),
f2bad367
JR
175 r"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*"
176 + re.escape(str(os_stream_path / "test_stream_0"))
177 + r"$",
a38d7650
SM
178 )
179 self.assertRegexpMatches(
180 str(streams[1]["port-name"]),
f2bad367
JR
181 r"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*"
182 + re.escape(str(os_stream_path / "test_stream_1"))
183 + r"$",
a38d7650
SM
184 )
185
186 def test_trace_uuid_no_stream_class_id_no_stream_id(self):
187 res = self._executor.query(
188 self._fs,
1a29b831 189 "babeltrace.trace-info",
73760435 190 {"inputs": [os.path.join(test_ctf_traces_path, "succeed", "succeed1")]},
a38d7650 191 )
f2bad367
JR
192
193 os_stream_path = PurePosixPath(
194 '/tests/data/ctf-traces/succeed/succeed1/dummystream'
195 )
196 if os.environ['BT_OS_TYPE'] == 'mingw':
197 os_stream_path = PureWindowsPath(os_stream_path)
198
a38d7650
SM
199 self.assertEqual(len(res), 1)
200 trace = res[0]
1d4ac4b6 201 streams = sorted(trace["streams"], key=sort_predictably)
a38d7650
SM
202 self.assertEqual(len(streams), 1)
203 self.assertRegexpMatches(
204 str(streams[0]["port-name"]),
f2bad367
JR
205 r"^2a6422d0-6cee-11e0-8c08-cb07d7b3a564 \| .*"
206 + re.escape(str(os_stream_path))
207 + r"$",
a38d7650
SM
208 )
209
210
1d4ac4b6
FD
211class QueryTraceInfoRangeTestCase(unittest.TestCase):
212 def setUp(self):
213 ctf = bt2.find_plugin("ctf")
214 self._fs = ctf.source_component_classes["fs"]
215
216 self._executor = bt2.QueryExecutor()
217
218 def test_trace_no_range(self):
1a29b831
PP
219 # This trace has no `timestamp_begin` and `timestamp_end` in its
220 # packet context. The `babeltrace.trace-info` query should omit
221 # the `range-ns` fields in the `trace` and `stream` data
222 # structures.
1d4ac4b6
FD
223
224 res = self._executor.query(
225 self._fs,
1a29b831 226 "babeltrace.trace-info",
73760435 227 {"inputs": [os.path.join(test_ctf_traces_path, "succeed", "succeed1")]},
1d4ac4b6
FD
228 )
229
230 self.assertEqual(len(res), 1)
231 trace = res[0]
232 streams = trace["streams"]
233 self.assertEqual(len(streams), 1)
234
235 self.assertRaises(KeyError, lambda: trace['range-ns'])
236 self.assertRaises(KeyError, lambda: streams[0]['range-ns'])
237
238
d907165c
SM
239if __name__ == '__main__':
240 unittest.main()
This page took 0.041565 seconds and 4 git commands to generate.