From: Simon Marchi Date: Fri, 10 Apr 2020 20:31:32 +0000 (-0400) Subject: Fix: bt2: add precond. check, for stream class supporting discarded msgs with clock... X-Git-Tag: v2.0.3~6 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=bcc1b6cda412d8ea9ffc70dba6db12028b84a599 Fix: bt2: add precond. check, for stream class supporting discarded msgs with clock snapshot without clock class We hit the following precondition failure from the Python bindings when creating a stream class that supports discarded event messages with clock snapshots, but does not have a default clock class. Same with discarded packet messages. 04-10 16:40:32.280 59345 59345 F LIB/STREAM-CLASS bt_stream_class_set_supports_discarded_events@stream-class.c:480 Babeltrace 2 library precondition not satisfied; error is: 04-10 16:40:32.280 59345 59345 F LIB/STREAM-CLASS bt_stream_class_set_supports_discarded_events@stream-class.c:480 Stream class has no default clock class: addr=0x60f0000023e0, id=0, is-frozen=0, event-class-count=0, packet-context-fc-addr=(nil), event-common-context-fc-addr=(nil), assigns-auto-ec-id=1, assigns-auto-stream-id=1, supports-packets=0, packets-have-begin-default-cs=0, packets-have-end-default-cs=0, supports-discarded-events=0, discarded-events-have-default-cs=0, supports-discarded-packets=0, discarded-packets-have-default-cs=0, trace-class-addr=0x608000002b20, pcf-pool-size=0, pcf-pool-cap=0 04-10 16:40:32.280 59345 59345 F LIB/STREAM-CLASS bt_stream_class_set_supports_discarded_events@stream-class.c:480 Aborting... Add some checks for that in _StreamClass._validate_create_params, and some corresponding tests. Change-Id: I5d79b8ecfc05acbb79b7b15d28ba2c5c34f00729 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/3390 Tested-by: jenkins Reviewed-by: Philippe Proulx (cherry picked from commit aa7407227594c8e5ebff8e1944a902760f2c9a17) Reviewed-on: https://review.lttng.org/c/babeltrace/+/3364 CI-Build: Philippe Proulx --- diff --git a/src/bindings/python/bt2/bt2/stream_class.py b/src/bindings/python/bt2/bt2/stream_class.py index 4468d5d5..98925136 100644 --- a/src/bindings/python/bt2/bt2/stream_class.py +++ b/src/bindings/python/bt2/bt2/stream_class.py @@ -405,13 +405,16 @@ class _StreamClass(_StreamClassConst): utils._check_bool(supports_discarded_events) utils._check_bool(discarded_events_have_default_clock_snapshots) - if ( - not supports_discarded_events - and discarded_events_have_default_clock_snapshots - ): - raise ValueError( - 'cannot not support discarded events, but have default clock snapshots for discarded event messages' - ) + if discarded_events_have_default_clock_snapshots: + if not supports_discarded_events: + raise ValueError( + 'cannot not support discarded events, but have default clock snapshots for discarded event messages' + ) + + if default_clock_class is None: + raise ValueError( + 'cannot have no default clock class, but have default clock snapshots for discarded event messages' + ) # Discarded packets utils._check_bool(supports_discarded_packets) @@ -422,10 +425,13 @@ class _StreamClass(_StreamClassConst): 'cannot support discarded packets, but not support packets' ) - if ( - not supports_discarded_packets - and discarded_packets_have_default_clock_snapshots - ): - raise ValueError( - 'cannot not support discarded packets, but have default clock snapshots for discarded packet messages' - ) + if discarded_packets_have_default_clock_snapshots: + if not supports_discarded_packets: + raise ValueError( + 'cannot not support discarded packets, but have default clock snapshots for discarded packet messages' + ) + + if default_clock_class is None: + raise ValueError( + 'cannot have no default clock class, but have default clock snapshots for discarded packet messages' + ) diff --git a/tests/bindings/python/bt2/test_stream_class.py b/tests/bindings/python/bt2/test_stream_class.py index 09537ee8..69da9db8 100644 --- a/tests/bindings/python/bt2/test_stream_class.py +++ b/tests/bindings/python/bt2/test_stream_class.py @@ -357,6 +357,20 @@ class StreamClassTestCase(unittest.TestCase): self.assertEqual(len(self._tc), 0) + def test_supports_discarded_events_with_clock_snapshots_without_default_clock_class_raises( + self, + ): + with self.assertRaisesRegex( + ValueError, + 'cannot have no default clock class, but have default clock snapshots for discarded event messages', + ): + self._tc.create_stream_class( + supports_discarded_events=True, + discarded_events_have_default_clock_snapshots=True, + ) + + self.assertEqual(len(self._tc), 0) + def test_supports_discarded_packets_without_cs(self): sc = self._tc.create_stream_class( default_clock_class=self._cc, @@ -419,6 +433,21 @@ class StreamClassTestCase(unittest.TestCase): self.assertEqual(len(self._tc), 0) + def test_supports_discarded_packets_with_clock_snapshots_without_default_clock_class_raises( + self, + ): + with self.assertRaisesRegex( + ValueError, + 'cannot have no default clock class, but have default clock snapshots for discarded packet messages', + ): + self._tc.create_stream_class( + supports_packets=True, + supports_discarded_packets=True, + discarded_packets_have_default_clock_snapshots=True, + ) + + self.assertEqual(len(self._tc), 0) + def test_trace_class(self): sc = self._tc.create_stream_class() self.assertEqual(sc.trace_class.addr, self._tc.addr)