From e250c79ad0980478a37bbb1ef5fe1ae391198f4a Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 12 Jun 2024 17:25:07 +0200 Subject: [PATCH 1/9] Allow framework scripts to import modules from the main project Allow framework scripts to import scripts from the main project as modules, for example config.py. Signed-off-by: Gilles Peskine --- scripts/project_scripts.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 scripts/project_scripts.py diff --git a/scripts/project_scripts.py b/scripts/project_scripts.py new file mode 100644 index 000000000..2666c7b10 --- /dev/null +++ b/scripts/project_scripts.py @@ -0,0 +1,17 @@ +"""Add the consuming repository's scripts to the module search path. + +Usage: + + import project_scripts # pylint: disable=unused-import +""" + +# Copyright The Mbed TLS Contributors +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(__file__), + os.path.pardir, os.path.pardir, + 'scripts')) From 1893bfb1ee4b1d971db38bf3ea1f8005fe3c8d9a Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 11 Jun 2024 19:32:22 +0200 Subject: [PATCH 2/9] Generate config test cases for single options Generate option-on and option-off cases for test_suite_config, for all boolean options (MBEDTLS_xxx and PSA_WANT_xxx, collected from the mbedtls and PSA config files). Signed-off-by: Gilles Peskine --- scripts/generate_config_tests.py | 96 ++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 scripts/generate_config_tests.py diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py new file mode 100755 index 000000000..e78ff35c9 --- /dev/null +++ b/scripts/generate_config_tests.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +"""Generate test data for configuration reporting. +""" + +# Copyright The Mbed TLS Contributors +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later + +import re +import sys +from typing import Iterable, Iterator, List, Optional, Tuple + +import project_scripts # pylint: disable=unused-import +import config +from mbedtls_framework import test_case +from mbedtls_framework import test_data_generation + + +def single_option_case(setting: config.Setting, when_on: bool, + dependencies: List[str], + note: Optional[str]) -> test_case.TestCase: + """Construct a test case for a boolean setting. + + This test case passes if the setting and its dependencies are enabled, + and is skipped otherwise. + + * setting: the setting to be tested. + * when_on: True to test with the setting enabled, or False to test + with the setting disabled. + * dependencies: extra dependencies for the test case. + * note: a note to add after the option name in the test description. + This is generally a summary of dependencies, and is generally empty + if the given setting is only tested once. + """ + base = setting.name if when_on else '!' + setting.name + tc = test_case.TestCase() + tc.set_function('pass') + description_suffix = ' (' + note + ')' if note else '' + tc.set_description('Config: ' + base + description_suffix) + tc.set_dependencies([base] + dependencies) + return tc + + +def conditions_for_option(cfg: config.Config, + setting: config.Setting + ) -> Iterator[Tuple[List[str], str]]: + """Enumerate the conditions under which to test the given setting. + + * cfg: all configuration options. + * setting: the setting to be tested. + + Generate a stream of conditions, i.e. extra dependencies to test with + together with a human-readable explanation of each dependency. Some + typical cases: + + * By default, generate a one-element stream with no extra dependencies. + * If the setting is ignored unless some other option is enabled, generate + a one-element stream with that other option as an extra dependency. + * If the setting is known to interact with some other option, generate + a stream with one element where this option is on and one where it's off. + * To skip the setting altogether, generate an empty stream. + """ + name = setting.name + if name.endswith('_ALT') and not config.is_seamless_alt(name): + # We don't test alt implementations, except (most) platform alts + return + yield [], '' + + +def enumerate_boolean_option_cases(cfg: config.Config + ) -> Iterable[test_case.TestCase]: + """Emit test cases for all boolean options.""" + for name in sorted(cfg.settings.keys()): + setting = cfg.settings[name] + if not name.startswith('PSA_WANT_') and setting.value: + continue # non-boolean setting + for when_on in True, False: + for deps, note in conditions_for_option(cfg, setting): + yield single_option_case(setting, when_on, deps, note) + + + +class ConfigTestGenerator(test_data_generation.TestGenerator): + """Generate test cases for configuration reporting.""" + + def __init__(self, options): + self.mbedtls_config = config.ConfigFile() + self.targets['test_suite_config.mbedtls_boolean'] = \ + lambda: enumerate_boolean_option_cases(self.mbedtls_config) + self.psa_config = config.ConfigFile('include/psa/crypto_config.h') + self.targets['test_suite_config.psa_boolean'] = \ + lambda: enumerate_boolean_option_cases(self.psa_config) + super().__init__(options) + + +if __name__ == '__main__': + test_data_generation.main(sys.argv[1:], __doc__, ConfigTestGenerator) From 9d7c805224fd8f855e358b3b44a7f6dde88d6165 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 23 May 2024 16:32:39 +0200 Subject: [PATCH 3/9] Detect sub-options When option A is only meaningful if option B is enabled, when enumerating single-option test cases, emit A:B and !A:B rather than A and !A. This way the "!A" case is actually meaningful. Signed-off-by: Gilles Peskine --- scripts/generate_config_tests.py | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index e78ff35c9..d97adada9 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -40,6 +40,63 @@ def single_option_case(setting: config.Setting, when_on: bool, return tc +PSA_WANT_KEY_TYPE_KEY_PAIR_RE = \ + re.compile(r'(?PPSA_WANT_KEY_TYPE_(?P\w+)_KEY_PAIR_)(?P\w+)\Z') + +# If foo is an option that is only meaningful when bar is enabled, set +# SUPER_SETTINGS[foo]=bar. More generally, bar can be a colon-separated +# list of options, meaning that all the options must be enabled. Each option +# can be prefixed with '!' to negate it. This is the same syntax as a +# depends_on directive in test data. +# See also `find_super_option`. +SUPER_SETTINGS = { + 'MBEDTLS_AESCE_C': 'MBEDTLS_AES_C', + 'MBEDTLS_AESNI_C': 'MBEDTLS_AES_C', + 'MBEDTLS_ERROR_STRERROR_DUMMY': '!MBEDTLS_ERROR_C', + 'MBEDTLS_GENPRIME': 'MBEDTLS_RSA_C', + 'MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES': 'MBEDTLS_ENTROPY_C', + 'MBEDTLS_NO_PLATFORM_ENTROPY': 'MBEDTLS_ENTROPY_C', + 'MBEDTLS_PKCS1_V15': 'MBEDTLS_RSA_C', + 'MBEDTLS_PKCS1_V21': 'MBEDTLS_RSA_C', + 'MBEDTLS_PSA_CRYPTO_CLIENT': 'MBEDTLS_PSA_CRYPTO_C', + 'MBEDTLS_PSA_INJECT_ENTROPY': 'MBEDTLS_PSA_CRYPTO_C', + 'MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS': 'MBEDTLS_PSA_CRYPTO_C', +} + +def find_super_option(cfg: config.Config, + setting: config.Setting) -> Optional[str]: + """If setting is only meaningful when some option is enabled, return that option. + + The return value can be a colon-separated list of options, if the setting + is only meaningful when all of these options are enabled. Options can be + negated by prefixing them with '!'. This is the same syntax as a + depends_on directive in test data. + """ + #pylint: disable=too-many-return-statements + name = setting.name + if name in SUPER_SETTINGS: + return SUPER_SETTINGS[name] + if name.startswith('MBEDTLS_') and not name.endswith('_C'): + if name.startswith('MBEDTLS_CIPHER_PADDING_'): + return 'MBEDTLS_CIPHER_C:MBEDTLS_CIPHER_MODE_CBC' + if name.startswith('MBEDTLS_PK_PARSE_EC_'): + return 'MBEDTLS_PK_C:MBEDTLS_PK_HAVE_ECC_KEYS' + if name.startswith('MBEDTLS_SSL_TLS1_3_') or \ + name == 'MBEDTLS_SSL_EARLY_DATA': + return 'MBEDTLS_SSL_CLI_C:MBEDTLS_SSL_SRV_C:MBEDTLS_SSL_PROTO_TLS1_3' + if name.startswith('MBEDTLS_SSL_DTLS_'): + return 'MBEDTLS_SSL_CLI_C:MBEDTLS_SSL_SRV_C:MBEDTLS_SSL_PROTO_DTLS' + if name.startswith('MBEDTLS_SSL_'): + return 'MBEDTLS_SSL_CLI_C:MBEDTLS_SSL_SRV_C' + for m in re.finditer(r'_', name): + super_name = name[:m.start()] + '_C' + if cfg.known(super_name): + return super_name + m = re.match(PSA_WANT_KEY_TYPE_KEY_PAIR_RE, name) + if m and m.group('operation') != 'BASIC': + return m.group('prefix') + 'BASIC' + return None + def conditions_for_option(cfg: config.Config, setting: config.Setting ) -> Iterator[Tuple[List[str], str]]: @@ -63,6 +120,10 @@ def conditions_for_option(cfg: config.Config, if name.endswith('_ALT') and not config.is_seamless_alt(name): # We don't test alt implementations, except (most) platform alts return + super_setting = find_super_option(cfg, setting) + if super_setting: + yield [super_setting], '' + return yield [], '' From dcda48789c7ce6fd40cfb32d6231b3bd604b0ac4 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 23 May 2024 19:37:20 +0200 Subject: [PATCH 4/9] Pacify mypy I had accidentally reused a variable name inside the same function. Python copes but mypy doesn't. Signed-off-by: Gilles Peskine --- scripts/generate_config_tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index d97adada9..074b0e9d0 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -88,11 +88,11 @@ def find_super_option(cfg: config.Config, return 'MBEDTLS_SSL_CLI_C:MBEDTLS_SSL_SRV_C:MBEDTLS_SSL_PROTO_DTLS' if name.startswith('MBEDTLS_SSL_'): return 'MBEDTLS_SSL_CLI_C:MBEDTLS_SSL_SRV_C' - for m in re.finditer(r'_', name): - super_name = name[:m.start()] + '_C' + for pos in re.finditer(r'_', name): + super_name = name[:pos.start()] + '_C' if cfg.known(super_name): return super_name - m = re.match(PSA_WANT_KEY_TYPE_KEY_PAIR_RE, name) + m = PSA_WANT_KEY_TYPE_KEY_PAIR_RE.match(name) if m and m.group('operation') != 'BASIC': return m.group('prefix') + 'BASIC' return None From a9627428e209c5a73a1f3d589cb56e2f0610eb9c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 28 May 2024 19:18:31 +0200 Subject: [PATCH 5/9] Fix missing negation Signed-off-by: Gilles Peskine --- scripts/generate_config_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index 074b0e9d0..8121d1b2d 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -58,7 +58,7 @@ SUPER_SETTINGS = { 'MBEDTLS_NO_PLATFORM_ENTROPY': 'MBEDTLS_ENTROPY_C', 'MBEDTLS_PKCS1_V15': 'MBEDTLS_RSA_C', 'MBEDTLS_PKCS1_V21': 'MBEDTLS_RSA_C', - 'MBEDTLS_PSA_CRYPTO_CLIENT': 'MBEDTLS_PSA_CRYPTO_C', + 'MBEDTLS_PSA_CRYPTO_CLIENT': '!MBEDTLS_PSA_CRYPTO_C', 'MBEDTLS_PSA_INJECT_ENTROPY': 'MBEDTLS_PSA_CRYPTO_C', 'MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS': 'MBEDTLS_PSA_CRYPTO_C', } From 06c3484f8d8ef77c697ebd1f19d3280af42a2cce Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 28 May 2024 19:18:46 +0200 Subject: [PATCH 6/9] Explain why we require TLS client and server simultaneously Signed-off-by: Gilles Peskine --- scripts/generate_config_tests.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index 8121d1b2d..921c63522 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -81,6 +81,14 @@ def find_super_option(cfg: config.Config, return 'MBEDTLS_CIPHER_C:MBEDTLS_CIPHER_MODE_CBC' if name.startswith('MBEDTLS_PK_PARSE_EC_'): return 'MBEDTLS_PK_C:MBEDTLS_PK_HAVE_ECC_KEYS' + # For TLS options, insist on having them once off and once on in + # a configuration where both client support and server support are + # enabled. The options are also meaningful when only one side is + # enabled, but there isn't much point in having separate records + # for client-side and server-side, so we keep things simple. + # Requiring both sides to be enabled also means we know we'll run + # tests that only run Mbed TLS against itself, which only run in + # configurations with both sides enabled. if name.startswith('MBEDTLS_SSL_TLS1_3_') or \ name == 'MBEDTLS_SSL_EARLY_DATA': return 'MBEDTLS_SSL_CLI_C:MBEDTLS_SSL_SRV_C:MBEDTLS_SSL_PROTO_TLS1_3' From 24172404660308163071a78ae2f261f77b79b852 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 29 May 2024 16:37:38 +0200 Subject: [PATCH 7/9] Terminology: consistently use "setting", not "option" The two were used interchangeably. Align on "setting", which is what config.py uses in its documentation. Signed-off-by: Gilles Peskine --- scripts/generate_config_tests.py | 62 ++++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index 921c63522..3d6a520c4 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -15,9 +15,9 @@ from mbedtls_framework import test_case from mbedtls_framework import test_data_generation -def single_option_case(setting: config.Setting, when_on: bool, - dependencies: List[str], - note: Optional[str]) -> test_case.TestCase: +def single_setting_case(setting: config.Setting, when_on: bool, + dependencies: List[str], + note: Optional[str]) -> test_case.TestCase: """Construct a test case for a boolean setting. This test case passes if the setting and its dependencies are enabled, @@ -27,7 +27,7 @@ def single_option_case(setting: config.Setting, when_on: bool, * when_on: True to test with the setting enabled, or False to test with the setting disabled. * dependencies: extra dependencies for the test case. - * note: a note to add after the option name in the test description. + * note: a note to add after the setting name in the test description. This is generally a summary of dependencies, and is generally empty if the given setting is only tested once. """ @@ -43,12 +43,12 @@ def single_option_case(setting: config.Setting, when_on: bool, PSA_WANT_KEY_TYPE_KEY_PAIR_RE = \ re.compile(r'(?PPSA_WANT_KEY_TYPE_(?P\w+)_KEY_PAIR_)(?P\w+)\Z') -# If foo is an option that is only meaningful when bar is enabled, set +# If foo is a setting that is only meaningful when bar is enabled, set # SUPER_SETTINGS[foo]=bar. More generally, bar can be a colon-separated -# list of options, meaning that all the options must be enabled. Each option +# list of settings, meaning that all the settings must be enabled. Each setting # can be prefixed with '!' to negate it. This is the same syntax as a # depends_on directive in test data. -# See also `find_super_option`. +# See also `find_super_setting`. SUPER_SETTINGS = { 'MBEDTLS_AESCE_C': 'MBEDTLS_AES_C', 'MBEDTLS_AESNI_C': 'MBEDTLS_AES_C', @@ -63,12 +63,12 @@ SUPER_SETTINGS = { 'MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS': 'MBEDTLS_PSA_CRYPTO_C', } -def find_super_option(cfg: config.Config, - setting: config.Setting) -> Optional[str]: - """If setting is only meaningful when some option is enabled, return that option. +def find_super_setting(cfg: config.Config, + setting: config.Setting) -> Optional[str]: + """If setting is only meaningful when some setting is enabled, return that setting. - The return value can be a colon-separated list of options, if the setting - is only meaningful when all of these options are enabled. Options can be + The return value can be a colon-separated list of settings, if the setting + is only meaningful when all of these settings are enabled. Settings can be negated by prefixing them with '!'. This is the same syntax as a depends_on directive in test data. """ @@ -81,9 +81,9 @@ def find_super_option(cfg: config.Config, return 'MBEDTLS_CIPHER_C:MBEDTLS_CIPHER_MODE_CBC' if name.startswith('MBEDTLS_PK_PARSE_EC_'): return 'MBEDTLS_PK_C:MBEDTLS_PK_HAVE_ECC_KEYS' - # For TLS options, insist on having them once off and once on in + # For TLS settings, insist on having them once off and once on in # a configuration where both client support and server support are - # enabled. The options are also meaningful when only one side is + # enabled. The settings are also meaningful when only one side is # enabled, but there isn't much point in having separate records # for client-side and server-side, so we keep things simple. # Requiring both sides to be enabled also means we know we'll run @@ -105,12 +105,12 @@ def find_super_option(cfg: config.Config, return m.group('prefix') + 'BASIC' return None -def conditions_for_option(cfg: config.Config, - setting: config.Setting - ) -> Iterator[Tuple[List[str], str]]: +def conditions_for_setting(cfg: config.Config, + setting: config.Setting + ) -> Iterator[Tuple[List[str], str]]: """Enumerate the conditions under which to test the given setting. - * cfg: all configuration options. + * cfg: all configuration settings. * setting: the setting to be tested. Generate a stream of conditions, i.e. extra dependencies to test with @@ -118,47 +118,47 @@ def conditions_for_option(cfg: config.Config, typical cases: * By default, generate a one-element stream with no extra dependencies. - * If the setting is ignored unless some other option is enabled, generate - a one-element stream with that other option as an extra dependency. - * If the setting is known to interact with some other option, generate - a stream with one element where this option is on and one where it's off. + * If the setting is ignored unless some other setting is enabled, generate + a one-element stream with that other setting as an extra dependency. + * If the setting is known to interact with some other setting, generate + a stream with one element where this setting is on and one where it's off. * To skip the setting altogether, generate an empty stream. """ name = setting.name if name.endswith('_ALT') and not config.is_seamless_alt(name): # We don't test alt implementations, except (most) platform alts return - super_setting = find_super_option(cfg, setting) + super_setting = find_super_setting(cfg, setting) if super_setting: yield [super_setting], '' return yield [], '' -def enumerate_boolean_option_cases(cfg: config.Config +def enumerate_boolean_setting_cases(cfg: config.Config ) -> Iterable[test_case.TestCase]: - """Emit test cases for all boolean options.""" + """Emit test cases for all boolean settings.""" for name in sorted(cfg.settings.keys()): setting = cfg.settings[name] if not name.startswith('PSA_WANT_') and setting.value: continue # non-boolean setting for when_on in True, False: - for deps, note in conditions_for_option(cfg, setting): - yield single_option_case(setting, when_on, deps, note) + for deps, note in conditions_for_setting(cfg, setting): + yield single_setting_case(setting, when_on, deps, note) class ConfigTestGenerator(test_data_generation.TestGenerator): """Generate test cases for configuration reporting.""" - def __init__(self, options): + def __init__(self, settings): self.mbedtls_config = config.ConfigFile() self.targets['test_suite_config.mbedtls_boolean'] = \ - lambda: enumerate_boolean_option_cases(self.mbedtls_config) + lambda: enumerate_boolean_setting_cases(self.mbedtls_config) self.psa_config = config.ConfigFile('include/psa/crypto_config.h') self.targets['test_suite_config.psa_boolean'] = \ - lambda: enumerate_boolean_option_cases(self.psa_config) - super().__init__(options) + lambda: enumerate_boolean_setting_cases(self.psa_config) + super().__init__(settings) if __name__ == '__main__': From 757d47cc3ee9a5e5edc8ac9e10d659c14706e520 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 29 May 2024 16:44:52 +0200 Subject: [PATCH 8/9] Terminology: use "dependencies" for a list of settings "Super settings" were effectively the dependencies of a setting, so align on that terminology. Signed-off-by: Gilles Peskine --- scripts/generate_config_tests.py | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index 3d6a520c4..c0b4ab969 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -44,12 +44,12 @@ PSA_WANT_KEY_TYPE_KEY_PAIR_RE = \ re.compile(r'(?PPSA_WANT_KEY_TYPE_(?P\w+)_KEY_PAIR_)(?P\w+)\Z') # If foo is a setting that is only meaningful when bar is enabled, set -# SUPER_SETTINGS[foo]=bar. More generally, bar can be a colon-separated +# SIMPLE_DEPENDENCIES[foo]=bar. More generally, bar can be a colon-separated # list of settings, meaning that all the settings must be enabled. Each setting -# can be prefixed with '!' to negate it. This is the same syntax as a +# in bar can be prefixed with '!' to negate it. This is the same syntax as a # depends_on directive in test data. -# See also `find_super_setting`. -SUPER_SETTINGS = { +# See also `dependencies_of_settting`. +SIMPLE_DEPENDENCIES = { 'MBEDTLS_AESCE_C': 'MBEDTLS_AES_C', 'MBEDTLS_AESNI_C': 'MBEDTLS_AES_C', 'MBEDTLS_ERROR_STRERROR_DUMMY': '!MBEDTLS_ERROR_C', @@ -63,19 +63,25 @@ SUPER_SETTINGS = { 'MBEDTLS_PSA_ASSUME_EXCLUSIVE_BUFFERS': 'MBEDTLS_PSA_CRYPTO_C', } -def find_super_setting(cfg: config.Config, - setting: config.Setting) -> Optional[str]: - """If setting is only meaningful when some setting is enabled, return that setting. +def dependencies_of_setting(cfg: config.Config, + setting: config.Setting) -> Optional[str]: + """Return dependencies without which a setting is not meaningful. + + The dependencies of a setting express when a setting can be enabled and + is relevant. For example, if ``check_config.h`` errors out when + ``defined(FOO) && !defined(BAR)``, then ``BAR`` is a dependency of ``FOO``. + If ``FOO`` has no effect when ``CORGE`` is disabled, then ``CORGE`` + is a dependency of ``FOO``. The return value can be a colon-separated list of settings, if the setting - is only meaningful when all of these settings are enabled. Settings can be - negated by prefixing them with '!'. This is the same syntax as a + is only meaningful when all of these settings are enabled. Each setting can + be negated by prefixing them with '!'. This is the same syntax as a depends_on directive in test data. """ #pylint: disable=too-many-return-statements name = setting.name - if name in SUPER_SETTINGS: - return SUPER_SETTINGS[name] + if name in SIMPLE_DEPENDENCIES: + return SIMPLE_DEPENDENCIES[name] if name.startswith('MBEDTLS_') and not name.endswith('_C'): if name.startswith('MBEDTLS_CIPHER_PADDING_'): return 'MBEDTLS_CIPHER_C:MBEDTLS_CIPHER_MODE_CBC' @@ -128,9 +134,9 @@ def conditions_for_setting(cfg: config.Config, if name.endswith('_ALT') and not config.is_seamless_alt(name): # We don't test alt implementations, except (most) platform alts return - super_setting = find_super_setting(cfg, setting) - if super_setting: - yield [super_setting], '' + dependencies = dependencies_of_setting(cfg, setting) + if dependencies: + yield [dependencies], '' return yield [], '' From 558804797e617af23957bbe94a5e74af8ae83e38 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 20 Jun 2024 17:05:41 +0200 Subject: [PATCH 9/9] Adjust temporarily the location of PSA headers Continuation of 030b14c2bce1dff5bd28b08b2c00b6bc1fdd66d5 for a file added in parallel. Signed-off-by: Gilles Peskine --- scripts/generate_config_tests.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index c0b4ab969..d1991c0dc 100755 --- 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 os import re import sys from typing import Iterable, Iterator, List, Optional, Tuple @@ -161,7 +162,14 @@ class ConfigTestGenerator(test_data_generation.TestGenerator): self.mbedtls_config = config.ConfigFile() self.targets['test_suite_config.mbedtls_boolean'] = \ lambda: enumerate_boolean_setting_cases(self.mbedtls_config) - self.psa_config = config.ConfigFile('include/psa/crypto_config.h') + # Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto + # build system to build its crypto library. When it does, the first + # case can just be removed. + if os.path.isdir('tf-psa-crypto'): + crypto_config_file = 'tf-psa-crypto/include/psa/crypto_config.h' + else: + crypto_config_file = 'include/psa/crypto_config.h' + self.psa_config = config.ConfigFile(crypto_config_file) self.targets['test_suite_config.psa_boolean'] = \ lambda: enumerate_boolean_setting_cases(self.psa_config) super().__init__(settings)