Rework TestGenerator to add file targets

BaseTarget-derived targets are now added to TestGenerator.targets in
initialization. This reduces repeated code in generate_xxx_tests.py
scripts which use this framework.

Signed-off-by: Werner Lewis <werner.lewis@arm.com>
diff --git a/scripts/mbedtls_dev/test_generation.py b/scripts/mbedtls_dev/test_generation.py
index 6382a99..5341c9a 100644
--- a/scripts/mbedtls_dev/test_generation.py
+++ b/scripts/mbedtls_dev/test_generation.py
@@ -133,6 +133,11 @@
     def __init__(self, options) -> None:
         self.test_suite_directory = self.get_option(options, 'directory',
                                                     'tests/suites')
+        # Add file Targets which have been declared in other modules
+        self.targets.update({
+            subclass.target_basename: subclass.generate_tests
+            for subclass in BaseTarget.__subclasses__()
+        })
 
     @staticmethod
     def get_option(options, name: str, default: T) -> T:
@@ -154,7 +159,7 @@
 
     # Note that targets whose names contain 'test_format' have their content
     # validated by `abi_check.py`.
-    TARGETS = {} # type: Dict[str, Callable[..., Iterable[test_case.TestCase]]]
+    targets = {} # type: Dict[str, Callable[..., Iterable[test_case.TestCase]]]
 
     def generate_target(self, name: str, *target_args) -> None:
         """Generate cases and write to data file for a target.
@@ -162,7 +167,7 @@
         For target callables which require arguments, override this function
         and pass these arguments using super() (see PSATestGenerator).
         """
-        test_cases = self.TARGETS[name](*target_args)
+        test_cases = self.targets[name](*target_args)
         self.write_test_data_file(name, test_cases)
 
 def main(args, generator_class: Type[TestGenerator] = TestGenerator):
@@ -171,19 +176,21 @@
     parser.add_argument('--list', action='store_true',
                         help='List available targets and exit')
     parser.add_argument('targets', nargs='*', metavar='TARGET',
-                        default=sorted(generator_class.TARGETS),
                         help='Target file to generate (default: all; "-": none)')
     options = parser.parse_args(args)
     generator = generator_class(options)
     if options.list:
-        for name in sorted(generator.TARGETS):
+        for name in sorted(generator.targets):
             print(generator.filename_for(name))
         return
-    # Allow "-" as a special case so you can run
-    # ``generate_xxx_tests.py - $targets`` and it works uniformly whether
-    # ``$targets`` is empty or not.
-    options.targets = [os.path.basename(re.sub(r'\.data\Z', r'', target))
-                       for target in options.targets
-                       if target != '-']
+    if options.targets:
+        # Allow "-" as a special case so you can run
+        # ``generate_xxx_tests.py - $targets`` and it works uniformly whether
+        # ``$targets`` is empty or not.
+        options.targets = [os.path.basename(re.sub(r'\.data\Z', r'', target))
+                            for target in options.targets
+                            if target != '-']
+    else:
+        options.targets = sorted(generator.targets)
     for target in options.targets:
         generator.generate_target(target)