| 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 | import time |
| 27 | import socket |
| 28 | |
| 29 | import lttng_ivc.utils.ProjectFactory as ProjectFactory |
| 30 | import lttng_ivc.utils.utils as utils |
| 31 | import lttng_ivc.utils.runtime as Run |
| 32 | import lttng_ivc.settings as Settings |
| 33 | |
| 34 | """ |
| 35 | TODO: Add Command header section |
| 36 | """ |
| 37 | |
| 38 | """ |
| 39 | TODO: snapshot, file rotation, rotate |
| 40 | """ |
| 41 | |
| 42 | """ |
| 43 | First member: relayd via lttng-tools |
| 44 | Second member: consumerd via lttng-tools |
| 45 | """ |
| 46 | test_matrix_streaming_base = [ |
| 47 | ("lttng-tools-2.7", "lttng-tools-2.7", True), |
| 48 | ("lttng-tools-2.7", "lttng-tools-2.8", True), |
| 49 | ("lttng-tools-2.7", "lttng-tools-2.9", True), |
| 50 | ("lttng-tools-2.7", "lttng-tools-2.10", True), |
| 51 | ("lttng-tools-2.8", "lttng-tools-2.7", True), |
| 52 | ("lttng-tools-2.8", "lttng-tools-2.8", True), |
| 53 | ("lttng-tools-2.8", "lttng-tools-2.9", True), |
| 54 | ("lttng-tools-2.8", "lttng-tools-2.10", True), |
| 55 | ("lttng-tools-2.9", "lttng-tools-2.7", True), |
| 56 | ("lttng-tools-2.9", "lttng-tools-2.8", True), |
| 57 | ("lttng-tools-2.9", "lttng-tools-2.9", True), |
| 58 | ("lttng-tools-2.9", "lttng-tools-2.10", True), |
| 59 | ("lttng-tools-2.10", "lttng-tools-2.7", True), |
| 60 | ("lttng-tools-2.10", "lttng-tools-2.8", True), |
| 61 | ("lttng-tools-2.10", "lttng-tools-2.9", True), |
| 62 | ("lttng-tools-2.10", "lttng-tools-2.10", True), |
| 63 | ] |
| 64 | |
| 65 | test_matrix_streaming_regenerate_metadata = [ |
| 66 | ("lttng-tools-2.7", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"), |
| 67 | ("lttng-tools-2.7", "lttng-tools-2.8", "metadata regenerate", "Unsupported by relayd"), |
| 68 | ("lttng-tools-2.7", "lttng-tools-2.9", "regenerate metadata", "Unsupported by relayd"), |
| 69 | ("lttng-tools-2.7", "lttng-tools-2.10", "regenerate metadata", "Unsupported by relayd"), |
| 70 | ("lttng-tools-2.8", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"), |
| 71 | ("lttng-tools-2.8", "lttng-tools-2.8", "metadata regenerate", "Supported"), |
| 72 | ("lttng-tools-2.8", "lttng-tools-2.9", "regenerate metadata", "Supported"), |
| 73 | ("lttng-tools-2.8", "lttng-tools-2.10", "regenerate metadata", "Supported"), |
| 74 | ("lttng-tools-2.9", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"), |
| 75 | ("lttng-tools-2.9", "lttng-tools-2.8", "metadata regenerate", "Supported"), |
| 76 | ("lttng-tools-2.9", "lttng-tools-2.9", "regenerate metadata", "Supported"), |
| 77 | ("lttng-tools-2.9", "lttng-tools-2.10", "regenerate metadata", "Supported"), |
| 78 | ("lttng-tools-2.10", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"), |
| 79 | ("lttng-tools-2.10", "lttng-tools-2.8", "metadata regenerate", "Supported"), |
| 80 | ("lttng-tools-2.10", "lttng-tools-2.9", "regenerate metadata", "Supported"), |
| 81 | ("lttng-tools-2.10", "lttng-tools-2.10", "regenerate metadata", "Supported"), |
| 82 | ] |
| 83 | |
| 84 | test_matrix_live_base = [ |
| 85 | ("lttng-tools-2.7", "lttng-tools-2.7", True), |
| 86 | ("lttng-tools-2.7", "lttng-tools-2.8", True), |
| 87 | ("lttng-tools-2.7", "lttng-tools-2.9", True), |
| 88 | ("lttng-tools-2.7", "lttng-tools-2.10", True), |
| 89 | ("lttng-tools-2.8", "lttng-tools-2.7", True), |
| 90 | ("lttng-tools-2.8", "lttng-tools-2.8", True), |
| 91 | ("lttng-tools-2.8", "lttng-tools-2.9", True), |
| 92 | ("lttng-tools-2.8", "lttng-tools-2.10", True), |
| 93 | ("lttng-tools-2.9", "lttng-tools-2.7", True), |
| 94 | ("lttng-tools-2.9", "lttng-tools-2.8", True), |
| 95 | ("lttng-tools-2.9", "lttng-tools-2.9", True), |
| 96 | ("lttng-tools-2.9", "lttng-tools-2.10", True), |
| 97 | ("lttng-tools-2.10", "lttng-tools-2.7", True), |
| 98 | ("lttng-tools-2.10", "lttng-tools-2.8", True), |
| 99 | ("lttng-tools-2.10", "lttng-tools-2.9", True), |
| 100 | ("lttng-tools-2.10", "lttng-tools-2.10", True), |
| 101 | ] |
| 102 | |
| 103 | runtime_matrix_streaming_base = [] |
| 104 | runtime_matrix_streaming_regenerate_metadata = [] |
| 105 | runtime_matrix_live_base = [] |
| 106 | |
| 107 | if not Settings.test_only: |
| 108 | runtime_matrix_streaming_base = test_matrix_streaming_base |
| 109 | runtime_matrix_streaming_regenerate_metadata = test_matrix_streaming_regenerate_metadata |
| 110 | runtime_matrix_live_base = test_matrix_live_base |
| 111 | else: |
| 112 | for tup in test_matrix_streaming_base: |
| 113 | if (tup[0] in Settings.test_only or tup[1] in |
| 114 | Settings.test_only): |
| 115 | runtime_matrix_streaming_base.append(tup) |
| 116 | for tup in test_matrix_streaming_regenerate_metadata: |
| 117 | if (tup[0] in Settings.test_only or tup[1] in |
| 118 | Settings.test_only): |
| 119 | runtime_matrix_streaming_regenerate_metadata.append(tup) |
| 120 | for tup in test_matrix_live_base: |
| 121 | if (tup[0] in Settings.test_only or tup[1] in |
| 122 | Settings.test_only): |
| 123 | runtime_matrix_live_base.append(tup) |
| 124 | |
| 125 | @pytest.mark.parametrize("relayd_label,consumerd_label,scenario", runtime_matrix_streaming_base) |
| 126 | def test_relayd_vs_consumerd_streaming_base(tmpdir, relayd_label, consumerd_label, scenario): |
| 127 | |
| 128 | nb_loop = 100 |
| 129 | nb_expected_events = 100 |
| 130 | |
| 131 | # Prepare environment |
| 132 | relayd = ProjectFactory.get_precook(relayd_label) |
| 133 | consumerd = ProjectFactory.get_precook(consumerd_label) |
| 134 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) |
| 135 | |
| 136 | relayd_runtime_path = os.path.join(str(tmpdir), "relayd") |
| 137 | consumerd_runtime_path = os.path.join(str(tmpdir), "consumerd") |
| 138 | app_path = os.path.join(str(tmpdir), "app") |
| 139 | |
| 140 | with Run.get_runtime(relayd_runtime_path) as runtime_relayd, Run.get_runtime(consumerd_runtime_path) as runtime_consumerd: |
| 141 | runtime_relayd.add_project(relayd) |
| 142 | runtime_relayd.add_project(babeltrace) |
| 143 | runtime_consumerd.add_project(consumerd) |
| 144 | |
| 145 | # Make application using the ust runtime |
| 146 | shutil.copytree(Settings.apps_gen_events_folder, app_path) |
| 147 | runtime_consumerd.run("make V=1", cwd=app_path) |
| 148 | |
| 149 | # Start lttng-sessiond |
| 150 | relayd = runtime_relayd.spawn_subprocess('lttng-relayd -vvv') |
| 151 | # FIX: No way to know if good to go... |
| 152 | time.sleep(1) |
| 153 | |
| 154 | sessiond = utils.sessiond_spawn(runtime_consumerd) |
| 155 | |
| 156 | url = "net://localhost" |
| 157 | |
| 158 | # Create session using mi to get path and session name |
| 159 | runtime_consumerd.run('lttng create --set-url={} trace '.format(url)) |
| 160 | |
| 161 | runtime_consumerd.run('lttng enable-event -u tp:tptest') |
| 162 | runtime_consumerd.run('lttng start') |
| 163 | |
| 164 | # Run application |
| 165 | cmd = './app {}'.format(nb_loop) |
| 166 | runtime_consumerd.run(cmd, cwd=app_path) |
| 167 | |
| 168 | # Stop tracing |
| 169 | runtime_consumerd.run('lttng stop') |
| 170 | runtime_consumerd.run('lttng destroy -a') |
| 171 | runtime_consumerd.subprocess_terminate(sessiond) |
| 172 | |
| 173 | # TODO check for error. |
| 174 | runtime_relayd.subprocess_terminate(relayd) |
| 175 | |
| 176 | |
| 177 | # Read trace with babeltrace and check for event count via number of line |
| 178 | cmd = 'babeltrace {}'.format(runtime_relayd.lttng_home) |
| 179 | cp_process, cp_out, cp_err = runtime_relayd.run(cmd) |
| 180 | assert(utils.line_count(cp_out) == nb_expected_events) |
| 181 | |
| 182 | |
| 183 | @pytest.mark.parametrize("relayd_label,consumerd_label,command, scenario", runtime_matrix_streaming_regenerate_metadata) |
| 184 | def test_relayd_vs_consumerd_streaming_regenerate_metadata(tmpdir, relayd_label, consumerd_label, command, scenario): |
| 185 | |
| 186 | nb_loop = 100 |
| 187 | nb_expected_events = 100 |
| 188 | |
| 189 | # Prepare environment |
| 190 | relayd = ProjectFactory.get_precook(relayd_label) |
| 191 | consumerd = ProjectFactory.get_precook(consumerd_label) |
| 192 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) |
| 193 | |
| 194 | relayd_runtime_path = os.path.join(str(tmpdir), "relayd") |
| 195 | consumerd_runtime_path = os.path.join(str(tmpdir), "consumerd") |
| 196 | app_path = os.path.join(str(tmpdir), "app") |
| 197 | |
| 198 | |
| 199 | with Run.get_runtime(relayd_runtime_path) as runtime_relayd, Run.get_runtime(consumerd_runtime_path) as runtime_consumerd: |
| 200 | runtime_relayd.add_project(relayd) |
| 201 | runtime_relayd.add_project(babeltrace) |
| 202 | runtime_consumerd.add_project(consumerd) |
| 203 | |
| 204 | babeltrace_cmd = 'babeltrace {}'.format(runtime_relayd.lttng_home) |
| 205 | |
| 206 | # Make application using the ust runtime |
| 207 | shutil.copytree(Settings.apps_gen_events_folder, app_path) |
| 208 | runtime_consumerd.run("make V=1", cwd=app_path) |
| 209 | |
| 210 | # Start lttng-sessiond |
| 211 | relayd = runtime_relayd.spawn_subprocess('lttng-relayd -vvv') |
| 212 | # FIX: No way to know if good to go... |
| 213 | time.sleep(1) |
| 214 | |
| 215 | sessiond = utils.sessiond_spawn(runtime_consumerd) |
| 216 | |
| 217 | url = "net://localhost" |
| 218 | |
| 219 | # Create session using mi to get path and session name |
| 220 | runtime_consumerd.run('lttng create --set-url={} trace '.format(url)) |
| 221 | |
| 222 | runtime_consumerd.run('lttng enable-event -u tp:tptest') |
| 223 | runtime_consumerd.run('lttng start') |
| 224 | |
| 225 | # Run application |
| 226 | cmd = './app {}'.format(nb_loop) |
| 227 | runtime_consumerd.run(cmd, cwd=app_path) |
| 228 | |
| 229 | # Stop tracing |
| 230 | runtime_consumerd.run('lttng stop') |
| 231 | |
| 232 | # Empty the metadata file |
| 233 | metadata = utils.find_file(runtime_relayd.lttng_home, "metadata") |
| 234 | open(metadata, 'w').close() |
| 235 | |
| 236 | # Babeltrace should never be able to parse the trace |
| 237 | with pytest.raises(subprocess.CalledProcessError): |
| 238 | runtime_relayd.run(babeltrace_cmd) |
| 239 | |
| 240 | runtime_consumerd.run("lttng start") |
| 241 | |
| 242 | # TODO: rework this a bit to differentiate each errors and rework how |
| 243 | # the condition are meet |
| 244 | if scenario == "Unsupported by tools" or scenario == "Unsupported by relayd": |
| 245 | with pytest.raises(subprocess.CalledProcessError): |
| 246 | runtime_consumerd.run("lttng {}".format(command)) |
| 247 | |
| 248 | # Make sure everything looks good on this side |
| 249 | sessiond = runtime_consumerd.subprocess_terminate(sessiond) |
| 250 | if sessiond.returncode != 0: |
| 251 | pytest.fail("Return value of sessiond is not zero") |
| 252 | relayd = runtime_relayd.subprocess_terminate(relayd) |
| 253 | if relayd.returncode != 0: |
| 254 | pytest.fail("Return value of relayd is not zero") |
| 255 | return |
| 256 | |
| 257 | runtime_consumerd.run("lttng {}".format(command)) |
| 258 | |
| 259 | runtime_consumerd.run('lttng stop') |
| 260 | runtime_consumerd.run('lttng destroy -a') |
| 261 | |
| 262 | # Make sure everything looks good |
| 263 | sessiond = runtime_consumerd.subprocess_terminate(sessiond) |
| 264 | if sessiond.returncode != 0: |
| 265 | pytest.fail("Return value of sessiond is not zero") |
| 266 | relayd = runtime_relayd.subprocess_terminate(relayd) |
| 267 | if relayd.returncode != 0: |
| 268 | pytest.fail("Return value of relayd is not zero") |
| 269 | |
| 270 | # Read trace with babeltrace and check for event count via number of line |
| 271 | cp_process, cp_out, cp_err = runtime_relayd.run(babeltrace_cmd) |
| 272 | assert(utils.line_count(cp_out) == nb_expected_events) |
| 273 | |
| 274 | @pytest.mark.parametrize("relayd_label,consumerd_label,scenario", runtime_matrix_streaming_base) |
| 275 | def test_relayd_vs_consumerd_live_base(tmpdir, relayd_label, consumerd_label, scenario): |
| 276 | |
| 277 | nb_loop = 100 |
| 278 | nb_expected_events = 100 |
| 279 | |
| 280 | # Prepare environment |
| 281 | relayd = ProjectFactory.get_precook(relayd_label) |
| 282 | consumerd = ProjectFactory.get_precook(consumerd_label) |
| 283 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) |
| 284 | |
| 285 | relayd_runtime_path = os.path.join(str(tmpdir), "relayd") |
| 286 | consumerd_runtime_path = os.path.join(str(tmpdir), "consumerd") |
| 287 | app_path = os.path.join(str(tmpdir), "app") |
| 288 | |
| 289 | with Run.get_runtime(relayd_runtime_path) as runtime_relayd, Run.get_runtime(consumerd_runtime_path) as runtime_consumerd: |
| 290 | runtime_relayd.add_project(relayd) |
| 291 | runtime_relayd.add_project(babeltrace) |
| 292 | runtime_consumerd.add_project(consumerd) |
| 293 | |
| 294 | # Make application using the ust runtime |
| 295 | shutil.copytree(Settings.apps_gen_events_folder, app_path) |
| 296 | runtime_consumerd.run("make V=1", cwd=app_path) |
| 297 | |
| 298 | # Start lttng-sessiond |
| 299 | relayd = runtime_relayd.spawn_subprocess('lttng-relayd -vvv') |
| 300 | # FIX: No way to know if good to go... |
| 301 | time.sleep(1) |
| 302 | |
| 303 | sessiond = utils.sessiond_spawn(runtime_consumerd) |
| 304 | |
| 305 | url = "net://localhost" |
| 306 | |
| 307 | # Create session using mi to get path and session name |
| 308 | runtime_consumerd.run('lttng create --live --set-url={} trace '.format(url)) |
| 309 | |
| 310 | runtime_consumerd.run('lttng enable-event -u tp:tptest') |
| 311 | runtime_consumerd.run('lttng start') |
| 312 | |
| 313 | # Run application |
| 314 | cmd = './app {}'.format(nb_loop) |
| 315 | runtime_consumerd.run(cmd, cwd=app_path) |
| 316 | |
| 317 | # Stop tracing |
| 318 | runtime_consumerd.run('lttng stop') |
| 319 | runtime_consumerd.run('lttng destroy -a') |
| 320 | runtime_consumerd.subprocess_terminate(sessiond) |
| 321 | |
| 322 | # TODO check for error. |
| 323 | runtime_relayd.subprocess_terminate(relayd) |
| 324 | |
| 325 | |
| 326 | # Read trace with babeltrace and check for event count via number of line |
| 327 | cmd = 'babeltrace {}'.format(runtime_relayd.lttng_home) |
| 328 | cp_process, cp_out, cp_err = runtime_relayd.run(cmd) |
| 329 | assert(utils.line_count(cp_out) == nb_expected_events) |
| 330 | |
| 331 | |