Licensing information
[deliverable/lttng-ivc.git] / lttng_ivc / tests / ust_tracepoint_ABI-API_vs_ust / test_ust_tracepoint_ABI_API_vs_ust.py
1 # Copyright (c) 2017 Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy
4 # of this software and associated documentation files (the "Software"), to deal
5 # in the Software without restriction, including without limitation the rights
6 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 # copies of the Software, and to permit persons to whom the Software is
8 # furnished to do so, subject to the following conditions:
9 #
10 # The above copyright notice and this permission notice shall be included in all
11 # copies or substantial portions of the Software.
12 #
13 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 # SOFTWARE.
20
21 import pytest
22 import os
23 import shutil
24 import signal
25 import subprocess
26
27 import lttng_ivc.utils.ProjectFactory as ProjectFactory
28 import lttng_ivc.utils.utils as utils
29 import lttng_ivc.utils.runtime as Run
30 import lttng_ivc.settings as Settings
31
32 """
33
34 FC: Fully Compatible
35 BC: Feature of the smallest version number will works.
36
37 +-----------------------------------------+-----+------+------+-------+
38 | LTTng UST tracepoint instrumentation API/ABI: |
39 | Application vs LTTng UST library |
40 +-----------------------------------------+-----+------+------+-------+
41 | Application Instrumentation / LTTng UST | 2.7 | 2.8 | 2.9 | 2.10 |
42 +-----------------------------------------+-----+------+------+-------+
43 | 2.7 | FC | BC | BC | BC |
44 | 2.8 | BC | FC | BC | BC |
45 | 2.9 | BC | BC | FC | BC |
46 | 2.10 | BC | BC | BC | FC |
47 +-----------------------------------------+-----+------+------+-------+
48
49 Using tracepoint.h as a reference for change between version.
50
51 Compile application with under test version (Application instrumentation) tracepoints but do not link with provider.
52 Build provider with reference version (ust)
53 Launch application with provider using ld_preload.
54 Validate that events are registered.
55
56 """
57
58 """
59 First tuple member: application lttng-ust version
60 Second tuple member: reference (lttng-ust,lttng-tools) version
61 Third tuple member: expected scenario
62 """
63
64 """
65 We use lttng-tools instead of lttng-ust as second tuple since each
66 lttng-tools is locked with the corresponding lttng-ust we want to test given
67 that we use pre_cooked one.
68 """
69
70 fail_provider = "fail_on_provider"
71 fail_app = "fail_on_app"
72 success = "success"
73
74 test_matrix_enum = [
75 ("lttng-ust-2.7", "lttng-tools-2.7", fail_provider),
76 ("lttng-ust-2.7", "lttng-tools-2.8", fail_app),
77 ("lttng-ust-2.7", "lttng-tools-2.9", fail_app),
78 ("lttng-ust-2.7", "lttng-tools-2.10", fail_app),
79 ("lttng-ust-2.8", "lttng-tools-2.7", fail_provider),
80 ("lttng-ust-2.8", "lttng-tools-2.8", success),
81 ("lttng-ust-2.8", "lttng-tools-2.9", success),
82 ("lttng-ust-2.8", "lttng-tools-2.10", success),
83 ("lttng-ust-2.9", "lttng-tools-2.7", fail_provider),
84 ("lttng-ust-2.9", "lttng-tools-2.8", success),
85 ("lttng-ust-2.9", "lttng-tools-2.9", success),
86 ("lttng-ust-2.9", "lttng-tools-2.10", success),
87 ("lttng-ust-2.10", "lttng-tools-2.7", fail_provider),
88 ("lttng-ust-2.10", "lttng-tools-2.8", success),
89 ("lttng-ust-2.10", "lttng-tools-2.9", success),
90 ("lttng-ust-2.10", "lttng-tools-2.10", success),
91 ]
92
93 test_matrix_base = [
94 ("lttng-ust-2.7", "lttng-tools-2.7", success),
95 ("lttng-ust-2.7", "lttng-tools-2.8", success),
96 ("lttng-ust-2.7", "lttng-tools-2.9", success),
97 ("lttng-ust-2.7", "lttng-tools-2.10", success),
98 ("lttng-ust-2.8", "lttng-tools-2.7", success),
99 ("lttng-ust-2.8", "lttng-tools-2.8", success),
100 ("lttng-ust-2.8", "lttng-tools-2.9", success),
101 ("lttng-ust-2.8", "lttng-tools-2.10", success),
102 ("lttng-ust-2.9", "lttng-tools-2.7", success),
103 ("lttng-ust-2.9", "lttng-tools-2.8", success),
104 ("lttng-ust-2.9", "lttng-tools-2.9", success),
105 ("lttng-ust-2.9", "lttng-tools-2.10", success),
106 ("lttng-ust-2.10", "lttng-tools-2.7", success),
107 ("lttng-ust-2.10", "lttng-tools-2.8", success),
108 ("lttng-ust-2.10", "lttng-tools-2.9", success),
109 ("lttng-ust-2.10", "lttng-tools-2.10", success),
110 ]
111
112 runtime_matrix_enum = []
113 runtime_matrix_base = []
114
115 if not Settings.test_only:
116 runtime_matrix_enum = test_matrix_enum
117 runtime_matrix_base = test_matrix_base
118 else:
119 for tup in test_matrix_enum:
120 if (tup[0] in Settings.test_only or tup[1] in
121 Settings.test_only):
122 runtime_matrix_enum.append(tup)
123 for tup in test_matrix_base:
124 if (tup[0] in Settings.test_only or tup[1] in
125 Settings.test_only):
126 runtime_matrix_base.append(tup)
127
128 @pytest.mark.parametrize("ust_label,tools_label,scenario", runtime_matrix_enum)
129 def test_ust_tracepoint_abi_api_vs_ust_enum(tmpdir, ust_label, tools_label, scenario):
130
131 nb_loop = 100
132 nb_expected_events = 200
133
134 # Prepare environment
135 ust = ProjectFactory.get_precook(ust_label)
136 tools = ProjectFactory.get_precook(tools_label)
137 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
138
139 tools_runtime_path = os.path.join(str(tmpdir), "tools")
140 ust_runtime_path = os.path.join(str(tmpdir), "ust")
141 app_path = os.path.join(str(tmpdir), "app")
142
143 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
144 runtime_tools.add_project(tools)
145 runtime_tools.add_project(babeltrace)
146
147 runtime_app.add_project(ust)
148 runtime_app.lttng_home = runtime_tools.lttng_home
149
150 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
151
152 # Make application using the ust runtime
153 shutil.copytree(Settings.apps_preload_provider_folder, app_path)
154
155 # Use the testing env to make the probe
156 if scenario == fail_provider:
157 with pytest.raises(subprocess.CalledProcessError):
158 runtime_tools.run("make provider-enum", cwd=app_path)
159 return
160 else:
161 runtime_tools.run("make provider-enum", cwd=app_path)
162
163 # Use the ust env to test tracepoint instrumentation
164 if scenario == fail_app:
165 with pytest.raises(subprocess.CalledProcessError):
166 runtime_app.run("make app-enum", cwd=app_path)
167 return
168 else:
169 runtime_app.run("make app-enum", cwd=app_path)
170
171 # Start lttng-sessiond
172 sessiond = utils.sessiond_spawn(runtime_tools)
173
174 # Create session using mi to get path and session name
175 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
176
177 runtime_tools.run('lttng enable-event -u tp:tptest,tp:tpenum')
178 runtime_tools.run('lttng start')
179
180 # Run application
181 cmd = './app-enum {}'.format(nb_loop)
182 runtime_tools.run(cmd, cwd=app_path, ld_preload="./libtp-enum.so")
183
184 # Stop tracing
185 runtime_tools.run('lttng stop')
186 runtime_tools.run('lttng destroy -a')
187 runtime_tools.subprocess_terminate(sessiond)
188
189
190 # Read trace with babeltrace and check for event count via number of line
191 cmd = 'babeltrace {}'.format(trace_path)
192 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
193 assert(utils.line_count(cp_out) == nb_expected_events)
194
195 @pytest.mark.parametrize("ust_label,tools_label,scenario", runtime_matrix_base)
196 def test_ust_tracepoint_abi_api_vs_ust_base(tmpdir, ust_label, tools_label, scenario):
197
198 nb_loop = 100
199 nb_expected_events = 200
200
201 # Prepare environment
202 ust = ProjectFactory.get_precook(ust_label)
203 tools = ProjectFactory.get_precook(tools_label)
204 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
205
206 tools_runtime_path = os.path.join(str(tmpdir), "tools")
207 ust_runtime_path = os.path.join(str(tmpdir), "ust")
208 app_path = os.path.join(str(tmpdir), "app")
209
210 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
211 runtime_tools.add_project(tools)
212 runtime_tools.add_project(babeltrace)
213
214 runtime_app.add_project(ust)
215 runtime_app.lttng_home = runtime_tools.lttng_home
216
217 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
218
219 # Make application using the ust runtime
220 shutil.copytree(Settings.apps_preload_provider_folder, app_path)
221
222 # Use the testing env to make the probe
223 runtime_tools.run("make provider", cwd=app_path)
224
225 # Use the ust env to test tracepoint instrumentation
226 runtime_app.run("make app", cwd=app_path)
227
228 # Start lttng-sessiond
229 sessiond = utils.sessiond_spawn(runtime_tools)
230
231 # Create session using mi to get path and session name
232 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
233
234 runtime_tools.run('lttng enable-event -u tp:tptest,tp:tpenum')
235 runtime_tools.run('lttng start')
236
237 # Run application
238 cmd = './app {}'.format(nb_loop)
239 runtime_tools.run(cmd, cwd=app_path, ld_preload="./libtp.so")
240
241 # Stop tracing
242 runtime_tools.run('lttng stop')
243 runtime_tools.run('lttng destroy -a')
244 runtime_tools.subprocess_terminate(sessiond)
245
246
247 # Read trace with babeltrace and check for event count via number of line
248 cmd = 'babeltrace {}'.format(trace_path)
249 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
250 assert(utils.line_count(cp_out) == nb_expected_events)
This page took 0.035646 seconds and 5 git commands to generate.