lib: make packets and packet messages optional, disabled by default
[babeltrace.git] / tests / bindings / python / bt2 / test_packet.py
1 #
2 # Copyright (C) 2019 EfficiOS Inc.
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; only version 2
7 # of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #
18
19 from collections import OrderedDict
20 import unittest
21 from utils import run_in_component_init
22
23
24 class PacketTestCase(unittest.TestCase):
25 @staticmethod
26 def _create_packet(with_pc):
27 def create_tc_cc(comp_self):
28 cc = comp_self._create_clock_class(frequency=1000, name='my_cc')
29 tc = comp_self._create_trace_class()
30 return cc, tc
31
32 clock_class, tc = run_in_component_init(create_tc_cc)
33
34 # stream event context
35 sec = tc.create_structure_field_class()
36 sec += OrderedDict((
37 ('cpu_id', tc.create_signed_integer_field_class(8)),
38 ('stuff', tc.create_real_field_class()),
39 ))
40
41 # packet context
42 pc = None
43 if with_pc:
44 pc = tc.create_structure_field_class()
45 pc += OrderedDict((
46 ('something', tc.create_signed_integer_field_class(8)),
47 ('something_else', tc.create_real_field_class()),
48 ('events_discarded', tc.create_unsigned_integer_field_class(64)),
49 ('packet_seq_num', tc.create_unsigned_integer_field_class(64)),
50 ))
51
52 # stream class
53 sc = tc.create_stream_class(default_clock_class=clock_class,
54 event_common_context_field_class=sec,
55 packet_context_field_class=pc,
56 supports_packets=True)
57
58 # event context
59 ec = tc.create_structure_field_class()
60 ec += OrderedDict((
61 ('ant', tc.create_signed_integer_field_class(16)),
62 ('msg', tc.create_string_field_class()),
63 ))
64
65 # event payload
66 ep = tc.create_structure_field_class()
67 ep += OrderedDict((
68 ('giraffe', tc.create_signed_integer_field_class(32)),
69 ('gnu', tc.create_signed_integer_field_class(8)),
70 ('mosquito', tc.create_signed_integer_field_class(8)),
71 ))
72
73 # event class
74 event_class = sc.create_event_class(name='ec', payload_field_class=ep)
75 event_class.common_context_field_class = ec
76
77 # trace
78 trace = tc()
79
80 # stream
81 stream = trace.create_stream(sc)
82
83 # packet
84 return stream.create_packet(), stream, pc
85
86 def test_attr_stream(self):
87 packet, stream, _ = self._create_packet(with_pc=True)
88 self.assertEqual(packet.stream.addr, stream.addr)
89
90 def test_context_field(self):
91 packet, stream, pc_fc = self._create_packet(with_pc=True)
92 self.assertEqual(packet.context_field.field_class.addr, pc_fc.addr)
93
94 def test_no_context_field(self):
95 packet, _, _ = self._create_packet(with_pc=False)
96 self.assertIsNone(packet.context_field)
This page took 0.030561 seconds and 4 git commands to generate.