diff options
| author | Theofilos Augoustis <theofilos.augoustis@gmail.com> | 2023-12-26 21:03:01 +0100 |
|---|---|---|
| committer | Theofilos Augoustis <theofilos.augoustis@gmail.com> | 2023-12-26 21:03:01 +0100 |
| commit | d26ae0a7d583da5034cd6271f953b6253119ceae (patch) | |
| tree | 250dec66897abd594e007dfe8beed06519e7a4cf /tools/convert.py | |
| parent | f2246e641d494d5df76458db4fb4928f5c2cfc7f (diff) | |
| download | focaccia-d26ae0a7d583da5034cd6271f953b6253119ceae.tar.gz focaccia-d26ae0a7d583da5034cd6271f953b6253119ceae.zip | |
Verify QEMU by converting logs to internal data format
Co-authored-by: Theofilos Augoustis <theofilos.augoustis@gmail.com> Co-authored-by: Nicola Crivellin <nicola.crivellin98@gmail.com>
Diffstat (limited to 'tools/convert.py')
| -rw-r--r-- | tools/convert.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/tools/convert.py b/tools/convert.py new file mode 100644 index 0000000..27a8a4a --- /dev/null +++ b/tools/convert.py @@ -0,0 +1,47 @@ +import argparse +import sys + +import focaccia.parser as parser +from focaccia.arch import supported_architectures + +convert_funcs = { + 'qemu': parser.parse_qemu, + 'arancini': parser.parse_arancini, +} + +def main(): + """Main.""" + prog = argparse.ArgumentParser() + prog.description = 'Convert other programs\' logs to focaccia\'s log format.' + prog.add_argument('file', help='The log to convert.') + prog.add_argument('--type', + required=True, + choices=convert_funcs.keys(), + help='The log type of `file`') + prog.add_argument('--output', '-o', + help='Output file (default is stdout)') + prog.add_argument('--arch', + default='x86_64', + choices=supported_architectures.keys(), + help='Processor architecture of input log (default is x86)') + args = prog.parse_args() + + # Parse arancini log + arch = supported_architectures[args.arch] + parse_log = convert_funcs[args.type] + with open(args.file, 'r') as in_file: + try: + snapshots = parse_log(in_file, arch) + except parser.ParseError as err: + print(f'Parse error: {err}. Exiting.', file=sys.stderr) + exit(1) + + # Write log in focaccia's format + if args.output: + with open(args.output, 'w') as out_file: + parser.serialize_snapshots(snapshots, out_file) + else: + parser.serialize_snapshots(snapshots, sys.stdout) + +if __name__ == '__main__': + main() |