Tests: use babeltrace2 for all tests
[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 # SPDX-License-Identifier: GPL-2.0-only
6
7 import os
8 import subprocess
9 import re
10 import shutil
11 import sys
12
13 test_path = os.path.dirname(os.path.abspath(__file__)) + "/"
14 test_utils_path = test_path
15 for i in range(4):
16 test_utils_path = os.path.dirname(test_utils_path)
17 test_utils_path = test_utils_path + "/utils"
18 sys.path.append(test_utils_path)
19 from test_utils import *
20
21
22 def check_ust_test_demo2_event(event_line, expected_int_field_value):
23 match = re.search(r".*ust_tests_demo2:loop.*", event_line)
24 if match is None:
25 return False
26 match = re.search(r".*intfield = (\d+)", event_line)
27 if match is None or int(match.group(1)) != expected_int_field_value:
28 return False
29 match = re.search(r".*longfield = (\d+)", event_line)
30 if match is None or int(match.group(1)) != expected_int_field_value:
31 return False
32 match = re.search(r".*netintfield = (\d+)", event_line)
33 if match is None or int(match.group(1)) != expected_int_field_value:
34 return False
35 match = re.search(r".*intfield2 = 0x(\d+)", event_line)
36 if match is None or int(match.group(1)) != expected_int_field_value:
37 return False
38 match = re.search(r".*netintfieldhex = 0x(\d+)", event_line)
39 if match is None or int(match.group(1)) != expected_int_field_value:
40 return False
41 match = re.search(r".*floatfield = (\d+)", event_line)
42 if match is None or int(match.group(1)) != 2222:
43 return False
44 match = re.search(r".*doublefield = (\d+)", event_line)
45 if match is None or int(match.group(1)) != 2:
46 return False
47 match = re.search(r".*_seqfield1_length = (\d+)", event_line)
48 if match is None or int(match.group(1)) != 4:
49 return False
50 match = re.search(r".*seqfield1 = \[ \[0\] = (\d+), \[1\] = (\d+), \[2\] = (\d+), \[3\] = (\d+) \]", event_line)
51 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:
52 return False
53 match = re.search(r".*arrfield1 = \[ \[0\] = (\d), \[1\] = (\d), \[2\] = (\d) \]", event_line)
54 if match is None or int(match.group(1)) != 1 or int(match.group(2)) != 2 or int(match.group(3)) != 3:
55 return False
56 match = re.search(r".*arrfield2 = \"([a-z]*)\"", event_line)
57 if match is None or match.group(1) != "test":
58 return False
59 match = re.search(r".*_seqfield2_length = (\d+)", event_line)
60 if match is None or int(match.group(1)) != 4:
61 return False
62 match = re.search(r".*seqfield2 = \"([a-z]*)\"", event_line)
63 if match is None or match.group(1) != "test":
64 return False
65 match = re.search(r".*stringfield = \"([a-z]*)\"", event_line)
66 if match is None or match.group(1) != "test":
67 return False
68
69 return True
70
71 NR_TESTS = 0
72 DYNAMIC_TEST_ENABLED = False
73
74 test_executables = [test_path + "demo_static", test_path + "demo_builtin"]
75 if os.path.exists(test_path + "demo"):
76 test_executables.append(test_path + "demo_preload")
77 NR_TESTS = 2
78 DYNAMIC_TEST_ENABLED = True
79
80 # Only enable tests that were compiled successfully
81 test_executables = [executable for executable in test_executables if os.path.exists(executable)]
82
83 NR_TESTS += len(test_executables) * 10
84
85 current_test = 1
86 print("1..{0}".format(NR_TESTS))
87
88 if NR_TESTS == 0:
89 print("# No test binary found")
90 exit(-1)
91
92 # Check if a sessiond is running... bail out if none found.
93 if session_daemon_alive() == 0:
94 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.")
95
96 if DYNAMIC_TEST_ENABLED:
97 session_info = create_session()
98 enable_ust_tracepoint_event(session_info, "ust_tests_demo*")
99 start_session(session_info)
100
101 # Dry run, no events should be logged
102 demo_process = subprocess.Popen(test_path + "demo", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
103 demo_process.wait()
104 stop_session(session_info)
105
106 print_test_result(demo_process.returncode == 0, current_test,\
107 "Running application dynamically linked to providers, no preload")
108 current_test += 1
109 trace_path = os.path.join(session_info.trace_path, "ust", "uid")
110 print_test_result(not os.path.exists(trace_path), current_test,\
111 "No events logged when running demo application without preloading providers")
112 current_test += 1
113
114 shutil.rmtree(session_info.tmp_directory)
115
116 for executable in test_executables:
117 executable_name = os.path.basename(executable)
118 session_info = create_session()
119 enable_ust_tracepoint_event(session_info, "ust_tests_demo*")
120 start_session(session_info)
121
122 demo_process = subprocess.Popen(executable, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
123 demo_process.wait()
124 stop_session(session_info)
125
126 trace_found = os.path.exists(session_info.trace_path)
127 print_test_result(trace_found, current_test,\
128 "{0}, resulting trace found".format(executable_name))
129 current_test += 1
130
131 if not trace_found:
132 print("# Skipping " + executable_name + " trace verification tests")
133 continue
134
135 try:
136 babeltrace_process = subprocess.Popen([BABELTRACE_BIN, session_info.trace_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
137 except FileNotFoundError:
138 bail("Could not open {}. Please make sure it is installed.".format(BABELTRACE_BIN))
139
140 # We should find 8 events in the resulting trace
141 event_entries = []
142 for event_line in babeltrace_process.stdout:
143 event_line = event_line.decode('utf-8').replace("\n", "")
144 event_entries.append(event_line)
145
146 if len(event_entries) != 8:
147 bail("{0}, wrong number of events found in resulting trace.".format(executable_name))
148
149 shutil.rmtree(session_info.tmp_directory)
150
151 print_test_result(len(event_entries) == 8, current_test,\
152 "{0}, total number of events logged is correct".format(executable_name))
153 current_test += 1
154
155 # Check each loop event
156 match = re.search(r".*ust_tests_demo:starting.*value = (\d+) ", event_entries[0])
157 print_test_result(match is not None and (int(match.group(1)) == 123), current_test,\
158 "{0}, ust_tests_demo:starting event found in trace with a correct integer argument".format(executable_name))
159 current_test += 1
160
161 for i in range(5):
162 print_test_result(check_ust_test_demo2_event(event_entries[i+1], i), current_test,\
163 "{0}, ust_tests_demo2:loop event found in trace and arguments are correct, iteration ".format(executable_name)\
164 + str(i + 1))
165 current_test += 1
166
167 match = re.search(r".*ust_tests_demo:done.*value = (\d+)", event_entries[6])
168 print_test_result(match is not None and (int(match.group(1)) == 456), current_test,\
169 "{0}, ust_tests_demo:done event found in resulting trace with a correct integer argument".format(executable_name))
170 current_test += 1
171
172 match = re.search(r".*ust_tests_demo3:done.*value = (\d+)", event_entries[7])
173 print_test_result(match is not None and (int(match.group(1)) == 42), current_test,\
174 "{0}, ust_tests_demo3:done event found in resulting trace with a correct integer argument".format(executable_name))
175 current_test += 1
This page took 0.034236 seconds and 4 git commands to generate.