Bignum Tests: remove OperationCommonArchSplit
The ArchSplit functionality was duplicated and moved to OperationCommon from the other copy. The remnants of the functionality is moved to the only subclass using this. There is no semantic change to the generated tests. The order has changed however: core_add tests have been moved before core_mla tests and the order of the 64 and 32 bit versions have been swapped. Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
b41ab926b2
commit
6fa3f0653a
3 changed files with 29 additions and 49 deletions
|
@ -80,17 +80,18 @@ class OperationCommon(test_data_generation.BaseTest):
|
|||
unique_combinations_only: Boolean to select if test case combinations
|
||||
must be unique. If True, only A,B or B,A would be included as a test
|
||||
case. If False, both A,B and B,A would be included.
|
||||
arch_split: Boolean to select if different test cases are needed
|
||||
depending on the architecture/limb size. This will cause test
|
||||
objects being generated with different architectures. Individual
|
||||
test objects can tell their architecture by accessing the
|
||||
bits_in_limb instance variable.
|
||||
input_style: Controls the way how test data is passed to the functions
|
||||
in the generated test cases. "variable" passes them as they are
|
||||
defined in the python source. "arch_split" pads the values with
|
||||
zeroes depending on the architecture/limb size. If this is set,
|
||||
test cases are generated for all architectures.
|
||||
"""
|
||||
symbol = ""
|
||||
input_values = [] # type: List[str]
|
||||
input_cases = [] # type: List[Tuple[str, str]]
|
||||
unique_combinations_only = True
|
||||
arch_split = False
|
||||
input_styles = ["variable", "arch_split"] # type: List[str]
|
||||
input_style = "variable" # type: str
|
||||
limb_sizes = [32, 64] # type: List[int]
|
||||
|
||||
def __init__(self, val_a: str, val_b: str, bits_in_limb: int = 64) -> None:
|
||||
|
@ -100,7 +101,7 @@ class OperationCommon(test_data_generation.BaseTest):
|
|||
self.int_b = hex_to_int(val_b)
|
||||
if bits_in_limb not in self.limb_sizes:
|
||||
raise ValueError("Invalid number of bits in limb!")
|
||||
if self.arch_split:
|
||||
if self.input_style == "arch_split":
|
||||
self.dependencies = ["MBEDTLS_HAVE_INT{:d}".format(bits_in_limb)]
|
||||
self.bits_in_limb = bits_in_limb
|
||||
|
||||
|
@ -109,6 +110,10 @@ class OperationCommon(test_data_generation.BaseTest):
|
|||
data_in = [self.int_a, self.int_b]
|
||||
return max([n for n in data_in if n is not None])
|
||||
|
||||
@property
|
||||
def limb_boundary(self) -> int:
|
||||
return bound_mpi(self.boundary, self.bits_in_limb)
|
||||
|
||||
@property
|
||||
def limbs(self) -> int:
|
||||
return limbs_mpi(self.boundary, self.bits_in_limb)
|
||||
|
@ -171,8 +176,10 @@ class OperationCommon(test_data_generation.BaseTest):
|
|||
|
||||
@classmethod
|
||||
def generate_function_tests(cls) -> Iterator[test_case.TestCase]:
|
||||
if cls.input_style not in cls.input_styles:
|
||||
raise ValueError("Unknown input style!")
|
||||
for a_value, b_value in cls.get_value_pairs():
|
||||
if cls.arch_split:
|
||||
if cls.input_style == "arch_split":
|
||||
for bil in cls.limb_sizes:
|
||||
yield cls(a_value, b_value,
|
||||
bits_in_limb=bil).create_test_case()
|
||||
|
@ -216,35 +223,6 @@ class ModOperationCommon(OperationCommon):
|
|||
return pow(self.r, 2)
|
||||
|
||||
|
||||
class OperationCommonArchSplit(OperationCommon):
|
||||
#pylint: disable=abstract-method
|
||||
"""Common features for 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)
|
||||
bound_val = max(self.int_a, self.int_b)
|
||||
self.bits_in_limb = bits_in_limb
|
||||
self.bound = bound_mpi(bound_val, self.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"]
|
||||
else:
|
||||
raise ValueError("Invalid number of bits in limb!")
|
||||
self.arg_a = self.arg_a.zfill(self.hex_digits)
|
||||
self.arg_b = self.arg_b.zfill(self.hex_digits)
|
||||
|
||||
def pad_to_limbs(self, val) -> str:
|
||||
return "{:x}".format(val).zfill(self.hex_digits)
|
||||
|
||||
@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()
|
||||
|
||||
|
||||
# BEGIN MERGE SLOT 1
|
||||
|
||||
# END MERGE SLOT 1
|
||||
|
|
|
@ -106,6 +106,7 @@ class BignumCoreCTLookup(BignumCoreTarget, test_data_generation.BaseTest):
|
|||
yield (cls(bitsize, bitsize_description, window_size)
|
||||
.create_test_case())
|
||||
|
||||
|
||||
INPUT_VALUES = [
|
||||
"0", "1", "3", "f", "fe", "ff", "100", "ff00", "fffe", "ffff", "10000",
|
||||
"fffffffe", "ffffffff", "100000000", "1f7f7f7f7f7f7f",
|
||||
|
@ -127,38 +128,39 @@ INPUT_VALUES = [
|
|||
)
|
||||
]
|
||||
|
||||
|
||||
class BignumCoreOperation(BignumCoreTarget, bignum_common.OperationCommon):
|
||||
#pylint: disable=abstract-method
|
||||
"""Common features for bignum core operations."""
|
||||
input_values = INPUT_VALUES
|
||||
|
||||
|
||||
class BignumCoreOperationArchSplit(BignumCoreTarget,
|
||||
bignum_common.OperationCommonArchSplit):
|
||||
#pylint: disable=abstract-method
|
||||
"""Common features for bignum core operations where the result depends on
|
||||
the limb size."""
|
||||
input_values = INPUT_VALUES
|
||||
|
||||
|
||||
class BignumCoreAddAndAddIf(BignumCoreOperationArchSplit):
|
||||
class BignumCoreAddAndAddIf(BignumCoreOperation):
|
||||
"""Test cases for bignum core add and add-if."""
|
||||
count = 0
|
||||
symbol = "+"
|
||||
test_function = "mpi_core_add_and_add_if"
|
||||
test_name = "mpi_core_add_and_add_if"
|
||||
input_style = "arch_split"
|
||||
|
||||
def __init__(self, val_a: str, val_b: str, bits_in_limb: int) -> None:
|
||||
super().__init__(val_a, val_b)
|
||||
self.arg_a = self.arg_a.zfill(self.hex_digits)
|
||||
self.arg_b = self.arg_b.zfill(self.hex_digits)
|
||||
|
||||
def pad_to_limbs(self, val) -> str:
|
||||
return "{:x}".format(val).zfill(self.hex_digits)
|
||||
|
||||
def result(self) -> List[str]:
|
||||
result = self.int_a + self.int_b
|
||||
|
||||
carry, result = divmod(result, self.bound)
|
||||
carry, result = divmod(result, self.limb_boundary)
|
||||
|
||||
return [
|
||||
bignum_common.quote_str(self.pad_to_limbs(result)),
|
||||
str(carry)
|
||||
]
|
||||
|
||||
|
||||
class BignumCoreSub(BignumCoreOperation):
|
||||
"""Test cases for bignum core sub."""
|
||||
count = 0
|
||||
|
|
|
@ -56,7 +56,7 @@ class BignumModRawConvertToMont(bignum_common.ModOperationCommon,
|
|||
|
||||
test_function = "mpi_mod_raw_to_mont_rep"
|
||||
test_name = "Convert into Mont: "
|
||||
arch_split = True
|
||||
input_style = "arch_split"
|
||||
|
||||
test_data_moduli = ["b",
|
||||
"fd",
|
||||
|
|
Loading…
Reference in a new issue