1#
2# Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
3#
4# SPDX-License-Identifier: BSD-2-Clause
5#
6
7default: AutoCorresTest
8
9all: AutoCorres AutoCorresTest AutoCorresSEL4 AutoCorresDoc
10
11report-regression:
12	@echo AutoCorres AutoCorresTest AutoCorresDoc AutoCorresSEL4
13
14PARSE_TESTS_C := $(wildcard tests/parse-tests/*.c)
15PARSE_TESTS_THY := $(patsubst %.c,%.thy,$(PARSE_TESTS_C))
16
17PROOF_TESTS_C := $(wildcard tests/proof-tests/*.c)
18PROOF_TESTS_THY := $(wildcard tests/proof-tests/*.thy)
19
20EXAMPLES_C := $(wildcard tests/examples/*.c)
21EXAMPLES_THY := $(wildcard tests/examples/*.thy)
22
23ALL_TESTS_C := $(PARSE_TESTS_C) $(PROOF_TESTS_C) $(EXAMPLES_C)
24ALL_TESTS_THY := $(PARSE_TESTS_THY) $(PROOF_TESTS_THY) $(EXAMPLES_THY)
25
26# Generate an Isabelle "ROOT" file containing all of our test cases.
27tests/ROOT: $(ALL_TESTS_C) $(ALL_TESTS_THY) ../../misc/scripts/gen_isabelle_root.py
28	python3 ../../misc/scripts/gen_isabelle_root.py -o $@ -b AutoCorres -s AutoCorresTest -d HOL-Number_Theory \
29		-i tests/parse-tests -i tests/proof-tests -i tests/examples --quick-and-dirty --dir parse-tests --dir proof-tests --dir examples
30
31# Generate a Isabelle "All.thy" file containing imports to all the test cases.
32tests/All.thy: $(ALL_TESTS_C) $(ALL_TESTS_THY) ../../misc/scripts/gen_isabelle_root.py
33	python3 ../../misc/scripts/gen_isabelle_root.py -T -o $@ \
34		-i tests/parse-tests -i tests/proof-tests -i tests/examples
35
36SPDX_TAG=SPDX-License-Identifier
37
38# Generate a template ".thy" file from a ".c" file,
39# but only for ".c" files in tests/parse-tests.
40$(PARSE_TESTS_THY): %.thy: %.c
41	@echo "Generating '$@' from '$<'..."
42	@printf '(*\n * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)\n *\n' > $@
43	@printf ' * $(SPDX_TAG): BSD-2-Clause\n *)\n\n' >> $@
44	@printf '(* This file was generated by tools/autocorres/Makefile *)\n\n' >> $@
45	@printf 'theory %s\nimports "AutoCorres.AutoCorres"\nbegin\n\n' $(notdir $(basename $<)) >> $@
46	@printf 'external_file "%s"\n\n' $(notdir $<) >> $@
47	@printf 'install_C_file "%s"\n\n' $(notdir $<) >> $@
48	@printf 'autocorres "%s"\n\n' $(notdir $<) >> $@
49	@printf 'end\n' >> $@
50
51# Test all the files in our "tests/" directory.
52AutoCorresTest: clean-tests tests/ROOT
53	$(ISABELLE_TOOL) build -d ../.. -d tests -v AutoCorresTest
54.PHONY: AutoCorresTest
55
56# Parse the seL4 kernel
57AutoCorresSEL4:
58	make -C ../../proof CBaseRefine
59	$(ISABELLE_TOOL) build -d ../.. -v AutoCorresSEL4
60.PHONY: AutoCorresSEL4
61
62# Build the documentation sub-sessions.
63AutoCorresDoc:
64	$(ISABELLE_TOOL) build -d ../.. -D doc/quickstart
65
66# Clean out files generated by the test suite.
67clean-tests:
68	rm -f tests/parse-tests/*.thy
69	rm -f tests/ROOT
70.PHONY: clean-tests
71
72clean: clean-tests
73
74HEAPS := AutoCorres
75
76include ../../misc/isa-common.mk
77
78