Revision d64b28331ca2c1db7b12b904a73cd4358181aaba authored by Bob Carpenter on 24 June 2018, 21:55:20 UTC, committed by Bob Carpenter on 24 June 2018, 21:55:20 UTC
1 parent 50c8586
tests
##
# LIBGTEST is the google test library
# GTEST_MAIN is the file that contains the google test
##
LIBGTEST = test/libgtest.a
GTEST_MAIN = $(GTEST)/src/gtest_main.cc
GTEST_CXXFLAGS += -isystem $(GTEST)/include -isystem $(GTEST)
##
# Build the google test library.
$(LIBGTEST): $(LIBGTEST)(test/gtest.o)
test/gtest.o: $(GTEST)/src/gtest-all.cc
@mkdir -p test
$(COMPILE.cc) -O$O $(GTEST_CXXFLAGS) $< $(OUTPUT_OPTION)
##
# Rule for building a test
##
test/%.o : src/test/%_test.cpp
@mkdir -p $(dir $@)
$(COMPILE.cc) -O$O $(GTEST_CXXFLAGS) $< $(OUTPUT_OPTION)
##
# Rule for building a test executable
##
test/%$(EXE) : test/%.o $(LIBGTEST) $(LIBSUNDIALS)
@mkdir -p $(dir $@)
$(LINK.cc) -O$O $(GTEST_MAIN) $< $(GTEST_CXXFLAGS) $(OUTPUT_OPTION) $(LIBGTEST) $(LDLIBS) $(LIBSUNDIALS)
##
# 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/%_test.cpp,%.o,$(STANC_TESTS_HEADERS))
STANC_TESTS := $(patsubst src/%_test.cpp,%$(EXE),$(STANC_TESTS_HEADERS))
# add additional dependency to libstanc.a
##$(patsubst src/%_test.cpp,%.o,$(STANC_TEST_HEADERS)) : test/%.o : bin/libstanc.a
$(STANC_TESTS_O) : bin/libstanc.a
$(STANC_TESTS) : LDLIBS += $(LDLIBS_STANC)
##
# Rule for generating dependencies.
##
.PRECIOUS: test/%.d
test/%.d : src/test/%_test.cpp
@mkdir -p $(dir $@)
@set -e; \
rm -f $@; \
$(COMPILE.cc) -O$O $(GTEST_CXXFLAGS) $(TARGET_ARCH) -MM $< > $@.$$$$; \
sed -e 's,\($(notdir $*)\)\(_test\)\.o[ :]*,$(dir $@)\1\$(EXE) $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
.PRECIOUS: test/test-models/stanc.d
test/test-models/stanc.d : src/test/test-models/stanc.cpp
@mkdir -p $(dir $@)
@set -e; \
rm -f $@; \
$(COMPILE.cc) -O$O $(GTEST_CXXFLAGS) $(TARGET_ARCH) -MM $< > $@.$$$$; \
sed -e 's,\($(basename $(@F))\)\.o[ :]*,$(dir $@)\1\$(EXE) $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
############################################################
##
# 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_TYPE),win)
DEV_NULL = nul
else
DEV_NULL = /dev/null
endif
##
# 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
src/test/test-models/good/%.hpp-test : src/test/test-models/good/%.hpp test/test-model-main.cpp
$(COMPILE.cc) -O0 -include $< -o $(DEV_NULL) test/test-model-main.cpp
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 >> $@
.PHONY: HEADER_TESTS
%.hpp-test : %.hpp test/dummy.cpp
$(COMPILE.cc) -O0 -include $< -o $(DEV_NULL) test/dummy.cpp
test/dummy.cpp:
@mkdir -p test
@touch $@
@echo "int main() {return 0;}" >> $@
.PHONY: test-headers
test-headers: $(HEADER_TESTS)
##
# Adding a test for multiple translation units. If this fails,
# a new function is probably missing an inline
##
test/unit/multiple_translation_units%.o : src/test/unit/multiple_translation_units%.cpp
@mkdir -p $(dir $@)
$(COMPILE.cc) -O$O $< $(OUTPUT_OPTION)
test/unit/libmultiple.so : test/unit/multiple_translation_units1.o test/unit/multiple_translation_units2.o
@mkdir -p $(dir $@)
$(COMPILE.cc) -shared $(OUTPUT_OPTION) $^
src/test/unit/multiple_translation_units_test.cpp : test/unit/libmultiple.so
############################################################
##
# Use the stanc compiler to generate C++ from Stan programs
##
.PRECIOUS: test/test-models/stanc$(EXE)
test/test-models/stanc$(EXE) : src/test/test-models/stanc.cpp bin/libstanc.a
@mkdir -p $(dir $@)
$(LINK.cc) -O$(O_STANC) $(OUTPUT_OPTION) $< $(LDLIBS_STANC)
TEST_MODELS := $(shell find src/test/test-models -type f -name '*.stan')
$(patsubst %.stan,%.hpp,$(TEST_MODELS)) : %.hpp : %.stan test/test-models/stanc$(EXE)
$(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 %.stanfuncs,%.hpp,$(TEST_FUNCTIONS)) : %.hpp : %.stanfuncs test/test-models/stanc$(EXE)
$(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_TYPE),win)
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
src/test/unit/lang/stanc_helper_test.cpp: change-file-permissions
##
# Explicitly specify dependencies for tests that depend on the generated C++ of Stan programs.
##
src/test/performance/logistic_test.cpp: src/test/test-models/performance/logistic.hpp
src/test/unit/lang/generator_test.cpp: src/test/test-models/good/lang/test_lp.hpp
src/test/unit/lang/parser_generator_test.cpp: $(patsubst %.stan,%.hpp,$(shell find src/test/test-models/good/parser-generator -type f -name '*.stan'))
src/test/unit/io/random_var_context_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/lang/parser/functions_standalone_instantiate_test.cpp: src/test/test-models/good-standalone-functions/basic.hpp src/test/test-models/good-standalone-functions/special_functions.hpp src/test/test-models/good-standalone-functions/integrate.hpp
src/test/unit/lang/reject/reject_func_call_generated_quantities_test.cpp: src/test/test-models/good/lang/reject_func_call_generated_quantities.hpp
src/test/unit/lang/reject/reject_func_call_model_test.cpp: src/test/test-models/good/lang/reject_func_call_model.hpp
src/test/unit/lang/reject/reject_func_call_transformed_data_test.cpp: src/test/test-models/good/lang/reject_func_call_transformed_data.hpp
src/test/unit/lang/reject/reject_func_call_transformed_parameters_test.cpp: src/test/test-models/good/lang/reject_func_call_transformed_parameters.hpp
src/test/unit/lang/reject/reject_generated_quantities_test.cpp: src/test/test-models/good/lang/reject_generated_quantities.hpp
src/test/unit/lang/reject/reject_model_test.cpp: src/test/test-models/good/lang/reject_model.hpp
src/test/unit/lang/reject/reject_mult_args_test.cpp: src/test/test-models/good/lang/reject_mult_args.hpp
src/test/unit/lang/reject/reject_transformed_data_test.cpp: src/test/test-models/good/lang/reject_transformed_data.hpp
src/test/unit/lang/reject/reject_transformed_parameters_test.cpp: src/test/test-models/good/lang/reject_transformed_parameters.hpp
src/test/unit/lang/reject/print_reject_function_gq_test.cpp: src/test/test-models/good/lang/print_reject_function_gq.hpp
src/test/unit/lang/reject/print_reject_function_model_test.cpp: src/test/test-models/good/lang/print_reject_function_model.hpp
src/test/unit/lang/reject/print_reject_function_tparams_test.cpp: src/test/test-models/good/lang/print_reject_function_tparams.hpp
src/test/unit/lang/reject/print_reject_function_tdata_test.cpp: src/test/test-models/good/lang/print_reject_function_tdata.hpp
src/test/unit/lang/reject/print_reject_gq_test.cpp: src/test/test-models/good/lang/print_reject_gq_block.hpp
src/test/unit/lang/reject/print_reject_model_test.cpp: src/test/test-models/good/lang/print_reject_model_block.hpp
src/test/unit/lang/reject/print_reject_tparams_test.cpp: src/test/test-models/good/lang/print_reject_tparams_block.hpp
src/test/unit/lang/reject/print_reject_tdata_test.cpp: src/test/test-models/good/lang/print_reject_tdata_block.hpp
src/test/unit/mcmc/hmc/hamiltonians/base_hamiltonian_test.cpp: src/test/test-models/good/mcmc/hmc/hamiltonians/funnel.hpp
src/test/unit/mcmc/hmc/hamiltonians/dense_e_metric_test.cpp: src/test/test-models/good/mcmc/hmc/hamiltonians/funnel.hpp
src/test/unit/mcmc/hmc/hamiltonians/diag_e_metric_test.cpp: src/test/test-models/good/mcmc/hmc/hamiltonians/funnel.hpp
src/test/unit/mcmc/hmc/hamiltonians/unit_e_metric_test.cpp: src/test/test-models/good/mcmc/hmc/hamiltonians/funnel.hpp
src/test/unit/mcmc/hmc/hamiltonians/softabs_metric_test.cpp: src/test/test-models/good/mcmc/hmc/hamiltonians/funnel.hpp
src/test/unit/mcmc/hmc/integrators/expl_leapfrog_test.cpp: src/test/test-models/good/mcmc/hmc/integrators/command.hpp
src/test/unit/mcmc/hmc/integrators/expl_leapfrog2_test.cpp: src/test/test-models/good/mcmc/hmc/integrators/gauss.hpp
src/test/unit/mcmc/hmc/integrators/impl_leapfrog_test.cpp: src/test/test-models/good/mcmc/hmc/integrators/command.hpp
src/test/unit/mcmc/hmc/integrators/impl_leapfrog2_test.cpp: src/test/test-models/good/mcmc/hmc/integrators/gauss.hpp
src/test/unit/mcmc/hmc/nuts/unit_e_nuts_test.cpp: src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/mcmc/hmc/nuts/softabs_nuts_test.cpp: src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/mcmc/hmc/nuts/instantiation_test.cpp: src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/mcmc/hmc/nuts_classic/instantiation_test.cpp: src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/mcmc/hmc/xhmc/unit_e_xhmc_test.cpp: src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/mcmc/hmc/xhmc/softabs_xhmc_test.cpp: src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/mcmc/hmc/static_uniform/derived_static_uniform_test.cpp: src/test/test-models/good/mcmc/hmc/common/gauss.hpp
src/test/unit/model/finite_diff_grad_test.cpp src/test/unit/model/grad_hess_log_prob_test.cpp src/test/unit/model/grad_tr_mat_times_hessian_test.cpp src/test/unit/model/gradient_dot_vector_test.cpp src/test/unit/model/gradient_test.cpp src/test/unit/model/hessian_test.cpp src/test/unit/model/hessian_times_vector_test.cpp src/test/unit/model/log_prob_grad_test.cpp src/test/unit/model/log_prob_propto_test.cpp src/test/unit/model/model_functional_test.cpp src/test/unit/model/test_gradients_test.cpp : src/test/test-models/good/model/valid.hpp
src/test/unit/optimization/bfgs_linesearch_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/optimization/bfgs_minimizer_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/optimization/bfgs_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/optimization/bfgs_update_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/optimization/lbfgs_update_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/old_services/init/command_init_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/io/write_iteration_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/mcmc/sample_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/mcmc/warmup_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/optimize/do_bfgs_optimize_test.cpp: src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/diagnose/diagnose_test.cpp : src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/optimize/bfgs_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/optimize/lbfgs_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/optimize/newton_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/experimental/advi/fullrank_test.cpp src/test/unit/services/experimental/advi/meanfield_test.cpp : src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/sample/fixed_param_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_dense_e_adapt_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_dense_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_diag_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_diag_e_adapt_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_unit_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_unit_e_adapt_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_dense_e_adapt_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_dense_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_diag_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_diag_e_adapt_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_unit_e_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_static_unit_e_adapt_test.cpp : src/test/test-models/good/optimization/rosenbrock.hpp
src/test/unit/services/sample/hmc_nuts_dense_inv_metric_test.cpp : src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/services/sample/hmc_nuts_diag_inv_metric_test.cpp : src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/services/sample/hmc_static_dense_inv_metric_test.cpp : src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/services/sample/hmc_static_diag_inv_metric_test.cpp : src/test/test-models/good/mcmc/hmc/common/gauss3D.hpp
src/test/unit/services/sample/standalone_gqs_test.cpp : src/test/test-models/good/services/test_gq.hpp
src/test/unit/services/sample/standalone_gqs_bad_test.cpp : src/test/test-models/good/services/test_gq2.hpp
src/test/unit/services/sample/standalone_gqs_big_test.cpp : src/test/test-models/good/services/bym2_offset_only.hpp
src/test/unit/services/util/generate_transitions_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/util/gq_writer_test.cpp : src/test/test-models/good/services/test_gq.hpp
src/test/unit/services/util/initialize_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/util/run_adaptive_sampler_test.cpp src/test/unit/services/util/run_sampler_test.cpp: src/test/test-models/good/services/test_lp.hpp
src/test/unit/services/util/mcmc_writer_test.cpp : src/test/test-models/good/services/test_lp.hpp
src/test/unit/old_services/sample/mcmc_writer_test.cpp: src/test/test-models/good/io_example.hpp
src/test/unit/variational/advi_univar_no_constraint_test.cpp: src/test/test-models/good/variational/univariate_no_constraint.hpp
src/test/unit/variational/advi_univar_with_constraint_test.cpp: src/test/test-models/good/variational/univariate_with_constraint.hpp
src/test/unit/variational/advi_multivar_no_constraint_test.cpp: src/test/test-models/good/variational/multivariate_no_constraint.hpp
src/test/unit/variational/advi_multivar_with_constraint_test.cpp: src/test/test-models/good/variational/multivariate_with_constraint.hpp
src/test/unit/variational/gradient_warn_test.cpp: src/test/test-models/good/variational/gradient_warn.hpp
src/test/unit/variational/hier_logistic_test.cpp: src/test/test-models/good/variational/hier_logistic.hpp
src/test/unit/variational/hier_logistic_cp_test.cpp: src/test/test-models/good/variational/hier_logistic_cp.hpp
src/test/unit/variational/advi_messages_test.cpp:src/test/test-models/good/variational/univariate_no_constraint.hpp
src/test/unit/variational/eta_adapt_fail_test.cpp:src/test/test-models/good/variational/eta_should_fail.hpp
src/test/unit/variational/eta_adapt_big_test.cpp:src/test/test-models/good/variational/eta_should_be_big.hpp
src/test/unit/variational/eta_adapt_small_test.cpp:src/test/test-models/good/variational/eta_should_be_small.hpp
##
# 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$(EXE) : $(patsubst %.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$(EXE) : $(patsubst %.stanfuncs,%.hpp-test,$(shell find src/test/test-models/good-standalone-functions -type f -name '*.stanfuncs'))
test_name = $(shell echo $(1) | sed 's,_[0-9]\{5\},_test.hpp,g')
ifneq (,$(filter test/% src/test/test-models/%.hpp,$(MAKECMDGOALS)))
-include test/test-models/stanc.d
endif
ifneq (,$(filter $(STANC_TESTS),$(MAKECMDGOALS)))
-include $(patsubst src/%.cpp,bin/%.d,$(TEMPLATE_INSTANTIATION_CPP))
endif
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...