blob: 36f8de0920fa345b71fe0a8a0e8e2dc4667d5faa [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
James Kuszmaul5ab990d2022-11-07 16:35:49 -080013def make_permutations(options):
14 if len(options) == 0:
15 return [[]]
16 permutations = []
17 for option in options[0]:
18 for sub_permutations in make_permutations(options[1:]):
19 permutations.append([option] + sub_permutations)
20 return permutations
21
22
23def generate_argument_permutations():
24 arg_sets = [["--compress", "--nocompress"],
25 ["--mode=flatbuffer", "--mode=json"],
26 ["--canonical_channel_names", "--nocanonical_channel_names"],
27 ["--mcap_chunk_size=1000", "--mcap_chunk_size=10000000"],
28 ["--fetch", "--nofetch"]]
29 permutations = make_permutations(arg_sets)
30 print(permutations)
31 return permutations
32
33
James Kuszmaul5c56ed32022-03-30 15:10:07 -070034def main(argv: Sequence[Text]):
35 parser = argparse.ArgumentParser()
Ravago Jones5127ccc2022-07-31 16:32:45 -070036 parser.add_argument("--log_to_mcap",
37 required=True,
38 help="Path to log_to_mcap binary.")
James Kuszmaul5c56ed32022-03-30 15:10:07 -070039 parser.add_argument("--mcap", required=True, help="Path to mcap binary.")
Ravago Jones5127ccc2022-07-31 16:32:45 -070040 parser.add_argument("--generate_log",
41 required=True,
42 help="Path to logfile generator.")
James Kuszmaul5c56ed32022-03-30 15:10:07 -070043 args = parser.parse_args(argv)
James Kuszmaul5ab990d2022-11-07 16:35:49 -080044 log_to_mcap_argument_permutations = generate_argument_permutations()
45 for log_to_mcap_args in log_to_mcap_argument_permutations:
46 with tempfile.TemporaryDirectory() as tmpdir:
47 log_name = tmpdir + "/test_log/"
48 mcap_name = tmpdir + "/log.mcap"
49 subprocess.run([args.generate_log, "--output_folder",
50 log_name]).check_returncode()
51 # Run with a really small chunk size, to force a multi-chunk file.
52 subprocess.run([
53 args.log_to_mcap, "--output_path", mcap_name,
54 "--mcap_chunk_size", "1000", "--mode", "json", log_name
55 ] + log_to_mcap_args).check_returncode()
56 # MCAP attempts to find $HOME/.mcap.yaml, and dies on $HOME not existing. So
57 # give it an arbitrary config location (it seems to be fine with a non-existent config).
58 doctor_result = subprocess.run([
59 args.mcap, "doctor", mcap_name, "--config",
60 tmpdir + "/.mcap.yaml"
61 ],
62 stdout=subprocess.PIPE,
63 stderr=subprocess.PIPE,
64 encoding='utf-8')
65 print(doctor_result.stdout)
66 print(doctor_result.stderr)
67 # mcap doctor doesn't actually return a non-zero exit code on certain failures...
68 # See https://github.com/foxglove/mcap/issues/356
69 if len(doctor_result.stderr) != 0:
70 print("Didn't expect any stderr output.")
71 return 1
72 if doctor_result.stdout != f"Examining {mcap_name}\nHeader.profile field \"x-aos\" is not a well-known profile.\n":
73 print("Only expected two lines of stdout.")
74 return 1
75 doctor_result.check_returncode()
James Kuszmaul5c56ed32022-03-30 15:10:07 -070076 return 0
77
78
79if __name__ == '__main__':
80 sys.exit(main(sys.argv[1:]))