From 0c19a6853623fcd2508f78f2969a9509d8fdf9b1 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Fri, 4 Jul 2025 12:49:00 -0500 Subject: [PATCH] scripts: test.py/bench.py: Added support for multiple header files Like test.py --gdb-script, being able to specify multiple header files seems useful and is easy enough to add. --- Note that the default is only used if no other header files are specified, so this _replaces_ the default header file: $ ./scripts/test.py --include=my_header.h If you don't want to replace the default header file, you currently need to specify it explicitly: $ ./scripts/test.py \ --include=runners/test_runner.h \ --include=my_header.h --- scripts/bench.py | 10 +++++----- scripts/test.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/bench.py b/scripts/bench.py index b0f3dfe9..e17fe379 100755 --- a/scripts/bench.py +++ b/scripts/bench.py @@ -37,7 +37,7 @@ except ModuleNotFoundError: RUNNER_PATH = ['./runners/bench_runner'] -HEADER_PATH = 'runners/bench_runner.h' +HEADER_PATHS = ['./runners/bench_runner.h'] GDB_PATH = ['gdb'] GDB_SCRIPTS = ['./scripts/dbg.gdb.py'] @@ -383,7 +383,8 @@ def compile(bench_paths, **args): f.writeln() # include bench_runner.h in every generated file - f.writeln("#include \"%s\"" % args['include']) + for header in (args.get('include') or HEADER_PATHS): + f.writeln("#include \"%s\"" % header) f.writeln() # write out generated functions, this can end up in different @@ -1765,9 +1766,8 @@ if __name__ == "__main__": help="Source file to compile, possibly injecting internal benches.") comp_parser.add_argument( '--include', - default=HEADER_PATH, - help="Inject this header file into every compiled bench file. " - "Defaults to %r." % HEADER_PATH) + help="Inject these header files into every compiled bench file. " + "Defaults to %r." % HEADER_PATHS) comp_parser.add_argument( '-o', '--output', help="Output file.") diff --git a/scripts/test.py b/scripts/test.py index f7f757b2..0d2f2f1c 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -38,7 +38,7 @@ except ModuleNotFoundError: RUNNER_PATH = ['./runners/test_runner'] -HEADER_PATH = 'runners/test_runner.h' +HEADER_PATHS = ['./runners/test_runner.h'] GDB_PATH = ['gdb'] GDB_SCRIPTS = ['./scripts/dbg.gdb.py'] @@ -395,7 +395,8 @@ def compile(test_paths, **args): f.writeln() # include test_runner.h in every generated file - f.writeln("#include \"%s\"" % args['include']) + for header in (args.get('include') or HEADER_PATHS): + f.writeln("#include \"%s\"" % header) f.writeln() # write out generated functions, this can end up in different @@ -1800,9 +1801,8 @@ if __name__ == "__main__": help="Source file to compile, possibly injecting internal tests.") comp_parser.add_argument( '--include', - default=HEADER_PATH, - help="Inject this header file into every compiled test file. " - "Defaults to %r." % HEADER_PATH) + help="Inject these header files into every compiled test file. " + "Defaults to %r." % HEADER_PATHS) comp_parser.add_argument( '-o', '--output', help="Output file.")