Skip to content

Commit aa695b9

Browse files
authored
Merge pull request #3978 from mtzguido/ocaml-unit-tests
Restore internal (OCaml) unit tests
2 parents 17d67a5 + b106698 commit aa695b9

18 files changed

+664
-433
lines changed

.github/workflows/tests.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
- name: Run tests, without forcing a build
7777
run: make -skj$(nproc) _test
7878

79-
# This runs the bare tests over the bare stage1 compiler.
79+
# This runs the bare tests over the bare stage2 compiler.
8080
# We start from the built repo.
8181
bare:
8282
runs-on: ubuntu-latest
@@ -91,7 +91,24 @@ jobs:
9191
with:
9292
name: fstar-repo
9393

94-
- run: make -skj$(nproc) test-1-bare
94+
- run: make -skj$(nproc) test-2-bare
95+
working-directory: FStar
96+
97+
# The internal tests (src/tests)
98+
internal:
99+
runs-on: ubuntu-latest
100+
container: mtzguido/dev-base
101+
steps:
102+
- name: Cleanup
103+
run: sudo find . -delete
104+
- run: echo "HOME=/home/user" >> $GITHUB_ENV
105+
- uses: mtzguido/set-opam-env@master
106+
107+
- uses: mtzguido/gci-download@master
108+
with:
109+
name: fstar-repo
110+
111+
- run: make -skj$(nproc) stage2-unit-tests
95112
working-directory: FStar
96113

97114
binary-smoke:

Makefile

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ include mk/common.mk
99
FSTAR_DEFAULT_GOAL ?= build
1010
.DEFAULT_GOAL := $(FSTAR_DEFAULT_GOAL)
1111

12-
all: stage1 stage2 stage3-bare lib-fsharp
12+
all: stage1 stage2 1.tests 2.tests stage3-bare lib-fsharp
1313
all-packages: package-1 package-2 package-src-1 package-src-2
1414

1515
### STAGES
@@ -38,12 +38,14 @@ FSTAR0_EXE ?= stage0/out/bin/fstar.exe
3838
# stage 1 libraries for the stage 2, which does not need them at all (currently?).
3939
#
4040
# I'd love a better alternative.
41-
FSTAR1_BARE_EXE := stage1/dune/_build/default/fstarc-bare/fstarc1_bare.exe
42-
FSTAR1_FULL_EXE := stage1/dune/_build/default/fstarc-full/fstarc1_full.exe
41+
FSTAR1_BARE_EXE := stage1/dune/_build/default/fstarc-bare/fstarc1_bare.exe
42+
FSTAR1_FULL_EXE := stage1/dune/_build/default/fstarc-full/fstarc1_full.exe
4343
INSTALLED_FSTAR1_FULL_EXE := stage1/out/bin/fstar.exe
44-
FSTAR2_BARE_EXE := stage2/dune/_build/default/fstarc-bare/fstarc2_bare.exe
45-
FSTAR2_FULL_EXE := stage2/dune/_build/default/fstarc-full/fstarc2_full.exe
44+
FSTAR2_BARE_EXE := stage2/dune/_build/default/fstarc-bare/fstarc2_bare.exe
45+
FSTAR2_FULL_EXE := stage2/dune/_build/default/fstarc-full/fstarc2_full.exe
4646
INSTALLED_FSTAR2_FULL_EXE := stage2/out/bin/fstar.exe
47+
TESTS1_EXE := stage1/dune/_build/default/tests/fstarc1_tests.exe
48+
TESTS2_EXE := stage2/dune/_build/default/tests/fstarc2_tests.exe
4749

4850
.PHONY: .force
4951
.force:
@@ -59,10 +61,12 @@ endif
5961
build: 2
6062

6163
0: $(FSTAR0_EXE)
62-
1.bare: $(FSTAR1_BARE_EXE)
63-
1.full: $(FSTAR1_FULL_EXE)
64-
2.bare: $(FSTAR2_BARE_EXE)
65-
2.full: $(FSTAR2_FULL_EXE)
64+
1.bare: $(FSTAR1_BARE_EXE)
65+
1.tests: $(TESTS1_EXE)
66+
1.full: $(FSTAR1_FULL_EXE)
67+
2.bare: $(FSTAR2_BARE_EXE)
68+
2.tests: $(TESTS2_EXE)
69+
2.full: $(FSTAR2_FULL_EXE)
6670

6771
# This file's timestamp is updated whenever anything in stage0/
6872
# (excluding some build directories)
@@ -92,13 +96,27 @@ stage0/out/bin/fstar.exe: .stage0.touch
9296
env \
9397
SRC=src/ \
9498
FSTAR_EXE=$(FSTAR0_EXE) \
99+
FSTAR_LIB=$(abspath ulib) \
95100
CACHE_DIR=stage1/fstarc.checked/ \
96101
OUTPUT_DIR=stage1/fstarc.ml/ \
97102
CODEGEN=OCaml \
98103
TAG=fstarc \
99104
TOUCH=$@ \
100105
$(MAKE) -f mk/fstar-01.mk ocaml
101106

