From eead7a7694f1f7e4bfb7b9e62832da077c5a0f51 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 27 Nov 2023 15:41:31 -0500 Subject: [PATCH] Fix: bt2: pass _TraceClassConst to destruction listeners 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/11447 Tested-by: jenkins Reviewed-by: Philippe Proulx (cherry picked from commit 2d6b60ff29423b918ac791f35d4f259178107cc1) Reviewed-on: https://review.lttng.org/c/babeltrace/+/11709 CI-Build: Philippe Proulx --- src/bindings/python/bt2/bt2/trace_class.py | 2 +- tests/bindings/python/bt2/test_trace.py | 5 +++++ tests/bindings/python/bt2/test_trace_class.py | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bindings/python/bt2/bt2/trace_class.py b/src/bindings/python/bt2/bt2/trace_class.py index 184de804..91c0980f 100644 --- a/src/bindings/python/bt2/bt2/trace_class.py +++ b/src/bindings/python/bt2/bt2/trace_class.py @@ -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() diff --git a/tests/bindings/python/bt2/test_trace.py b/tests/bindings/python/bt2/test_trace.py index 70e70e75..3b26826d 100644 --- a/tests/bindings/python/bt2/test_trace.py +++ b/tests/bindings/python/bt2/test_trace.py @@ -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 diff --git a/tests/bindings/python/bt2/test_trace_class.py b/tests/bindings/python/bt2/test_trace_class.py index eca5274e..2fe61463 100644 --- a/tests/bindings/python/bt2/test_trace_class.py +++ b/tests/bindings/python/bt2/test_trace_class.py @@ -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() -- 2.34.1