Fix: bt2: pass _TraceClassConst to destruction listeners
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 27 Nov 2023 20:41:31 +0000 (15:41 -0500)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 23 Jan 2024 20:27:35 +0000 (15:27 -0500)
Trace class destruction listeners currently receive a _TraceClass.  I
think it's a mistake, in that they should receive a _TraceClassConst.
Fix that, tweak the tests to test it.  Test the same thing for trace
destruction listeners (they didn't suffer from the same issue).

Change-Id: I4651ffc44c916d64f6e6f2944fa856b4ed5bb5f6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11447
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
(cherry picked from commit 2d6b60ff29423b918ac791f35d4f259178107cc1)
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11709
CI-Build: Philippe Proulx <eeppeliteloop@gmail.com>

src/bindings/python/bt2/bt2/trace_class.py
tests/bindings/python/bt2/test_trace.py
tests/bindings/python/bt2/test_trace_class.py

index 184de804bf1e614b41313e2d6ae50de588e2aabc..91c0980ff8a0190cb2f31ebe4c50556aed8067ce 100644 (file)
@@ -36,7 +36,7 @@ import bt2
 def _trace_class_destruction_listener_from_native(
     user_listener, handle, trace_class_ptr
 ):
-    trace_class = _TraceClass._create_from_ptr_and_get_ref(trace_class_ptr)
+    trace_class = _TraceClassConst._create_from_ptr_and_get_ref(trace_class_ptr)
     user_listener(trace_class)
     handle._invalidate()
 
index 70e70e7548003bb52bc3e7f3cf7b93dd4f7c3d2d..3b26826de6acf0fed0188b1665f60331b22f72d8 100644 (file)
@@ -149,11 +149,15 @@ class TraceTestCase(unittest.TestCase):
             num_trace_class_destroyed_calls += 1
 
         def on_trace_destruction(trace):
+            nonlocal type_of_passed_trace
+            type_of_passed_trace = type(trace)
+
             nonlocal num_trace_destroyed_calls
             num_trace_destroyed_calls += 1
 
         num_trace_class_destroyed_calls = 0
         num_trace_destroyed_calls = 0
+        type_of_passed_trace = None
 
         trace_class = get_default_trace_class()
         stream_class = trace_class.create_stream_class()
@@ -180,6 +184,7 @@ class TraceTestCase(unittest.TestCase):
 
         self.assertEqual(num_trace_class_destroyed_calls, 0)
         self.assertEqual(num_trace_destroyed_calls, 1)
+        self.assertIs(type_of_passed_trace, bt2_trace._TraceConst)
 
         del trace_class
 
index eca5274e03f13682eeb808d7049aee3083943d92..2fe61463f7d4d0f74c98d0c3cbf397599f9a905c 100644 (file)
@@ -184,9 +184,13 @@ class TraceClassTestCase(unittest.TestCase):
 
     def test_destruction_listener(self):
         def on_trace_class_destruction(trace_class):
+            nonlocal type_of_passed_trace_class
+            type_of_passed_trace_class = type(trace_class)
+
             nonlocal num_destruct_calls
             num_destruct_calls += 1
 
+        type_of_passed_trace_class = None
         num_destruct_calls = 0
 
         trace_class = get_default_trace_class()
@@ -203,6 +207,7 @@ class TraceClassTestCase(unittest.TestCase):
         del trace_class
 
         self.assertEqual(num_destruct_calls, 1)
+        self.assertIs(type_of_passed_trace_class, bt2_trace_class._TraceClassConst)
 
     def test_remove_destruction_listener_wrong_type(self):
         trace_class = get_default_trace_class()
This page took 0.029307 seconds and 4 git commands to generate.