-
-
Notifications
You must be signed in to change notification settings - Fork 376
/
Copy pathtests
208 lines (177 loc) · 6.7 KB
/
tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
##
# Build/download stanc3
##
STANC_DL_RETRY = 5
STANC_DL_DELAY = 10
ifeq ($(OS),Windows_NT)
OS_TAG := windows
else ifeq ($(OS),Darwin)
OS_TAG := mac
else ifeq ($(OS),Linux)
OS_TAG := linux
endif
ifneq ($(STANC3),)
# build stanc3 from local installation
bin/stanc$(EXE) : $(call findfiles,$(STANC3)/src/,*.ml*) $(STANC#)
@mkdir -p $(dir $@)
cd $(STANC3) && echo "--- Rebuilding stanc ---\n" && dune build @install
cp $(STANC3)/_build/default/src/stanc/stanc.exe $@
else ifneq ($(STANC3_TEST_BIN_URL),)
# download stanc3 build from specific branch
ifeq ($(OS_TAG),windows)
bin/stanc$(EXE) :
@mkdir -p $(dir $@)
$(shell echo "curl -L $(STANC3_TEST_BIN_URL)/bin/$(OS_TAG)-stanc -o bin/stanc$(EXE) --retry $(STANC_DL_RETRY) --retry-delay $(STANC_DL_DELAY)")
else
bin/stanc$(EXE) :
@mkdir -p $(dir $@)
curl -L $(STANC3_TEST_BIN_URL)/bin/$(OS_TAG)-stanc -o bin/stanc$(EXE) --retry $(STANC_DL_RETRY) --retry-delay $(STANC_DL_DELAY)
chmod +x bin/stanc$(EXE)
endif # end download if/else
else ifeq ($(OS_TAG),windows)
# get latest stanc3 - Windows
bin/stanc$(EXE) :
@mkdir -p $(dir $@)
$(shell echo "curl -L https://github.com/stan-dev/stanc3/releases/download/nightly/$(OS_TAG)-stanc -o bin/stanc$(EXE) --retry $(STANC_DL_RETRY) --retry-delay $(STANC_DL_DELAY)")
else
# get latest stanc3 - Linux & MacOS
bin/stanc$(EXE) :
@mkdir -p $(dir $@)
curl -L https://github.com/stan-dev/stanc3/releases/download/nightly/$(OS_TAG)-stanc -o bin/stanc$(EXE) --retry $(STANC_DL_RETRY) --retry-delay $(STANC_DL_DELAY)
chmod +x bin/stanc$(EXE)
endif
##
# Build test executables
##
test/%$(EXE) : CXXFLAGS += $(CXXFLAGS_GTEST)
test/%$(EXE) : CPPFLAGS += $(CPPFLAGS_GTEST)
test/%$(EXE) : INC_FIRST = -I $(if $(STAN),$(STAN)/src,src) -I $(if $(STAN),$(STAN),.) -I $(RAPIDJSON)
test/%$(EXE) : INC += $(INC_GTEST)
test/%$(EXE) : test/%.o $(GTEST)/src/gtest_main.cc $(GTEST)/src/gtest-all.o $(SUNDIALS_TARGETS) $(MPI_TARGETS) $(TBB_TARGETS)
$(LINK.cpp) $(filter-out test/%.hpp %.hpp-test,$^) $(LDLIBS) $(OUTPUT_OPTION)
test/%.o : src/test/%.cpp
@mkdir -p $(dir $@)
$(COMPILE.cpp) $< $(OUTPUT_OPTION)
##
# Customization for generating dependencies
##
src/test/%.d : CXXFLAGS += $(CXXFLAGS_GTEST)
src/test/%.d : CPPFLAGS += $(CPPFLAGS_GTEST)
src/test/%.d : INC_FIRST = -I $(if $(STAN),$(STAN)/src,src) -I $(if $(STAN),$(STAN),.) -I $(RAPIDJSON)
src/test/%.d : INC += $(INC_GTEST)
src/test/%.d : DEPTARGETS = -MT $(patsubst src/test/%.d,test/%.o,$@) -MT $@
ifneq ($(filter test/%$(EXE),$(MAKECMDGOALS)),)
-include $(patsubst test/%$(EXE),src/test/%.d,$(filter test/%,$(MAKECMDGOALS)))
endif
############################################################
##
# Target to verify header files within Stan has
# enough include calls
##
HEADER_TESTS := $(addsuffix -test,$(call findfiles,src/stan,*.hpp))
ifeq ($(OS),Windows_NT)
DEV_NULL = nul
ifeq ($(IS_UCRT),true)
UCRT_NULL_FLAG = -S
endif
else
DEV_NULL = /dev/null
endif
%.hpp-test : %.hpp test/dummy.cpp
$(COMPILE.cpp) -O0 -include $^ $(UCRT_NULL_FLAG) -o $(DEV_NULL)
test/dummy.cpp:
@mkdir -p test
@touch $@
@echo "int main() {return 0;}" >> $@
.PHONY: test-headers
test-headers: $(HEADER_TESTS)
##
# Target to verify code generated Stan programs
# (.stan -> .hpp) are compilable
#
# Running:
# > make test/integration/compile_models
# will make sure everything in src/test/test-models/good/
# compiles
##
.PHONY: %.hpp-test
ifneq ($(OS),Windows_NT)
test/test-models/good/%.hpp-test : O = 0
else
test/test-models/good/%.hpp-test : O = 1
endif
test/test-models/good/%.hpp-test : test/test-models/good/%.hpp test/test-model-main.cpp
$(COMPILE.cpp) -o $(DEV_NULL) -include $^
test/test-model-main.cpp:
@mkdir -p test
@touch $@
@echo "int main() {" >> $@
@echo " stan::io::var_context *data = NULL;" >> $@
@echo " stan_model model(*data);" >> $@
@echo >> $@
@echo " std::vector<stan::math::var> params;" >> $@
@echo " std::vector<double> x_r;" >> $@
@echo " std::vector<int> x_i;" >> $@
@echo >> $@
@echo " model.log_prob<false, false>(params, x_i);" >> $@
@echo " model.log_prob<false, true>(params, x_i);" >> $@
@echo " model.log_prob<true, false>(params, x_i);" >> $@
@echo " model.log_prob<true, true>(params, x_i);" >> $@
@echo " model.log_prob<false, false>(x_r, x_i);" >> $@
@echo " model.log_prob<false, true>(x_r, x_i);" >> $@
@echo " model.log_prob<true, false>(x_r, x_i);" >> $@
@echo " model.log_prob<true, true>(x_r, x_i);" >> $@
@echo >> $@
@echo " return 0;" >> $@
@echo "}" >> $@
@echo >> $@
##
# Adding a test for multiple translation units. If this fails,
# a new function is probably missing an inline.
# Templates for such test are prefixed with 'mtu_'.
##
test/integration/mtu :
mkdir -p test/integration/mtu
test/integration/mtu/%_1.cpp : src/test/integration/mtu/%.cpp test/integration/mtu
cp $< $@
test/integration/mtu/%_2.cpp : src/test/integration/mtu/%.cpp test/integration/mtu
cp $< $@
ifneq ($(OS),Windows_NT)
test/integration/mtu/%.o : CXXFLAGS += -fPIC
test/integration/mtu/%.o : O = 0
else
test/integration/mtu/%.o : O = 1
endif
test/integration/mtu/%.o : %.cpp
$(COMPILE.cpp) -pipe -o $(DEV_NULL) -include $^
test/integration/libmtu_%.so : LDFLAGS += -shared
test/integration/libmtu_%.so : test/integration/mtu/%_1.o test/integration/mtu/%_2.o $(MPI_TARGETS) $(TBB_TARGETS)
$(LINK.cpp) $^ $(LDLIBS) $(OUTPUT_OPTION)
test/integration/multiple_translation_units_test$(EXE) : test/integration/libmtu_model.so test/integration/libmtu_mcmc.so
############################################################
##
# Use the stanc compiler to generate C++ from Stan programs
##
TEST_MODELS = $(call findfiles,src/test/test-models,*.stan)
$(patsubst src/%.stan,%.hpp,$(TEST_MODELS)) : test/test-models/%.hpp : src/test/test-models/%.stan bin/stanc$(EXE)
@mkdir -p $(dir $@)
$(WINE) bin/stanc$(EXE) $(STANCFLAGS) $< --o=$@
##
# Generate C++ from Stan standalone functions
##
TEST_FUNCTIONS = $(call findfiles,src/test/test-models,*.stanfuncs)
$(patsubst src/%.stanfuncs,%.hpp,$(TEST_FUNCTIONS)) : test/test-models/%.hpp : src/test/test-models/%.stanfuncs bin/stanc$(EXE)
@mkdir -p $(dir $@)
$(WINE) bin/stanc$(EXE) $(STANCFLAGS) --standalone-functions $< --o=$@
##
# Compile models depends on every model within
# src/test/test-models/good/*.stan being able to
# be code-generated to a *.hpp, then passed through
# the compiler using the -fsyntax-only flag
##
test/integration/compile_models_test$(EXE): $(patsubst src/%.stan,%.hpp-test,$(call findfiles,src/test/test-models/good,*.stan))
##
# Same trick as above for models, but for standalone functions, using
# "src/test/test-models/good-standalone-functions/*.stanfuncs"
##
test/integration/compile_standalone_functions_test$(EXE): $(patsubst src/%.stanfuncs,%.hpp-test,$(call findfiles,src/test/test-models/good-standalone-functions,*.stanfuncs))