| 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 | |
| 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 | |
| 23 | have_dlmopen = os.environ.get("LTTNG_TOOLS_HAVE_DLMOPEN") == "1" |
| 24 | |
| 25 | |
| 26 | NR_TESTS = 14 |
| 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: |
| 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 | |
| 38 | session_info = create_session() |
| 39 | enable_ust_tracepoint_event(session_info, "*") |
| 40 | start_session(session_info) |
| 41 | |
| 42 | test_env = os.environ.copy() |
| 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 |
| 45 | test_process = subprocess.Popen( |
| 46 | test_path + "prog", |
| 47 | stdout=subprocess.DEVNULL, |
| 48 | stderr=subprocess.DEVNULL, |
| 49 | env=test_env, |
| 50 | ) |
| 51 | test_process.wait() |
| 52 | |
| 53 | print_test_result( |
| 54 | test_process.returncode == 0, current_test, "Test application exited normally" |
| 55 | ) |
| 56 | current_test += 1 |
| 57 | |
| 58 | stop_session(session_info) |
| 59 | |
| 60 | # Check for dl events in the resulting trace |
| 61 | try: |
| 62 | babeltrace_process = subprocess.Popen( |
| 63 | [BABELTRACE_BIN, session_info.trace_path], |
| 64 | stdout=subprocess.PIPE, |
| 65 | stderr=subprocess.PIPE, |
| 66 | ) |
| 67 | except FileNotFoundError: |
| 68 | bail( |
| 69 | "Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN), |
| 70 | session_info, |
| 71 | ) |
| 72 | |
| 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 |
| 85 | |
| 86 | for 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 | |
| 114 | babeltrace_process.wait() |
| 115 | |
| 116 | print_test_result( |
| 117 | babeltrace_process.returncode == 0, current_test, "Resulting trace is readable" |
| 118 | ) |
| 119 | current_test += 1 |
| 120 | |
| 121 | print_test_result( |
| 122 | dlopen_event_found > 0, |
| 123 | current_test, |
| 124 | "lttng_ust_dl:dlopen event found in resulting trace", |
| 125 | ) |
| 126 | current_test += 1 |
| 127 | |
| 128 | if 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 | ) |
| 134 | else: |
| 135 | skip_test(current_test, "dlmopen() is not available") |
| 136 | |
| 137 | current_test += 1 |
| 138 | |
| 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 | ) |
| 144 | current_test += 1 |
| 145 | |
| 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 | ) |
| 151 | current_test += 1 |
| 152 | |
| 153 | print_test_result( |
| 154 | dlclose_event_found > 0, |
| 155 | current_test, |
| 156 | "lttng_ust_dl:dlclose event found in resulting trace", |
| 157 | ) |
| 158 | current_test += 1 |
| 159 | |
| 160 | print_test_result( |
| 161 | load_event_found > 0, |
| 162 | current_test, |
| 163 | "lttng_ust_lib:load event found in resulting trace", |
| 164 | ) |
| 165 | current_test += 1 |
| 166 | |
| 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 | ) |
| 172 | current_test += 1 |
| 173 | |
| 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 | ) |
| 179 | current_test += 1 |
| 180 | |
| 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 | ) |
| 186 | current_test += 1 |
| 187 | |
| 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 | ) |
| 193 | current_test += 1 |
| 194 | |
| 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 | ) |
| 200 | current_test += 1 |
| 201 | |
| 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 | ) |
| 207 | current_test += 1 |
| 208 | |
| 209 | shutil.rmtree(session_info.tmp_directory) |