From 635babfa7766ea97e8a1003b7fc1df326778bb4d Mon Sep 17 00:00:00 2001 From: "Thing-han, Lim" <15379156+potsrevennil@users.noreply.github.com> Date: Thu, 20 Jun 2024 14:53:54 +0800 Subject: [PATCH] use env vars for setting makefile cflags from cli Signed-off-by: Thing-han, Lim <15379156+potsrevennil@users.noreply.github.com> --- Makefile | 8 ++++---- scripts/tests | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 7913708b1..f24454db8 100644 --- a/Makefile +++ b/Makefile @@ -9,23 +9,23 @@ INCLUDE_FIPS202 = -I fips202 INCLUDE_MLKEM = -I mlkem INCLUDE_RANDOM = -I randombytes INCLUDE_NISTRANDOM = -I test/nistrng -override CFLAGS += -Wall -Wextra -Wpedantic -Werror -Wmissing-prototypes -Wredundant-decls \ +CFLAGS += -Wall -Wextra -Wpedantic -Werror -Wmissing-prototypes -Wredundant-decls \ -Wshadow -Wpointer-arith -Wno-unknown-pragmas -O3 -fomit-frame-pointer -pedantic \ ${INCLUDE_MLKEM} ${INCLUDE_FIPS202} HOST_PLATFORM := $(shell uname -s)-$(shell uname -m) ifeq ($(HOST_PLATFORM),Linux-x86_64) - override CFLAGS += -static + CFLAGS += -static endif CYCLES ?= NO ifeq ($(CYCLES),PMU) - override CFLAGS += -DPMU_CYCLES + CFLAGS += -DPMU_CYCLES endif ifeq ($(CYCLES),PERF) - override CFLAGS += -DPERF_CYCLES + CFLAGS += -DPERF_CYCLES endif CFLAGS_RANDOMBYTES = ${CFLAGS} ${INCLUDE_RANDOM} diff --git a/scripts/tests b/scripts/tests index a69599082..4f69fb689 100755 --- a/scripts/tests +++ b/scripts/tests @@ -25,7 +25,13 @@ def sha256sum(result): return m.hexdigest() -def base_run(bin, force_qemu, verbose, extra_make_args=[]): +def base_run(bin, force_qemu, verbose, extra_make_envs={}, extra_make_args=[]): + def dict2str(dict): + s = "" + for k, v in dict.items(): + s += f"{k}={v} " + return s + if force_qemu or (platform.system() == "Linux" and platform.machine() == "x86_64"): logging.debug(f"Emulating {bin} with QEMU") @@ -35,11 +41,12 @@ def base_run(bin, force_qemu, verbose, extra_make_args=[]): f"{bin}", ] + extra_make_args - logging.info(" ".join(args)) + logging.info(dict2str(extra_make_envs) + " ".join(args)) p = subprocess.run( args, stdout=subprocess.DEVNULL if not verbose else None, + env=os.environ.copy() | extra_make_envs, ) if p.returncode != 0: logging.error(f"make failed: {p.returncode}") @@ -61,11 +68,12 @@ def base_run(bin, force_qemu, verbose, extra_make_args=[]): logging.debug(f"Running {bin} natively") args = ["make", f"{bin}"] + extra_make_args - logging.info(" ".join(args)) + logging.info(dict2str(extra_make_envs) + " ".join(args)) p = subprocess.run( args, stdout=subprocess.DEVNULL if not verbose else None, + env=os.environ.copy() | extra_make_envs, ) if p.returncode != 0: @@ -122,6 +130,7 @@ def test_schemes( process_result, force_qemu, verbose, + extra_make_envs={}, extra_make_args=[], ): """ @@ -136,7 +145,7 @@ def test_schemes( results = {} for scheme in SCHEME: bin = scheme2file(scheme) - result = base_run(bin, force_qemu, verbose, extra_make_args) + result = base_run(bin, force_qemu, verbose, extra_make_envs, extra_make_args) results[scheme] = result actual = actual_proc(result) @@ -328,7 +337,8 @@ def bench(force_qemu, verbose, cycles, cpu): process_bench, force_qemu, verbose, - [f"CYCLES={cycles}", *([f"CFLAGS=-mcpu={cpu}"] if cpu is not None else [])], + ({"CFLAGS": f"-mcpu={cpu}"} if cpu is not None else {}), + [f"CYCLES={cycles}"], )