Fix: bt2: add precond. check, for stream class supporting discarded msgs with clock...
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 10 Apr 2020 20:31:32 +0000 (16:31 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 13 Apr 2020 13:44:33 +0000 (09:44 -0400)
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 <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3390
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
(cherry picked from commit aa7407227594c8e5ebff8e1944a902760f2c9a17)
Reviewed-on: https://review.lttng.org/c/babeltrace/+/3364
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

src/bindings/python/bt2/bt2/stream_class.py
tests/bindings/python/bt2/test_stream_class.py

index 4468d5d5696150597dfe91982b154dab259677e0..9892513630649ddf45378832aead0f3a48fc8fb2 100644 (file)
@@ -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'
+                )
index 09537ee85332e245d9414b79899691c4522ea859..69da9db8bbb2433d354a6d0b06b493ddfe0b33a7 100644 (file)
@@ -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)
This page took 0.026267 seconds and 4 git commands to generate.