Commit | Line | Data |
---|---|---|
75267569 JR |
1 | import pytest |
2 | import os | |
3 | import shutil | |
4 | import signal | |
5 | import subprocess | |
6 | ||
7 | import lttng_ivc.utils.ProjectFactory as ProjectFactory | |
8 | import lttng_ivc.utils.utils as utils | |
9 | import lttng_ivc.utils.runtime as Run | |
10 | import lttng_ivc.settings as Settings | |
11 | ||
12 | """ | |
13 | ||
14 | FC: Fully Compatible | |
15 | BC: Feature of the smallest version number will works. | |
16 | EU: Event unavailable for tracing | |
17 | ||
18 | +-----------------------------------------+-----+------+------+-------+ | |
19 | | LTTng UST tracepoint API/ABI: | | |
20 | | Probe provider vs LTTng UST library | | |
21 | +-----------------------------------------+-----+------+------+-------+ | |
22 | | Probe Provider / LTTng UST | 2.7 | 2.8 | 2.9 | 2.10 | | |
23 | +-----------------------------------------+-----+------+------+-------+ | |
24 | | 2.7 | FC | BC | BC | BC | | |
25 | | 2.8 | EU | FC | BC | BC | | |
26 | | 2.9 | EU | EU | FC | BC | | |
27 | | 2.10 | EU | EU | EU | FC | | |
28 | +-----------------------------------------+-----+------+------+-------+ | |
29 | ||
30 | Using tracepoint.h as a reference for change between version. | |
31 | ||
32 | Compile application with version under test (Probe Provider) tracepoints but do not link with provider. | |
33 | Build provider with version under test (Probe Provider) | |
34 | Launch application with provider using ld_preload. | |
35 | Validate that events are registered and present in trace. | |
36 | """ | |
37 | ||
38 | """ | |
39 | First tuple member: application lttng-ust version | |
40 | Second tuple member: reference (lttng-ust,lttng-tools) version | |
41 | Third tuple member: expected scenario | |
42 | """ | |
43 | ||
44 | """ | |
45 | We use lttng-tools instead of lttng-ust as second tuple since each | |
46 | lttng-tools is locked with the corresponding lttng-ust we want to test given | |
47 | that we use pre_cooked one. | |
48 | """ | |
49 | ||
50 | fail_provider = "fail_on_provider" | |
51 | fail_app = "fail_on_app" | |
52 | success = "success" | |
53 | ||
54 | test_matrix_enum = [ | |
55 | ("lttng-ust-2.7", "lttng-tools-2.7", fail_provider, 0), | |
56 | ("lttng-ust-2.7", "lttng-tools-2.8", fail_provider, 0), | |
57 | ("lttng-ust-2.7", "lttng-tools-2.9", fail_provider, 0), | |
58 | ("lttng-ust-2.7", "lttng-tools-2.10", fail_provider, 0), | |
59 | ("lttng-ust-2.8", "lttng-tools-2.7", success, 100), | |
60 | ("lttng-ust-2.8", "lttng-tools-2.8", success, 200), | |
61 | ("lttng-ust-2.8", "lttng-tools-2.9", success, 200), | |
62 | ("lttng-ust-2.8", "lttng-tools-2.10", success, 200), | |
63 | ("lttng-ust-2.9", "lttng-tools-2.7", success, 100), | |
64 | ("lttng-ust-2.9", "lttng-tools-2.8", success, 200), | |
65 | ("lttng-ust-2.9", "lttng-tools-2.9", success, 200), | |
66 | ("lttng-ust-2.9", "lttng-tools-2.10", success, 200), | |
67 | ("lttng-ust-2.10", "lttng-tools-2.7", success, 100), | |
68 | ("lttng-ust-2.10", "lttng-tools-2.8", success, 200), | |
69 | ("lttng-ust-2.10", "lttng-tools-2.9", success, 200), | |
70 | ("lttng-ust-2.10", "lttng-tools-2.10", success, 200), | |
71 | ] | |
72 | ||
73 | test_matrix_base = [ | |
74 | ("lttng-ust-2.7", "lttng-tools-2.7", success), | |
75 | ("lttng-ust-2.7", "lttng-tools-2.8", success), | |
76 | ("lttng-ust-2.7", "lttng-tools-2.9", success), | |
77 | ("lttng-ust-2.7", "lttng-tools-2.10", success), | |
78 | ("lttng-ust-2.8", "lttng-tools-2.7", success), | |
79 | ("lttng-ust-2.8", "lttng-tools-2.8", success), | |
80 | ("lttng-ust-2.8", "lttng-tools-2.9", success), | |
81 | ("lttng-ust-2.8", "lttng-tools-2.10", success), | |
82 | ("lttng-ust-2.9", "lttng-tools-2.7", success), | |
83 | ("lttng-ust-2.9", "lttng-tools-2.8", success), | |
84 | ("lttng-ust-2.9", "lttng-tools-2.9", success), | |
85 | ("lttng-ust-2.9", "lttng-tools-2.10", success), | |
86 | ("lttng-ust-2.10", "lttng-tools-2.7", success), | |
87 | ("lttng-ust-2.10", "lttng-tools-2.8", success), | |
88 | ("lttng-ust-2.10", "lttng-tools-2.9", success), | |
89 | ("lttng-ust-2.10", "lttng-tools-2.10", success), | |
90 | ] | |
91 | ||
92 | runtime_matrix_enum = [] | |
93 | runtime_matrix_base = [] | |
94 | ||
95 | if not Settings.test_only: | |
96 | runtime_matrix_enum = test_matrix_enum | |
97 | runtime_matrix_base = test_matrix_base | |
98 | else: | |
99 | for tup in test_matrix_enum: | |
100 | if (tup[0] in Settings.test_only or tup[1] in | |
101 | Settings.test_only): | |
102 | runtime_matrix_enum.append(tup) | |
103 | for tup in test_matrix_base: | |
104 | if (tup[0] in Settings.test_only or tup[1] in | |
105 | Settings.test_only): | |
106 | runtime_matrix_base.append(tup) | |
107 | ||
108 | @pytest.mark.parametrize("ust_label,tools_label,scenario, expected_event", runtime_matrix_enum) | |
109 | def test_ust_tracepoint_abi_api_vs_ust_enum(tmpdir, ust_label, tools_label, scenario, expected_event): | |
110 | ||
111 | nb_loop = 100 | |
112 | nb_expected_events = expected_event | |
113 | ||
114 | # Prepare environment | |
115 | ust = ProjectFactory.get_precook(ust_label) | |
116 | tools = ProjectFactory.get_precook(tools_label) | |
117 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
118 | ||
119 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
120 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
121 | app_path = os.path.join(str(tmpdir), "app") | |
122 | ||
123 | with Run.get_runtime(ust_runtime_path) as runtime_ust, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
124 | runtime_tools.add_project(tools) | |
125 | runtime_tools.add_project(babeltrace) | |
126 | ||
127 | runtime_ust.add_project(ust) | |
128 | runtime_ust.lttng_home = runtime_tools.lttng_home | |
129 | ||
130 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
131 | ||
132 | # Make application using the ust runtime | |
133 | shutil.copytree(Settings.apps_preload_provider_folder, app_path) | |
134 | ||
135 | # Use the testing env to make the probe | |
136 | if scenario == fail_provider: | |
137 | with pytest.raises(subprocess.CalledProcessError): | |
138 | runtime_ust.run("make provider-enum", cwd=app_path) | |
139 | return | |
140 | else: | |
141 | runtime_ust.run("make provider-enum", cwd=app_path) | |
142 | ||
143 | # Use the ust env to test tracepoint instrumentation | |
144 | if scenario == fail_app: | |
145 | with pytest.raises(subprocess.CalledProcessError): | |
146 | runtime_tools.run("make app-enum", cwd=app_path) | |
147 | return | |
148 | else: | |
149 | runtime_ust.run("make app-enum", cwd=app_path) | |
150 | ||
151 | # Start lttng-sessiond | |
152 | sessiond = utils.sessiond_spawn(runtime_tools) | |
153 | ||
154 | # Create session using mi to get path and session name | |
155 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
156 | ||
157 | runtime_tools.run('lttng enable-event -u tp:tptest,tp:tpenum') | |
158 | runtime_tools.run('lttng start') | |
159 | ||
160 | # Run application | |
161 | cmd = './app-enum {}'.format(nb_loop) | |
162 | runtime_tools.run(cmd, cwd=app_path, ld_preload="./libtp-enum.so") | |
163 | ||
164 | # Stop tracing | |
87e6d73a | 165 | runtime_tools.run('lttng stop') |
75267569 JR |
166 | runtime_tools.run('lttng destroy -a') |
167 | runtime_tools.subprocess_terminate(sessiond) | |
168 | ||
169 | ||
170 | # Read trace with babeltrace and check for event count via number of line | |
171 | cmd = 'babeltrace {}'.format(trace_path) | |
172 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
173 | assert(utils.line_count(cp_out) == nb_expected_events) | |
174 | ||
175 | @pytest.mark.parametrize("ust_label,tools_label,scenario", runtime_matrix_base) | |
176 | def test_ust_tracepoint_probe_abi_api_vs_ust_base(tmpdir, ust_label, tools_label, scenario): | |
177 | ||
178 | nb_loop = 100 | |
179 | nb_expected_events = 200 | |
180 | ||
181 | # Prepare environment | |
182 | ust = ProjectFactory.get_precook(ust_label) | |
183 | tools = ProjectFactory.get_precook(tools_label) | |
184 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
185 | ||
186 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
187 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
188 | app_path = os.path.join(str(tmpdir), "app") | |
189 | ||
190 | with Run.get_runtime(ust_runtime_path) as runtime_ust, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
191 | runtime_tools.add_project(tools) | |
192 | runtime_tools.add_project(babeltrace) | |
193 | ||
194 | runtime_ust.add_project(ust) | |
195 | runtime_ust.lttng_home = runtime_tools.lttng_home | |
196 | ||
197 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
198 | ||
199 | # Make application using the ust runtime | |
200 | shutil.copytree(Settings.apps_preload_provider_folder, app_path) | |
201 | ||
202 | # Use the testing env to make the probe | |
203 | runtime_ust.run("make provider", cwd=app_path) | |
204 | ||
205 | # Use the ust env to test tracepoint instrumentation | |
206 | runtime_ust.run("make app", cwd=app_path) | |
207 | ||
208 | # Start lttng-sessiond | |
209 | sessiond = utils.sessiond_spawn(runtime_tools) | |
210 | ||
211 | # Create session using mi to get path and session name | |
212 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
213 | ||
214 | runtime_tools.run('lttng enable-event -u tp:tptest,tp:tpenum') | |
215 | runtime_tools.run('lttng start') | |
216 | ||
217 | # Run application | |
218 | cmd = './app {}'.format(nb_loop) | |
219 | runtime_tools.run(cmd, cwd=app_path, ld_preload="./libtp.so") | |
220 | ||
221 | # Stop tracing | |
87e6d73a | 222 | runtime_tools.run('lttng stop') |
75267569 JR |
223 | runtime_tools.run('lttng destroy -a') |
224 | runtime_tools.subprocess_terminate(sessiond) | |
225 | ||
226 | ||
227 | # Read trace with babeltrace and check for event count via number of line | |
228 | cmd = 'babeltrace {}'.format(trace_path) | |
229 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
230 | assert(utils.line_count(cp_out) == nb_expected_events) |