| 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 glob |
| 24 | import subprocess |
| 25 | |
| 26 | import lttng_ivc.utils.ProjectFactory as ProjectFactory |
| 27 | import lttng_ivc.utils.runtime as Run |
| 28 | import lttng_ivc.settings as Settings |
| 29 | from lttng_ivc.utils.skip import must_be_root |
| 30 | from lttng_ivc.utils.utils import sessiond_spawn |
| 31 | from lttng_ivc.utils.utils import line_count |
| 32 | |
| 33 | """ |
| 34 | |
| 35 | NOTE: Kernel version is left to the Lttng-modules object on building. We assume |
| 36 | that a failing lttng-modules build is caused only by version validation. This |
| 37 | project is not dedicated to finding build problem but inter version problem. |
| 38 | |
| 39 | NOTE: The command for regenerate metadata changed between 2.8 and 2.9 from |
| 40 | "metadata regenerate" to "regenerate metadata" breaking the cli ....bad |
| 41 | jdesfossez :P |
| 42 | |
| 43 | TODO:Packet sequence number. 5b3cf4f924befda843a7736daf84f8ecae5e86a4 |
| 44 | LTTNG_RING_BUFFER_GET_SEQ_NUM |
| 45 | TODO:Stream instance id. 5594698f9c8ad13e0964c67946d1867df7757dae |
| 46 | LTTNG_RING_BUFFER_INSTANCE_ID |
| 47 | |
| 48 | |
| 49 | FC: Fully Compatible |
| 50 | BC: Feature of the smallest version number will works. |
| 51 | |
| 52 | +-------------------------------------------------------+ |
| 53 | | LTTng Modules ABI vs LTTng Tools compatibility matrix | |
| 54 | +-------------------------------------------------------+ |
| 55 | | Modules / Tools | 2.7 | 2.8 | 2.9 | 2.10 | |
| 56 | +------------------+------+------+------+---------------+ |
| 57 | | 2.7 | FC | BC | BC | BC | |
| 58 | | 2.8 | BC | FC | BC | BC | |
| 59 | | 2.9 | BC | BC | FC | BC | |
| 60 | | 2.10 | BC | BC | BC | FC | |
| 61 | +------------------+------+------+------+---------------+ |
| 62 | |
| 63 | """ |
| 64 | |
| 65 | """ |
| 66 | First tuple member: lttng-ust label |
| 67 | Second tuple member: lttng-tool label |
| 68 | Third tuple member: expected scenario |
| 69 | """ |
| 70 | test_matrix_base_tracing = [ |
| 71 | ("lttng-modules-2.7", "lttng-tools-2.7"), |
| 72 | ("lttng-modules-2.7", "lttng-tools-2.8"), |
| 73 | ("lttng-modules-2.7", "lttng-tools-2.9"), |
| 74 | ("lttng-modules-2.7", "lttng-tools-2.10"), |
| 75 | ("lttng-modules-2.8", "lttng-tools-2.7"), |
| 76 | ("lttng-modules-2.8", "lttng-tools-2.8"), |
| 77 | ("lttng-modules-2.8", "lttng-tools-2.9"), |
| 78 | ("lttng-modules-2.8", "lttng-tools-2.10"), |
| 79 | ("lttng-modules-2.9", "lttng-tools-2.7"), |
| 80 | ("lttng-modules-2.9", "lttng-tools-2.8"), |
| 81 | ("lttng-modules-2.9", "lttng-tools-2.9"), |
| 82 | ("lttng-modules-2.9", "lttng-tools-2.10"), |
| 83 | ("lttng-modules-2.10", "lttng-tools-2.7"), |
| 84 | ("lttng-modules-2.10", "lttng-tools-2.8"), |
| 85 | ("lttng-modules-2.10", "lttng-tools-2.9"), |
| 86 | ("lttng-modules-2.10", "lttng-tools-2.10"), |
| 87 | ] |
| 88 | |
| 89 | test_matrix_regen_metadata = [ |
| 90 | ("lttng-modules-2.7", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"), |
| 91 | ("lttng-modules-2.7", "lttng-tools-2.8", "metadata regenerate", "Unsupported by module"), |
| 92 | ("lttng-modules-2.7", "lttng-tools-2.9", "regenerate metadata", "Unsupported by module"), |
| 93 | ("lttng-modules-2.7", "lttng-tools-2.10", "regenerate metadata", "Unsupported by module"), |
| 94 | ("lttng-modules-2.8", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"), |
| 95 | ("lttng-modules-2.8", "lttng-tools-2.8", "metadata regenerate", "Supported"), |
| 96 | ("lttng-modules-2.8", "lttng-tools-2.9", "regenerate metadata", "Supported"), |
| 97 | ("lttng-modules-2.8", "lttng-tools-2.10", "regenerate metadata", "Supported"), |
| 98 | ("lttng-modules-2.9", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"), |
| 99 | ("lttng-modules-2.9", "lttng-tools-2.8", "metadata regenerate", "Supported"), |
| 100 | ("lttng-modules-2.9", "lttng-tools-2.9", "regenerate metadata", "Supported"), |
| 101 | ("lttng-modules-2.9", "lttng-tools-2.10", "regenerate metadata", "Supported"), |
| 102 | ("lttng-modules-2.10", "lttng-tools-2.7", "metadata regenerate", "Unsupported by tools"), |
| 103 | ("lttng-modules-2.10", "lttng-tools-2.8", "metadata regenerate", "Supported"), |
| 104 | ("lttng-modules-2.10", "lttng-tools-2.9", "regenerate metadata", "Supported"), |
| 105 | ("lttng-modules-2.10", "lttng-tools-2.10","regenerate metadata", "Supported"), |
| 106 | ] |
| 107 | |
| 108 | test_matrix_statedump = [ |
| 109 | ("lttng-modules-2.7", "lttng-tools-2.7", "Unsupported by tools"), |
| 110 | ("lttng-modules-2.7", "lttng-tools-2.8", "Unsupported by tools"), |
| 111 | ("lttng-modules-2.7", "lttng-tools-2.9", "Unsupported by module"), |
| 112 | ("lttng-modules-2.7", "lttng-tools-2.10", "Unsupported by module"), |
| 113 | ("lttng-modules-2.8", "lttng-tools-2.7", "Unsupported by tools"), |
| 114 | ("lttng-modules-2.8", "lttng-tools-2.8", "Unsupported by tools"), |
| 115 | ("lttng-modules-2.8", "lttng-tools-2.9", "Unsupported by modules"), |
| 116 | ("lttng-modules-2.8", "lttng-tools-2.10", "Unsupported by modules"), |
| 117 | ("lttng-modules-2.9", "lttng-tools-2.7", "Unsupported by tools"), |
| 118 | ("lttng-modules-2.9", "lttng-tools-2.8", "Unsupported by tools"), |
| 119 | ("lttng-modules-2.9", "lttng-tools-2.9", "Supported"), |
| 120 | ("lttng-modules-2.9", "lttng-tools-2.10", "Supported"), |
| 121 | ("lttng-modules-2.10", "lttng-tools-2.7", "Unsupported by tools"), |
| 122 | ("lttng-modules-2.10", "lttng-tools-2.8", "Unsupported by tools"), |
| 123 | ("lttng-modules-2.10", "lttng-tools-2.9", "Supported"), |
| 124 | ("lttng-modules-2.10", "lttng-tools-2.10", "Supported"), |
| 125 | ] |
| 126 | |
| 127 | test_matrix_starglobing_enabler = [ |
| 128 | ("lttng-modules-2.7", "lttng-tools-2.7", "Unsupported by tools"), |
| 129 | ("lttng-modules-2.7", "lttng-tools-2.8", "Unsupported by tools"), |
| 130 | ("lttng-modules-2.7", "lttng-tools-2.9", "Unsupported by tools"), |
| 131 | ("lttng-modules-2.7", "lttng-tools-2.10", "Unsupported by modules"), |
| 132 | ("lttng-modules-2.8", "lttng-tools-2.7", "Unsupported by tools"), |
| 133 | ("lttng-modules-2.8", "lttng-tools-2.8", "Unsupported by tools"), |
| 134 | ("lttng-modules-2.8", "lttng-tools-2.9", "Unsupported by tools"), |
| 135 | ("lttng-modules-2.8", "lttng-tools-2.10", "Unsupported by modules"), |
| 136 | ("lttng-modules-2.9", "lttng-tools-2.7", "Unsupported by tools"), |
| 137 | ("lttng-modules-2.9", "lttng-tools-2.8", "Unsupported by tools"), |
| 138 | ("lttng-modules-2.9", "lttng-tools-2.9", "Unsupported by tools"), |
| 139 | ("lttng-modules-2.9", "lttng-tools-2.10", "Unsupported by modules"), |
| 140 | ("lttng-modules-2.10", "lttng-tools-2.7", "Unsupported by tools"), |
| 141 | ("lttng-modules-2.10", "lttng-tools-2.8", "Unsupported by tools"), |
| 142 | ("lttng-modules-2.10", "lttng-tools-2.9", "Unsupported by tools"), |
| 143 | ("lttng-modules-2.10", "lttng-tools-2.10", "Supported"), |
| 144 | ] |
| 145 | |
| 146 | |
| 147 | def get_metadata_file_path(base_trace_path): |
| 148 | metadata = os.path.join(base_trace_path, 'kernel', 'metadata') |
| 149 | return metadata |
| 150 | |
| 151 | |
| 152 | runtime_matrix_base_tracing = [] |
| 153 | runtime_matrix_regen_metadata = [] |
| 154 | runtime_matrix_statedump = [] |
| 155 | runtime_matrix_starglobing_enabler = [] |
| 156 | |
| 157 | if not Settings.test_only: |
| 158 | runtime_matrix_base_tracing = test_matrix_base_tracing |
| 159 | runtime_matrix_regen_metadata = test_matrix_regen_metadata |
| 160 | runtime_matrix_statedump = test_matrix_statedump |
| 161 | runtime_matrix_starglobing_enabler = test_matrix_starglobing_enabler |
| 162 | else: |
| 163 | for tup in test_matrix_base_tracing: |
| 164 | if (tup[0] in Settings.test_only or tup[1] in |
| 165 | Settings.test_only): |
| 166 | runtime_matrix_base_tracing.append(tup) |
| 167 | for tup in test_matrix_regen_metadata: |
| 168 | if (tup[0] in Settings.test_only or tup[1] in |
| 169 | Settings.test_only): |
| 170 | runtime_matrix_regen_metadata.append(tup) |
| 171 | for tup in test_matrix_statedump: |
| 172 | if (tup[0] in Settings.test_only or tup[1] in |
| 173 | Settings.test_only): |
| 174 | runtime_matrix_statedump.append(tup) |
| 175 | for tup in test_matrix_starglobing_enabler: |
| 176 | if (tup[0] in Settings.test_only or tup[1] in |
| 177 | Settings.test_only): |
| 178 | runtime_matrix_starglobing_enabler.append(tup) |
| 179 | |
| 180 | |
| 181 | @must_be_root |
| 182 | @pytest.mark.parametrize("modules_label,tools_label", runtime_matrix_base_tracing) |
| 183 | def test_modules_base_tracing(tmpdir, modules_label, tools_label): |
| 184 | modules = ProjectFactory.get_precook(modules_label) |
| 185 | if modules.skip: |
| 186 | pytest.skip("{} cannot be built on this kernel".format(modules.label)) |
| 187 | tools = ProjectFactory.get_precook(tools_label) |
| 188 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) |
| 189 | |
| 190 | nb_events = 100 |
| 191 | |
| 192 | with Run.get_runtime(str(tmpdir)) as runtime: |
| 193 | runtime.add_project(modules) |
| 194 | runtime.add_project(tools) |
| 195 | runtime.add_project(babeltrace) |
| 196 | |
| 197 | trace_path = os.path.join(runtime.lttng_home, 'trace') |
| 198 | babeltrace_cmd = 'babeltrace {}'.format(trace_path) |
| 199 | |
| 200 | sessiond = sessiond_spawn(runtime) |
| 201 | runtime.load_test_module() |
| 202 | |
| 203 | runtime.run("lttng create trace -o {}".format(trace_path)) |
| 204 | runtime.run("lttng enable-event -k lttng_test_filter_event") |
| 205 | runtime.run("lttng start") |
| 206 | with open(Settings.lttng_test_procfile, 'w') as procfile: |
| 207 | procfile.write("{}".format(nb_events)) |
| 208 | |
| 209 | runtime.run("lttng stop") |
| 210 | runtime.run("lttng destroy -a") |
| 211 | |
| 212 | sessiond = runtime.subprocess_terminate(sessiond) |
| 213 | if sessiond.returncode != 0: |
| 214 | pytest.fail("Return value of sessiond is not zero") |
| 215 | return |
| 216 | |
| 217 | cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd) |
| 218 | assert(line_count(cp_out) == nb_events) |
| 219 | |
| 220 | |
| 221 | @must_be_root |
| 222 | @pytest.mark.parametrize("modules_label,tools_label,command,scenario", runtime_matrix_regen_metadata) |
| 223 | def test_modules_regen_metadata(tmpdir, modules_label, tools_label, command, scenario): |
| 224 | modules = ProjectFactory.get_precook(modules_label) |
| 225 | if modules.skip: |
| 226 | pytest.skip("{} cannot be built on this kernel".format(modules.label)) |
| 227 | tools = ProjectFactory.get_precook(tools_label) |
| 228 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) |
| 229 | |
| 230 | nb_events = 10 |
| 231 | |
| 232 | with Run.get_runtime(str(tmpdir)) as runtime: |
| 233 | runtime.add_project(modules) |
| 234 | runtime.add_project(tools) |
| 235 | runtime.add_project(babeltrace) |
| 236 | |
| 237 | trace_path = os.path.join(runtime.lttng_home, 'trace') |
| 238 | babeltrace_cmd = 'babeltrace {}'.format(trace_path) |
| 239 | |
| 240 | sessiond = sessiond_spawn(runtime) |
| 241 | runtime.load_test_module() |
| 242 | |
| 243 | runtime.run("lttng create trace -o {}".format(trace_path)) |
| 244 | runtime.run("lttng enable-event -k lttng_test_filter_event") |
| 245 | runtime.run("lttng start") |
| 246 | with open(Settings.lttng_test_procfile, 'w') as procfile: |
| 247 | procfile.write("{}".format(nb_events)) |
| 248 | |
| 249 | runtime.run("lttng stop") |
| 250 | |
| 251 | # Validate that we have all event base on the current metadata |
| 252 | cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd) |
| 253 | assert(line_count(cp_out) == nb_events) |
| 254 | |
| 255 | # Empty the metadata file |
| 256 | open(get_metadata_file_path(trace_path), 'w').close() |
| 257 | |
| 258 | # Babeltrace should never be able to parse the trace |
| 259 | with pytest.raises(subprocess.CalledProcessError): |
| 260 | runtime.run(babeltrace_cmd) |
| 261 | |
| 262 | runtime.run("lttng start") |
| 263 | |
| 264 | # TODO: rework this a bit to differentiate each errors and rework how |
| 265 | # the condition are meet |
| 266 | if scenario == "Unsupported by tools" or scenario == "Unsupported by modules": |
| 267 | with pytest.raises(subprocess.CalledProcessError): |
| 268 | runtime.run("lttng {}".format(command)) |
| 269 | |
| 270 | # Make sure everything looks good on this side |
| 271 | sessiond = runtime.subprocess_terminate(sessiond) |
| 272 | if sessiond.returncode != 0: |
| 273 | pytest.fail("Return value of sessiond is not zero") |
| 274 | return |
| 275 | |
| 276 | runtime.run("lttng {}".format(command)) |
| 277 | runtime.run("lttng stop") |
| 278 | runtime.run("lttng destroy -a") |
| 279 | |
| 280 | sessiond = runtime.subprocess_terminate(sessiond) |
| 281 | if sessiond.returncode != 0: |
| 282 | pytest.fail("Return value of sessiond is not zero") |
| 283 | |
| 284 | cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd) |
| 285 | assert(line_count(cp_out) == nb_events) |
| 286 | |
| 287 | |
| 288 | @must_be_root |
| 289 | @pytest.mark.parametrize("modules_label,tools_label,scenario", runtime_matrix_statedump) |
| 290 | def test_modules_statedump(tmpdir, modules_label, tools_label, scenario): |
| 291 | modules = ProjectFactory.get_precook(modules_label) |
| 292 | if modules.skip: |
| 293 | pytest.skip("{} cannot be built on this kernel".format(modules.label)) |
| 294 | tools = ProjectFactory.get_precook(tools_label) |
| 295 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) |
| 296 | |
| 297 | nb_events = 100 |
| 298 | if scenario == "Unsupported by tools" or scenario == "Unsupported by modules": |
| 299 | expected_event = 2 |
| 300 | else: |
| 301 | expected_event = 4 |
| 302 | |
| 303 | with Run.get_runtime(str(tmpdir)) as runtime: |
| 304 | runtime.add_project(modules) |
| 305 | runtime.add_project(tools) |
| 306 | runtime.add_project(babeltrace) |
| 307 | |
| 308 | trace_path = os.path.join(runtime.lttng_home, 'trace') |
| 309 | babeltrace_cmd = 'babeltrace {}'.format(trace_path) |
| 310 | |
| 311 | sessiond = sessiond_spawn(runtime) |
| 312 | runtime.load_test_module() |
| 313 | |
| 314 | runtime.run("lttng create trace -o {}".format(trace_path)) |
| 315 | runtime.run("lttng enable-event -k lttng_statedump_start,lttng_statedump_end") |
| 316 | runtime.run("lttng start") |
| 317 | |
| 318 | # Generate some event |
| 319 | with open(Settings.lttng_test_procfile, 'w') as procfile: |
| 320 | procfile.write("{}".format(nb_events)) |
| 321 | |
| 322 | if scenario == "Unsupported by tools" or scenario == "Unsupported by modules": |
| 323 | with pytest.raises(subprocess.CalledProcessError): |
| 324 | runtime.run("lttng regenerate statedump") |
| 325 | else: |
| 326 | runtime.run("lttng regenerate statedump") |
| 327 | |
| 328 | runtime.run("lttng stop") |
| 329 | runtime.run("lttng destroy -a") |
| 330 | |
| 331 | sessiond = runtime.subprocess_terminate(sessiond) |
| 332 | if sessiond.returncode != 0: |
| 333 | pytest.fail("Return value of sessiond is not zero") |
| 334 | |
| 335 | cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd) |
| 336 | assert(line_count(cp_out) == expected_event) |
| 337 | |
| 338 | |
| 339 | @must_be_root |
| 340 | @pytest.mark.parametrize("modules_label,tools_label, scenario", runtime_matrix_starglobing_enabler) |
| 341 | def test_modules_starglobing_enabler(tmpdir, modules_label, tools_label, scenario): |
| 342 | modules = ProjectFactory.get_precook(modules_label) |
| 343 | if modules.skip: |
| 344 | pytest.skip("{} cannot be built on this kernel".format(modules.label)) |
| 345 | tools = ProjectFactory.get_precook(tools_label) |
| 346 | babeltrace = ProjectFactory.get_precook(Settings.default_babeltrace) |
| 347 | |
| 348 | nb_events = 100 |
| 349 | |
| 350 | if scenario == "Unsupported by modules": |
| 351 | expected_events = 0 |
| 352 | else: |
| 353 | expected_events = nb_events |
| 354 | |
| 355 | with Run.get_runtime(str(tmpdir)) as runtime: |
| 356 | runtime.add_project(modules) |
| 357 | runtime.add_project(tools) |
| 358 | runtime.add_project(babeltrace) |
| 359 | |
| 360 | trace_path = os.path.join(runtime.lttng_home, 'trace') |
| 361 | babeltrace_cmd = 'babeltrace {}'.format(trace_path) |
| 362 | |
| 363 | sessiond = sessiond_spawn(runtime) |
| 364 | runtime.load_test_module() |
| 365 | |
| 366 | runtime.run("lttng create trace -o {}".format(trace_path)) |
| 367 | |
| 368 | if scenario == "Unsupported by tools": |
| 369 | with pytest.raises(subprocess.CalledProcessError): |
| 370 | runtime.run("lttng enable-event -k 'lttng_test_*_even*'") |
| 371 | sessiond = runtime.subprocess_terminate(sessiond) |
| 372 | if sessiond.returncode != 0: |
| 373 | pytest.fail("Return value of sessiond is not zero") |
| 374 | return |
| 375 | |
| 376 | runtime.run("lttng enable-event -k 'lttng_test_*_even*'") |
| 377 | runtime.run("lttng start") |
| 378 | |
| 379 | # Generate some event |
| 380 | with open(Settings.lttng_test_procfile, 'w') as procfile: |
| 381 | procfile.write("{}".format(nb_events)) |
| 382 | |
| 383 | runtime.run("lttng stop") |
| 384 | runtime.run("lttng destroy -a") |
| 385 | |
| 386 | sessiond = runtime.subprocess_terminate(sessiond) |
| 387 | if sessiond.returncode != 0: |
| 388 | pytest.fail("Return value of sessiond is not zero") |
| 389 | |
| 390 | cp_process, cp_out, cp_err = runtime.run(babeltrace_cmd) |
| 391 | assert(line_count(cp_out) == expected_events) |