From 91bf8843463d4b05ea401c8318a4154007098a7d Mon Sep 17 00:00:00 2001 From: Alessandro Gatti Date: Tue, 7 Nov 2023 22:32:12 +0100 Subject: [PATCH] tools/tinytest-codegen: Ensure consistent tests order. Make sure the the generated header file contains tests appearing in a predictable order, conforming to `tests/run-tests.py`'s behaviour. Signed-off-by: Alessandro Gatti --- tools/tinytest-codegen.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/tinytest-codegen.py b/tools/tinytest-codegen.py index 8178b56020..781b8de8d2 100755 --- a/tools/tinytest-codegen.py +++ b/tools/tinytest-codegen.py @@ -32,10 +32,24 @@ def script_to_map(test_file): return r +def flatten_iterable(iterable): + flattened = set() + for element in iterable: + if isinstance(element, (list, tuple, set)): + flattened = flattened.union(flatten_iterable(element)) + elif isinstance(element, str): + flattened.add(element) + else: + raise TypeError("Invalid type %s for element `%s`" % (type(element), element)) + return flattened + + def load_profile(profile_file, test_dirs, exclude_tests): profile_globals = {"test_dirs": test_dirs, "exclude_tests": exclude_tests} exec(profile_file.read(), profile_globals) - return profile_globals["test_dirs"], profile_globals["exclude_tests"] + return flatten_iterable(profile_globals["test_dirs"]), flatten_iterable( + profile_globals["exclude_tests"] + ) test_function = ( @@ -127,8 +141,10 @@ if not args.stdin: test_dirs, exclude_tests = load_profile(args.profile, test_dirs, exclude_tests) if args.exclude: exclude_tests = exclude_tests.union(args.exclude) - for group in test_dirs: - tests += [test for test in glob("{}/*.py".format(group)) if test not in exclude_tests] + for group in sorted(test_dirs): + tests += [ + test for test in sorted(glob("{}/*.py".format(group))) if test not in exclude_tests + ] else: for l in sys.stdin: tests.append(l.rstrip())