tests: Move to kernel style SPDX license identifiers
[lttng-tools.git] / tests / regression / ust / ust-dl / test_ust-dl.py
CommitLineData
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
8import os
9import subprocess
10import re
11import shutil
12import sys
13
14test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
15test_utils_path = test_path
16for i in range(4):
17 test_utils_path = os.path.dirname(test_utils_path)
18test_utils_path = test_utils_path + "/utils"
19sys.path.append(test_utils_path)
20from test_utils import *
21
22
bc1d8ca0
PP
23have_dlmopen = (os.environ.get('LTTNG_TOOLS_HAVE_DLMOPEN') == '1')
24
25
3b8ab2d8 26NR_TESTS = 14
c70c42cc
AB
27current_test = 1
28print("1..{0}".format(NR_TESTS))
29
30# Check if a sessiond is running... bail out if none found.
31if 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
36session_info = create_session()
37enable_ust_tracepoint_event(session_info, "*")
38start_session(session_info)
39
40test_env = os.environ.copy()
1f8f19a4
JR
41test_env["LD_PRELOAD"] = test_env.get("LD_PRELOAD", "") + ":liblttng-ust-dl.so"
42test_env["LD_LIBRARY_PATH"] = test_env.get("LD_LIBRARY_PATH", "") + ":" + test_path
c70c42cc 43test_process = subprocess.Popen(test_path + "prog",
5e7baece 44 stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
c70c42cc 45 env=test_env)
b6e2447a 46test_process.wait()
c70c42cc
AB
47
48print_test_result(test_process.returncode == 0, current_test, "Test application exited normally")
49current_test += 1
50
51stop_session(session_info)
52
53# Check for dl events in the resulting trace
54try:
55 babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
56except FileNotFoundError:
57 bail("Could not open babeltrace. Please make sure it is installed.", session_info)
58
d8ed06af
MD
59dlopen_event_found = 0
60dlmopen_event_found = 0
61build_id_event_found = 0
62debug_link_event_found = 0
63dlclose_event_found = 0
64load_event_found = 0
65load_build_id_event_found = 0
66load_debug_link_event_found = 0
67unload_event_found = 0
68load_libfoo_found = 0
69load_libbar_found = 0
70load_libzzz_found = 0
c70c42cc
AB
71
72for 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
100babeltrace_process.wait()
101
102print_test_result(babeltrace_process.returncode == 0, current_test, "Resulting trace is readable")
103current_test += 1
104
d8ed06af 105print_test_result(dlopen_event_found > 0, current_test, "lttng_ust_dl:dlopen event found in resulting trace")
c70c42cc
AB
106current_test += 1
107
bc1d8ca0
PP
108if have_dlmopen:
109 print_test_result(dlmopen_event_found > 0, current_test, "lttng_ust_dl:dlmopen event found in resulting trace")
110else:
111 skip_test(current_test, 'dlmopen() is not available')
112
c70c42cc
AB
113current_test += 1
114
d8ed06af 115print_test_result(build_id_event_found > 0, current_test, "lttng_ust_dl:build_id event found in resulting trace")
c70c42cc
AB
116current_test += 1
117
d8ed06af
MD
118print_test_result(debug_link_event_found > 0, current_test, "lttng_ust_dl:debug_link event found in resulting trace")
119current_test += 1
120
121print_test_result(dlclose_event_found > 0, current_test, "lttng_ust_dl:dlclose event found in resulting trace")
122current_test += 1
123
124print_test_result(load_event_found > 0, current_test, "lttng_ust_lib:load event found in resulting trace")
125current_test += 1
126
127print_test_result(load_build_id_event_found > 0, current_test, "lttng_ust_lib:build_id event found in resulting trace")
128current_test += 1
129
130print_test_result(load_debug_link_event_found > 0, current_test, "lttng_ust_lib:debug_link event found in resulting trace")
131current_test += 1
132
133print_test_result(unload_event_found == 3, current_test, "lttng_ust_lib:unload event found 3 times in resulting trace")
134current_test += 1
135
136print_test_result(load_libfoo_found == 1, current_test, "lttng_ust_lib:load libfoo.so event found once in resulting trace")
137current_test += 1
138
139print_test_result(load_libbar_found == 1, current_test, "lttng_ust_lib:load libbar.so event found once in resulting trace")
140current_test += 1
141
142print_test_result(load_libzzz_found == 1, current_test, "lttng_ust_lib:load libzzz.so event found once in resulting trace")
c70c42cc
AB
143current_test += 1
144
145shutil.rmtree(session_info.tmp_directory)
This page took 0.046733 seconds and 5 git commands to generate.