tests: Move to kernel style SPDX license identifiers
[lttng-tools.git] / tests / regression / ust / ust-dl / test_ust-dl.py
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("""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()
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
43 test_process = subprocess.Popen(test_path + "prog",
44 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
45 env=test_env)
46 test_process.wait()
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:
55 babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
56 except FileNotFoundError:
57 bail("Could not open babeltrace. Please make sure it is installed.", session_info)
58
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
71
72 for event_line in babeltrace_process.stdout:
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:
76 dlopen_event_found += 1
77 elif re.search(r".*lttng_ust_dl:dlmopen.*", event_line) is not None:
78 dlmopen_event_found += 1
79 elif re.search(r".*lttng_ust_dl:build_id.*", event_line) is not None:
80 build_id_event_found += 1
81 elif re.search(r".*lttng_ust_dl:debug_link.*", event_line) is not None:
82 debug_link_event_found += 1
83 elif re.search(r".*lttng_ust_dl:dlclose.*", event_line) is not None:
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
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
105 print_test_result(dlopen_event_found > 0, current_test, "lttng_ust_dl:dlopen event found in resulting trace")
106 current_test += 1
107
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
113 current_test += 1
114
115 print_test_result(build_id_event_found > 0, current_test, "lttng_ust_dl:build_id event found in resulting trace")
116 current_test += 1
117
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")
143 current_test += 1
144
145 shutil.rmtree(session_info.tmp_directory)
This page took 0.036398 seconds and 5 git commands to generate.