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 18:26:57 +0000 (13:26 -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>
src/bindings/python/bt2/bt2/trace_class.py
tests/bindings/python/bt2/test_trace.py
tests/bindings/python/bt2/test_trace_class.py

index 418639405a0fed653c62241ebe2bbb6c969447d2..a691da30d1492748a950d12cff8ea0a06fb8614d 100644 (file)
@@ -21,7 +21,7 @@ from bt2 import integer_range_set as bt2_integer_range_set
 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 e7aa18be209ca0d50d0350e9f4ec1746ad9a23ed..0ce6e1358a89c886043e9eb7545b4ef55300a1e2 100644 (file)
@@ -137,11 +137,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()
@@ -168,6 +172,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 4b861a0db82ecc2972171e8c3104ae42b620ed0c..fd5f8deb26b1a1f75691bbb14176103e7335a967 100644 (file)
@@ -172,9 +172,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()
@@ -191,6 +195,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.039555 seconds and 4 git commands to generate.