Commit | Line | Data |
---|---|---|
2094d672 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 | TU: Tracing unavailable | |
17 | ||
18 | Note: 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 | """ | |
34 | First tuple member: lttng-ust label | |
35 | Second tuple member: lttng-tool label | |
36 | Thirdd tuple member: expected scenario | |
37 | """ | |
38 | ||
39 | test_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 | ||
58 | test_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 | ||
77 | runtime_matrix_tracing_available = [] | |
78 | runtime_matrix_agent_interface = [] | |
79 | ||
80 | if not Settings.test_only: | |
81 | runtime_matrix_tracing_available = test_matrix_tracing_available | |
82 | runtime_matrix_agent_interface = test_matrix_agent_interface | |
83 | else: | |
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) | |
95 | def 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 | |
135 | runtime_tools.run('lttng destroy -a') | |
136 | cp = runtime_tools.subprocess_terminate(sessiond) | |
137 | if cp.returncode != 0: | |
138 | pytest.fail("Sessiond return code") | |
139 | ||
140 | # Read trace with babeltrace and check for event count via number of line | |
141 | cmd = 'babeltrace {}'.format(trace_path) | |
142 | if should_trace: | |
143 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
144 | assert(utils.line_count(cp_out) == nb_events) | |
145 | else: | |
146 | with pytest.raises(subprocess.CalledProcessError): | |
147 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
148 | ||
149 | @pytest.mark.parametrize("ust_label,tools_label,outcome", runtime_matrix_agent_interface) | |
150 | def test_ust_python_agent_interface(tmpdir, ust_label, tools_label, outcome): | |
151 | """ | |
152 | Use the agent coming from ust_label, but run app under tools_version runtime using ust agent. | |
153 | """ | |
154 | ||
155 | nb_iter = 100 | |
156 | nb_events = 5 * nb_iter | |
157 | ||
158 | # Prepare environment | |
159 | ust = ProjectFactory.get_precook(ust_label) | |
160 | tools = ProjectFactory.get_precook(tools_label) | |
161 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) | |
162 | ||
163 | tools_runtime_path = os.path.join(str(tmpdir), "tools") | |
164 | ust_runtime_path = os.path.join(str(tmpdir), "ust") | |
165 | app_path = os.path.join(str(tmpdir), "app") | |
166 | ||
167 | with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools: | |
168 | runtime_tools.add_project(tools) | |
169 | runtime_tools.add_project(babeltrace) | |
170 | ||
171 | runtime_app.add_project(ust) | |
172 | runtime_app.lttng_home = runtime_tools.lttng_home | |
173 | ||
174 | trace_path = os.path.join(runtime_tools.lttng_home, 'trace') | |
175 | ||
176 | # Make application using the ust runtime | |
177 | shutil.copytree(Settings.apps_python, app_path) | |
178 | ||
179 | # Start lttng-sessiond | |
180 | sessiond = utils.sessiond_spawn(runtime_tools) | |
181 | ||
182 | # Create session using mi to get path and session name | |
183 | runtime_tools.run('lttng create trace --output={}'.format(trace_path)) | |
184 | ||
185 | runtime_tools.run('lttng enable-event -p pello') | |
186 | runtime_tools.run('lttng start') | |
187 | ||
188 | # Steal the PYTHONPATH from ust project and force it on the tools | |
189 | # project | |
190 | python_path = ust.special_env_variables['PYTHONPATH'] | |
191 | tools.special_env_variables['PYTHONPATH'] = python_path | |
192 | ||
193 | # Run application with tools runtime | |
194 | cmd = 'python app.py -i {}'.format(nb_iter) | |
195 | runtime_tools.run(cmd, cwd=app_path) | |
196 | ||
197 | # Stop tracing | |
198 | runtime_tools.run('lttng destroy -a') | |
199 | cp = runtime_tools.subprocess_terminate(sessiond) | |
200 | if cp.returncode != 0: | |
201 | pytest.fail("Sessiond return code") | |
202 | ||
203 | # Read trace with babeltrace and check for event count via number of line | |
204 | cmd = 'babeltrace {}'.format(trace_path) | |
205 | if outcome == "Success": | |
206 | assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"])) | |
207 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
208 | assert(utils.line_count(cp_out) == nb_events) | |
209 | else: | |
210 | if outcome == "Unsupported protocol": | |
211 | assert(not(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"]))) | |
212 | cp_process, cp_out, cp_err = runtime_tools.run(cmd) | |
213 | assert(utils.line_count(cp_out) == 0) |