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