From 1b4546326687cb0f3ccf19640804608281806f25 Mon Sep 17 00:00:00 2001 From: "Lim, Thing-han" <15379156+potsrevennil@users.noreply.github.com> Date: Sun, 8 Sep 2024 12:58:33 +0800 Subject: [PATCH] Refactor Build System for Easier Extensibility and Future Optimizations (#100) * place all artifacts under test/build dir Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * refactor the build system Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * refactor build system objs macro Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * make don't print directory Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * integrate the new build system to python script Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * format nix file Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * fix arch flags not correctly set Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * ci fix -static to be cflags Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> * fix static compilation for benchmarking on a55 Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> --------- Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> --- .github/workflows/bench.yml | 6 +- .gitignore | 3 +- Makefile | 115 ++++++--------------------------- cbmc/litani.nix | 2 +- mk/config.mk | 18 ++++-- mk/crypto.mk | 23 +++++++ mk/hal.mk | 9 +++ mk/rules.mk | 46 ++++++++++++++ mk/schemes.mk | 18 ++++++ scripts/tests | 122 +++++++++++++++++++----------------- test/{ => hal}/hal.c | 0 test/{ => hal}/hal.h | 0 12 files changed, 200 insertions(+), 162 deletions(-) create mode 100644 mk/crypto.mk create mode 100644 mk/hal.mk create mode 100644 mk/rules.mk create mode 100644 mk/schemes.mk rename test/{ => hal}/hal.c (100%) rename test/{ => hal}/hal.h (100%) diff --git a/.github/workflows/bench.yml b/.github/workflows/bench.yml index 1d684c15b..70b87e3d0 100644 --- a/.github/workflows/bench.yml +++ b/.github/workflows/bench.yml @@ -16,13 +16,13 @@ jobs: target: - system: rpi4 name: Arm Cortex-A72 (Raspberry Pi 4) benchmarks - cmd: tests bench -c PMU --cflags -mcpu=cortex-a72 -v --output output.json + cmd: tests bench -c PMU --arch-flags -mcpu=cortex-a72 -v --output output.json - system: rpi5 name: Arm Cortex-A76 (Raspberry Pi 5) benchmarks - cmd: tests bench -c PERF --cflags -mcpu=cortex-a76 --arch-flags -march=armv8.2-a -v --output output.json + cmd: tests bench -c PERF --arch-flags "-mcpu=cortex-a76 -march=armv8.2-a" -v --output output.json - system: a55 name: Arm Cortex-A55 (Snapdragon 888) benchmarks - cmd: tests bench -c PERF --cflags "-static -mcpu=cortex-a55" --arch-flags -march=armv8.2-a -w exec-on-a55 -v --output output.json + cmd: tests bench -c PERF --cflags -static --arch-flags "-mcpu=cortex-a55 -march=armv8.2-a" -w exec-on-a55 -v --output output.json runs-on: self-hosted-${{ matrix.target.system }} defaults: run: diff --git a/.gitignore b/.gitignore index db9ffe367..37072c2f7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,5 +4,4 @@ .direnv .vscode .idea -test/bin/ -test/obj/ +test/build diff --git a/Makefile b/Makefile index 690086f22..1ec09925f 100644 --- a/Makefile +++ b/Makefile @@ -6,106 +6,32 @@ all: mlkem bench kat nistkat include mk/config.mk +include mk/crypto.mk +include mk/schemes.mk +include mk/hal.mk +include mk/rules.mk -INCLUDE_RANDOM = -I randombytes -INCLUDE_NISTRANDOM = -I test/nistrng - -CFLAGS_RANDOMBYTES = ${CFLAGS} ${INCLUDE_RANDOM} -CFLAGS_NISTRANDOMBYTES = ${CFLAGS} ${INCLUDE_NISTRANDOM} -NISTFLAGS += -Wno-unused-result -O3 -fomit-frame-pointer -RM = /bin/rm - -SOURCES = mlkem/kem.c mlkem/indcpa.c mlkem/polyvec.c mlkem/poly.c mlkem/ntt.c mlkem/cbd.c mlkem/reduce.c mlkem/verify.c -SOURCESKECCAK = $(SOURCES) fips202/keccakf1600.c fips202/fips202.c fips202/fips202x4.c mlkem/symmetric-shake.c -SOURCESKECCAKRANDOM = $(SOURCESKECCAK) randombytes/randombytes.c -SOURCESNISTKATS = $(SOURCESKECCAK) test/nistrng/aes.c test/nistrng/rng.c -SOURCESBENCH = $(SOURCESKECCAKRANDOM) test/hal.c - -HEADERS = mlkem/params.h mlkem/kem.h mlkem/indcpa.h mlkem/polyvec.h mlkem/poly.h mlkem/ntt.h mlkem/cbd.h mlkem/reduce.c mlkem/verify.h mlkem/symmetric.h -HEADERSKECCAK = $(HEADERS) fips202/keccakf1600.h fips202/fips202.h fips202/fips202x4.h -HEADERSKECCAKRANDOM = $(HEADERSKECCAK) randombytes/randombytes.h -HEADERNISTKATS = $(HEADERSKECCAK) test/nistrng/aes.h test/nistrng/randombytes.h -HEADERSBENCH = $(HEADERSKECCAKRANDOM) test/hal.h +MAKEFLAGS = --no-print-directory mlkem: \ - test/bin/test_kyber512 \ - test/bin/test_kyber768 \ - test/bin/test_kyber1024 + $(MLKEM512_DIR)/bin/test_kyber512 \ + $(MLKEM768_DIR)/bin/test_kyber768 \ + $(MLKEM1024_DIR)/bin/test_kyber1024 \ -bench: \ - test/bin/bench_kyber512 \ - test/bin/bench_kyber768 \ - test/bin/bench_kyber1024 +bench: + $(MAKE) $(MAKEFLAGS) BENCH=1 $(MLKEM512_DIR)/bin/bench_kyber512 + $(MAKE) $(MAKEFLAGS) BENCH=1 $(MLKEM768_DIR)/bin/bench_kyber768 + $(MAKE) $(MAKEFLAGS) BENCH=1 $(MLKEM1024_DIR)/bin/bench_kyber1024 -nistkat: \ - test/bin/gen_NISTKAT512 \ - test/bin/gen_NISTKAT768 \ - test/bin/gen_NISTKAT1024 +nistkat: + $(MAKE) $(MAKEFLAGS) RNG=NISTRNG $(MLKEM512_DIR)/bin/gen_NISTKAT512 + $(MAKE) $(MAKEFLAGS) RNG=NISTRNG $(MLKEM768_DIR)/bin/gen_NISTKAT768 + $(MAKE) $(MAKEFLAGS) RNG=NISTRNG $(MLKEM1024_DIR)/bin/gen_NISTKAT1024 kat: \ - test/bin/gen_KAT512 \ - test/bin/gen_KAT768 \ - test/bin/gen_KAT1024 - -test/bin/test_kyber512: test/test_kyber.c $(SOURCESKECCAKRANDOM) $(HEADERSKECCAKRANDOM) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=2 $(SOURCESKECCAKRANDOM) $< -o $@ - -test/bin/test_kyber768: test/test_kyber.c $(SOURCESKECCAKRANDOM) $(HEADERSKECCAKRANDOM) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=3 $(SOURCESKECCAKRANDOM) $< -o $@ - -test/bin/test_kyber1024: test/test_kyber.c $(SOURCESKECCAKRANDOM) $(HEADERSKECCAKRANDOM) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=4 $(SOURCESKECCAKRANDOM) $< -o $@ - -test/bin/bench_kyber512: test/bench_kyber.c $(SOURCESBENCH) $(HEADERSBENCH) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=2 $(SOURCESBENCH) $< -o $@ - -test/bin/bench_kyber768: test/bench_kyber.c $(SOURCESBENCH) $(HEADERSBENCH) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=3 $(SOURCESBENCH) $< -o $@ - -test/bin/bench_kyber1024: test/bench_kyber.c $(SOURCESBENCH) $(HEADERSBENCH) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=4 $(SOURCESBENCH) $< -o $@ - -test/bin/gen_KAT512: test/gen_KAT.c $(SOURCESKECCAKRANDOM) $(HEADERSKECCAKRANDOM) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=2 $(SOURCESKECCAKRANDOM) $< -o $@ - -test/bin/gen_KAT768: test/gen_KAT.c $(SOURCESKECCAKRANDOM) $(HEADERSKECCAKRANDOM) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=3 $(SOURCESKECCAKRANDOM) $< -o $@ - -test/bin/gen_KAT1024: test/gen_KAT.c $(SOURCESKECCAKRANDOM) $(HEADERSKECCAKRANDOM) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_RANDOMBYTES) -DKYBER_K=4 $(SOURCESKECCAKRANDOM) $< -o $@ - -test/bin/gen_NISTKAT512: test/gen_NISTKAT.c $(SOURCESNISTKATS) $(HEADERNISTKATS) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_NISTRANDOMBYTES) -DKYBER_K=2 $(SOURCESNISTKATS) $< -o $@ - -test/bin/gen_NISTKAT768: test/gen_NISTKAT.c $(SOURCESNISTKATS) $(HEADERNISTKATS) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_NISTRANDOMBYTES) -DKYBER_K=3 $(SOURCESNISTKATS) $< -o $@ - -test/bin/gen_NISTKAT1024: test/gen_NISTKAT.c $(SOURCESNISTKATS) $(HEADERNISTKATS) $(CONFIG) - $(Q)echo " CC $@" - $(Q)[ -d $(@D) ] || mkdir -p $(@D) - $(CC) $(CFLAGS_NISTRANDOMBYTES) -DKYBER_K=4 $(SOURCESNISTKATS) $< -o $@ + $(MLKEM512_DIR)/bin/gen_KAT512 \ + $(MLKEM768_DIR)/bin/gen_KAT768 \ + $(MLKEM1024_DIR)/bin/gen_KAT1024 # emulate ARM64 binary on x86_64 machine emulate: @@ -114,5 +40,4 @@ emulate: clean: -$(RM) -rf *.gcno *.gcda *.lcov *.o *.so - -$(RM) -rf test/bin - -$(RM) -rf test/obj + -$(RM) -rf $(BUILD_DIR) diff --git a/cbmc/litani.nix b/cbmc/litani.nix index 2165e2932..7cacd4048 100644 --- a/cbmc/litani.nix +++ b/cbmc/litani.nix @@ -4,7 +4,7 @@ , fetchFromGitHub }: -stdenvNoCC.mkDerivation rec { +stdenvNoCC.mkDerivation { pname = "litani"; version = "8002c240ef4f424039ed3cc32e076c0234d01768"; src = fetchFromGitHub { diff --git a/mk/config.mk b/mk/config.mk index d6016524f..4bfc5943c 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -7,7 +7,7 @@ SRCDIR := $(CURDIR) ############## # GCC config # ############## -CROSS_PREFIX ?= +CROSS_PREFIX ?= CC := $(CROSS_PREFIX)gcc CPP := $(CROSS_PREFIX)cpp AR := $(CROSS_PREFIX)ar @@ -32,10 +32,13 @@ CFLAGS += \ -O3 \ -fomit-frame-pointer \ -pedantic \ + -MMD \ -I mlkem \ -I fips202 \ $(CPPFLAGS) +LINKDEPS += $(LIBDEPS) + ################## # Some Variables # ################## @@ -65,9 +68,16 @@ endif # Include retained variables # ############################## -RETAINED_VARS := +RNG ?= +RETAINED_VARS := RNG BENCH CYCLES + +BUILD_DIR := test/build +LIB_DIR := $(BUILD_DIR)/lib -CONFIG := test/obj/.config.mk +MAKE_OBJS = $(2:%=$(1)/%.o) +OBJS = $(call MAKE_OBJS,$(BUILD_DIR),$(1)) + +CONFIG := $(BUILD_DIR)/config.mk -include $(CONFIG) @@ -77,8 +87,6 @@ $(CONFIG): @echo "# These variables are retained and can't be changed without a clean" > $@ @$(foreach var,$(RETAINED_VARS),echo "$(var) := $($(var))" >> $@; echo "LAST_$(var) := $($(var))" >> $@;) -RETAINED_VARS += CYCLES - define VAR_CHECK ifneq ($$(origin LAST_$(1)),undefined) ifneq "$$($(1))" "$$(LAST_$(1))" diff --git a/mk/crypto.mk b/mk/crypto.mk new file mode 100644 index 000000000..476191ab4 --- /dev/null +++ b/mk/crypto.mk @@ -0,0 +1,23 @@ +# SPDX-License-Identifier: Apache-2.0 +LDLIBS += -L$(LIB_DIR) + +LIBDEPS += $(LIB_DIR)/libfips202.a +LDLIBS += -lfips202 +CPPFLAGS += -Ifips202 + +ifeq ($(RNG),NISTRNG) + LIBDEPS += $(LIB_DIR)/libnistrng.a + LDLIBS += -lnistrng + CPPFLAGS += -Itest/nistrng +else + LIBDEPS += $(LIB_DIR)/librng.a + LDLIBS += -lrng + CPPFLAGS += -Irandombytes +endif + +$(LIB_DIR)/librng.a: $(call OBJS,$(wildcard randombytes/*.c)) + +$(LIB_DIR)/libnistrng.a: CFLAGS += -Wno-unused-result -O3 -fomit-frame-pointer +$(LIB_DIR)/libnistrng.a: $(call OBJS,$(wildcard test/nistrng/*.c)) + +$(LIB_DIR)/libfips202.a: $(call OBJS,$(wildcard fips202/*.c)) diff --git a/mk/hal.mk b/mk/hal.mk new file mode 100644 index 000000000..e2de83a95 --- /dev/null +++ b/mk/hal.mk @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 +ifdef BENCH + +LIBDEPS += $(LIB_DIR)/libhal.a +LDLIBS += -lhal +CPPFLAGS += -Itest/hal +$(LIB_DIR)/libhal.a: $(call OBJS,$(wildcard test/hal/*.c)) + +endif diff --git a/mk/rules.mk b/mk/rules.mk new file mode 100644 index 000000000..0f009f692 --- /dev/null +++ b/mk/rules.mk @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: Apache-2.0 +$(BUILD_DIR)/%: $(LINKDEPS) $(CONFIG) + $(Q)echo " LD $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(LD) $(CFLAGS) -o $@ $(filter %.o,$^) $(LDLIBS) + +$(LIB_DIR)/%.a: $(CONFIG) + $(Q)echo " AR $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(Q)rm -f $@ + $(Q)$(AR) rcs $@ $(filter %.o,$^) + +$(BUILD_DIR)/%.c.o: %.c $(CONFIG) + $(Q)echo " CC $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(Q)$(CC) -c -o $@ $(CFLAGS) $< + +$(BUILD_DIR)/mlkem512/%.c.o: %.c $(CONFIG) + $(Q)echo " CC $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(Q)$(CC) -c -o $@ $(CFLAGS) $< + +$(BUILD_DIR)/mlkem512/%.S.o: %.S $(CONFIG) + $(Q)echo " AS $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(Q)$(CC) -c -o $@ $(CFLAGS) $< + +$(BUILD_DIR)/mlkem768/%.c.o: %.c $(CONFIG) + $(Q)echo " CC $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(Q)$(CC) -c -o $@ $(CFLAGS) $< + +$(BUILD_DIR)/mlkem768/%.S.o: %.S $(CONFIG) + $(Q)echo " AS $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(Q)$(CC) -c -o $@ $(CFLAGS) $< + +$(BUILD_DIR)/mlkem1024/%.c.o: %.c $(CONFIG) + $(Q)echo " CC $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(Q)$(CC) -c -o $@ $(CFLAGS) $< + +$(BUILD_DIR)/mlkem1024/%.S.o: %.S $(CONFIG) + $(Q)echo " AS $@" + $(Q)[ -d $(@D) ] || mkdir -p $(@D) + $(Q)$(CC) -c -o $@ $(CFLAGS) $< diff --git a/mk/schemes.mk b/mk/schemes.mk new file mode 100644 index 000000000..24fc1f6c1 --- /dev/null +++ b/mk/schemes.mk @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: Apache-2.0 +SOURCES = $(wildcard mlkem/*.c) + +CPPFLAGS += -Imlkem +TESTS = test_kyber bench_kyber gen_NISTKAT gen_KAT + +MLKEM512_DIR = $(BUILD_DIR)/mlkem512 +MLKEM768_DIR = $(BUILD_DIR)/mlkem768 +MLKEM1024_DIR = $(BUILD_DIR)/mlkem1024 + +$(MLKEM512_DIR)/bin/%: CPPFLAGS += -DKYBER_K=2 +$(TESTS:%=$(MLKEM512_DIR)/bin/%512):$(MLKEM512_DIR)/bin/%512: $(MLKEM512_DIR)/test/%.c.o $(call MAKE_OBJS,$(MLKEM512_DIR),$(SOURCES)) + +$(MLKEM768_DIR)/bin/%: CPPFLAGS += -DKYBER_K=3 +$(TESTS:%=$(MLKEM768_DIR)/bin/%768):$(MLKEM768_DIR)/bin/%768: $(MLKEM768_DIR)/test/%.c.o $(call MAKE_OBJS,$(MLKEM768_DIR),$(SOURCES)) + +$(MLKEM1024_DIR)/bin/%: CPPFLAGS += -DKYBER_K=4 +$(TESTS:%=$(MLKEM1024_DIR)/bin/%1024):$(MLKEM1024_DIR)/bin/%1024: $(MLKEM1024_DIR)/test/%.c.o $(call MAKE_OBJS,$(MLKEM1024_DIR),$(SOURCES)) diff --git a/scripts/tests b/scripts/tests index 959eba0cf..d63131013 100755 --- a/scripts/tests +++ b/scripts/tests @@ -25,8 +25,55 @@ def sha256sum(result): return m.hexdigest() +class TEST_TYPES(Enum): + MLKEM = 1 + BENCH = 2 + NISTKAT = 3 + KAT = 4 + + def __str__(self): + return self.name.lower() + + def desc(self): + match self: + case TEST_TYPES.MLKEM: + return "Functional Test" + case TEST_TYPES.BENCH: + return "Benchmark" + case TEST_TYPES.NISTKAT: + return "Nistkat Test" + case TEST_TYPES.KAT: + return "Kat Test" + + def bin(self): + match self: + case TEST_TYPES.MLKEM: + return "test_kyber" + case TEST_TYPES.BENCH: + return "bench_kyber" + case TEST_TYPES.NISTKAT: + return "gen_NISTKAT" + case TEST_TYPES.KAT: + return "gen_KAT" + + def bin_path(self, scheme): + return f"test/build/{scheme.name.lower()}/bin/{self.bin()}{scheme.suffix()}" + + +class SCHEME(Enum): + MLKEM512 = 1 + MLKEM768 = 2 + MLKEM1024 = 3 + + def __str__(self): + return self.name + + def suffix(self): + return self.name.removeprefix("MLKEM") + + def base_compile( - bin, + test, verbose, cross_prefix, extra_make_envs={}, @@ -40,11 +87,11 @@ def base_compile( s += f"{k}={v} " return s - logging.debug(f"Compiling {bin}...") + logging.debug(f"Compiling {test}...") args = [ "make", f"CROSS_PREFIX={cross_prefix}", - f"{bin}", + f"{test}", ] + extra_make_args logging.info(dict2str(extra_make_envs) + " ".join(args)) @@ -100,15 +147,6 @@ def base_run( return result.stdout -class SCHEME(Enum): - MLKEM512 = 1 - MLKEM768 = 2 - MLKEM1024 = 3 - - def __str__(self): - return self.name - - def parse_meta(scheme, field): result = subprocess.run( [ @@ -128,8 +166,7 @@ def parse_meta(scheme, field): def test_schemes( - title, - scheme2file, + test, actual_proc, expect_proc, process_result, @@ -144,18 +181,17 @@ def test_schemes( """ :param process_result: process result and return summary """ - logging.info(f"{title}") + logging.info(f"{test.desc()}") summary_file = os.environ.get("GITHUB_STEP_SUMMARY") - summary = f"## {title}\n" + summary = f"## {test.desc()}\n" fail = False results = {} + base_compile(test, verbose, cross_prefix, extra_make_envs, extra_make_args) for scheme in SCHEME: - bin = scheme2file(scheme) - base_compile(bin, verbose, cross_prefix, extra_make_envs, extra_make_args) result = base_run( - bin, + test.bin_path(scheme), force_qemu, verbose, run_as_root, @@ -261,29 +297,6 @@ def add_options(options): return lambda func: reduce(lambda f, o: o(f), reversed(options), func) -@click.command( - short_help="Run the specified binary file", - context_settings={"show_default": True}, -) -@add_options(_shared_options) -@click.option( - "-b", - "--bin", - type=click.Path(), - help="The binary file that you wanted to test.", -) -def run(bin, force_qemu, verbose, cross_prefix, cflags, arch_flags): - config_logger(verbose) - - base_compile(bin, verbose, process_make_envs(cflags, arch_flags)) - result = base_run( - bin, - force_qemu, - verbose, - ) - logging.info(str(result, encoding="utf-8")) - - @click.command( short_help="Run the functional tests for all parameter sets", context_settings={"show_default": True}, @@ -304,15 +317,14 @@ def func(force_qemu, verbose, cross_prefix, cflags, arch_flags): ) test_schemes( - "Functional test", - lambda scheme: scheme.name.replace("MLKEM", "test/bin/test_kyber"), + TEST_TYPES.MLKEM, lambda result: str(result, encoding="utf-8"), expect, process_test, force_qemu, verbose, cross_prefix, - process_make_envs(cflags, arch_flags), + extra_make_envs=process_make_envs(cflags, arch_flags), ) @@ -325,15 +337,14 @@ def nistkat(force_qemu, verbose, cross_prefix, cflags, arch_flags): config_logger(verbose) test_schemes( - "Nistkat test", - lambda scheme: scheme.name.replace("MLKEM", "test/bin/gen_NISTKAT"), + TEST_TYPES.NISTKAT, sha256sum, lambda scheme: parse_meta(scheme, "nistkat-sha256"), process_test, force_qemu, verbose, cross_prefix, - process_make_envs(cflags, arch_flags), + extra_make_envs=process_make_envs(cflags, arch_flags), ) @@ -346,15 +357,14 @@ def kat(force_qemu, verbose, cross_prefix, cflags, arch_flags): config_logger(verbose) test_schemes( - "Kat test", - lambda scheme: scheme.name.replace("MLKEM", "test/bin/gen_KAT"), + TEST_TYPES.KAT, sha256sum, lambda scheme: parse_meta(scheme, "kat-sha256"), process_test, force_qemu, verbose, cross_prefix, - process_make_envs(cflags, arch_flags), + extra_make_envs=process_make_envs(cflags, arch_flags), ) @@ -424,8 +434,7 @@ def bench( exec_wrapper = f"taskpolicy -c {mac_taskpolicy}" results = test_schemes( - "benchmark", - lambda scheme: scheme.name.replace("MLKEM", "test/bin/bench_kyber"), + TEST_TYPES.BENCH, lambda _: True, lambda _: True, process_bench, @@ -434,8 +443,10 @@ def bench( cross_prefix, run_as_root, exec_wrapper, - process_make_envs(cflags, arch_flags), - [f"CYCLES={cycles}"], + extra_make_envs=process_make_envs(cflags, arch_flags), + extra_make_args=[ + f"CYCLES={cycles}", + ], ) if output: @@ -473,7 +484,6 @@ def cli(): pass -cli.add_command(run) cli.add_command(func) cli.add_command(nistkat) cli.add_command(kat) diff --git a/test/hal.c b/test/hal/hal.c similarity index 100% rename from test/hal.c rename to test/hal/hal.c diff --git a/test/hal.h b/test/hal/hal.h similarity index 100% rename from test/hal.h rename to test/hal/hal.h