d7818186c08f9815a2cc79f59e697583e6c052d7
3 # Copyright (C) 2022 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 # Copyright (C) 2023 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 # SPDX-License-Identifier: GPL-2.0-only
11 from typing
import Any
, Callable
, Type
14 Test instrumentation coverage of C/C++ constructors and destructors by LTTng-UST
17 This test successively sets up a session, traces a test application, and then
18 reads the resulting trace to determine if all the expected events are present.
21 # Import in-tree test utils
22 test_utils_import_path
= pathlib
.Path(__file__
).absolute().parents
[3] / "utils"
23 sys
.path
.append(str(test_utils_import_path
))
29 {"name": "tp_so:constructor_c_provider_shared_library", "msg": None, "count": 0},
30 {"name": "tp_a:constructor_c_provider_static_archive", "msg": None, "count": 0},
32 "name": "tp_so:constructor_cplusplus_provider_shared_library",
33 "msg": "global - shared library define and provider",
37 "name": "tp_a:constructor_cplusplus_provider_static_archive",
38 "msg": "global - static archive define and provider",
41 {"name": "tp:constructor_c_across_units_before_define", "msg": None, "count": 0},
43 "name": "tp:constructor_cplusplus",
44 "msg": "global - across units before define",
47 {"name": "tp:constructor_c_same_unit_before_define", "msg": None, "count": 0},
48 {"name": "tp:constructor_c_same_unit_after_define", "msg": None, "count": 0},
50 "name": "tp:constructor_cplusplus",
51 "msg": "global - same unit before define",
55 "name": "tp:constructor_cplusplus",
56 "msg": "global - same unit after define",
59 {"name": "tp:constructor_c_across_units_after_define", "msg": None, "count": 0},
61 "name": "tp:constructor_cplusplus",
62 "msg": "global - across units after define",
65 {"name": "tp:constructor_c_same_unit_before_provider", "msg": None, "count": 0},
66 {"name": "tp:constructor_c_same_unit_after_provider", "msg": None, "count": 0},
68 "name": "tp:constructor_cplusplus",
69 "msg": "global - same unit before provider",
73 "name": "tp:constructor_cplusplus",
74 "msg": "global - same unit after provider",
77 {"name": "tp:constructor_c_across_units_after_provider", "msg": None, "count": 0},
79 "name": "tp:constructor_cplusplus",
80 "msg": "global - across units after provider",
83 {"name": "tp:constructor_cplusplus", "msg": "main() local", "count": 0},
85 "name": "tp_so:constructor_cplusplus_provider_shared_library",
86 "msg": "main() local - shared library define and provider",
90 "name": "tp_a:constructor_cplusplus_provider_static_archive",
91 "msg": "main() local - static archive define and provider",
94 {"name": "tp:main", "msg": None, "count": 0},
96 "name": "tp_a:destructor_cplusplus_provider_static_archive",
97 "msg": "main() local - static archive define and provider",
101 "name": "tp_so:destructor_cplusplus_provider_shared_library",
102 "msg": "main() local - shared library define and provider",
105 {"name": "tp:destructor_cplusplus", "msg": "main() local", "count": 0},
107 "name": "tp:destructor_cplusplus",
108 "msg": "global - across units after provider",
112 "name": "tp:destructor_cplusplus",
113 "msg": "global - same unit after provider",
117 "name": "tp:destructor_cplusplus",
118 "msg": "global - same unit before provider",
122 "name": "tp:destructor_cplusplus",
123 "msg": "global - across units after define",
127 "name": "tp:destructor_cplusplus",
128 "msg": "global - same unit after define",
132 "name": "tp:destructor_cplusplus",
133 "msg": "global - same unit before define",
137 "name": "tp:destructor_cplusplus",
138 "msg": "global - across units before define",
142 "name": "tp_a:destructor_cplusplus_provider_static_archive",
143 "msg": "global - static archive define and provider",
147 "name": "tp_so:destructor_cplusplus_provider_shared_library",
148 "msg": "global - shared library define and provider",
151 {"name": "tp:destructor_c_across_units_after_provider", "msg": None, "count": 0},
152 {"name": "tp:destructor_c_same_unit_after_provider", "msg": None, "count": 0},
153 {"name": "tp:destructor_c_same_unit_before_provider", "msg": None, "count": 0},
154 {"name": "tp:destructor_c_across_units_after_define", "msg": None, "count": 0},
155 {"name": "tp:destructor_c_same_unit_after_define", "msg": None, "count": 0},
156 {"name": "tp:destructor_c_same_unit_before_define", "msg": None, "count": 0},
157 {"name": "tp:destructor_c_across_units_before_define", "msg": None, "count": 0},
158 {"name": "tp_a:destructor_c_provider_static_archive", "msg": None, "count": 0},
159 {"name": "tp_so:destructor_c_provider_shared_library", "msg": None, "count": 0},
162 num_tests
= 7 + len(expected_events
)
165 def capture_trace(tap
, test_env
):
166 # type: (lttngtest.TapGenerator, lttngtest._Environment) -> lttngtest.LocalSessionOutputLocation
168 "Capture trace from application with instrumented C/C++ constructors/destructors"
171 session_output_location
= lttngtest
.LocalSessionOutputLocation(
172 test_env
.create_temporary_directory("trace")
175 client
= lttngtest
.LTTngClient(test_env
, log
=tap
.diagnostic
)
177 with tap
.case("Create a session") as test_case
:
178 session
= client
.create_session(output
=session_output_location
)
179 tap
.diagnostic("Created session `{session_name}`".format(session_name
=session
.name
))
182 "Add a channel to session `{session_name}`".format(session_name
=session
.name
)
184 channel
= session
.add_channel(lttngtest
.TracingDomain
.User
)
185 tap
.diagnostic("Created channel `{channel_name}`".format(channel_name
=channel
.name
))
187 # Enable all user space events, the default for a user tracepoint event rule.
188 channel
.add_recording_rule(lttngtest
.UserTracepointEventRule("tp*"))
191 "Start session `{session_name}`".format(session_name
=session
.name
)
195 test_app
= test_env
.launch_trace_test_constructor_application()
196 with tap
.case("Run test app".format(session_name
=session
.name
)) as test_case
:
197 test_app
.wait_for_exit()
200 "Stop session `{session_name}`".format(session_name
=session
.name
)
205 "Destroy session `{session_name}`".format(session_name
=session
.name
)
209 return session_output_location
212 def validate_trace(trace_location
, tap
):
213 # type: (pathlib.Path, lttngtest.TapGenerator)
214 unknown_event_count
= 0
216 for msg
in bt2
.TraceCollectionMessageIterator(str(trace_location
)):
217 if type(msg
) is not bt2
._EventMessageConst
:
221 for event
in expected_events
:
222 if event
["name"] == msg
.event
.name
and event
["msg"] is None:
224 event
["count"] = event
["count"] + 1
227 event
["name"] == msg
.event
.name
228 and event
["msg"] is not None
229 and event
["msg"] == msg
.event
["msg"]
232 event
["count"] = event
["count"] + 1
236 unknown_event_count
= unknown_event_count
+ 1
238 if "msg" in msg
.event
:
239 printmsg
= msg
.event
["msg"]
241 'Unexpected event name="{}" msg="{}" encountered'.format(
242 msg
.event
.name
, str(printmsg
)
246 for event
in expected_events
:
249 'Found expected event name="{}" msg="{}"'.format(
250 event
["name"], str(event
["msg"])
254 tap
.test(unknown_event_count
== 0, "Found no unexpected events")
257 tap
= lttngtest
.TapGenerator(num_tests
)
258 tap
.diagnostic("Test user space constructor/destructor instrumentation coverage")
260 with lttngtest
.test_environment(with_sessiond
=True, log
=tap
.diagnostic
) as test_env
:
261 outputlocation
= capture_trace(tap
, test_env
)
262 validate_trace(outputlocation
.path
, tap
)
264 sys
.exit(0 if tap
.is_successful
else 1)
This page took 0.038856 seconds and 4 git commands to generate.