Skip to content

Commit

Permalink
Python 3.7: Do not rely on enum value evaluating to __str__(..)
Browse files Browse the repository at this point in the history
For some reason
f"{enum_value}" evaluates to the numeric representation
(e.g, "1" for TEST_TYPES.MLKEM) in Python3.7,
while it evaluates to the string representation (__str__)
in Python >=3.8.

Workaround would to be to add an explicit str(...), but
this commit instead adds an explicit function called
make_target mapping a test type to a make target.
This would also allow us to use a differnt name for
the make target than the name of the enum value.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
  • Loading branch information
mkannwischer committed Dec 21, 2024
1 parent 1514079 commit 4778401
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion scripts/lib/mlkem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def dict2str(dict):
args = [
"make",
f"CROSS_PREFIX={self.cross_prefix}",
f"{self.test_type}",
f"{self.test_type.make_target()}",
] + extra_make_args

env = os.environ.copy()
Expand Down
14 changes: 14 additions & 0 deletions scripts/lib/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ def bin(self):
if self == TEST_TYPES.ACVP:
return "acvp_mlkem"

def make_target(self):
if self == TEST_TYPES.MLKEM:
return "mlkem"
if self == TEST_TYPES.BENCH:
return "bench"
if self == TEST_TYPES.BENCH_COMPONENTS:
return "bench_components"
if self == TEST_TYPES.NISTKAT:
return "nistkat"
if self == TEST_TYPES.KAT:
return "kat"
if self == TEST_TYPES.ACVP:
return "acvp"

def bin_path(self, scheme):
return path(
f"test/build/{scheme.name.lower()}/bin/{self.bin()}{scheme.suffix()}"
Expand Down

0 comments on commit 4778401

Please sign in to comment.