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 | ||
bc1d8ca0 PP |
23 | have_dlmopen = (os.environ.get('LTTNG_TOOLS_HAVE_DLMOPEN') == '1') |
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: | |
32 | bail("""No sessiond running. Please make sure you are running this test | |
33 | with the "run" shell script and verify that the lttng tools are | |
34 | properly installed.""") | |
35 | ||
36 | session_info = create_session() | |
37 | enable_ust_tracepoint_event(session_info, "*") | |
38 | start_session(session_info) | |
39 | ||
40 | test_env = os.environ.copy() | |
1f8f19a4 JR |
41 | test_env["LD_PRELOAD"] = test_env.get("LD_PRELOAD", "") + ":liblttng-ust-dl.so" |
42 | test_env["LD_LIBRARY_PATH"] = test_env.get("LD_LIBRARY_PATH", "") + ":" + test_path | |
c70c42cc | 43 | test_process = subprocess.Popen(test_path + "prog", |
5e7baece | 44 | stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, |
c70c42cc | 45 | env=test_env) |
b6e2447a | 46 | test_process.wait() |
c70c42cc AB |
47 | |
48 | print_test_result(test_process.returncode == 0, current_test, "Test application exited normally") | |
49 | current_test += 1 | |
50 | ||
51 | stop_session(session_info) | |
52 | ||
53 | # Check for dl events in the resulting trace | |
54 | try: | |
c125de8f | 55 | babeltrace_process = subprocess.Popen([BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
c70c42cc | 56 | except FileNotFoundError: |
c125de8f | 57 | bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN), session_info) |
c70c42cc | 58 | |
d8ed06af MD |
59 | dlopen_event_found = 0 |
60 | dlmopen_event_found = 0 | |
61 | build_id_event_found = 0 | |
62 | debug_link_event_found = 0 | |
63 | dlclose_event_found = 0 | |
64 | load_event_found = 0 | |
65 | load_build_id_event_found = 0 | |
66 | load_debug_link_event_found = 0 | |
67 | unload_event_found = 0 | |
68 | load_libfoo_found = 0 | |
69 | load_libbar_found = 0 | |
70 | load_libzzz_found = 0 | |
c70c42cc AB |
71 | |
72 | for event_line in babeltrace_process.stdout: | |
c70c42cc AB |
73 | |
74 | event_line = event_line.decode('utf-8').replace("\n", "") | |
75 | if re.search(r".*lttng_ust_dl:dlopen.*", event_line) is not None: | |
d8ed06af MD |
76 | dlopen_event_found += 1 |
77 | elif re.search(r".*lttng_ust_dl:dlmopen.*", event_line) is not None: | |
78 | dlmopen_event_found += 1 | |
c70c42cc | 79 | elif re.search(r".*lttng_ust_dl:build_id.*", event_line) is not None: |
d8ed06af | 80 | build_id_event_found += 1 |
c70c42cc | 81 | elif re.search(r".*lttng_ust_dl:debug_link.*", event_line) is not None: |
d8ed06af | 82 | debug_link_event_found += 1 |
c70c42cc | 83 | elif re.search(r".*lttng_ust_dl:dlclose.*", event_line) is not None: |
d8ed06af MD |
84 | dlclose_event_found += 1 |
85 | elif re.search(r".*lttng_ust_lib:build_id.*", event_line) is not None: | |
86 | load_build_id_event_found += 1 | |
87 | elif re.search(r".*lttng_ust_lib:debug_link.*", event_line) is not None: | |
88 | load_debug_link_event_found += 1 | |
89 | elif re.search(r".*lttng_ust_lib:unload.*", event_line) is not None: | |
90 | unload_event_found += 1 | |
91 | elif re.search(r".*lttng_ust_lib:load.*", event_line) is not None: | |
92 | load_event_found += 1 | |
93 | if re.search(r".*lttng_ust_lib:load.*libfoo.*", event_line) is not None: | |
94 | load_libfoo_found += 1 | |
95 | elif re.search(r".*lttng_ust_lib:load.*libbar.*", event_line) is not None: | |
96 | load_libbar_found += 1 | |
97 | elif re.search(r".*lttng_ust_lib:load.*libzzz.*", event_line) is not None: | |
98 | load_libzzz_found += 1 | |
c70c42cc AB |
99 | |
100 | babeltrace_process.wait() | |
101 | ||
102 | print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable") | |
103 | current_test += 1 | |
104 | ||
d8ed06af | 105 | print_test_result(dlopen_event_found > 0, current_test, "lttng_ust_dl:dlopen event found in resulting trace") |
c70c42cc AB |
106 | current_test += 1 |
107 | ||
bc1d8ca0 PP |
108 | if have_dlmopen: |
109 | print_test_result(dlmopen_event_found > 0, current_test, "lttng_ust_dl:dlmopen event found in resulting trace") | |
110 | else: | |
111 | skip_test(current_test, 'dlmopen() is not available') | |
112 | ||
c70c42cc AB |
113 | current_test += 1 |
114 | ||
d8ed06af | 115 | print_test_result(build_id_event_found > 0, current_test, "lttng_ust_dl:build_id event found in resulting trace") |
c70c42cc AB |
116 | current_test += 1 |
117 | ||
d8ed06af MD |
118 | print_test_result(debug_link_event_found > 0, current_test, "lttng_ust_dl:debug_link event found in resulting trace") |
119 | current_test += 1 | |
120 | ||
121 | print_test_result(dlclose_event_found > 0, current_test, "lttng_ust_dl:dlclose event found in resulting trace") | |
122 | current_test += 1 | |
123 | ||
124 | print_test_result(load_event_found > 0, current_test, "lttng_ust_lib:load event found in resulting trace") | |
125 | current_test += 1 | |
126 | ||
127 | print_test_result(load_build_id_event_found > 0, current_test, "lttng_ust_lib:build_id event found in resulting trace") | |
128 | current_test += 1 | |
129 | ||
130 | print_test_result(load_debug_link_event_found > 0, current_test, "lttng_ust_lib:debug_link event found in resulting trace") | |
131 | current_test += 1 | |
132 | ||
133 | print_test_result(unload_event_found == 3, current_test, "lttng_ust_lib:unload event found 3 times in resulting trace") | |
134 | current_test += 1 | |
135 | ||
136 | print_test_result(load_libfoo_found == 1, current_test, "lttng_ust_lib:load libfoo.so event found once in resulting trace") | |
137 | current_test += 1 | |
138 | ||
139 | print_test_result(load_libbar_found == 1, current_test, "lttng_ust_lib:load libbar.so event found once in resulting trace") | |
140 | current_test += 1 | |
141 | ||
142 | print_test_result(load_libzzz_found == 1, current_test, "lttng_ust_lib:load libzzz.so event found once in resulting trace") | |
c70c42cc AB |
143 | current_test += 1 |
144 | ||
145 | shutil.rmtree(session_info.tmp_directory) |