Commit | Line | Data |
---|---|---|
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 | |
8 | import os | |
9 | import subprocess | |
10 | import re | |
11 | import shutil | |
12 | import sys | |
13 | ||
14 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" | |
15 | test_utils_path = test_path | |
16 | for i in range(4): | |
17 | test_utils_path = os.path.dirname(test_utils_path) | |
18 | test_utils_path = test_utils_path + "/utils" | |
19 | sys.path.append(test_utils_path) | |
20 | from test_utils import * | |
21 | ||
22 | ||
6a871bbe | 23 | have_dlmopen = os.environ.get("LTTNG_TOOLS_HAVE_DLMOPEN") == "1" |
bc1d8ca0 PP |
24 | |
25 | ||
3b8ab2d8 | 26 | NR_TESTS = 14 |
c70c42cc AB |
27 | current_test = 1 |
28 | print("1..{0}".format(NR_TESTS)) | |
29 | ||
30 | # Check if a sessiond is running... bail out if none found. | |
31 | if 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 | |
38 | session_info = create_session() | |
39 | enable_ust_tracepoint_event(session_info, "*") | |
40 | start_session(session_info) | |
41 | ||
42 | test_env = os.environ.copy() | |
1f8f19a4 JR |
43 | test_env["LD_PRELOAD"] = test_env.get("LD_PRELOAD", "") + ":liblttng-ust-dl.so" |
44 | test_env["LD_LIBRARY_PATH"] = test_env.get("LD_LIBRARY_PATH", "") + ":" + test_path | |
6a871bbe KS |
45 | test_process = subprocess.Popen( |
46 | test_path + "prog", | |
47 | stdout=subprocess.DEVNULL, | |
48 | stderr=subprocess.DEVNULL, | |
49 | env=test_env, | |
50 | ) | |
b6e2447a | 51 | test_process.wait() |
c70c42cc | 52 | |
6a871bbe KS |
53 | print_test_result( |
54 | test_process.returncode == 0, current_test, "Test application exited normally" | |
55 | ) | |
c70c42cc AB |
56 | current_test += 1 |
57 | ||
58 | stop_session(session_info) | |
59 | ||
60 | # Check for dl events in the resulting trace | |
61 | try: | |
6a871bbe KS |
62 | babeltrace_process = subprocess.Popen( |
63 | [BABELTRACE_BIN, session_info.trace_path], | |
64 | stdout=subprocess.PIPE, | |
65 | stderr=subprocess.PIPE, | |
66 | ) | |
c70c42cc | 67 | except 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 |
73 | dlopen_event_found = 0 |
74 | dlmopen_event_found = 0 | |
75 | build_id_event_found = 0 | |
76 | debug_link_event_found = 0 | |
77 | dlclose_event_found = 0 | |
78 | load_event_found = 0 | |
79 | load_build_id_event_found = 0 | |
80 | load_debug_link_event_found = 0 | |
81 | unload_event_found = 0 | |
82 | load_libfoo_found = 0 | |
83 | load_libbar_found = 0 | |
84 | load_libzzz_found = 0 | |
c70c42cc AB |
85 | |
86 | for 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 | |
114 | babeltrace_process.wait() | |
115 | ||
6a871bbe KS |
116 | print_test_result( |
117 | babeltrace_process.returncode == 0, current_test, "Resulting trace is readable" | |
118 | ) | |
c70c42cc AB |
119 | current_test += 1 |
120 | ||
6a871bbe KS |
121 | print_test_result( |
122 | dlopen_event_found > 0, | |
123 | current_test, | |
124 | "lttng_ust_dl:dlopen event found in resulting trace", | |
125 | ) | |
c70c42cc AB |
126 | current_test += 1 |
127 | ||
bc1d8ca0 | 128 | if 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 | 134 | else: |
6a871bbe | 135 | skip_test(current_test, "dlmopen() is not available") |
bc1d8ca0 | 136 | |
c70c42cc AB |
137 | current_test += 1 |
138 | ||
6a871bbe KS |
139 | print_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 |
144 | current_test += 1 |
145 | ||
6a871bbe KS |
146 | print_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 |
151 | current_test += 1 |
152 | ||
6a871bbe KS |
153 | print_test_result( |
154 | dlclose_event_found > 0, | |
155 | current_test, | |
156 | "lttng_ust_dl:dlclose event found in resulting trace", | |
157 | ) | |
d8ed06af MD |
158 | current_test += 1 |
159 | ||
6a871bbe KS |
160 | print_test_result( |
161 | load_event_found > 0, | |
162 | current_test, | |
163 | "lttng_ust_lib:load event found in resulting trace", | |
164 | ) | |
d8ed06af MD |
165 | current_test += 1 |
166 | ||
6a871bbe KS |
167 | print_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 |
172 | current_test += 1 |
173 | ||
6a871bbe KS |
174 | print_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 |
179 | current_test += 1 |
180 | ||
6a871bbe KS |
181 | print_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 |
186 | current_test += 1 |
187 | ||
6a871bbe KS |
188 | print_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 |
193 | current_test += 1 |
194 | ||
6a871bbe KS |
195 | print_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 |
200 | current_test += 1 |
201 | ||
6a871bbe KS |
202 | print_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 |
207 | current_test += 1 |
208 | ||
209 | shutil.rmtree(session_info.tmp_directory) |