Skip to content

Commit

Permalink
EC: add unit tests for extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
vbgl authored and bgregoir committed Feb 4, 2025
1 parent f131dbc commit 1ffac06
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ check-proofs:
- nix-shell --arg inCI true $EXTRA_NIX_ARGUMENTS --run 'easycrypt why3config -why3 $WHY3_CONF'
- nix-shell --arg inCI true $EXTRA_NIX_ARGUMENTS --run 'easycrypt config -why3 $WHY3_CONF'
- nix-shell --arg inCI true $EXTRA_NIX_ARGUMENTS --run 'make -C compiler/examples/gimli/proofs CT_MODE=$CT_MODE'
- nix-shell --arg inCI true $EXTRA_NIX_ARGUMENTS --run 'make -C compiler/examples/extraction-unit-tests'

libjade-compile-to-asm:
stage: test
Expand Down
1 change: 1 addition & 0 deletions compiler/examples/extraction-unit-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loops.ec
16 changes: 16 additions & 0 deletions compiler/examples/extraction-unit-tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ECARGS ?= -I Jasmin:../../../eclib

JASMIN2EC := ../../jasmin2ec

.SUFFIXES: .jazz .ec

all: loops.ec proofs.ec
easycrypt runtest $(ECARGS) ec.config $@

clean:
$(RM) loops.ec

%.ec: %.jazz
$(JASMIN2EC) -o $@ $^

.PHONY: all
6 changes: 6 additions & 0 deletions compiler/examples/extraction-unit-tests/ec.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[default]
bin = easycrypt

[test-all]
okdirs = .

24 changes: 24 additions & 0 deletions compiler/examples/extraction-unit-tests/loops.jazz
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Tests bounds of decreasing for loops */
export
fn forty() -> reg u32 {
inline int i j = 0;
for i = 10 downto 5 {
j += i;
}
reg u32 r = j;
return r;
}

/* Tests nested for loops with non-immediate bounds */
param int a = 10;
export
fn for_nest() -> reg u32 {
inline int i j k = 0;
for i = 0 to a + a {
for j = 0 to a * a {
k += 1;
}
}
reg u32 r = k;
return r;
}
16 changes: 16 additions & 0 deletions compiler/examples/extraction-unit-tests/proofs.ec
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require import AllCore.
from Jasmin require import JWord.

require Loops.

lemma loops_forty_correct : hoare [ Loops.M.forty: true ==> res = W32.of_int 40 ].
proof. by proc; unroll for ^while; auto. qed.

lemma loops_for_nest_correct : hoare [ Loops.M.for_nest: true ==> res = W32.of_int 2000 ].
proof.
proc; wp.
while (0 <= i <= inc /\ k = 100 * i).
- wp.
while (0 <= j <= inc_0 /\ k = 100 * i + j); by auto => /#.
auto => /#.
qed.

0 comments on commit 1ffac06

Please sign in to comment.