James Kuszmaul | 5c56ed3 | 2022-03-30 15:10:07 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # This script is meant to act as a test to confirm that our log_to_mcap converter produces |
| 3 | # a valid MCAP file. To do so, it first generates an AOS log, then converts it to MCAP, and |
| 4 | # then runs the "mcap doctor" tool on it to confirm compliance with the standard. |
| 5 | import argparse |
| 6 | import subprocess |
| 7 | import sys |
| 8 | import tempfile |
| 9 | import time |
| 10 | from typing import Sequence, Text |
| 11 | |
| 12 | |
| 13 | def main(argv: Sequence[Text]): |
| 14 | parser = argparse.ArgumentParser() |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 15 | parser.add_argument("--log_to_mcap", |
| 16 | required=True, |
| 17 | help="Path to log_to_mcap binary.") |
James Kuszmaul | 5c56ed3 | 2022-03-30 15:10:07 -0700 | [diff] [blame] | 18 | parser.add_argument("--mcap", required=True, help="Path to mcap binary.") |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 19 | parser.add_argument("--generate_log", |
| 20 | required=True, |
| 21 | help="Path to logfile generator.") |
James Kuszmaul | 5c56ed3 | 2022-03-30 15:10:07 -0700 | [diff] [blame] | 22 | args = parser.parse_args(argv) |
| 23 | with tempfile.TemporaryDirectory() as tmpdir: |
| 24 | log_name = tmpdir + "/test_log/" |
| 25 | mcap_name = tmpdir + "/log.mcap" |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 26 | subprocess.run([args.generate_log, "--output_folder", |
| 27 | log_name]).check_returncode() |
James Kuszmaul | 5c56ed3 | 2022-03-30 15:10:07 -0700 | [diff] [blame] | 28 | # Run with a really small chunk size, to force a multi-chunk file. |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 29 | subprocess.run([ |
| 30 | args.log_to_mcap, "--output_path", mcap_name, "--mcap_chunk_size", |
| 31 | "1000", "--mode", "json", log_name |
| 32 | ]).check_returncode() |
James Kuszmaul | 5c56ed3 | 2022-03-30 15:10:07 -0700 | [diff] [blame] | 33 | # MCAP attempts to find $HOME/.mcap.yaml, and dies on $HOME not existing. So |
| 34 | # give it an arbitrary config location (it seems to be fine with a non-existent config). |
Ravago Jones | 5127ccc | 2022-07-31 16:32:45 -0700 | [diff] [blame^] | 35 | doctor_result = subprocess.run([ |
| 36 | args.mcap, "doctor", mcap_name, "--config", tmpdir + "/.mcap.yaml" |
| 37 | ], |
| 38 | stdout=subprocess.PIPE, |
| 39 | stderr=subprocess.PIPE, |
| 40 | encoding='utf-8') |
James Kuszmaul | 5c56ed3 | 2022-03-30 15:10:07 -0700 | [diff] [blame] | 41 | print(doctor_result.stdout) |
| 42 | print(doctor_result.stderr) |
| 43 | # mcap doctor doesn't actually return a non-zero exit code on certain failures... |
| 44 | # See https://github.com/foxglove/mcap/issues/356 |
| 45 | if len(doctor_result.stderr) != 0: |
| 46 | print("Didn't expect any stderr output.") |
| 47 | return 1 |
| 48 | if doctor_result.stdout != f"Examining {mcap_name}\n": |
| 49 | print("Only expected one line of stdout.") |
| 50 | return 1 |
| 51 | doctor_result.check_returncode() |
| 52 | return 0 |
| 53 | |
| 54 | |
| 55 | if __name__ == '__main__': |
| 56 | sys.exit(main(sys.argv[1:])) |