3 # Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 # Copyright (C) 2015 Antoine Busque <abusque@efficios.com>
6 # SPDX-License-Identifier: GPL-2.0-only
14 test_path
= os
.path
.dirname(os
.path
.abspath(__file__
)) + "/"
15 test_utils_path
= test_path
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 *
23 have_dlmopen
= (os
.environ
.get('LTTNG_TOOLS_HAVE_DLMOPEN') == '1')
28 print("1..{0}".format(NR_TESTS
))
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.""")
36 session_info
= create_session()
37 enable_ust_tracepoint_event(session_info
, "*")
38 start_session(session_info
)
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
,
48 print_test_result(test_process
.returncode
== 0, current_test
, "Test application exited normally")
51 stop_session(session_info
)
53 # Check for dl events in the resulting trace
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
)
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
65 load_build_id_event_found
= 0
66 load_debug_link_event_found
= 0
67 unload_event_found
= 0
72 for event_line
in babeltrace_process
.stdout
:
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:
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
100 babeltrace_process
.wait()
102 print_test_result(babeltrace_process
.returncode
== 0, current_test
, "Resulting trace is readable")
105 print_test_result(dlopen_event_found
> 0, current_test
, "lttng_ust_dl:dlopen event found in resulting trace")
109 print_test_result(dlmopen_event_found
> 0, current_test
, "lttng_ust_dl:dlmopen event found in resulting trace")
111 skip_test(current_test
, 'dlmopen() is not available')
115 print_test_result(build_id_event_found
> 0, current_test
, "lttng_ust_dl:build_id event found in resulting trace")
118 print_test_result(debug_link_event_found
> 0, current_test
, "lttng_ust_dl:debug_link event found in resulting trace")
121 print_test_result(dlclose_event_found
> 0, current_test
, "lttng_ust_dl:dlclose event found in resulting trace")
124 print_test_result(load_event_found
> 0, current_test
, "lttng_ust_lib:load event found in resulting trace")
127 print_test_result(load_build_id_event_found
> 0, current_test
, "lttng_ust_lib:build_id event found in resulting trace")
130 print_test_result(load_debug_link_event_found
> 0, current_test
, "lttng_ust_lib:debug_link event found in resulting trace")
133 print_test_result(unload_event_found
== 3, current_test
, "lttng_ust_lib:unload event found 3 times in resulting trace")
136 print_test_result(load_libfoo_found
== 1, current_test
, "lttng_ust_lib:load libfoo.so event found once in resulting trace")
139 print_test_result(load_libbar_found
== 1, current_test
, "lttng_ust_lib:load libbar.so event found once in resulting trace")
142 print_test_result(load_libzzz_found
== 1, current_test
, "lttng_ust_lib:load libzzz.so event found once in resulting trace")
145 shutil
.rmtree(session_info
.tmp_directory
)