Tests: Add "linking" ust regression test
[lttng-tools.git] / tests / regression / ust / linking / test_linking.py
1 #!/usr/bin/env python3
2 #
3 # Copyright (C) - 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 #
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License, version 2 only, as
7 # published by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc., 51
16 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 import os
19 import subprocess
20 import re
21 import shutil
22 import sys
23
24 test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
25 test_utils_path = test_path
26 for i in range(4):
27 test_utils_path = os.path.dirname(test_utils_path)
28 test_utils_path = test_utils_path + "/utils"
29 sys.path.append(test_utils_path)
30 from test_utils import *
31
32
33 def check_ust_test_demo2_event(event_line, expected_int_field_value):
34 match = re.search(r".*ust_tests_demo2:loop.*", event_line)
35 if match is None:
36 return False
37 match = re.search(r".*intfield = (\d+)", event_line)
38 if match is None or int(match.group(1)) != expected_int_field_value:
39 return False
40 match = re.search(r".*longfield = (\d+)", event_line)
41 if match is None or int(match.group(1)) != expected_int_field_value:
42 return False
43 match = re.search(r".*netintfield = (\d+)", event_line)
44 if match is None or int(match.group(1)) != expected_int_field_value:
45 return False
46 match = re.search(r".*intfield2 = 0x(\d+)", event_line)
47 if match is None or int(match.group(1)) != expected_int_field_value:
48 return False
49 match = re.search(r".*netintfieldhex = 0x(\d+)", event_line)
50 if match is None or int(match.group(1)) != expected_int_field_value:
51 return False
52 match = re.search(r".*floatfield = (\d+)", event_line)
53 if match is None or int(match.group(1)) != 2222:
54 return False
55 match = re.search(r".*doublefield = (\d+)", event_line)
56 if match is None or int(match.group(1)) != 2:
57 return False
58 match = re.search(r".*_seqfield1_length = (\d+)", event_line)
59 if match is None or int(match.group(1)) != 4:
60 return False
61 match = re.search(r".*seqfield1 = \[ \[0\] = (\d+), \[1\] = (\d+), \[2\] = (\d+), \[3\] = (\d+) \]", event_line)
62 if match is None or int(match.group(1)) != 116 or int(match.group(2)) != 101 or int(match.group(3)) != 115 or int(match.group(4)) != 116:
63 return False
64 match = re.search(r".*arrfield1 = \[ \[0\] = (\d), \[1\] = (\d), \[2\] = (\d) \]", event_line)
65 if match is None or int(match.group(1)) != 1 or int(match.group(2)) != 2 or int(match.group(3)) != 3:
66 return False
67 match = re.search(r".*arrfield2 = \"([a-z]*)\"", event_line)
68 if match is None or match.group(1) != "test":
69 return False
70 match = re.search(r".*_seqfield2_length = (\d+)", event_line)
71 if match is None or int(match.group(1)) != 4:
72 return False
73 match = re.search(r".*seqfield2 = \"([a-z]*)\"", event_line)
74 if match is None or match.group(1) != "test":
75 return False
76 match = re.search(r".*stringfield = \"([a-z]*)\"", event_line)
77 if match is None or match.group(1) != "test":
78 return False
79
80 return True
81
82 NR_TESTS = 0
83 DYNAMIC_TEST_ENABLED = False
84
85 test_executables = [test_path + "demo_static", test_path + "demo_builtin"]
86 if os.path.exists(test_path + "demo"):
87 test_executables.append(test_path + "demo_preload")
88 NR_TESTS = 2
89 DYNAMIC_TEST_ENABLED = True
90
91 # Only enable tests that were compiled successfully
92 test_executables = [executable for executable in test_executables if os.path.exists(executable)]
93
94 NR_TESTS += len(test_executables) * 10
95
96 current_test = 1
97 print("1..{0}".format(NR_TESTS))
98
99 if NR_TESTS == 0:
100 print("# No test binary found")
101 exit(-1)
102
103 # Check if a sessiond is running... bail out if none found.
104 if session_daemon_alive() == 0:
105 bail("No sessiond running. Please make sure you are running this test with the \"run\" shell script and verify that the lttng tools are properly installed.")
106
107 if DYNAMIC_TEST_ENABLED:
108 session_info = create_session()
109 enable_ust_tracepoint_event(session_info, "ust_tests_demo*")
110 start_session(session_info)
111
112 # Dry run, no events should be logged
113 demo_process = subprocess.Popen(test_path + "demo", stdout=subprocess.PIPE, stderr=subprocess.PIPE)
114 if sys.version_info >= (3 ,3):
115 try:
116 demo_process.wait(5)
117 except TimeoutExpired:
118 demo_process.kill()
119 bail("Failed to run demo test application without preloading")
120 else:
121 demo_process.wait()
122 stop_session(session_info)
123
124 print_test_result(demo_process.returncode == 0, current_test,\
125 "Running application dynamically linked to providers, no preload")
126 current_test += 1
127 print_test_result(not os.path.exists(session_info.trace_path), current_test,\
128 "No events logged when running demo application without preloading providers")
129 current_test += 1
130
131 shutil.rmtree(session_info.tmp_directory)
132
133 for executable in test_executables:
134 executable_name = os.path.basename(executable)
135 session_info = create_session()
136 enable_ust_tracepoint_event(session_info, "ust_tests_demo*")
137 start_session(session_info)
138
139 demo_process = subprocess.Popen(executable, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
140 if sys.version_info >= (3, 3):
141 try:
142 demo_process.wait(5)
143 except TimeoutExpired:
144 demo_process.kill()
145 bail("Failed to run {0} test application".format(executable_name))
146 else:
147 demo_process.wait()
148 stop_session(session_info)
149
150 trace_found = os.path.exists(session_info.trace_path)
151 print_test_result(trace_found, current_test,\
152 "{0}, resulting trace found".format(executable_name))
153 current_test += 1
154
155 if not trace_found:
156 print("# Skipping " + executable_name + " trace verification tests")
157 continue
158
159 try:
160 babeltrace_process = subprocess.Popen(["babeltrace", session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
161 except FileNotFoundError:
162 bail("Could not open babeltrace. Please make sure it is installed.")
163
164 # We should find 8 events in the resulting trace
165 event_entries = []
166 for event_line in babeltrace_process.stdout:
167 event_line = event_line.decode('utf-8').replace("\n", "")
168 event_entries.append(event_line)
169
170 if len(event_entries) != 8:
171 bail("{0}, wrong number of events found in resulting trace.".format(executable_name))
172
173 shutil.rmtree(session_info.tmp_directory)
174
175 print_test_result(len(event_entries) == 8, current_test,\
176 "{0}, total number of events logged is correct".format(executable_name))
177 current_test += 1
178
179 # Check each loop event
180 match = re.search(r".*ust_tests_demo:starting.*value = (\d+) ", event_entries[0])
181 print_test_result(match is not None and (int(match.group(1)) == 123), current_test,\
182 "{0}, ust_tests_demo:starting event found in trace with a correct integer argument".format(executable_name))
183 current_test += 1
184
185 for i in range(5):
186 print_test_result(check_ust_test_demo2_event(event_entries[i+1], i), current_test,\
187 "{0}, ust_tests_demo2:loop event found in trace and arguments are correct, iteration ".format(executable_name)\
188 + str(i + 1))
189 current_test += 1
190
191 match = re.search(r".*ust_tests_demo:done.*value = (\d+)", event_entries[6])
192 print_test_result(match is not None and (int(match.group(1)) == 456), current_test,\
193 "{0}, ust_tests_demo:done event found in resulting trace with a correct integer argument".format(executable_name))
194 current_test += 1
195
196 match = re.search(r".*ust_tests_demo3:done.*value = (\d+)", event_entries[7])
197 print_test_result(match is not None and (int(match.group(1)) == 42), current_test,\
198 "{0}, ust_tests_demo3:done event found in resulting trace with a correct integer argument".format(executable_name))
199 current_test += 1
This page took 0.034415 seconds and 4 git commands to generate.