Skip to content

Commit

Permalink
use env vars for setting makefile cflags from cli
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 20, 2024
1 parent 1d13369 commit 635babf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
20 changes: 15 additions & 5 deletions scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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}")
Expand All @@ -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:
Expand Down Expand Up @@ -122,6 +130,7 @@ def test_schemes(
process_result,
force_qemu,
verbose,
extra_make_envs={},
extra_make_args=[],
):
"""
Expand All @@ -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)
Expand Down Expand Up @@ -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}"],
)


Expand Down

0 comments on commit 635babf

Please sign in to comment.