| 335 | @pytest.mark.parametrize("example", CLI_INSPECT_EXAMPLES, ids=lambda case: str(case)) |
| 336 | @pytest.mark.script_launch_mode("subprocess") |
| 337 | def test_cli_inspect_examples(example, sandboxed_install_run): |
| 338 | if mod.version(trt.__version__) < mod.version("8.5") and example.path.endswith("02_inspecting_a_tensorrt_engine"): |
| 339 | pytest.skip("Engine layer inspection example is not supported on older versions of TRT") |
| 340 | |
| 341 | if mod.version(trt.__version__) < mod.version("8.2") and example.path.endswith( |
| 342 | "08_inspecting_tensorrt_onnx_support" |
| 343 | ): |
| 344 | pytest.skip("Capability subtool is not supported on older versions of TRT") |
| 345 | |
| 346 | # Last block should be the expected output, and last command should generate it. |
| 347 | with example as blocks: |
| 348 | command_blocks, expected_output = blocks[:-1], str(blocks[-1]) |
| 349 | for cmd_block in command_blocks: |
| 350 | actual_output = example.run(cmd_block, sandboxed_install_run).stdout |
| 351 | |
| 352 | print(actual_output) |
| 353 | # Makes reading the diff way easier |
| 354 | actual_lines = [ |
| 355 | line |
| 356 | for line in actual_output.splitlines() |
| 357 | if "[I] Loading " not in line |
| 358 | and "[I] Saving" not in line |
| 359 | and not line.startswith("[W]") |
| 360 | and not line.startswith("[E]") |
| 361 | ] |
| 362 | |
| 363 | expected_lines = expected_output.splitlines() |
| 364 | assert len(actual_lines) == len(expected_lines) |
| 365 | |
| 366 | # Indicates lines that may not match exactly |
| 367 | NON_EXACT_LINE_MARKERS = ["---- ", " Layer", " Algorithm:"] |
| 368 | |
| 369 | for index, (actual_line, expected_line) in enumerate(zip(actual_lines, expected_lines)): |
| 370 | # Skip whitespace, and lines that include runner names (since those have timestamps) |
| 371 | if expected_line.strip() and all([marker not in expected_line for marker in NON_EXACT_LINE_MARKERS]): |
| 372 | print(f"Checking line {index}: {expected_line}") |
| 373 | assert actual_line == expected_line |
| 374 | |
| 375 | |
| 376 | DEV_EXAMPLES = [ |