blob: 7bdffe4247c6ce8359f7bb9cf95588bc89dbb6ab [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()
Ravago Jones5127ccc2022-07-31 16:32:45 -070015 parser.add_argument("--log_to_mcap",
16 required=True,
17 help="Path to log_to_mcap binary.")
James Kuszmaul5c56ed32022-03-30 15:10:07 -070018 parser.add_argument("--mcap", required=True, help="Path to mcap binary.")
Ravago Jones5127ccc2022-07-31 16:32:45 -070019 parser.add_argument("--generate_log",
20 required=True,
21 help="Path to logfile generator.")
James Kuszmaul5c56ed32022-03-30 15:10:07 -070022 args = parser.parse_args(argv)
23 with tempfile.TemporaryDirectory() as tmpdir:
24 log_name = tmpdir + "/test_log/"
25 mcap_name = tmpdir + "/log.mcap"
Ravago Jones5127ccc2022-07-31 16:32:45 -070026 subprocess.run([args.generate_log, "--output_folder",
27 log_name]).check_returncode()
James Kuszmaul5c56ed32022-03-30 15:10:07 -070028 # Run with a really small chunk size, to force a multi-chunk file.
Ravago Jones5127ccc2022-07-31 16:32:45 -070029 subprocess.run([
30 args.log_to_mcap, "--output_path", mcap_name, "--mcap_chunk_size",
31 "1000", "--mode", "json", log_name
32 ]).check_returncode()
James Kuszmaul5c56ed32022-03-30 15:10:07 -070033 # 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 Jones5127ccc2022-07-31 16:32:45 -070035 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 Kuszmaul5c56ed32022-03-30 15:10:07 -070041 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
55if __name__ == '__main__':
56 sys.exit(main(sys.argv[1:]))