From d85217d8f58aa5f5428e9b92f9d8ee65804a797b Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 11 Feb 2026 16:38:28 +0100 Subject: [PATCH] Support test data generators in generate_files_helper.py Support check and always-update mode. Update-if-needed mode falls back to always-update mode because test_data_generation.py doesn't support update-if-needed. Signed-off-by: Gilles Peskine --- .../generate_files_helper.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/scripts/mbedtls_framework/generate_files_helper.py b/scripts/mbedtls_framework/generate_files_helper.py index a4ec4a54b..10ab2e977 100644 --- a/scripts/mbedtls_framework/generate_files_helper.py +++ b/scripts/mbedtls_framework/generate_files_helper.py @@ -6,6 +6,8 @@ and configuration-independent. # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later import argparse +import os +import subprocess import sys from typing import Dict, Iterable, List, Sequence, Set @@ -46,6 +48,39 @@ class Generator: raise NotImplementedError +class TestDataGenerator(Generator): + """A test data generator script. + + Even though the test data generator scripts are written in Python, we + run them as a separate process, because their output depends on the + program name (they write sys.argv[0] in a comment in the .data file). + """ + + def __init__(self, script: str) -> None: + """Run the specified test generator to generate files. + + Assume that the script is written in Python and has the command line + interface of test_data_generation.py. + """ + self.script = script + + def generator_name(self) -> str: + return os.path.basename(self.script) + + def target_files(self) -> List[str]: + output = subprocess.check_output([sys.executable, self.script, '--list'], + encoding='utf-8') + return output.splitlines() + + def outdated_files(self) -> List[str]: + output = subprocess.check_output([sys.executable, self.script, '--list-outdated'], + encoding='utf-8') + return output.splitlines() + + def update(self, _always) -> None: + subprocess.check_call([sys.executable, self.script]) + + def assemble(available: Iterable[Generator]) -> Dict[str, Generator]: """Assemble the generators into a dictionary with both names and targets as keys.""" by_ident = {} #type: Dict[str, Generator]