Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / tests / regression / ust / ust-dl / test_ust-dl.py
... / ...
CommitLineData
1#!/usr/bin/env python3
2#
3# Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4# Copyright (C) 2015 Antoine Busque <abusque@efficios.com>
5#
6# SPDX-License-Identifier: GPL-2.0-only
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
23have_dlmopen = os.environ.get("LTTNG_TOOLS_HAVE_DLMOPEN") == "1"
24
25
26NR_TESTS = 14
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:
32 bail(
33 """No sessiond running. Please make sure you are running this test
34 with the "run" shell script and verify that the lttng tools are
35 properly installed."""
36 )
37
38session_info = create_session()
39enable_ust_tracepoint_event(session_info, "*")
40start_session(session_info)
41
42test_env = os.environ.copy()
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
45test_process = subprocess.Popen(
46 test_path + "prog",
47 stdout=subprocess.DEVNULL,
48 stderr=subprocess.DEVNULL,
49 env=test_env,
50)
51test_process.wait()
52
53print_test_result(
54 test_process.returncode == 0, current_test, "Test application exited normally"
55)
56current_test += 1
57
58stop_session(session_info)
59
60# Check for dl events in the resulting trace
61try:
62 babeltrace_process = subprocess.Popen(
63 [BABELTRACE_BIN, session_info.trace_path],
64 stdout=subprocess.PIPE,
65 stderr=subprocess.PIPE,
66 )
67except FileNotFoundError:
68 bail(
69 "Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN),
70 session_info,
71 )
72
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
85
86for event_line in babeltrace_process.stdout:
87
88 event_line = event_line.decode("utf-8").replace("\n", "")
89 if re.search(r".*lttng_ust_dl:dlopen.*", event_line) is not None:
90 dlopen_event_found += 1
91 elif re.search(r".*lttng_ust_dl:dlmopen.*", event_line) is not None:
92 dlmopen_event_found += 1
93 elif re.search(r".*lttng_ust_dl:build_id.*", event_line) is not None:
94 build_id_event_found += 1
95 elif re.search(r".*lttng_ust_dl:debug_link.*", event_line) is not None:
96 debug_link_event_found += 1
97 elif re.search(r".*lttng_ust_dl:dlclose.*", event_line) is not None:
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
113
114babeltrace_process.wait()
115
116print_test_result(
117 babeltrace_process.returncode == 0, current_test, "Resulting trace is readable"
118)
119current_test += 1
120
121print_test_result(
122 dlopen_event_found > 0,
123 current_test,
124 "lttng_ust_dl:dlopen event found in resulting trace",
125)
126current_test += 1
127
128if have_dlmopen:
129 print_test_result(
130 dlmopen_event_found > 0,
131 current_test,
132 "lttng_ust_dl:dlmopen event found in resulting trace",
133 )
134else:
135 skip_test(current_test, "dlmopen() is not available")
136
137current_test += 1
138
139print_test_result(
140 build_id_event_found > 0,
141 current_test,
142 "lttng_ust_dl:build_id event found in resulting trace",
143)
144current_test += 1
145
146print_test_result(
147 debug_link_event_found > 0,
148 current_test,
149 "lttng_ust_dl:debug_link event found in resulting trace",
150)
151current_test += 1
152
153print_test_result(
154 dlclose_event_found > 0,
155 current_test,
156 "lttng_ust_dl:dlclose event found in resulting trace",
157)
158current_test += 1
159
160print_test_result(
161 load_event_found > 0,
162 current_test,
163 "lttng_ust_lib:load event found in resulting trace",
164)
165current_test += 1
166
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)
172current_test += 1
173
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)
179current_test += 1
180
181print_test_result(
182 unload_event_found == 3,
183 current_test,
184 "lttng_ust_lib:unload event found 3 times in resulting trace",
185)
186current_test += 1
187
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)
193current_test += 1
194
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)
200current_test += 1
201
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)
207current_test += 1
208
209shutil.rmtree(session_info.tmp_directory)
This page took 0.024484 seconds and 5 git commands to generate.