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