Bignum tests: make args use input_style
Before arg_ attributes were the arguments as they were defined in the python script. Turning these into properties and having them take the form respect the style set in input_style makes the class easier to use and more consistent. This change makes the hex_ properties redundant and therefore they are removed. There are no semantic changes to the generated test cases. (The order of appearance of 64 and 32 bit mpi_core_add_and_add_if test cases has changed.) Signed-off-by: Janos Follath <janos.follath@arm.com>
This commit is contained in:
parent
6fa3f0653a
commit
4c59d35e00
3 changed files with 24 additions and 20 deletions
|
@ -95,8 +95,8 @@ class OperationCommon(test_data_generation.BaseTest):
|
|||
limb_sizes = [32, 64] # type: List[int]
|
||||
|
||||
def __init__(self, val_a: str, val_b: str, bits_in_limb: int = 64) -> None:
|
||||
self.arg_a = val_a
|
||||
self.arg_b = val_b
|
||||
self.val_a = val_a
|
||||
self.val_b = val_b
|
||||
self.int_a = hex_to_int(val_a)
|
||||
self.int_b = hex_to_int(val_b)
|
||||
if bits_in_limb not in self.limb_sizes:
|
||||
|
@ -122,13 +122,25 @@ class OperationCommon(test_data_generation.BaseTest):
|
|||
def hex_digits(self) -> int:
|
||||
return 2 * (self.limbs * self.bits_in_limb // 8)
|
||||
|
||||
@property
|
||||
def hex_a(self) -> str:
|
||||
return "{:x}".format(self.int_a).zfill(self.hex_digits)
|
||||
def format_arg(self, val) -> str:
|
||||
if self.input_style not in self.input_styles:
|
||||
raise ValueError("Unknown input style!")
|
||||
if self.input_style == "variable":
|
||||
return val
|
||||
else:
|
||||
return val.zfill(self.hex_digits)
|
||||
|
||||
def format_result(self, res) -> str:
|
||||
res_str = '{:x}'.format(res)
|
||||
return quote_str(self.format_arg(res_str))
|
||||
|
||||
@property
|
||||
def hex_b(self) -> str:
|
||||
return "{:x}".format(self.int_b).zfill(self.hex_digits)
|
||||
def arg_a(self) -> str:
|
||||
return self.format_arg(self.val_a)
|
||||
|
||||
@property
|
||||
def arg_b(self) -> str:
|
||||
return self.format_arg(self.val_b)
|
||||
|
||||
def arguments(self) -> List[str]:
|
||||
return [
|
||||
|
@ -206,8 +218,8 @@ class ModOperationCommon(OperationCommon):
|
|||
return max([n for n in data_in if n is not None])
|
||||
|
||||
@property
|
||||
def hex_n(self) -> str:
|
||||
return "{:x}".format(self.int_n).zfill(self.hex_digits)
|
||||
def arg_n(self) -> str:
|
||||
return self.format_arg(self.val_n)
|
||||
|
||||
@property
|
||||
def r(self) -> int: # pylint: disable=invalid-name
|
||||
|
|
|
@ -142,21 +142,13 @@ class BignumCoreAddAndAddIf(BignumCoreOperation):
|
|||
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.limb_boundary)
|
||||
|
||||
return [
|
||||
bignum_common.quote_str(self.pad_to_limbs(result)),
|
||||
self.format_result(result),
|
||||
str(carry)
|
||||
]
|
||||
|
||||
|
|
|
@ -114,8 +114,8 @@ class BignumModRawConvertToMont(bignum_common.ModOperationCommon,
|
|||
return [self.hex_x]
|
||||
|
||||
def arguments(self) -> List[str]:
|
||||
return [bignum_common.quote_str(n) for n in [self.hex_n,
|
||||
self.hex_a,
|
||||
return [bignum_common.quote_str(n) for n in [self.arg_n,
|
||||
self.arg_a,
|
||||
self.hex_x]]
|
||||
|
||||
def description(self) -> str:
|
||||
|
|
Loading…
Reference in a new issue