Commit | Line | Data |
---|---|---|
c70c42cc AB |
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 | # This program is free software; you can redistribute it and/or modify it | |
7 | # under the terms of the GNU General Public License, version 2 only, as | |
8 | # published by the Free Software Foundation. | |
9 | # | |
10 | # This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | # more details. | |
14 | # | |
15 | # You should have received a copy of the GNU General Public License along with | |
16 | # this program; if not, write to the Free Software Foundation, Inc., 51 | |
17 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 | ||
19 | import os | |
20 | import subprocess | |
21 | import re | |
22 | import shutil | |
23 | import sys | |
24 | ||
25 | test_path = os.path.dirname(os.path.abspath(__file__)) + "/" | |
26 | test_utils_path = test_path | |
27 | for i in range(4): | |
28 | test_utils_path = os.path.dirname(test_utils_path) | |
29 | test_utils_path = test_utils_path + "/utils" | |
30 | sys.path.append(test_utils_path) | |
31 | from test_utils import * | |
32 | ||
33 | ||
3b8ab2d8 | 34 | NR_TESTS = 14 |
c70c42cc AB |
35 | current_test = 1 |
36 | print("1..{0}".format(NR_TESTS)) | |
37 | ||
38 | # Check if a sessiond is running... bail out if none found. | |
39 | if session_daemon_alive() == 0: | |
40 | bail("""No sessiond running. Please make sure you are running this test | |
41 | with the "run" shell script and verify that the lttng tools are | |
42 | properly installed.""") | |
43 | ||
44 | session_info = create_session() | |
45 | enable_ust_tracepoint_event(session_info, "*") | |
46 | start_session(session_info) | |
47 | ||
48 | test_env = os.environ.copy() | |
1f8f19a4 JR |
49 | test_env["LD_PRELOAD"] = test_env.get("LD_PRELOAD", "") + ":liblttng-ust-dl.so" |
50 | test_env["LD_LIBRARY_PATH"] = test_env.get("LD_LIBRARY_PATH", "") + ":" + test_path | |
c70c42cc | 51 | test_process = subprocess.Popen(test_path + "prog", |
5e7baece | 52 | stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, |
c70c42cc | 53 | env=test_env) |
b6e2447a | 54 | test_process.wait() |
c70c42cc AB |
55 | |
56 | print_test_result(test_process.returncode == 0, current_test, "Test application exited normally") | |
57 | current_test += 1 | |
58 | ||
59 | stop_session(session_info) | |
60 | ||
61 | # Check for dl events in the resulting trace | |
62 | try: | |
63 | babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
64 | except FileNotFoundError: | |
65 | bail("Could not open babeltrace. Please make sure it is installed.", session_info) | |
66 | ||
d8ed06af MD |
67 | dlopen_event_found = 0 |
68 | dlmopen_event_found = 0 | |
69 | build_id_event_found = 0 | |
70 | debug_link_event_found = 0 | |
71 | dlclose_event_found = 0 | |
72 | load_event_found = 0 | |
73 | load_build_id_event_found = 0 | |
74 | load_debug_link_event_found = 0 | |
75 | unload_event_found = 0 | |
76 | load_libfoo_found = 0 | |
77 | load_libbar_found = 0 | |
78 | load_libzzz_found = 0 | |
c70c42cc AB |
79 | |
80 | for event_line in babeltrace_process.stdout: | |
c70c42cc AB |
81 | |
82 | event_line = event_line.decode('utf-8').replace("\n", "") | |
83 | if re.search(r".*lttng_ust_dl:dlopen.*", event_line) is not None: | |
d8ed06af MD |
84 | dlopen_event_found += 1 |
85 | elif re.search(r".*lttng_ust_dl:dlmopen.*", event_line) is not None: | |
86 | dlmopen_event_found += 1 | |
c70c42cc | 87 | elif re.search(r".*lttng_ust_dl:build_id.*", event_line) is not None: |
d8ed06af | 88 | build_id_event_found += 1 |
c70c42cc | 89 | elif re.search(r".*lttng_ust_dl:debug_link.*", event_line) is not None: |
d8ed06af | 90 | debug_link_event_found += 1 |
c70c42cc | 91 | elif re.search(r".*lttng_ust_dl:dlclose.*", event_line) is not None: |
d8ed06af MD |
92 | dlclose_event_found += 1 |
93 | elif re.search(r".*lttng_ust_lib:build_id.*", event_line) is not None: | |
94 | load_build_id_event_found += 1 | |
95 | elif re.search(r".*lttng_ust_lib:debug_link.*", event_line) is not None: | |
96 | load_debug_link_event_found += 1 | |
97 | elif re.search(r".*lttng_ust_lib:unload.*", event_line) is not None: | |
98 | unload_event_found += 1 | |
99 | elif re.search(r".*lttng_ust_lib:load.*", event_line) is not None: | |
100 | load_event_found += 1 | |
101 | if re.search(r".*lttng_ust_lib:load.*libfoo.*", event_line) is not None: | |
102 | load_libfoo_found += 1 | |
103 | elif re.search(r".*lttng_ust_lib:load.*libbar.*", event_line) is not None: | |
104 | load_libbar_found += 1 | |
105 | elif re.search(r".*lttng_ust_lib:load.*libzzz.*", event_line) is not None: | |
106 | load_libzzz_found += 1 | |
c70c42cc AB |
107 | |
108 | babeltrace_process.wait() | |
109 | ||
110 | print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable") | |
111 | current_test += 1 | |
112 | ||
d8ed06af | 113 | print_test_result(dlopen_event_found > 0, current_test, "lttng_ust_dl:dlopen event found in resulting trace") |
c70c42cc AB |
114 | current_test += 1 |
115 | ||
d8ed06af | 116 | print_test_result(dlmopen_event_found > 0, current_test, "lttng_ust_dl:dlmopen event found in resulting trace") |
c70c42cc AB |
117 | current_test += 1 |
118 | ||
d8ed06af | 119 | print_test_result(build_id_event_found > 0, current_test, "lttng_ust_dl:build_id event found in resulting trace") |
c70c42cc AB |
120 | current_test += 1 |
121 | ||
d8ed06af MD |
122 | print_test_result(debug_link_event_found > 0, current_test, "lttng_ust_dl:debug_link event found in resulting trace") |
123 | current_test += 1 | |
124 | ||
125 | print_test_result(dlclose_event_found > 0, current_test, "lttng_ust_dl:dlclose event found in resulting trace") | |
126 | current_test += 1 | |
127 | ||
128 | print_test_result(load_event_found > 0, current_test, "lttng_ust_lib:load event found in resulting trace") | |
129 | current_test += 1 | |
130 | ||
131 | print_test_result(load_build_id_event_found > 0, current_test, "lttng_ust_lib:build_id event found in resulting trace") | |
132 | current_test += 1 | |
133 | ||
134 | print_test_result(load_debug_link_event_found > 0, current_test, "lttng_ust_lib:debug_link event found in resulting trace") | |
135 | current_test += 1 | |
136 | ||
137 | print_test_result(unload_event_found == 3, current_test, "lttng_ust_lib:unload event found 3 times in resulting trace") | |
138 | current_test += 1 | |
139 | ||
140 | print_test_result(load_libfoo_found == 1, current_test, "lttng_ust_lib:load libfoo.so event found once in resulting trace") | |
141 | current_test += 1 | |
142 | ||
143 | print_test_result(load_libbar_found == 1, current_test, "lttng_ust_lib:load libbar.so event found once in resulting trace") | |
144 | current_test += 1 | |
145 | ||
146 | print_test_result(load_libzzz_found == 1, current_test, "lttng_ust_lib:load libzzz.so event found once in resulting trace") | |
c70c42cc AB |
147 | current_test += 1 |
148 | ||
149 | shutil.rmtree(session_info.tmp_directory) |