From dd2e4683d0bdfada6a40e49154b3c02f67f62bfa Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Mon, 17 Oct 2022 10:16:56 +0100 Subject: [PATCH] Bignum Core: add limb size specific test generation In Bignum Core the result also involves a carry and both the result and the carry depend on the size of the limbs. Before this change both 32 and 64 bit specific result have been passed to the test functions. Moving this decision out of the tests makes the test functions easier to write and read and the test cases easier to read and debug. The change doesn't make writing the generator script any harder and might even make reading it easier. Signed-off-by: Janos Follath --- scripts/mbedtls_dev/bignum_core.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/mbedtls_dev/bignum_core.py b/scripts/mbedtls_dev/bignum_core.py index 3652ac20ab..23db980e80 100644 --- a/scripts/mbedtls_dev/bignum_core.py +++ b/scripts/mbedtls_dev/bignum_core.py @@ -72,6 +72,24 @@ class BignumCoreOperation(bignum_common.OperationCommon, BignumCoreTarget, metac yield cls(a_value, b_value).create_test_case() +class BignumCoreOperationArchSplit(BignumCoreOperation): + #pylint: disable=abstract-method + """Common features for bignum core operations where the result depends on + the limb size.""" + + def __init__(self, val_a: str, val_b: str, bits_in_limb: int) -> None: + super().__init__(val_a, val_b) + self.bits_in_limb = bits_in_limb + if self.bits_in_limb == 32: + self.dependencies = ["MBEDTLS_HAVE_INT32"] + elif self.bits_in_limb == 64: + self.dependencies = ["MBEDTLS_HAVE_INT64"] + + @classmethod + def generate_function_tests(cls) -> Iterator[test_case.TestCase]: + for a_value, b_value in cls.get_value_pairs(): + yield cls(a_value, b_value, 32).create_test_case() + yield cls(a_value, b_value, 64).create_test_case() class BignumCoreAddIf(BignumCoreOperation): """Test cases for bignum core add if."""