Skip to content

Commit

Permalink
CBMC: add tests cbmc command
Browse files Browse the repository at this point in the history
Currently to run all CBMC proofs, we have to run

cd cbmc/proofs
MLKEM_K=2 python3 run-cbmc-proofs.py
MLKEM_K=3 python3 run-cbmc-proofs.py
MLKEM_K=4 python3 run-cbmc-proofs.py

This commit wraps all that into a single wrapper:
tests cbmc

It is also added to CI.

Signed-off-by: Matthias J. Kannwischer <[email protected]>
  • Loading branch information
mkannwischer committed Dec 3, 2024
1 parent 6ce990f commit f88eeb6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .github/actions/cbmc/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ runs:
- name: Run CBMC proofs (MLKEM_K=${{ inputs.mlkem_k }})
shell: ${{ env.SHELL }}
run: |
cd cbmc/proofs;
echo "::group::cbmc_${{ inputs.mlkem_k }}"
MLKEM_K=${{ inputs.mlkem_k }} ./run-cbmc-proofs.py --summarize --no-coverage -j8;
tests cbmc --k ${{ inputs.mlkem_k }};
echo "::endgroup::"
20 changes: 20 additions & 0 deletions scripts/lib/mlkem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self):
self.run = True
self.exec_wrapper = ""
self.run_as_root = ""
self.k = "ALL"


class Base:
Expand Down Expand Up @@ -709,3 +710,22 @@ def all(opt: bool):
exit_code = exit_code or all(True)

exit(exit_code)

def cbmc(self, k):
config_logger(self.verbose)
def run_cbmc(mlkem_k):
envvars = {"MLKEM_K": mlkem_k}
cpucount = os.cpu_count()
p = subprocess.Popen(
["python3", "run-cbmc-proofs.py", "--summarize", "--no-coverage", f"-j{cpucount}"],
cwd="cbmc/proofs",
env=os.environ.copy() | envvars,
)
p.communicate()
assert p.returncode == 0
if k == "ALL":
run_cbmc("2")
run_cbmc("3")
run_cbmc("4")
else:
run_cbmc(k)
23 changes: 23 additions & 0 deletions scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -291,5 +291,28 @@ def all(
Tests(opts).all(func, kat, nistkat, acvp)


@cli.command(
short_help="Run the CBMC proofs for all parameter sets",
context_settings={"show_default": True},
)
@click.make_pass_decorator(Options, ensure=True)
@add_options(
[
click.option(
"--k",
expose_value=False,
nargs=1,
type=click.Choice(["2", "3", "4", "ALL"]),
show_default=True,
default="ALL",
help="MLKEM parameter set (MLKEM_K).",
callback=__callback("k"),
)
]
)
def cbmc(opts: Options):
Tests(opts).cbmc(opts.k)


if __name__ == "__main__":
cli()

0 comments on commit f88eeb6

Please sign in to comment.