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.
22 test_ctf_traces_path
= os
.environ
['TEST_CTF_TRACES_PATH']
25 # Key to streams by their being timestamp. Used to get the list of streams in
26 # a predictable order.
28 def sort_by_begin(stream
):
29 return stream
['range-ns']['begin']
32 class QueryTraceInfoClockOffsetTestCase(unittest
.TestCase
):
35 ctf
= bt2
.find_plugin('ctf')
36 self
._fs
= ctf
.source_component_classes
['fs']
38 self
._paths
= [os
.path
.join(test_ctf_traces_path
, 'intersection', '3eventsintersect')]
39 self
._executor
= bt2
.QueryExecutor()
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
)
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
)
53 # Test various cominations of the clock-class-offset-s and
54 # clock-class-offset-ns parameters to trace-info queries.
56 # Without clock class offset
58 def test_no_clock_class_offset(self
):
59 res
= self
._executor
.query(self
._fs
, 'trace-info', {
65 # With clock-class-offset-s
67 def test_clock_class_offset_s(self
):
68 res
= self
._executor
.query(self
._fs
, 'trace-info', {
70 'clock-class-offset-s': 2,
73 self
._check
(trace
, 2000000000)
75 # With clock-class-offset-ns
77 def test_clock_class_offset_ns(self
):
78 res
= self
._executor
.query(self
._fs
, 'trace-info', {
80 'clock-class-offset-ns': 2,
87 def test_clock_class_offset_both(self
):
88 res
= self
._executor
.query(self
._fs
, 'trace-info', {
90 'clock-class-offset-s': -2,
91 'clock-class-offset-ns': -2,
94 self
._check
(trace
, -2000000002)
96 def test_clock_class_offset_s_wrong_type(self
):
97 with self
.assertRaises(bt2
.InvalidQueryParams
):
98 self
._executor
.query(self
._fs
, 'trace-info', {
100 'clock-class-offset-s': "2",
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,
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",
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,
124 if __name__
== '__main__':
This page took 0.053754 seconds and 5 git commands to generate.