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 <Gilles.Peskine@arm.com>
diff --git a/scripts/mbedtls_framework/generate_files_helper.py b/scripts/mbedtls_framework/generate_files_helper.py
index a4ec4a5..10ab2e9 100644
--- a/scripts/mbedtls_framework/generate_files_helper.py
+++ b/scripts/mbedtls_framework/generate_files_helper.py
@@ -6,6 +6,8 @@
 # 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 @@
         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]