X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=tests%2Fregression%2Fust%2Fust-constructor%2Ftest_ust_constructor.py;h=d7818186c08f9815a2cc79f59e697583e6c052d7;hb=03f7bb03e6c63b16e2992a53b4d9abab80fce07f;hp=5e6523c765bb5cc3a31bc15ae04fea5c591f0b5a;hpb=da1e97c944bb51fa96e89235240bc8bc8b02eeb4;p=lttng-tools.git diff --git a/tests/regression/ust/ust-constructor/test_ust_constructor.py b/tests/regression/ust/ust-constructor/test_ust_constructor.py index 5e6523c76..d7818186c 100755 --- a/tests/regression/ust/ust-constructor/test_ust_constructor.py +++ b/tests/regression/ust/ust-constructor/test_ust_constructor.py @@ -5,7 +5,6 @@ # # SPDX-License-Identifier: GPL-2.0-only -from cgi import test import pathlib import sys import os @@ -26,8 +25,6 @@ sys.path.append(str(test_utils_import_path)) import lttngtest import bt2 -num_tests = 3 - expected_events = [ {"name": "tp_so:constructor_c_provider_shared_library", "msg": None, "count": 0}, {"name": "tp_a:constructor_c_provider_static_archive", "msg": None, "count": 0}, @@ -162,10 +159,11 @@ expected_events = [ {"name": "tp_so:destructor_c_provider_shared_library", "msg": None, "count": 0}, ] +num_tests = 7 + len(expected_events) + -def capture_trace( - tap: lttngtest.TapGenerator, test_env: lttngtest._Environment -) -> lttngtest.LocalSessionOutputLocation: +def capture_trace(tap, test_env): + # type: (lttngtest.TapGenerator, lttngtest._Environment) -> lttngtest.LocalSessionOutputLocation tap.diagnostic( "Capture trace from application with instrumented C/C++ constructors/destructors" ) @@ -174,7 +172,7 @@ def capture_trace( test_env.create_temporary_directory("trace") ) - client: lttngtest.Controller = lttngtest.LTTngClient(test_env, log=tap.diagnostic) + client = lttngtest.LTTngClient(test_env, log=tap.diagnostic) with tap.case("Create a session") as test_case: session = client.create_session(output=session_output_location) @@ -189,16 +187,30 @@ def capture_trace( # Enable all user space events, the default for a user tracepoint event rule. channel.add_recording_rule(lttngtest.UserTracepointEventRule("tp*")) - session.start() + with tap.case( + "Start session `{session_name}`".format(session_name=session.name) + ) as test_case: + session.start() + test_app = test_env.launch_trace_test_constructor_application() - test_app.wait_for_exit() - session.stop() - session.destroy() + with tap.case("Run test app".format(session_name=session.name)) as test_case: + test_app.wait_for_exit() + + with tap.case( + "Stop session `{session_name}`".format(session_name=session.name) + ) as test_case: + session.stop() + + with tap.case( + "Destroy session `{session_name}`".format(session_name=session.name) + ) as test_case: + session.destroy() + return session_output_location -def validate_trace(trace_location: pathlib.Path, tap: lttngtest.TapGenerator) -> bool: - success = True +def validate_trace(trace_location, tap): + # type: (pathlib.Path, lttngtest.TapGenerator) unknown_event_count = 0 for msg in bt2.TraceCollectionMessageIterator(str(trace_location)): @@ -219,6 +231,7 @@ def validate_trace(trace_location: pathlib.Path, tap: lttngtest.TapGenerator) -> found = True event["count"] = event["count"] + 1 break + if found == False: unknown_event_count = unknown_event_count + 1 printmsg = None @@ -231,12 +244,14 @@ def validate_trace(trace_location: pathlib.Path, tap: lttngtest.TapGenerator) -> ) for event in expected_events: - if event["count"] != 1: - success = False - tap.diagnostic("Expected event {} not found".format(event["name"])) - if unknown_event_count != 0: - success = False - return success + tap.test( + event["count"] == 1, + 'Found expected event name="{}" msg="{}"'.format( + event["name"], str(event["msg"]) + ), + ) + + tap.test(unknown_event_count == 0, "Found no unexpected events") tap = lttngtest.TapGenerator(num_tests) @@ -244,9 +259,6 @@ tap.diagnostic("Test user space constructor/destructor instrumentation coverage" with lttngtest.test_environment(with_sessiond=True, log=tap.diagnostic) as test_env: outputlocation = capture_trace(tap, test_env) - tap.test( - validate_trace(outputlocation.path, tap), - "Validate that trace constains expected events", - ) + validate_trace(outputlocation.path, tap) sys.exit(0 if tap.is_successful else 1)