Add test_ust_java_agent_vs_tools
[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 destroy -a')
141 cp = runtime_tools.subprocess_terminate(sessiond)
142 if cp.returncode != 0:
143 pytest.fail("Sessiond return code")
144
145 # Read trace with babeltrace and check for event count via number of line
146 cmd = 'babeltrace {}'.format(trace_path)
147 if should_trace:
148 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
149 assert(utils.line_count(cp_out) == nb_events)
150 else:
151 with pytest.raises(subprocess.CalledProcessError):
152 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
153
154 @pytest.mark.parametrize("ust_label,tools_label,app_version,outcome", runtime_matrix_agent_interface)
155 def test_ust_java_agent_interface(tmpdir, ust_label, tools_label, app_version, outcome):
156 """
157 Use the agent coming from ust_label, but run app under tools_version runtime using ust agent.
158 """
159
160 nb_iter = 100
161 nb_events = 3 * nb_iter
162
163 # Prepare environment
164 ust = ProjectFactory.get_precook(ust_label)
165 tools = ProjectFactory.get_precook(tools_label)
166 babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace)
167
168 tools_runtime_path = os.path.join(str(tmpdir), "tools")
169 ust_runtime_path = os.path.join(str(tmpdir), "ust")
170 app_path = os.path.join(str(tmpdir), "app")
171
172 with Run.get_runtime(ust_runtime_path) as runtime_app, Run.get_runtime(tools_runtime_path) as runtime_tools:
173 runtime_tools.add_project(tools)
174 runtime_tools.add_project(babeltrace)
175
176 runtime_app.add_project(ust)
177 runtime_app.lttng_home = runtime_tools.lttng_home
178
179 trace_path = os.path.join(runtime_tools.lttng_home, 'trace')
180
181 # Make application using the ust runtime
182 shutil.copytree(version_to_app[app_version], app_path)
183 runtime_app.run("javac App.java", cwd=app_path)
184
185 # Start lttng-sessiond
186 sessiond = utils.sessiond_spawn(runtime_tools)
187
188 # Create session using mi to get path and session name
189 runtime_tools.run('lttng create trace --output={}'.format(trace_path))
190
191 runtime_tools.run('lttng enable-event -j jello')
192 runtime_tools.run('lttng start')
193
194 # Steal the classpath from ust project
195 ust_classpath = ust.special_env_variables['CLASSPATH']
196
197 # Run application with tools runtime
198 cmd = 'java App {}'.format(nb_iter)
199 runtime_tools.run(cmd, cwd=app_path, classpath=ust_classpath)
200
201 # Stop tracing
202 runtime_tools.run('lttng destroy -a')
203 cp = runtime_tools.subprocess_terminate(sessiond)
204 if cp.returncode != 0:
205 pytest.fail("Sessiond return code")
206
207 # Read trace with babeltrace and check for event count via number of line
208 cmd = 'babeltrace {}'.format(trace_path)
209 if outcome == "Success":
210 assert(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"]))
211 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
212 assert(utils.line_count(cp_out) == nb_events)
213 else:
214 if outcome == "Unsupported protocol":
215 assert(not(utils.file_contains(runtime_tools.get_subprocess_stderr_path(sessiond),["New registration for pid"])))
216 cp_process, cp_out, cp_err = runtime_tools.run(cmd)
217 assert(utils.line_count(cp_out) == 0)
This page took 0.035949 seconds and 5 git commands to generate.