X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Fregression%2Fust%2Fust-constructor%2Ftest_ust_constructor.py;h=f9d97e20b39af30f2b375f31c5282e877e2539b7;hb=ab4919b5b443ac46269a5ba9f6bd00f0cbd9f35b;hp=ea6a125d08b8d4d94045ffe4dc23c7bb44071dd5;hpb=d2455527078ecb1963372d67323a32e9be02cda2;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 ea6a125d0..f9d97e20b 100755 --- a/tests/regression/ust/ust-constructor/test_ust_constructor.py +++ b/tests/regression/ust/ust-constructor/test_ust_constructor.py @@ -5,10 +5,10 @@ # # SPDX-License-Identifier: GPL-2.0-only -from cgi import test import pathlib import sys import os +import subprocess from typing import Any, Callable, Type """ @@ -26,51 +26,110 @@ sys.path.append(str(test_utils_import_path)) import lttngtest import bt2 -num_tests = 3 +# Determine if LTTNG_UST_ALLOCATE_COMPOUND_LITERAL_ON_HEAP is set. This will +# affect if certain events may or may not be expected when compiling with +# C++. +# @see https://github.com/lttng/lttng-ust/blob/47fa3e4ed7ab43e034dc61fc1480f919f4ee51d0/include/lttng/ust-compiler.h#L51 +# +compound_literal_on_heap = False +process = subprocess.Popen( + [ + os.path.join( + str(test_utils_import_path), + "testapp", + "gen-ust-events-constructor", + "uses_heap", + ) + ] +) +process.wait() +if process.returncode == 0: + compound_literal_on_heap = True 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}, + { + "name": "tp_a:constructor_c_provider_static_archive", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, { "name": "tp_so:constructor_cplusplus_provider_shared_library", "msg": "global - shared library define and provider", "count": 0, }, { - "name": "tp_a:constructor_cplusplus_provider_static_archive", + "name": "tp_a_c:constructor_cplusplus_provider_static_archive", "msg": "global - static archive define and provider", "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_across_units_before_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, }, - {"name": "tp:constructor_c_across_units_before_define", "msg": None, "count": 0}, { "name": "tp:constructor_cplusplus", "msg": "global - across units before define", "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_same_unit_before_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_same_unit_after_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, }, - {"name": "tp:constructor_c_same_unit_before_define", "msg": None, "count": 0}, - {"name": "tp:constructor_c_same_unit_after_define", "msg": None, "count": 0}, { "name": "tp:constructor_cplusplus", "msg": "global - same unit before define", "count": 0, + "may_fail": compound_literal_on_heap, }, { "name": "tp:constructor_cplusplus", "msg": "global - same unit after define", "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_across_units_after_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, }, - {"name": "tp:constructor_c_across_units_after_define", "msg": None, "count": 0}, { "name": "tp:constructor_cplusplus", "msg": "global - across units after define", "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_same_unit_before_provider", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:constructor_c_same_unit_after_provider", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, }, - {"name": "tp:constructor_c_same_unit_before_provider", "msg": None, "count": 0}, - {"name": "tp:constructor_c_same_unit_after_provider", "msg": None, "count": 0}, { "name": "tp:constructor_cplusplus", "msg": "global - same unit before provider", "count": 0, + "may_fail": compound_literal_on_heap, }, { "name": "tp:constructor_cplusplus", @@ -120,48 +179,96 @@ expected_events = [ "name": "tp:destructor_cplusplus", "msg": "global - same unit before provider", "count": 0, + "may_fail": compound_literal_on_heap, }, { "name": "tp:destructor_cplusplus", "msg": "global - across units after define", "count": 0, + "may_fail": compound_literal_on_heap, }, { "name": "tp:destructor_cplusplus", "msg": "global - same unit after define", "count": 0, + "may_fail": compound_literal_on_heap, }, { "name": "tp:destructor_cplusplus", "msg": "global - same unit before define", "count": 0, + "may_fail": compound_literal_on_heap, }, { "name": "tp:destructor_cplusplus", "msg": "global - across units before define", "count": 0, + "may_fail": compound_literal_on_heap, }, { "name": "tp_a:destructor_cplusplus_provider_static_archive", "msg": "global - static archive define and provider", "count": 0, + "may_fail": compound_literal_on_heap, }, { "name": "tp_so:destructor_cplusplus_provider_shared_library", "msg": "global - shared library define and provider", "count": 0, }, - {"name": "tp:destructor_c_across_units_after_provider", "msg": None, "count": 0}, - {"name": "tp:destructor_c_same_unit_after_provider", "msg": None, "count": 0}, - {"name": "tp:destructor_c_same_unit_before_provider", "msg": None, "count": 0}, - {"name": "tp:destructor_c_across_units_after_define", "msg": None, "count": 0}, - {"name": "tp:destructor_c_same_unit_after_define", "msg": None, "count": 0}, - {"name": "tp:destructor_c_same_unit_before_define", "msg": None, "count": 0}, - {"name": "tp:destructor_c_across_units_before_define", "msg": None, "count": 0}, - {"name": "tp_a:destructor_c_provider_static_archive", "msg": None, "count": 0}, + { + "name": "tp:destructor_c_across_units_after_provider", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:destructor_c_same_unit_after_provider", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:destructor_c_same_unit_before_provider", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:destructor_c_across_units_after_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:destructor_c_same_unit_after_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:destructor_c_same_unit_before_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp:destructor_c_across_units_before_define", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, + { + "name": "tp_a_c:destructor_c_provider_static_archive", + "msg": None, + "count": 0, + "may_fail": compound_literal_on_heap, + }, {"name": "tp_so:destructor_c_provider_shared_library", "msg": None, "count": 0}, ] +num_tests = 7 + len(expected_events) + def capture_trace(tap, test_env): # type: (lttngtest.TapGenerator, lttngtest._Environment) -> lttngtest.LocalSessionOutputLocation @@ -173,7 +280,7 @@ def capture_trace(tap, test_env): 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) @@ -188,17 +295,30 @@ def capture_trace(tap, test_env): # 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, tap) -> bool: - # type: (pathlib.Path, 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 +339,7 @@ def validate_trace(trace_location, tap) -> bool: found = True event["count"] = event["count"] + 1 break + if found == False: unknown_event_count = unknown_event_count + 1 printmsg = None @@ -231,12 +352,18 @@ def validate_trace(trace_location, tap) -> bool: ) 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 + may_fail = "may_fail" in event.keys() and event["may_fail"] + if not may_fail: + tap.test( + event["count"] == 1, + 'Found expected event name="{}" msg="{}"'.format( + event["name"], str(event["msg"]) + ), + ), + else: + tap.skip("Event '{}' may or may not be recorded".format(event["name"])) + + tap.test(unknown_event_count == 0, "Found no unexpected events") tap = lttngtest.TapGenerator(num_tests) @@ -244,9 +371,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)