Skip to content

Commit

Permalink
add --force-qemu flag for tests script
Browse files Browse the repository at this point in the history
Signed-off-by: Thing-han, Lim <[email protected]>
  • Loading branch information
potsrevennil committed Jun 17, 2024
1 parent 3d1e447 commit 5c453be
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def sha256sum(result):
return m.hexdigest()


def base_run(bin, verbose):
if platform.system() == "Linux" and platform.machine() == "x86_64":
def base_run(bin, force_qemu, verbose):
if force_qemu or (platform.system() == "Linux" and platform.machine() == "x86_64"):
logging.debug(f"Emulating {bin} with QEMU")

p = subprocess.run(
Expand Down Expand Up @@ -90,7 +90,7 @@ def parse_meta(scheme, field):
return result.stdout.strip()


def test_schemes(title, scheme2file, actual_proc, expect_proc, verbose):
def test_schemes(title, scheme2file, actual_proc, expect_proc, force_qemu, verbose):
logging.info(f"{title}")

summary_file = os.environ.get("GITHUB_STEP_SUMMARY")
Expand All @@ -112,7 +112,7 @@ def test_schemes(title, scheme2file, actual_proc, expect_proc, verbose):
fail = False
for scheme in SCHEME:
bin = scheme2file(scheme)
result = base_run(bin, verbose)
result = base_run(bin, force_qemu, verbose)

actual = actual_proc(result)
expect = expect_proc(scheme)
Expand All @@ -128,8 +128,24 @@ def test_schemes(title, scheme2file, actual_proc, expect_proc, verbose):
if fail:
sys.exit(1)

def validate_force_qemu(ctx, _, v):
if platform.system() == "Darwin" and v:
config_logger(False)
logging.error("qemu-aarch64 is not supported on Darwin")
ctx.exit(1)

_shared_options = [
click.option(
"--force-qemu",
is_flag=True,
show_default=True,
default=False,
type=bool,
hidden=platform.system() == "Darwin",
callback=validate_force_qemu,
is_eager=True,
help="Force to emulate with QEMU",
),
click.option(
"-v",
"--verbose",
Expand Down Expand Up @@ -157,10 +173,10 @@ def add_options(options):
type=click.Path(),
help="The binary file that you wanted to test.",
)
def run(bin, verbose):
def run(bin, force_qemu, verbose):
config_logger(verbose)

result = base_run(bin, verbose)
result = base_run(bin, force_qemu, verbose)
logging.info(str(result, encoding="utf-8"))


Expand All @@ -169,7 +185,7 @@ def run(bin, verbose):
context_settings={"show_default": True},
)
@add_options(_shared_options)
def func(verbose):
def func(force_qemu, verbose):
config_logger(verbose)

def expect(scheme):
Expand All @@ -188,6 +204,7 @@ def func(verbose):
lambda scheme: scheme.name.replace("MLKEM", "test/bin/test_kyber"),
lambda result: str(result, encoding="utf-8"),
expect,
force_qemu,
verbose,
)

Expand All @@ -197,14 +214,15 @@ def func(verbose):
context_settings={"show_default": True},
)
@add_options(_shared_options)
def nistkat(verbose):
def nistkat(force_qemu, verbose):
config_logger(verbose)

test_schemes(
"Nistkat test",
lambda scheme: scheme.name.replace("MLKEM", "test/bin/gen_NISTKAT"),
sha256sum,
lambda scheme: parse_meta(scheme, "nistkat-sha256"),
force_qemu,
verbose,
)

Expand All @@ -214,14 +232,15 @@ def nistkat(verbose):
context_settings={"show_default": True},
)
@add_options(_shared_options)
def kat(verbose):
def kat(force_qemu, verbose):
config_logger(verbose)

test_schemes(
"Kat test",
lambda scheme: scheme.name.replace("MLKEM", "test/bin/gen_KAT"),
sha256sum,
lambda scheme: parse_meta(scheme, "kat-sha256"),
force_qemu,
verbose,
)

Expand Down

0 comments on commit 5c453be

Please sign in to comment.