vscode: Add configurations to run the executables under the debugger
[lttng-tools.git] / tests / regression / ust / ust-dl / test_ust-dl.py
CommitLineData
c70c42cc
AB
1#!/usr/bin/env python3
2#
9d16b343
MJ
3# Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4# Copyright (C) 2015 Antoine Busque <abusque@efficios.com>
c70c42cc 5#
9d16b343 6# SPDX-License-Identifier: GPL-2.0-only
c70c42cc
AB
7
8import os
9import subprocess
10import re
11import shutil
12import sys
13
14test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
15test_utils_path = test_path
16for i in range(4):
17 test_utils_path = os.path.dirname(test_utils_path)
18test_utils_path = test_utils_path + "/utils"
19sys.path.append(test_utils_path)
20from test_utils import *
21
22
6a871bbe 23have_dlmopen = os.environ.get("LTTNG_TOOLS_HAVE_DLMOPEN") == "1"
bc1d8ca0
PP
24
25
3b8ab2d8 26NR_TESTS = 14
c70c42cc
AB
27current_test = 1
28print("1..{0}".format(NR_TESTS))
29
30# Check if a sessiond is running... bail out if none found.
31if session_daemon_alive() == 0:
6a871bbe
KS
32 bail(
33 """No sessiond running. Please make sure you are running this test
c70c42cc 34 with the "run" shell script and verify that the lttng tools are
6a871bbe
KS
35 properly installed."""
36 )
c70c42cc
AB
37
38session_info = create_session()
39enable_ust_tracepoint_event(session_info, "*")
40start_session(session_info)
41
42test_env = os.environ.copy()
1f8f19a4
JR
43test_env["LD_PRELOAD"] = test_env.get("LD_PRELOAD", "") + ":liblttng-ust-dl.so"
44test_env["LD_LIBRARY_PATH"] = test_env.get("LD_LIBRARY_PATH", "") + ":" + test_path
6a871bbe
KS
45test_process = subprocess.Popen(
46 test_path + "prog",
47 stdout=subprocess.DEVNULL,
48 stderr=subprocess.DEVNULL,
49 env=test_env,
50)
b6e2447a 51test_process.wait()
c70c42cc 52
6a871bbe
KS
53print_test_result(
54 test_process.returncode == 0, current_test, "Test application exited normally"
55)
c70c42cc
AB
56current_test += 1
57
58stop_session(session_info)
59
60# Check for dl events in the resulting trace
61try:
6a871bbe
KS
62 babeltrace_process = subprocess.Popen(
63 [BABELTRACE_BIN, session_info.trace_path],
64 stdout=subprocess.PIPE,
65 stderr=subprocess.PIPE,
66 )
c70c42cc 67except FileNotFoundError:
6a871bbe
KS
68 bail(
69 "Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN),
70 session_info,
71 )
c70c42cc 72
d8ed06af
MD
73dlopen_event_found = 0
74dlmopen_event_found = 0
75build_id_event_found = 0
76debug_link_event_found = 0
77dlclose_event_found = 0
78load_event_found = 0
79load_build_id_event_found = 0
80load_debug_link_event_found = 0
81unload_event_found = 0
82load_libfoo_found = 0
83load_libbar_found = 0
84load_libzzz_found = 0
c70c42cc
AB
85
86for event_line in babeltrace_process.stdout:
c70c42cc 87
6a871bbe 88 event_line = event_line.decode("utf-8").replace("\n", "")
c70c42cc 89 if re.search(r".*lttng_ust_dl:dlopen.*", event_line) is not None:
d8ed06af
MD
90 dlopen_event_found += 1
91 elif re.search(r".*lttng_ust_dl:dlmopen.*", event_line) is not None:
92 dlmopen_event_found += 1
c70c42cc 93 elif re.search(r".*lttng_ust_dl:build_id.*", event_line) is not None:
d8ed06af 94 build_id_event_found += 1
c70c42cc 95 elif re.search(r".*lttng_ust_dl:debug_link.*", event_line) is not None:
d8ed06af 96 debug_link_event_found += 1
c70c42cc 97 elif re.search(r".*lttng_ust_dl:dlclose.*", event_line) is not None:
d8ed06af
MD
98 dlclose_event_found += 1
99 elif re.search(r".*lttng_ust_lib:build_id.*", event_line) is not None:
100 load_build_id_event_found += 1
101 elif re.search(r".*lttng_ust_lib:debug_link.*", event_line) is not None:
102 load_debug_link_event_found += 1
103 elif re.search(r".*lttng_ust_lib:unload.*", event_line) is not None:
104 unload_event_found += 1
105 elif re.search(r".*lttng_ust_lib:load.*", event_line) is not None:
106 load_event_found += 1
107 if re.search(r".*lttng_ust_lib:load.*libfoo.*", event_line) is not None:
108 load_libfoo_found += 1
109 elif re.search(r".*lttng_ust_lib:load.*libbar.*", event_line) is not None:
110 load_libbar_found += 1
111 elif re.search(r".*lttng_ust_lib:load.*libzzz.*", event_line) is not None:
112 load_libzzz_found += 1
c70c42cc
AB
113
114babeltrace_process.wait()
115
6a871bbe
KS
116print_test_result(
117 babeltrace_process.returncode == 0, current_test, "Resulting trace is readable"
118)
c70c42cc
AB
119current_test += 1
120
6a871bbe
KS
121print_test_result(
122 dlopen_event_found > 0,
123 current_test,
124 "lttng_ust_dl:dlopen event found in resulting trace",
125)
c70c42cc
AB
126current_test += 1
127
bc1d8ca0 128if have_dlmopen:
6a871bbe
KS
129 print_test_result(
130 dlmopen_event_found > 0,
131 current_test,
132 "lttng_ust_dl:dlmopen event found in resulting trace",
133 )
bc1d8ca0 134else:
6a871bbe 135 skip_test(current_test, "dlmopen() is not available")
bc1d8ca0 136
c70c42cc
AB
137current_test += 1
138
6a871bbe
KS
139print_test_result(
140 build_id_event_found > 0,
141 current_test,
142 "lttng_ust_dl:build_id event found in resulting trace",
143)
c70c42cc
AB
144current_test += 1
145
6a871bbe
KS
146print_test_result(
147 debug_link_event_found > 0,
148 current_test,
149 "lttng_ust_dl:debug_link event found in resulting trace",
150)
d8ed06af
MD
151current_test += 1
152
6a871bbe
KS
153print_test_result(
154 dlclose_event_found > 0,
155 current_test,
156 "lttng_ust_dl:dlclose event found in resulting trace",
157)
d8ed06af
MD
158current_test += 1
159
6a871bbe
KS
160print_test_result(
161 load_event_found > 0,
162 current_test,
163 "lttng_ust_lib:load event found in resulting trace",
164)
d8ed06af
MD
165current_test += 1
166
6a871bbe
KS
167print_test_result(
168 load_build_id_event_found > 0,
169 current_test,
170 "lttng_ust_lib:build_id event found in resulting trace",
171)
d8ed06af
MD
172current_test += 1
173
6a871bbe
KS
174print_test_result(
175 load_debug_link_event_found > 0,
176 current_test,
177 "lttng_ust_lib:debug_link event found in resulting trace",
178)
d8ed06af
MD
179current_test += 1
180
6a871bbe
KS
181print_test_result(
182 unload_event_found == 3,
183 current_test,
184 "lttng_ust_lib:unload event found 3 times in resulting trace",
185)
d8ed06af
MD
186current_test += 1
187
6a871bbe
KS
188print_test_result(
189 load_libfoo_found == 1,
190 current_test,
191 "lttng_ust_lib:load libfoo.so event found once in resulting trace",
192)
d8ed06af
MD
193current_test += 1
194
6a871bbe
KS
195print_test_result(
196 load_libbar_found == 1,
197 current_test,
198 "lttng_ust_lib:load libbar.so event found once in resulting trace",
199)
d8ed06af
MD
200current_test += 1
201
6a871bbe
KS
202print_test_result(
203 load_libzzz_found == 1,
204 current_test,
205 "lttng_ust_lib:load libzzz.so event found once in resulting trace",
206)
c70c42cc
AB
207current_test += 1
208
209shutil.rmtree(session_info.tmp_directory)
This page took 0.061391 seconds and 5 git commands to generate.