doc: Rename to babeltrace2
[babeltrace.git] / tests / plugins / ctf / 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
d907165c
SM
21
22
23test_ctf_traces_path = os.environ['TEST_CTF_TRACES_PATH']
24
25
26# Key to streams by their being timestamp. Used to get the list of streams in
27# a predictable order.
28
29def sort_by_begin(stream):
30 return stream['range-ns']['begin']
31
32
33class QueryTraceInfoClockOffsetTestCase(unittest.TestCase):
34
35 def setUp(self):
36 ctf = bt2.find_plugin('ctf')
37 self._fs = ctf.source_component_classes['fs']
38
39 self._paths = [os.path.join(test_ctf_traces_path, 'intersection', '3eventsintersect')]
40 self._executor = bt2.QueryExecutor()
41
42 def _check(self, trace, offset):
43 self.assertEqual(trace['range-ns']['begin'], 13515309000000000 + offset)
44 self.assertEqual(trace['range-ns']['end'], 13515309000000120 + offset)
45 self.assertEqual(trace['intersection-range-ns']['begin'], 13515309000000070 + offset)
46 self.assertEqual(trace['intersection-range-ns']['end'], 13515309000000100 + offset)
47
48 streams = sorted(trace['streams'], key=sort_by_begin)
49 self.assertEqual(streams[0]['range-ns']['begin'], 13515309000000000 + offset)
50 self.assertEqual(streams[0]['range-ns']['end'], 13515309000000100 + offset)
51 self.assertEqual(streams[1]['range-ns']['begin'], 13515309000000070 + offset)
52 self.assertEqual(streams[1]['range-ns']['end'], 13515309000000120 + offset)
53
54 # Test various cominations of the clock-class-offset-s and
55 # clock-class-offset-ns parameters to trace-info queries.
56
57 # Without clock class offset
58
59 def test_no_clock_class_offset(self):
60 res = self._executor.query(self._fs, 'trace-info', {
61 'paths': self._paths,
62 })
63 trace = res[0]
64 self._check(trace, 0)
65
66 # With clock-class-offset-s
67
68 def test_clock_class_offset_s(self):
69 res = self._executor.query(self._fs, 'trace-info', {
70 'paths': self._paths,
71 'clock-class-offset-s': 2,
72 })
73 trace = res[0]
74 self._check(trace, 2000000000)
75
76 # With clock-class-offset-ns
77
78 def test_clock_class_offset_ns(self):
79 res = self._executor.query(self._fs, 'trace-info', {
80 'paths': self._paths,
81 'clock-class-offset-ns': 2,
82 })
83 trace = res[0]
84 self._check(trace, 2)
85
86 # With both, negative
87
88 def test_clock_class_offset_both(self):
89 res = self._executor.query(self._fs, 'trace-info', {
90 'paths': self._paths,
91 'clock-class-offset-s': -2,
92 'clock-class-offset-ns': -2,
93 })
94 trace = res[0]
95 self._check(trace, -2000000002)
96
97 def test_clock_class_offset_s_wrong_type(self):
98 with self.assertRaises(bt2.InvalidQueryParams):
99 self._executor.query(self._fs, 'trace-info', {
100 'paths': self._paths,
101 'clock-class-offset-s': "2",
102 })
103
104 def test_clock_class_offset_s_wrong_type_none(self):
105 with self.assertRaises(bt2.InvalidQueryParams):
106 self._executor.query(self._fs, 'trace-info', {
107 'paths': self._paths,
108 'clock-class-offset-s': None,
109 })
110
111 def test_clock_class_offset_ns_wrong_type(self):
112 with self.assertRaises(bt2.InvalidQueryParams):
113 self._executor.query(self._fs, 'trace-info', {
114 'paths': self._paths,
115 'clock-class-offset-ns': "2",
116 })
117
118 def test_clock_class_offset_ns_wrong_type_none(self):
119 with self.assertRaises(bt2.InvalidQueryParams):
120 self._executor.query(self._fs, 'trace-info', {
121 'paths': self._paths,
122 'clock-class-offset-ns': None,
123 })
124
a38d7650
SM
125
126class QueryTraceInfoPortNameTestCase(unittest.TestCase):
127 def setUp(self):
128 ctf = bt2.find_plugin("ctf")
129 self._fs = ctf.source_component_classes["fs"]
130
131 self._executor = bt2.QueryExecutor()
132
133 def test_trace_uuid_stream_class_id_no_stream_id(self):
134 res = self._executor.query(
135 self._fs,
136 "trace-info",
137 {
138 "paths": [
139 os.path.join(
140 test_ctf_traces_path, "intersection", "3eventsintersect"
141 )
142 ]
143 },
144 )
145 self.assertEqual(len(res), 1)
146 trace = res[0]
147 streams = sorted(trace["streams"], key=sort_by_begin)
148 self.assertEqual(len(streams), 2)
149 self.assertRegexpMatches(
150 str(streams[0]["port-name"]),
151 r"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*/tests/ctf-traces/intersection/3eventsintersect/test_stream_0$",
152 )
153 self.assertRegexpMatches(
154 str(streams[1]["port-name"]),
155 r"^7afe8fbe-79b8-4f6a-bbc7-d0c782e7ddaf \| 0 \| .*/tests/ctf-traces/intersection/3eventsintersect/test_stream_1$",
156 )
157
158 def test_trace_uuid_no_stream_class_id_no_stream_id(self):
159 res = self._executor.query(
160 self._fs,
161 "trace-info",
162 {"paths": [os.path.join(test_ctf_traces_path, "succeed", "succeed1")]},
163 )
164 self.assertEqual(len(res), 1)
165 trace = res[0]
166 streams = sorted(trace["streams"], key=sort_by_begin)
167 self.assertEqual(len(streams), 1)
168 self.assertRegexpMatches(
169 str(streams[0]["port-name"]),
170 r"^2a6422d0-6cee-11e0-8c08-cb07d7b3a564 \| .*/tests/ctf-traces/succeed/succeed1/dummystream$",
171 )
172
173
d907165c
SM
174if __name__ == '__main__':
175 unittest.main()
This page took 0.030377 seconds and 4 git commands to generate.