From 2d2e924401cc5471ad56712e5f891036b2fc7156 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 12 Jan 2021 00:52:31 +0100 Subject: [PATCH] Implement basic update of PSA_WANT dependencies Remove any existing PSA_WANT_xxx dependency. Add PSA_WANT_xxx dependencies based on the PSA_KEY_TYPE_xxx and PSA_ALG_xxx symbols used in the test case arguments. PSA_ECC_FAMILY_xxx and PSA_DH_GROUP_xxx are not implemented yet in the PSA conditional inclusion mechanism in Mbed TLS, so this script doesn't handle them yet. Signed-off-by: Gilles Peskine --- tests/scripts/set_psa_test_dependencies.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/scripts/set_psa_test_dependencies.py b/tests/scripts/set_psa_test_dependencies.py index 41a24d1a6..8bbb711a6 100755 --- a/tests/scripts/set_psa_test_dependencies.py +++ b/tests/scripts/set_psa_test_dependencies.py @@ -22,6 +22,23 @@ import os import re import sys +def is_systematic_dependency(dep): + """Whether dep is a PSA dependency which is determined systematically.""" + return dep.startswith('PSA_WANT_') + +def dependencies_of_symbol(symbol): + """Return the dependencies for a symbol that designates a cryptographic mechanism.""" + return {symbol.replace('_', '_WANT_', 1)} + +def systematic_dependencies(file_name, function_name, arguments): + #pylint: disable=unused-argument + """List the systematically determined dependency for a test case.""" + deps = set() + for arg in arguments: + for symbol in re.findall(r'PSA_(?:ALG|KEY_TYPE)_\w+', arg): + deps.update(dependencies_of_symbol(symbol)) + return sorted(deps) + def updated_dependencies(file_name, function_name, arguments, dependencies): """Rework the list of dependencies into PSA_WANT_xxx. @@ -31,7 +48,10 @@ def updated_dependencies(file_name, function_name, arguments, dependencies): Add systematic PSA_WANT_xxx dependencies based on the called function and its arguments, replacing existing PSA_WANT_xxx dependencies. """ - return dependencies #TODO + automatic = systematic_dependencies(file_name, function_name, arguments) + manual = [dep for dep in dependencies + if not is_systematic_dependency(dep)] + return automatic + manual def keep_manual_dependencies(file_name, function_name, arguments): #pylint: disable=unused-argument