Skip to content

Commit 425bc20

Browse files
authored
Merge pull request #476 from pq-code-package/cbmc-test
CBMC: add `tests cbmc` command
2 parents 6ce990f + f88eeb6 commit 425bc20

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

.github/actions/cbmc/action.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ runs:
4646
- name: Run CBMC proofs (MLKEM_K=${{ inputs.mlkem_k }})
4747
shell: ${{ env.SHELL }}
4848
run: |
49-
cd cbmc/proofs;
5049
echo "::group::cbmc_${{ inputs.mlkem_k }}"
51-
MLKEM_K=${{ inputs.mlkem_k }} ./run-cbmc-proofs.py --summarize --no-coverage -j8;
50+
tests cbmc --k ${{ inputs.mlkem_k }};
5251
echo "::endgroup::"

scripts/lib/mlkem_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def __init__(self):
5050
self.run = True
5151
self.exec_wrapper = ""
5252
self.run_as_root = ""
53+
self.k = "ALL"
5354

5455

5556
class Base:
@@ -709,3 +710,22 @@ def all(opt: bool):
709710
exit_code = exit_code or all(True)
710711

711712
exit(exit_code)
713+
714+
def cbmc(self, k):
715+
config_logger(self.verbose)
716+
def run_cbmc(mlkem_k):
717+
envvars = {"MLKEM_K": mlkem_k}
718+
cpucount = os.cpu_count()
719+
p = subprocess.Popen(
720+
["python3", "run-cbmc-proofs.py", "--summarize", "--no-coverage", f"-j{cpucount}"],
721+
cwd="cbmc/proofs",
722+
env=os.environ.copy() | envvars,
723+
)
724+
p.communicate()
725+
assert p.returncode == 0
726+
if k == "ALL":
727+
run_cbmc("2")
728+
run_cbmc("3")
729+
run_cbmc("4")
730+
else:
731+
run_cbmc(k)

scripts/tests

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,5 +291,28 @@ def all(
291291
Tests(opts).all(func, kat, nistkat, acvp)
292292

293293

294+
@cli.command(
295+
short_help="Run the CBMC proofs for all parameter sets",
296+
context_settings={"show_default": True},
297+
)
298+
@click.make_pass_decorator(Options, ensure=True)
299+
@add_options(
300+
[
301+
click.option(
302+
"--k",
303+
expose_value=False,
304+
nargs=1,
305+
type=click.Choice(["2", "3", "4", "ALL"]),
306+
show_default=True,
307+
default="ALL",
308+
help="MLKEM parameter set (MLKEM_K).",
309+
callback=__callback("k"),
310+
)
311+
]
312+
)
313+
def cbmc(opts: Options):
314+
Tests(opts).cbmc(opts.k)
315+
316+
294317
if __name__ == "__main__":
295318
cli()

0 commit comments

Comments
 (0)