diff --git a/.travis.yml b/.travis.yml index 421d13a26..c311cddc2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,10 @@ language: c compiler: - clang - gcc + script: - make bin - - make test test_run - - make cleaner + - make cov cov_run + +after_success: + - bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports" diff --git a/makefile b/makefile index f53f9ea92..3b58c6395 100644 --- a/makefile +++ b/makefile @@ -1,8 +1,4 @@ #----------------------------------------------------------------------------------- -# 05/24/2012 (DLM) -# 07/14/2017 (drs) -# for use in terminal while in the project source directory to make compiling easier -#----------------------------------------------------------------------------------- # commands explanations #----------------------------------------------------------------------------------- # make all creates a shared object for use in rSOILWAT2 ('all' target is required @@ -14,8 +10,12 @@ # make lib create SOILWAT2 library # make test compile unit tests in 'test/ folder with googletest # make test_run run unit tests (in a previous step compiled with 'make test') -# make test_clean delete test files and libraries +# make cov same as 'make test' but with code coverage support +# make cov_run run unit tests and gcov on each source file (in a previous step +# compiled with 'make cov') # make clean delete all of the o files +# make test_clean delete test files and libraries +# make cov_clean delete files associated with code coverage # make cleaner delete all of the o files, the shared object file(s), test files and # libraries, and the binary exe #----------------------------------------------------------------------------------- @@ -26,6 +26,7 @@ uname_m = $(shell uname -m) # CXX = g++ CFLAGS = -O3 -Wall -Wextra -pedantic -std=c11 CXXFLAGS = -Wall -Wextra -std=gnu++11 # gnu++11 required for googletest on Windows/cygwin +CovFlags = -coverage -g -O0 LDFLAGS = -L. LDLIBS = -l$(target) -lm # order of libraries is important for GNU gcc (libSOILWAT2 depends on libm) @@ -57,6 +58,7 @@ target = SOILWAT2 bin_test = sw_test lib_target = lib$(target).a lib_target++ = lib$(target)++.a +lib_covtarget++ = libcov$(target)++.a SHLIB = r$(target)$(SHLIB_EXT) gtest = gtest @@ -66,6 +68,7 @@ GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS) GTEST_HEADERS = $(GTEST_DIR)/include/gtest/*.h \ $(GTEST_DIR)/include/gtest/internal/*.h gtest_LDLIBS = -l$(gtest) -l$(target)++ -lm +cov_LDLIBS = -l$(gtest) -lcov$(target)++ -lm all: $(SHLIB) @@ -86,6 +89,10 @@ $(lib_target++) : ar -rcsu $(lib_target++) $(objects_tests) @rm -f $(objects_tests) +$(lib_covtarget++) : + $(CXX) $(CXXFLAGS) $(CovFlags) -c $(sources_tests) + ar -rcsu $(lib_covtarget++) $(objects_tests) + @rm -f $(objects_tests) bin : $(target) @@ -116,9 +123,19 @@ test : $(lib_gtest) $(lib_target++) $(CXX) $(CXXFLAGS) $(LDFLAGS) -isystem ${GTEST_DIR}/include -pthread \ test/*.cc -o $(bin_test) $(gtest_LDLIBS) +.PHONY : test_run test_run : test ./$(bin_test) +cov : cov_clean $(lib_gtest) $(lib_covtarget++) + $(CXX) $(CXXFLAGS) $(CovFlags) $(LDFLAGS) -isystem ${GTEST_DIR}/include \ + -pthread test/*.cc -o $(bin_test) $(cov_LDLIBS) + +.PHONY : cov_run +cov_run : cov + ./$(bin_test) + ./run_gcov.sh + .PHONY : clean clean : @@ -134,5 +151,10 @@ clean2 : test_clean : @rm -f gtest-all.o $(lib_gtest) $(bin_test) +.PHONY : cov_clean +cov_clean : + @rm -f $(lib_covtarget++) *.gcda *.gcno *.gcov + @rm -fr *.dSYM + .PHONY : cleaner -cleaner : clean clean2 test_clean +cleaner : clean clean2 test_clean cov_clean diff --git a/run_gcov.sh b/run_gcov.sh new file mode 100755 index 000000000..fcaac86c9 --- /dev/null +++ b/run_gcov.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +sources_tests='SW_Main_lib.c SW_VegEstab.c SW_Control.c generic.c + rands.c Times.c mymemory.c filefuncs.c + SW_Files.c SW_Model.c SW_Site.c SW_SoilWater.c + SW_Markov.c SW_Weather.c SW_Sky.c SW_Output_mock.c + SW_VegProd.c SW_Flow_lib.c SW_Flow.c SW_Carbon.c' + +for sf in $sources_tests +do + gcov $sf +done