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>
diff --git a/scripts/mbedtls_dev/bignum_common.py b/scripts/mbedtls_dev/bignum_common.py
index 0784f84..907c0b6 100644
--- a/scripts/mbedtls_dev/bignum_common.py
+++ b/scripts/mbedtls_dev/bignum_common.py
@@ -95,8 +95,8 @@
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 @@
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 @@
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
diff --git a/scripts/mbedtls_dev/bignum_core.py b/scripts/mbedtls_dev/bignum_core.py
index 7494037..48390b9 100644
--- a/scripts/mbedtls_dev/bignum_core.py
+++ b/scripts/mbedtls_dev/bignum_core.py
@@ -142,21 +142,13 @@
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)
]
diff --git a/scripts/mbedtls_dev/bignum_mod_raw.py b/scripts/mbedtls_dev/bignum_mod_raw.py
index b330c49..e2d8cd6 100644
--- a/scripts/mbedtls_dev/bignum_mod_raw.py
+++ b/scripts/mbedtls_dev/bignum_mod_raw.py
@@ -114,8 +114,8 @@
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: