swh:1:snp:d80eec3f654c152adbdd6e641362bcb340d39fe2
Tip revision: 3c2c753ce2772c1e28ce47b670e7e1cf9a975ba2 authored by Ben Goodrich on 08 June 2019, 15:36:27 UTC
add standalone_gqs method back
add standalone_gqs method back
Tip revision: 3c2c753
tests
##
# 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),.)
test/%$(EXE) : INC += $(INC_GTEST)
test/%$(EXE) : test/%.o $(GTEST)/src/gtest_main.cc $(GTEST)/src/gtest-all.o $(LIBSUNDIALS) $(MPI_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),.)
src/test/%.d : INC += $(INC_GTEST)
src/test/%.d : DEPTARGETS = -MT $(patsubst src/test/%.d,test/%.o,$@) -MT $@
## this is for the $(STANC_TEMPLATE_INSTANTIATION) files
src/stan/%.d : DEPTARGETS = -MT test/test-models/stanc$(EXE) -MT $(patsubst src/%.d,test/%.o,$@) -MT $@
ifneq ($(filter test/%$(EXE),$(MAKECMDGOALS)),)
-include $(patsubst test/%$(EXE),src/test/%.d,$(filter test/%,$(MAKECMDGOALS)))
endif
ifneq ($(filter test/unit/lang/%$(EXE),$(MAKECMDGOALS)),)
-include src/test/test-models/stanc.d
-include $(patsubst %.cpp,%.d,$(STANC_TEMPLATE_INSTANTIATION_CPP))
endif
ifneq ($(filter test/test-models/stanc$(EXE) test/test-models/stanc.o,$(MAKECMDGOALS)),)
-include src/test/test-models/stanc.d
-include $(patsubst %.cpp,%.d,$(STANC_TEMPLATE_INSTANTIATION_CPP))
endif
ifneq ($(filter test/test-models/good/%.hpp test/test-models/good/%.hpp-test,$(MAKECMDGOALS)),)
-include src/test/test-models/stanc.d
-include $(patsubst %.cpp,%.d,$(STANC_TEMPLATE_INSTANTIATION_CPP))
endif
##
# static rule to link in libstanc.
# needed by subset of unit tests that test stan compiler
# all these tests are under stan/test/unit/lang
##
STANC_TESTS_HEADERS := $(shell find src/test/unit/lang -type f -name '*_test.cpp')
STANC_TESTS_O := $(patsubst src/%.cpp,%.o,$(STANC_TESTS_HEADERS))
STANC_TESTS := $(patsubst src/%.cpp,%$(EXE),$(STANC_TESTS_HEADERS))
# add additional dependency to libstanc.a
$(STANC_TESTS_O) : test/libstanc.a
$(STANC_TESTS) : LDLIBS += $(LDLIBS_STANC)
############################################################
##
# Target to verify header files within Stan has
# enough include calls
##
HEADER_TESTS := $(addsuffix -test,$(shell find src/stan -name '*.hpp' -type f))
ifeq ($(OS),Windows_NT)
DEV_NULL = nul
else
DEV_NULL = /dev/null
endif
%.hpp-test : %.hpp test/dummy.cpp
$(COMPILE.cpp) -O0 -include $^ -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
test/test-models/good/%.hpp-test : O = 0
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
##
ifneq ($(OS),Windows_NT)
test/unit/multiple_translation_units%.o : CXXFLAGS += -fPIC
endif
test/unit/multiple_translation_units%.o : CXXFLAGS += -pipe
test/unit/libmultiple.so : LDFLAGS += -shared
test/unit/libmultiple.so : test/unit/multiple_translation_units1.o test/unit/multiple_translation_units2.o $(MPI_TARGETS)
$(LINK.cpp) $^ $(LDLIBS) $(OUTPUT_OPTION)
test/unit/multiple_translation_units_test$(EXE) : test/unit/libmultiple.so
############################################################
##
# Use the stanc compiler to generate C++ from Stan programs
##
test/test-models/stanc$(EXE) : O = $(O_STANC)
test/test-models/stanc$(EXE) : test/libstanc.a
test/test-models/stanc$(EXE) : LDLIBS += $(LDLIBS_STANC)
test/test-models/stanc$(EXE) : %$(EXE) : %.o
@mkdir -p $(dir $@)
$(LINK.cpp) $< $(LDLIBS) $(OUTPUT_OPTION)
TEST_MODELS = $(shell find src/test/test-models -type f -name '*.stan')
$(patsubst src/%.stan,%.hpp,$(TEST_MODELS)) : test/test-models/%.hpp : src/test/test-models/%.stan test/test-models/stanc$(EXE)
@mkdir -p $(dir $@)
$(WINE) test/test-models/stanc$(EXE) $< --o=$@
##
# Generate C++ from Stan standalone functions
##
TEST_FUNCTIONS = $(shell find src/test/test-models -type f -name '*.stanfuncs')
$(patsubst src/%.stanfuncs,%.hpp,$(TEST_FUNCTIONS)) : test/test-models/%.hpp : src/test/test-models/%.stanfuncs test/test-models/stanc$(EXE)
@mkdir -p $(dir $@)
$(WINE) test/test-models/stanc$(EXE) $< --o=$@
##
# src/test/unit/lang/stanc_helper_test.cpp requires files to be read-only.
##
.PHONY: change-file-permissions
change-file-permissions:
ifeq ($(OS),Windows_NT)
attrib +r src\\test\\test-models\\good\\stanc_helper.stan
attrib +r src\\test\\test-models\\bad\\stanc_helper.stan
attrib +r src\\test\\test-models\\bad\\read_only
else
chmod 444 src/test/test-models/*/stanc_helper.stan
chmod 555 src/test/test-models/bad/read_only
endif
test/unit/lang/stanc_helper_test.o: change-file-permissions
##
# Add additional dependencies for tests that should translate Stan to hpp, but
# isn't included in the source using `#include`.
##
test/unit/lang/parser_generator_test$(EXE): $(patsubst src/%.stan,%.hpp,$(shell find src/test/test-models/good/parser-generator -type f -name '*.stan'))
##
# 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,$(shell find src/test/test-models/good -type f -name '*.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,$(shell find src/test/test-models/good-standalone-functions -type f -name '*.stanfuncs'))