Fix: sink.text.pretty: comma in enum fields
[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
20
21
22test_ctf_traces_path = os.environ['TEST_CTF_TRACES_PATH']
23
24
25# Key to streams by their being timestamp. Used to get the list of streams in
26# a predictable order.
27
28def sort_by_begin(stream):
29 return stream['range-ns']['begin']
30
31
32class QueryTraceInfoClockOffsetTestCase(unittest.TestCase):
33
34 def setUp(self):
35 ctf = bt2.find_plugin('ctf')
36 self._fs = ctf.source_component_classes['fs']
37
38 self._paths = [os.path.join(test_ctf_traces_path, 'intersection', '3eventsintersect')]
39 self._executor = bt2.QueryExecutor()
40
41 def _check(self, trace, offset):
42 self.assertEqual(trace['range-ns']['begin'], 13515309000000000 + offset)
43 self.assertEqual(trace['range-ns']['end'], 13515309000000120 + offset)
44 self.assertEqual(trace['intersection-range-ns']['begin'], 13515309000000070 + offset)
45 self.assertEqual(trace['intersection-range-ns']['end'], 13515309000000100 + offset)
46
47 streams = sorted(trace['streams'], key=sort_by_begin)
48 self.assertEqual(streams[0]['range-ns']['begin'], 13515309000000000 + offset)
49 self.assertEqual(streams[0]['range-ns']['end'], 13515309000000100 + offset)
50 self.assertEqual(streams[1]['range-ns']['begin'], 13515309000000070 + offset)
51 self.assertEqual(streams[1]['range-ns']['end'], 13515309000000120 + offset)
52
53 # Test various cominations of the clock-class-offset-s and
54 # clock-class-offset-ns parameters to trace-info queries.
55
56 # Without clock class offset
57
58 def test_no_clock_class_offset(self):
59 res = self._executor.query(self._fs, 'trace-info', {
60 'paths': self._paths,
61 })
62 trace = res[0]
63 self._check(trace, 0)
64
65 # With clock-class-offset-s
66
67 def test_clock_class_offset_s(self):
68 res = self._executor.query(self._fs, 'trace-info', {
69 'paths': self._paths,
70 'clock-class-offset-s': 2,
71 })
72 trace = res[0]
73 self._check(trace, 2000000000)
74
75 # With clock-class-offset-ns
76
77 def test_clock_class_offset_ns(self):
78 res = self._executor.query(self._fs, 'trace-info', {
79 'paths': self._paths,
80 'clock-class-offset-ns': 2,
81 })
82 trace = res[0]
83 self._check(trace, 2)
84
85 # With both, negative
86
87 def test_clock_class_offset_both(self):
88 res = self._executor.query(self._fs, 'trace-info', {
89 'paths': self._paths,
90 'clock-class-offset-s': -2,
91 'clock-class-offset-ns': -2,
92 })
93 trace = res[0]
94 self._check(trace, -2000000002)
95
96 def test_clock_class_offset_s_wrong_type(self):
97 with self.assertRaises(bt2.InvalidQueryParams):
98 self._executor.query(self._fs, 'trace-info', {
99 'paths': self._paths,
100 'clock-class-offset-s': "2",
101 })
102
103 def test_clock_class_offset_s_wrong_type_none(self):
104 with self.assertRaises(bt2.InvalidQueryParams):
105 self._executor.query(self._fs, 'trace-info', {
106 'paths': self._paths,
107 'clock-class-offset-s': None,
108 })
109
110 def test_clock_class_offset_ns_wrong_type(self):
111 with self.assertRaises(bt2.InvalidQueryParams):
112 self._executor.query(self._fs, 'trace-info', {
113 'paths': self._paths,
114 'clock-class-offset-ns': "2",
115 })
116
117 def test_clock_class_offset_ns_wrong_type_none(self):
118 with self.assertRaises(bt2.InvalidQueryParams):
119 self._executor.query(self._fs, 'trace-info', {
120 'paths': self._paths,
121 'clock-class-offset-ns': None,
122 })
123
124if __name__ == '__main__':
125 unittest.main()
This page took 0.027356 seconds and 4 git commands to generate.