1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
|
#!/usr/bin/env python3
#
# SPDX-FileCopyrightText: 2024 Kienan Stewart <kstewart@efficios.com>
# SPDX-License-Identifier: GPL-2.0-only
#
import copy
import pathlib
import sys
import os
import subprocess
from typing import Any, Callable, Type
# Import in-tree test utils
test_utils_import_path = pathlib.Path(__file__).absolute().parents[3] / "utils"
sys.path.append(str(test_utils_import_path))
import lttngtest
import bt2
# 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_common_cpp = [
{
"name": "tp:constructor_cplusplus",
"msg": "global - across units before define",
"count": 0,
"may_fail": compound_literal_on_heap,
},
{
"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_cplusplus",
"msg": "global - across units after define",
"count": 0,
"may_fail": compound_literal_on_heap,
},
{
"name": "tp:constructor_cplusplus",
"msg": "global - same unit before provider",
"count": 0,
"may_fail": compound_literal_on_heap,
},
{
"name": "tp:constructor_cplusplus",
"msg": "global - same unit after provider",
"count": 0,
},
{
"name": "tp:constructor_cplusplus",
"msg": "global - across units after provider",
"count": 0,
},
{"name": "tp:constructor_cplusplus", "msg": "main() local", "count": 0},
{"name": "tp:destructor_cplusplus", "msg": "main() local", "count": 0},
{
"name": "tp:destructor_cplusplus",
"msg": "global - across units after provider",
"count": 0,
},
{
"name": "tp:destructor_cplusplus",
"msg": "global - same unit after provider",
"count": 0,
},
{
"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,
},
]
expected_events_common = [
{
"name": "tp:constructor_c_across_units_before_define",
"msg": None,
"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_across_units_after_define",
"msg": None,
"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_across_units_after_provider", "msg": None, "count": 0},
{"name": "tp:main", "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,
},
]
expected_events_tp_so_cpp = [
{
"name": "tp_so:constructor_cplusplus_provider_shared_library",
"msg": "global - shared library define and provider",
"count": 0,
},
{
"name": "tp_so:constructor_cplusplus_provider_shared_library",
"msg": "main() local - shared library define and provider",
"count": 0,
},
{
"name": "tp_so:destructor_cplusplus_provider_shared_library",
"msg": "main() local - shared library define and provider",
"count": 0,
},
{
"name": "tp_so:destructor_cplusplus_provider_shared_library",
"msg": "global - shared library define and provider",
"count": 0,
},
]
expected_events_tp_so = [
{"name": "tp_so_c:constructor_c_provider_shared_library", "msg": None, "count": 0},
{"name": "tp_so_c:destructor_c_provider_shared_library", "msg": None, "count": 0},
]
expected_events_tp_a_cpp = [
{
"name": "tp_a:constructor_cplusplus_provider_static_archive",
"msg": "global - static archive define and provider",
"count": 0,
"may_fail": compound_literal_on_heap,
},
{
"name": "tp_a:constructor_cplusplus_provider_static_archive",
"msg": "main() local - static archive define and provider",
"count": 0,
},
{
"name": "tp_a:destructor_cplusplus_provider_static_archive",
"msg": "main() local - static archive define and provider",
"count": 0,
},
{
"name": "tp_a:destructor_cplusplus_provider_static_archive",
"msg": "global - static archive define and provider",
"count": 0,
"may_fail": compound_literal_on_heap,
},
]
expected_events_tp_a = [
{"name": "tp_a_c:constructor_c_provider_static_archive", "msg": None, "count": 0},
{"name": "tp_a_c:destructor_c_provider_static_archive", "msg": None, "count": 0},
]
def capture_trace(tap, test_env, application, description):
# type: (lttngtest.TapGenerator, lttngtest._Environment) -> lttngtest.LocalSessionOutputLocation
tap.diagnostic(description)
session_output_location = lttngtest.LocalSessionOutputLocation(
test_env.create_temporary_directory("trace")
)
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)
tap.diagnostic("Created session `{session_name}`".format(session_name=session.name))
with tap.case(
"Add a channel to session `{session_name}`".format(session_name=session.name)
) as test_case:
channel = session.add_channel(lttngtest.TracingDomain.User)
tap.diagnostic("Created channel `{channel_name}`".format(channel_name=channel.name))
# Enable all user space events, the default for a user tracepoint event rule.
channel.add_recording_rule(lttngtest.UserTracepointEventRule("tp*"))
with tap.case(
"Start session `{session_name}`".format(session_name=session.name)
) as test_case:
session.start()
test_app = test_env.launch_test_application(application)
with tap.case(
"Run test app '{}'".format(application, 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, expected_events):
# type: (pathlib.Path, lttngtest.TapGenerator)
unknown_event_count = 0
for msg in bt2.TraceCollectionMessageIterator(str(trace_location)):
if type(msg) is not bt2._EventMessageConst:
continue
found = False
for event in expected_events:
if event["name"] == msg.event.name and event["msg"] is None:
found = True
event["count"] = event["count"] + 1
break
elif (
event["name"] == msg.event.name
and event["msg"] is not None
and event["msg"] == msg.event["msg"]
):
found = True
event["count"] = event["count"] + 1
break
if found == False:
unknown_event_count = unknown_event_count + 1
printmsg = None
if "msg" in msg.event:
printmsg = msg.event["msg"]
tap.diagnostic(
'Unexpected event name="{}" msg="{}" encountered'.format(
msg.event.name, str(printmsg)
)
)
for event in expected_events:
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")
|