Always issues lttng stop before destroy
[deliverable/lttng-ivc.git] / lttng_ivc / tests / ust_java_agent_vs_tools / test_ust_java_agent_vs_tools.py
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 Java 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 (1.0) | FC | TU | TU | TU |
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 Third tuple member: app version to use
37 Fourth tuple member: expected scenario
38 """
39
40 version_to_app = {1: Settings.apps_jul_1,
41 2: Settings.apps_jul_2}
42
43 test_matrix_tracing_available = [
44 ("lttng-ust-2.7", "lttng-tools-2.7", 1, True),
45 ("lttng-ust-2.7", "lttng-tools-2.8", 1, False),
46 ("lttng-ust-2.7", "lttng-tools-2.9", 1, False),
47 ("lttng-ust-2.7", "lttng-tools-2.10", 1, False),
48 ("lttng-ust-2.8", "lttng-tools-2.7", 2, False),
49 ("lttng-ust-2.8", "lttng-tools-2.8", 2, True),
50 ("lttng-ust-2.8", "lttng-tools-2.9", 2, False),
51 ("lttng-ust-2.8", "lttng-tools-2.10", 2, False),
52 ("lttng-ust-2.9", "lttng-tools-2.7", 2, False),
53 ("lttng-ust-2.9", "lttng-tools-2.8", 2, False),
54 ("lttng-ust-2.9", "lttng-tools-2.9", 2, True),
55 ("lttng-ust-2.9", "lttng-tools-2.10", 2, True),
56 ("lttng-ust-2.10", "lttng-tools-2.7", 2, False),
57 ("lttng-ust-2.10", "lttng-tools-2.8", 2, False),
58 ("lttng-ust-2.10", "lttng-tools-2.9", 2, True),
59 ("lttng-ust-2.10", "lttng-tools-2.10", 2, True),
60 ]
61
62 test_matrix_agent_interface = [
63 ("lttng-ust-2.7", "lttng-tools-2.7", 1, "Success"),
64 ("lttng-ust-2.7", "lttng-tools-2.8", 1, "Unsupported protocol"),
65 ("lttng-ust-2.7", "lttng-tools-2.9", 1, "Unsupported protocol"),
66 ("lttng-ust-2.7", "lttng-tools-2.10", 1, "Unsupported protocol"),
67 ("lttng-ust-2.8", "lttng-tools-2.7", 2, "Unsupported protocol"),
68 ("lttng-ust-2.8", "lttng-tools-2.8", 2, "Success"),
69 ("lttng-ust-2.8", "lttng-tools-2.9", 2, "Success"),
70 ("lttng-ust-2.8", "lttng-tools-2.10", 2, "Success"),
71 ("lttng-ust-2.9", "lttng-tools-2.7", 2, "Unsupported protocol"),
72 ("lttng-ust-2.9", "lttng-tools-2.8", 2, "Success"),
73 ("lttng-ust-2.9", "lttng-tools-2.9", 2, "Success"),
74 ("lttng-ust-2.9", "lttng-tools-2.10", 2, "Success"),
75 ("lttng-ust-2.10", "lttng-tools-2.7", 2, "Unsupported protocol"),
76 ("lttng-ust-2.10", "lttng-tools-2.8", 2, "Success"),
77 ("lttng-ust-2.10", "lttng-tools-2.9", 2, "Success"),
78 ("lttng-ust-2.10", "lttng-tools-2.10", 2, "Success"),
79 ]
80
81 runtime_matrix_tracing_available = []
82 runtime_matrix_agent_interface = []
83
84 if not Settings.test_only:
85 runtime_matrix_tracing_available = test_matrix_tracing_available
86 runtime_matrix_agent_interface = test_matrix_agent_interface
87 else:
88 for tup in test_matrix_tracing_available:
89 if (tup[0] in Settings.test_only or tup[1] in
90 Settings.test_only):
91 runtime_matrix_tracing_available.append(tup)
92 for tup in test_matrix_agent_interface:
93 if (tup[0] in Settings.test_only or tup[1] in
94 Settings.test_only):
95 runtime_matrix_agent_interface.append(tup)
96
97
98 @pytest.mark.parametrize("ust_label,tools_label,app_version,should_trace", runtime_matrix_tracing_available)
99 def test_ust_java_agent_tracing_available(tmpdir, ust_label, tools_label, app_version, should_trace):
100
101 nb_iter = 100
102 nb_events = 3 * nb_iter
103
104 # Prepare environment
105 ust = ProjectFactory.get_precook(ust_label)
106 tools = ProjectFactory.get_precook(tools_label)
107 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
108
109 tools_runtime_path = os.path.join(str(tmpdir), "tools")
110 ust_runtime_path = os.path.join(str(tmpdir), "ust")
111 app_path = os.path.join(str(tmpdir), "app")
112
113 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
114 runtime_tools.add_project(tools)
115 runtime_tools.add_project(babeltrace)
116
117 runtime_app.add_project(ust)
118 runtime_app.lttng_home = runtime_tools.lttng_home
119
120 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
121
122 # Make application using the ust runtime
123 shutil.copytree(version_to_app[app_version], app_path)
124 runtime_app.run("javac App.java", cwd=app_path)
125
126 # Start lttng-sessiond
127 sessiond = utils.sessiond_spawn(runtime_tools)
128
129 # Create session using mi to get path and session name
130 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
131
132 runtime_tools.run('lttng enable-event -j jello')
133 runtime_tools.run('lttng start')
134
135 # Run application
136 cmd = 'java App {}'.format(nb_iter)
137 runtime_app.run(cmd, cwd=app_path)
138
139 # Stop tracing
140 runtime_tools.run('lttng stop')
141 runtime_tools.run('lttng destroy -a')
142 cp = runtime_tools.subprocess_terminate(sessiond)
143 if cp.returncode != 0:
144 pytest.fail("Sessiond return code")
145
146 # Read trace with babeltrace and check for event count via number of line
147 cmd = 'babeltrace {}'.format(trace_path)
148 if should_trace:
149 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
150 assert(utils.line_count(cp_out) == nb_events)
151 else:
152 with pytest.raises(subprocess.CalledProcessError):
153 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
154
155 @pytest.mark.parametrize("ust_label,tools_label,app_version,outcome", runtime_matrix_agent_interface)
156 def test_ust_java_agent_interface(tmpdir, ust_label, tools_label, app_version, outcome):
157 """
158 Use the agent coming from ust_label, but run app under tools_version runtime using ust agent.
159 """
160
161 nb_iter = 100
162 nb_events = 3 * nb_iter
163
164 # Prepare environment
165 ust = ProjectFactory.get_precook(ust_label)
166 tools = ProjectFactory.get_precook(tools_label)
167 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
168
169 tools_runtime_path = os.path.join(str(tmpdir), "tools")
170 ust_runtime_path = os.path.join(str(tmpdir), "ust")
171 app_path = os.path.join(str(tmpdir), "app")
172
173 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
174 runtime_tools.add_project(tools)
175 runtime_tools.add_project(babeltrace)
176
177 runtime_app.add_project(ust)
178 runtime_app.lttng_home = runtime_tools.lttng_home
179
180 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
181
182 # Make application using the ust runtime
183 shutil.copytree(version_to_app[app_version], app_path)
184 runtime_app.run("javac App.java", cwd=app_path)
185
186 # Start lttng-sessiond
187 sessiond = utils.sessiond_spawn(runtime_tools)
188
189 # Create session using mi to get path and session name
190 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
191
192 runtime_tools.run('lttng enable-event -j jello')
193 runtime_tools.run('lttng start')
194
195 # Steal the classpath from ust project
196 ust_classpath = ust.special_env_variables['CLASSPATH']
197
198 # Run application with tools runtime
199 cmd = 'java App {}'.format(nb_iter)
200 runtime_tools.run(cmd, cwd=app_path, classpath=ust_classpath)
201
202 # Stop tracing
203 runtime_tools.run('lttng stop')
204 runtime_tools.run('lttng destroy -a')
205 cp = runtime_tools.subprocess_terminate(sessiond)
206 if cp.returncode != 0:
207 pytest.fail("Sessiond return code")
208
209 # Read trace with babeltrace and check for event count via number of line
210 cmd = 'babeltrace {}'.format(trace_path)
211 if outcome == "Success":
212 assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"]))
213 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
214 assert(utils.line_count(cp_out) == nb_events)
215 else:
216 if outcome == "Unsupported protocol":
217 assert(not(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"])))
218 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
219 assert(utils.line_count(cp_out) == 0)
This page took 0.037252 seconds and 5 git commands to generate.