107+
.tests1.src.touch: .bare1.src.touch $(FSTAR0_EXE) .force
108+
$(call bold_msg, "EXTRACT", "STAGE 1 TESTS")
109+
env \
110+
SRC=src/ \
111+
FSTAR_EXE=$(FSTAR0_EXE) \
112+
FSTAR_LIB=$(abspath ulib) \
113+
CACHE_DIR=stage1/tests.checked/ \
114+
OUTPUT_DIR=stage1/tests.ml/ \
115+
CODEGEN=PluginNoLib \
116+
TAG=fstarc \
117+
TOUCH=$@ \
118+
$(MAKE) -f mk/tests-1.mk ocaml
119+
102120
# These files are regenerated as soon as *any* ml file reachable from
103121
# stage*/dune changes. This makes sure we trigger dune rebuilds when we
104122
# modify base ML files. However this will not catch deletion of a file.
@@ -111,6 +129,14 @@ $(FSTAR1_BARE_EXE): .bare1.src.touch .src.ml.touch $(MAYBEFORCE)
111129
$(MAKE) -C stage1 fstarc-bare
112130
touch -c $@
113131

132+
$(TESTS1_EXE): .tests1.src.touch .src.ml.touch $(MAYBEFORCE)
133+
$(call bold_msg, "BUILD", "STAGE 1 TESTS")
134+
$(MAKE) -C stage1 tests
135+
touch -c $@
136+
137+
stage1-unit-tests: $(TESTS1_EXE)
138+
FSTAR_LIB=$(CURDIR)/ulib $(TESTS1_EXE)
139+
114140
.full1.src.touch: $(FSTAR1_BARE_EXE) .force
115141
$(call bold_msg, "EXTRACT", "STAGE 1 PLUGINS")
116142
env \
@@ -183,6 +209,19 @@ $(FSTAR1_FULL_EXE): .bare1.src.touch .full1.src.touch .src.ml.touch $(MAYBEFORCE
183209
TOUCH=$@ \
184210
$(MAKE) -f mk/fstar-12.mk ocaml
185211

212+
.tests2.src.touch: .bare2.src.touch $(FSTAR1_FULL_EXE) .force
213+
$(call bold_msg, "EXTRACT", "STAGE 2 TESTS")
214+
env \
215+
SRC=src/ \
216+
FSTAR_EXE=$(FSTAR1_FULL_EXE) \
217+
FSTAR_LIB=$(abspath ulib) \
218+
CACHE_DIR=stage2/tests.checked/ \
219+
OUTPUT_DIR=stage2/tests.ml/ \
220+
CODEGEN=PluginNoLib \
221+
TAG=fstarc \
222+
TOUCH=$@ \
223+
$(MAKE) -f mk/tests-2.mk ocaml
224+
186225
$(FSTAR2_BARE_EXE): .bare2.src.touch .src.ml.touch $(MAYBEFORCE)
187226
$(call bold_msg, "BUILD", "STAGE 2 FSTARC-BARE")
188227
$(MAKE) -C stage2 fstarc-bare FSTAR_DUNE_RELEASE=1
@@ -191,6 +230,14 @@ $(FSTAR2_BARE_EXE): .bare2.src.touch .src.ml.touch $(MAYBEFORCE)
191230
# it is still part of the build of the full fstar, so
192231
# we set the release flag to have a more incremental build.
193232

233+
$(TESTS2_EXE): .tests2.src.touch .src.ml.touch $(MAYBEFORCE)
234+
$(call bold_msg, "BUILD", "STAGE 2 TESTS")
235+
$(MAKE) -C stage2 tests
236+
touch -c $@
237+
238+
stage2-unit-tests: $(TESTS2_EXE)
239+
FSTAR_LIB=$(CURDIR)/ulib $(TESTS2_EXE)
240+
194241
.full2.src.touch: $(FSTAR2_BARE_EXE) .force
195242
$(call bold_msg, "EXTRACT", "STAGE 2 PLUGINS")
196243
env \
@@ -385,14 +432,14 @@ package-2: .stage2.src.touch .force
385432
INSTALL_RULE=__do-install-stage2 \
386433
$(MAKE) __do-archive
387434

388-
package-src-1: .stage1.src.touch .force
435+
package-src-1: .stage1.src.touch .tests1.src.touch .force
389436
env \
390437
PKGTMP=_srcpak1 \
391438
BROOT=stage1/ \
392439
ARCHIVE=fstar$(FSTAR_TAG)-stage1-src \
393440
$(MAKE) __do-src-archive
394441

395-
package-src-2: .stage2.src.touch .force
442+
package-src-2: .stage2.src.touch .tests2.src.touch .force
396443
env \
397444
PKGTMP=_srcpak2 \
398445
BROOT=stage2/ \
@@ -451,7 +498,7 @@ _examples: need_fstar_exe .force
451498

452499
ci: .force
453500
+$(MAKE) 2
454-
+$(MAKE) test lib-fsharp stage3-diff
501+
+$(MAKE) test lib-fsharp stage3-diff test-2-bare stage2-unit-tests
455502

456503
save: stage0_new
457504

mk/stage.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ endif
3131
fstarc-bare: _force
3232
cd dune && $(DUNE) build $(FSTAR_DUNE_BUILD_OPTIONS) fstarc-bare
3333

34+
tests: _force
35+
cd dune && $(DUNE) build $(FSTAR_DUNE_BUILD_OPTIONS) tests
36+
3437
fstarc-full: _force
3538
cd dune && $(DUNE) build $(FSTAR_DUNE_BUILD_OPTIONS) fstarc-full
3639

mk/tests-1.mk

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FSTAR_OPTIONS += --lax
2+
# HACK ALERT! --MLish passed by generic.mk to FStarC modules
3+
# only. Passing it here would mean the library is checked with
4+
# --MLish, which fails.
5+
FSTAR_OPTIONS += --MLish_effect 'FStarC.Effect'
6+
7+
DEPFLAGS += --already_cached '+Prims,+FStar,+FStarC,-FStarC.Tests'
8+
9+
DEPFLAGS += --already_cached '-FStar'
10+
# ^ FIXME: This should be removed. All of the modules we *actually* depend on
11+
# in the FStar namespace are indeed already checked. But, if we claim that, the
12+
# dependency analysis will complain about modules such as
13+
# FStar.Stubs.Reflection.V2.Builtins not being checked, which is irrelevant.
14+
15+
# All other files have been extracted already into fstar-guts.
16+
EXTRACT :=
17+
EXTRACT += --extract +FStarC.Tests
18+
19+
# hack, reuse checked files from guts
20+
OTHERFLAGS += --include $(CACHE_DIR)/../fstarc.checked
21+
DEPFLAGS += --include $(CACHE_DIR)/../fstarc.checked
22+
23+
ROOTS :=
24+
ROOTS += $(SRC)/tests/FStarC.Tests.Test.fst
25+
26+
include mk/generic-0.mk

mk/tests-2.mk

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FSTAR_OPTIONS += --lax
2+
# HACK ALERT! --MLish passed by generic.mk to FStarC modules
3+
# only. Passing it here would mean the library is checked with
4+
# --MLish, which fails.
5+
FSTAR_OPTIONS += --MLish_effect 'FStarC.Effect'
6+
7+
DEPFLAGS += --already_cached '+FStarC.*,-FStarC.Tests.*'
8+
9+
# All other files have been extracted already into fstar-guts.
10+
EXTRACT :=
11+
EXTRACT += --extract +FStarC.Tests
12+
13+
# hack, reuse checked files from guts
14+
OTHERFLAGS += --include $(CACHE_DIR)/../fstarc.checked
15+
DEPFLAGS += --include $(CACHE_DIR)/../fstarc.checked
16+
17+
ROOTS :=
18+
ROOTS += $(SRC)/tests/FStarC.Tests.Test.fst
19+
20+
include mk/generic-1.mk

src/basic/FStarC.Options.fst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ module Ext = FStarC.Options.Ext
4343
let debug_embedding = mk_ref false
4444
let eager_embedding = mk_ref false
4545

46-
(* A FLAG TO INDICATE THAT WE'RE RUNNING UNIT TESTS *)
47-
let __unit_tests__ = mk_ref false
48-
let __unit_tests() = !__unit_tests__
49-
let __set_unit_tests () = __unit_tests__ := true
50-
let __clear_unit_tests () = __unit_tests__ := false
51-
5246
let as_bool = function
5347
| Bool b -> b
5448
| _ -> failwith "Impos: expected Bool"

src/basic/FStarC.Options.fsti

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ val set_verification_options : optionstate -> unit
102102
"--z3rlimit 25 --include /some/path" *)
103103
val show_options : unit -> string
104104

105-
val __unit_tests : unit -> bool
106-
val __set_unit_tests : unit -> unit
107-
val __clear_unit_tests : unit -> unit
108105
val parse_cmd_line : unit -> parse_cmdline_res & list string
109106
val add_verify_module : string -> unit
110107

0 commit comments

Comments
 (0)