blob: 72c90780be8e9dee3a307a38ec1659d02854145c [file] [log] [blame]
James Kuszmaul5c56ed32022-03-30 15:10:07 -07001#!/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.
5import argparse
6import subprocess
7import sys
8import tempfile
9import time
10from typing import Sequence, Text
11
12
13def main(argv: Sequence[Text]):
14 parser = argparse.ArgumentParser()
15 parser.add_argument("--log_to_mcap", required=True, help="Path to log_to_mcap binary.")
16 parser.add_argument("--mcap", required=True, help="Path to mcap binary.")
17 parser.add_argument("--generate_log", required=True, help="Path to logfile generator.")
18 args = parser.parse_args(argv)
19 with tempfile.TemporaryDirectory() as tmpdir:
20 log_name = tmpdir + "/test_log/"
21 mcap_name = tmpdir + "/log.mcap"
22 subprocess.run([args.generate_log, "--output_folder", log_name]).check_returncode()
23 # Run with a really small chunk size, to force a multi-chunk file.
24 subprocess.run(
James Kuszmaulc31d7362022-05-27 14:20:04 -070025 [args.log_to_mcap, "--output_path", mcap_name, "--mcap_chunk_size", "1000", "--mode", "json",
James Kuszmaul5c56ed32022-03-30 15:10:07 -070026 log_name]).check_returncode()
27 # MCAP attempts to find $HOME/.mcap.yaml, and dies on $HOME not existing. So
28 # give it an arbitrary config location (it seems to be fine with a non-existent config).
29 doctor_result = subprocess.run(
30 [args.mcap, "doctor", mcap_name, "--config", tmpdir + "/.mcap.yaml"],
31 stdout=subprocess.PIPE,
32 stderr=subprocess.PIPE,
33 encoding='utf-8')
34 print(doctor_result.stdout)
35 print(doctor_result.stderr)
36 # mcap doctor doesn't actually return a non-zero exit code on certain failures...
37 # See https://github.com/foxglove/mcap/issues/356
38 if len(doctor_result.stderr) != 0:
39 print("Didn't expect any stderr output.")
40 return 1
41 if doctor_result.stdout != f"Examining {mcap_name}\n":
42 print("Only expected one line of stdout.")
43 return 1
44 doctor_result.check_returncode()
45 return 0
46
47
48if __name__ == '__main__':
49 sys.exit(main(sys.argv[1:]))