Always issues lttng stop before destroy
[deliverable/lttng-ivc.git] / lttng_ivc / tests / ust_python_agent_vs_tools / test_ust_python_agent_vs_tools.py
CommitLineData
2094d672
JR
1import pytest
2import os
3import shutil
4import signal
5import subprocess
6
7import lttng_ivc.utils.ProjectFactory as ProjectFactory
8import lttng_ivc.utils.utils as utils
9import lttng_ivc.utils.runtime as Run
10import lttng_ivc.settings as Settings
11
12"""
13
14FC: Fully Compatible
15BC: Feature of the smallest version number will works.
16TU: Tracing unavailable
17
18Note: actual testing is limited by lttng-ust and lttng-tools abi/api.
19
20+----------------------------------------------------------------------------------+
21| LTTng UST Python agent protocol vs LTTng session daemon |
22+--------------------------+------------+------------+------------+----------------+
23| LTTng UST Java/ LTTng Tools | 2.7 (1.0) | 2.8 (2.0) | 2.9 (2.0) | 2.10 (2.0) |
24+--------------------------+------------+------------+------------+----------------+
25| 2.7 | NA | NA | NA | NA |
26| 2.8 (2.0) | TU | FC | BC | BC |
27| 2.9 (2.0) | TU | BC | FC | BC |
28| 2.10 (2.0) | TU | BC | BC | FC |
29+--------------------------+------------+------------+------------+----------------+
30
31"""
32
33"""
34First tuple member: lttng-ust label
35Second tuple member: lttng-tool label
36Thirdd tuple member: expected scenario
37"""
38
39test_matrix_tracing_available = [
40 ("lttng-ust-2.7", "lttng-tools-2.7", True),
41 ("lttng-ust-2.7", "lttng-tools-2.8", False),
42 ("lttng-ust-2.7", "lttng-tools-2.9", False),
43 ("lttng-ust-2.7", "lttng-tools-2.10", False),
44 ("lttng-ust-2.8", "lttng-tools-2.7", False),
45 ("lttng-ust-2.8", "lttng-tools-2.8", True),
46 ("lttng-ust-2.8", "lttng-tools-2.9", False),
47 ("lttng-ust-2.8", "lttng-tools-2.10", False),
48 ("lttng-ust-2.9", "lttng-tools-2.7", False),
49 ("lttng-ust-2.9", "lttng-tools-2.8", False),
50 ("lttng-ust-2.9", "lttng-tools-2.9", True),
51 ("lttng-ust-2.9", "lttng-tools-2.10", True),
52 ("lttng-ust-2.10", "lttng-tools-2.7", False),
53 ("lttng-ust-2.10", "lttng-tools-2.8", False),
54 ("lttng-ust-2.10", "lttng-tools-2.9", True),
55 ("lttng-ust-2.10", "lttng-tools-2.10", True),
56]
57
58test_matrix_agent_interface = [
59 ("lttng-ust-2.7", "lttng-tools-2.7", "Success"),
60 ("lttng-ust-2.7", "lttng-tools-2.8", "Unsupported protocol"),
61 ("lttng-ust-2.7", "lttng-tools-2.9", "Unsupported protocol"),
62 ("lttng-ust-2.7", "lttng-tools-2.10", "Unsupported protocol"),
63 ("lttng-ust-2.8", "lttng-tools-2.7", "Unsupported protocol"),
64 ("lttng-ust-2.8", "lttng-tools-2.8", "Success"),
65 ("lttng-ust-2.8", "lttng-tools-2.9", "Success"),
66 ("lttng-ust-2.8", "lttng-tools-2.10", "Success"),
67 ("lttng-ust-2.9", "lttng-tools-2.7", "Unsupported protocol"),
68 ("lttng-ust-2.9", "lttng-tools-2.8", "Success"),
69 ("lttng-ust-2.9", "lttng-tools-2.9", "Success"),
70 ("lttng-ust-2.9", "lttng-tools-2.10", "Success"),
71 ("lttng-ust-2.10", "lttng-tools-2.7", "Unsupported protocol"),
72 ("lttng-ust-2.10", "lttng-tools-2.8", "Success"),
73 ("lttng-ust-2.10", "lttng-tools-2.9", "Success"),
74 ("lttng-ust-2.10", "lttng-tools-2.10", "Success"),
75]
76
77runtime_matrix_tracing_available = []
78runtime_matrix_agent_interface = []
79
80if not Settings.test_only:
81 runtime_matrix_tracing_available = test_matrix_tracing_available
82 runtime_matrix_agent_interface = test_matrix_agent_interface
83else:
84 for tup in test_matrix_tracing_available:
85 if (tup[0] in Settings.test_only or tup[1] in
86 Settings.test_only):
87 runtime_matrix_tracing_available.append(tup)
88 for tup in test_matrix_agent_interface:
89 if (tup[0] in Settings.test_only or tup[1] in
90 Settings.test_only):
91 runtime_matrix_agent_interface.append(tup)
92
93
94@pytest.mark.parametrize("ust_label,tools_label,should_trace", runtime_matrix_tracing_available)
95def test_ust_python_agent_tracing_available(tmpdir, ust_label, tools_label, should_trace):
96
97 nb_iter = 100
98 nb_events = 5 * nb_iter
99
100 # Prepare environment
101 ust = ProjectFactory.get_precook(ust_label)
102 tools = ProjectFactory.get_precook(tools_label)
103 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
104
105 tools_runtime_path = os.path.join(str(tmpdir), "tools")
106 ust_runtime_path = os.path.join(str(tmpdir), "ust")
107 app_path = os.path.join(str(tmpdir), "app")
108
109 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
110 runtime_tools.add_project(tools)
111 runtime_tools.add_project(babeltrace)
112
113 runtime_app.add_project(ust)
114 runtime_app.lttng_home = runtime_tools.lttng_home
115
116 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
117
118 # Copy the python app
119 shutil.copytree(Settings.apps_python, app_path)
120
121 # Start lttng-sessiond
122 sessiond = utils.sessiond_spawn(runtime_tools)
123
124 # Create session using mi to get path and session name
125 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
126
127 runtime_tools.run('lttng enable-event -p pello')
128 runtime_tools.run('lttng start')
129
130 # Run application
131 cmd = 'python app.py -i {}'.format(nb_iter)
132 runtime_app.run(cmd, cwd=app_path)
133
134 # Stop tracing
87e6d73a 135 runtime_tools.run('lttng stop')
2094d672
JR
136 runtime_tools.run('lttng destroy -a')
137 cp = runtime_tools.subprocess_terminate(sessiond)
138 if cp.returncode != 0:
139 pytest.fail("Sessiond return code")
140
141 # Read trace with babeltrace and check for event count via number of line
142 cmd = 'babeltrace {}'.format(trace_path)
143 if should_trace:
144 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
145 assert(utils.line_count(cp_out) == nb_events)
146 else:
147 with pytest.raises(subprocess.CalledProcessError):
148 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
149
150@pytest.mark.parametrize("ust_label,tools_label,outcome", runtime_matrix_agent_interface)
151def test_ust_python_agent_interface(tmpdir, ust_label, tools_label, outcome):
152 """
153 Use the agent coming from ust_label, but run app under tools_version runtime using ust agent.
154 """
155
156 nb_iter = 100
157 nb_events = 5 * nb_iter
158
159 # Prepare environment
160 ust = ProjectFactory.get_precook(ust_label)
161 tools = ProjectFactory.get_precook(tools_label)
162 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
163
164 tools_runtime_path = os.path.join(str(tmpdir), "tools")
165 ust_runtime_path = os.path.join(str(tmpdir), "ust")
166 app_path = os.path.join(str(tmpdir), "app")
167
168 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
169 runtime_tools.add_project(tools)
170 runtime_tools.add_project(babeltrace)
171
172 runtime_app.add_project(ust)
173 runtime_app.lttng_home = runtime_tools.lttng_home
174
175 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
176
177 # Make application using the ust runtime
178 shutil.copytree(Settings.apps_python, app_path)
179
180 # Start lttng-sessiond
181 sessiond = utils.sessiond_spawn(runtime_tools)
182
183 # Create session using mi to get path and session name
184 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
185
186 runtime_tools.run('lttng enable-event -p pello')
187 runtime_tools.run('lttng start')
188
189 # Steal the PYTHONPATH from ust project and force it on the tools
190 # project
191 python_path = ust.special_env_variables['PYTHONPATH']
192 tools.special_env_variables['PYTHONPATH'] = python_path
193
194 # Run application with tools runtime
195 cmd = 'python app.py -i {}'.format(nb_iter)
196 runtime_tools.run(cmd, cwd=app_path)
197
198 # Stop tracing
87e6d73a 199 runtime_tools.run('lttng stop')
2094d672
JR
200 runtime_tools.run('lttng destroy -a')
201 cp = runtime_tools.subprocess_terminate(sessiond)
202 if cp.returncode != 0:
203 pytest.fail("Sessiond return code")
204
205 # Read trace with babeltrace and check for event count via number of line
206 cmd = 'babeltrace {}'.format(trace_path)
207 if outcome == "Success":
208 assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"]))
209 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
210 assert(utils.line_count(cp_out) == nb_events)
211 else:
212 if outcome == "Unsupported protocol":
213 assert(not(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"])))
214 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
215 assert(utils.line_count(cp_out) == 0)
This page took 0.032084 seconds and 5 git commands to generate.