From 7e4b36f2d7c8bdcd3425f6b2926d07680ad3bf7b Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Wed, 20 Nov 2024 17:42:06 +0100 Subject: [PATCH 1/5] Enable to specify multiple config file for config.py Signed-off-by: Gabor Mezei --- scripts/mbedtls_framework/config_common.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/mbedtls_framework/config_common.py b/scripts/mbedtls_framework/config_common.py index 05ad8d670..570eba2fd 100644 --- a/scripts/mbedtls_framework/config_common.py +++ b/scripts/mbedtls_framework/config_common.py @@ -387,7 +387,7 @@ class ConfigTool(metaclass=ABCMeta): Custom parser options can be added by overriding 'custom_parser_options'. """ - def __init__(self, default_file_path): + def __init__(self, default_file_path, single_config=True): """Create parser for config manipulation tool. :param default_file_path: Default configuration file path @@ -397,7 +397,7 @@ class ConfigTool(metaclass=ABCMeta): Configuration file manipulation tool.""") self.subparsers = self.parser.add_subparsers(dest='command', title='Commands') - self._common_parser_options(default_file_path) + self._common_parser_options(default_file_path, single_config) self.custom_parser_options() self.args = self.parser.parse_args() self.config = Config() # Make the pylint happy @@ -408,14 +408,17 @@ class ConfigTool(metaclass=ABCMeta): subparser = self.subparsers.add_parser(name, help=description) subparser.set_defaults(adapter=function) - def _common_parser_options(self, default_file_path): + def _common_parser_options(self, default_file_path, single_config=True): # pylint: disable=too-many-branches """Common parser options for config manipulation tool.""" self.parser.add_argument( '--file', '-f', - help="""File to read (and modify if requested). Default: {}. - """.format(default_file_path)) + action='store' if single_config else 'append', + help=("""File to read (and modify if requested). Default: {}.""" if single_config else + """Files to read (and modify if requested). Default: {}. + Can be used multiple times to specify more config files.""" + ).format(default_file_path)) self.parser.add_argument( '--force', '-o', action='store_true', From 7cb68054bf19d48a5c340cb2f53e05ddb50f11b1 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Wed, 20 Nov 2024 17:43:20 +0100 Subject: [PATCH 2/5] Fix existence check of config files Signed-off-by: Gabor Mezei --- scripts/mbedtls_framework/config_common.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/mbedtls_framework/config_common.py b/scripts/mbedtls_framework/config_common.py index 570eba2fd..0e2f48877 100644 --- a/scripts/mbedtls_framework/config_common.py +++ b/scripts/mbedtls_framework/config_common.py @@ -228,9 +228,10 @@ class ConfigFile(metaclass=ABCMeta): if os.path.lexists(candidate): filename = candidate break - else: - raise FileNotFoundError(f'{name} configuration file not found: ' - f'{filename if filename else default_path}') + + if not os.path.lexists(filename): + raise FileNotFoundError(f'{name} configuration file not found: ' + f'{filename if filename else default_path}') self.filename = filename self.templates = [] From 7a6b1b361746a77c72d346149c0c94c3aca797d4 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Fri, 29 Nov 2024 13:15:30 +0100 Subject: [PATCH 3/5] Revert "Enable to specify multiple config file for config.py" This reverts commit 721b7e14d39ab1ff0c3324302a8e66daec330f25. Signed-off-by: Gabor Mezei --- scripts/mbedtls_framework/config_common.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/scripts/mbedtls_framework/config_common.py b/scripts/mbedtls_framework/config_common.py index 0e2f48877..123785d4b 100644 --- a/scripts/mbedtls_framework/config_common.py +++ b/scripts/mbedtls_framework/config_common.py @@ -388,7 +388,7 @@ class ConfigTool(metaclass=ABCMeta): Custom parser options can be added by overriding 'custom_parser_options'. """ - def __init__(self, default_file_path, single_config=True): + def __init__(self, default_file_path): """Create parser for config manipulation tool. :param default_file_path: Default configuration file path @@ -398,7 +398,7 @@ class ConfigTool(metaclass=ABCMeta): Configuration file manipulation tool.""") self.subparsers = self.parser.add_subparsers(dest='command', title='Commands') - self._common_parser_options(default_file_path, single_config) + self._common_parser_options(default_file_path) self.custom_parser_options() self.args = self.parser.parse_args() self.config = Config() # Make the pylint happy @@ -409,17 +409,14 @@ class ConfigTool(metaclass=ABCMeta): subparser = self.subparsers.add_parser(name, help=description) subparser.set_defaults(adapter=function) - def _common_parser_options(self, default_file_path, single_config=True): + def _common_parser_options(self, default_file_path): # pylint: disable=too-many-branches """Common parser options for config manipulation tool.""" self.parser.add_argument( '--file', '-f', - action='store' if single_config else 'append', - help=("""File to read (and modify if requested). Default: {}.""" if single_config else - """Files to read (and modify if requested). Default: {}. - Can be used multiple times to specify more config files.""" - ).format(default_file_path)) + help="""File to read (and modify if requested). Default: {}. + """.format(default_file_path)) self.parser.add_argument( '--force', '-o', action='store_true', From ef74a5c148fff4aa3439f28f6070d7339dcd249e Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Fri, 29 Nov 2024 13:16:08 +0100 Subject: [PATCH 4/5] Update test generation to support TF-PSA-Crypto config.py Signed-off-by: Gabor Mezei --- scripts/generate_config_tests.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) mode change 100755 => 100644 scripts/generate_config_tests.py diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py old mode 100755 new mode 100644 index 469d895e4..0c1b4997f --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -5,6 +5,7 @@ # Copyright The Mbed TLS Contributors # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +import inspect import re import sys from typing import Iterable, Iterator, List, Optional, Tuple @@ -164,12 +165,19 @@ class ConfigTestGenerator(test_data_generation.TestGenerator): """Generate test cases for configuration reporting.""" def __init__(self, settings): - self.mbedtls_config = config.MbedTLSConfig() - self.targets['test_suite_config.mbedtls_boolean'] = \ - lambda: enumerate_boolean_setting_cases(self.mbedtls_config) - self.psa_config = config.CryptoConfig() - self.targets['test_suite_config.psa_boolean'] = \ - lambda: enumerate_boolean_setting_cases(self.psa_config) + config_members = dict(inspect.getmembers(config)) + if 'MbedTLSConfig' in config_members: + self.mbedtls_config = config.MbedTLSConfig() + self.targets['test_suite_config.mbedtls_boolean'] = \ + lambda: enumerate_boolean_setting_cases(self.mbedtls_config) + if 'CryptoConfig' in config_members: + self.psa_config = config.CryptoConfig() + self.targets['test_suite_config.psa_boolean'] = \ + lambda: enumerate_boolean_setting_cases(self.psa_config) + elif 'TFPSACryptoConfig' in config_members: + self.psa_config = config.TFPSACryptoConfig() + self.targets['test_suite_config.psa_boolean'] = \ + lambda: enumerate_boolean_setting_cases(self.psa_config) super().__init__(settings) From d4585fde2c09206d594826476a715fd075716fce Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Fri, 29 Nov 2024 16:45:46 +0000 Subject: [PATCH 5/5] Fix pylint issue Signed-off-by: Gabor Mezei --- scripts/generate_config_tests.py | 1 + 1 file changed, 1 insertion(+) mode change 100644 => 100755 scripts/generate_config_tests.py diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py old mode 100644 new mode 100755 index 0c1b4997f..e3c1d8ddc --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -165,6 +165,7 @@ class ConfigTestGenerator(test_data_generation.TestGenerator): """Generate test cases for configuration reporting.""" def __init__(self, settings): + # pylint: disable=no-member config_members = dict(inspect.getmembers(config)) if 'MbedTLSConfig' in config_members: self.mbedtls_config = config.MbedTLSConfig()