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