test/Makefile
branchlocal_cpptest
changeset 2637 30db80f1a874
parent 2495 ce2a95430d2d
child 2638 d52e41da942e
     1.1 --- a/test/Makefile	Mon Apr 30 09:23:34 2018 +0200
     1.2 +++ b/test/Makefile	Mon Apr 30 15:22:22 2018 +0200
     1.3 @@ -1,120 +1,185 @@
     1.4 +
     1.5  # Copyright 2017, pEp Foundation
     1.6  # This file is part of pEpEngine
     1.7  # This file may be used under the terms of the GNU General Public License version 3
     1.8  # see LICENSE.txt
     1.9  
    1.10 -HERE:=$(CURDIR)
    1.11 -
    1.12  include ../default.conf
    1.13  
    1.14 -TARGET=pEpEngineTest
    1.15 +HERE:=$(CURDIR)
    1.16 +TEST_HOME=$(HERE)pEp_test_home
    1.17  
    1.18 -unexport GNUPGHOME
    1.19 -TEST_HOME=$(HERE)test_home
    1.20 -TEST_GNUPGHOME=$(TEST_HOME)/gnupg
    1.21 +SRC_DIRS := ./src ./src/util ./src/engine_tests
    1.22 +SRCS := src/EngineTestSuite.cc src/EngineTestIndividualSuite.cc src/EngineTestSessionSuite.cc $(wildcard src/*/*.cc) src/SuiteMaker.cc src/TestDriver.cc
    1.23 +OBJS := $(addsuffix .o,$(basename $(SRCS)))
    1.24 +DEPS := $(OBJS:.o=.d)
    1.25 +
    1.26 +INC_DIRS := ./include /usr/local/include #$(shell find $(SRC_DIRS) -type d) 
    1.27 +INC_FLAGS := $(addprefix -I,$(INC_DIRS))
    1.28 +
    1.29 +LDFLAGS += -L/usr/local/lib
    1.30 +
    1.31 +CFLAGS += -Wno-deprecated
    1.32 +CXXFLAGS += -Wno-deprecated
    1.33  
    1.34  LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -L../src
    1.35  LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
    1.36  
    1.37  ifeq ($(BUILD_FOR),Linux)
    1.38 -    LDLIBS+= -luuid
    1.39 +	LDLIBS+= -luuid
    1.40  endif
    1.41  
    1.42  ifeq ($(OPENPGP),NETPGP)
    1.43 -    LDLIBS+= -lnetpgp
    1.44 +	LDLIBS+= -lnetpgp
    1.45  endif
    1.46  
    1.47  ifdef SQLITE3_FROM_OS
    1.48 -    LDLIBS+= -lsqlite3
    1.49 +	LDLIBS+= -lsqlite3
    1.50  endif
    1.51  
    1.52  ifeq ($(shell uname),Darwin)
    1.53 -    LIBPATH=DYLD_LIBRARY_PATH
    1.54 -    LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
    1.55 +	LIBPATH=DYLD_LIBRARY_PATH
    1.56 +	LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
    1.57  else
    1.58 -    LIBPATH=LD_LIBRARY_PATH
    1.59 -    LLDB_BIN=lldb
    1.60 +	LIBPATH=LD_LIBRARY_PATH
    1.61 +	LLDB_BIN=lldb
    1.62  endif
    1.63  
    1.64 +LDLIBS += -lcpptest
    1.65 +
    1.66 +
    1.67  # Create a list of the extra library paths for the loader. I do not assume that the engine (and its dependencies) are installed for testing.
    1.68  # Note that += can not be used here, as it changes the amount of whitespace
    1.69  EXTRA_LIB_PATHS=../src:
    1.70  ifdef ETPAN_LIB
    1.71 -    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
    1.72 +	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
    1.73  endif
    1.74  ifdef GPGME_LIB
    1.75 -    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
    1.76 +	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
    1.77  endif
    1.78  ifdef NETPGP_LIB
    1.79 -    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
    1.80 +	EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
    1.81  endif
    1.82 +
    1.83  # Remove trailing ':'
    1.84  EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
    1.85  
    1.86 -TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) HOME=$(TEST_HOME) GNUPGHOME=$(TEST_GNUPGHOME)
    1.87 -
    1.88 -UNIT_TESTS_SOURCE=$(wildcard *_test.cc) 
    1.89 -UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE))
    1.90 -UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE))
    1.91 -
    1.92  CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS))
    1.93  ifneq ($(MAKECMDGOALS),clean)
    1.94 -    ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
    1.95 -        $(error The macro NDEBUG must not be defined for test compilation.)
    1.96 -    endif
    1.97 +	ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
    1.98 +		$(error The macro NDEBUG must not be defined for test compilation.)
    1.99 +	endif
   1.100  endif
   1.101  
   1.102  CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
   1.103  ifneq ($(MAKECMDGOALS),clean)
   1.104 -    ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
   1.105 -        $(error The macro NDEBUG must not be defined for test compilation.)
   1.106 -    endif
   1.107 +	ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
   1.108 +		$(error The macro NDEBUG must not be defined for test compilation.)
   1.109 +	endif
   1.110  endif
   1.111  
   1.112 -.PHONY: all
   1.113 -all: $(TARGET) $(UNIT_TESTS)
   1.114  
   1.115 -# don't delete .o files!
   1.116 -.PRECIOUS: %.o
   1.117 +CPPFLAGS += $(INC_FLAGS) -MMD -MP
   1.118  
   1.119 -.PHONY: test_home_
   1.120 -test_home_: 
   1.121 -	-GNUPGHOME=$(TEST_GNUPGHOME) gpgconf --kill gpg-agent
   1.122 -	rm -rf $(TEST_HOME)
   1.123 -	mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
   1.124 -	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
   1.125 +$(TARGET): $(OBJS)
   1.126 +	$(CXX) $(CPPFLAGS) $(LDFLAGS) $(OBJS) -o $@ $(LOADLIBES) $(LDLIBS)
   1.127  
   1.128  .PHONY: clean
   1.129  clean:
   1.130 -	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc msg_encrypt_for_self.asc
   1.131 -	rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
   1.132 +	$(RM) $(TARGET) $(OBJS) $(DEPS)
   1.133  
   1.134 -.PHONY: test
   1.135 -test: $(TARGET) test_home_
   1.136 -	$(TEST_CMD_PFX) ./$<
   1.137 +-include $(DEPS)
   1.138  
   1.139 -%_test : %_test.o test_util.o
   1.140 -	$(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@
   1.141  
   1.142 -%_run : % test_home_
   1.143 -	$(TEST_CMD_PFX) ./$<
   1.144 -
   1.145 -%_lldb : % test_home_
   1.146 -	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
   1.147 -
   1.148 -%_valgrind : % test_home_
   1.149 -	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
   1.150 -
   1.151 -%_gdb : % test_home_
   1.152 -	$(TEST_CMD_PFX) gdb ./$<
   1.153 -
   1.154 -.PHONY: unit_tests
   1.155 -unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
   1.156 -
   1.157 -.PHONY: compile
   1.158 -compile: $(UNIT_TESTS) $(TARGET)
   1.159 -
   1.160 -# Installs the engine, not the test binaries
   1.161 -.PHONY: install
   1.162 -install:
   1.163 -	$(MAKE) -C .. install
   1.164 +# 
   1.165 +# TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) #HOME=$(TEST_HOME) GNUPGHOME=$(TEST_GNUPGHOME)
   1.166 +# 
   1.167 +# 
   1.168 +# CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS))
   1.169 +# ifneq ($(MAKECMDGOALS),clean)
   1.170 +# 	ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
   1.171 +# 		$(error The macro NDEBUG must not be defined for test compilation.)
   1.172 +# 	endif
   1.173 +# endif
   1.174 +# 
   1.175 +# CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
   1.176 +# ifneq ($(MAKECMDGOALS),clean)
   1.177 +# 	ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
   1.178 +# 		$(error The macro NDEBUG must not be defined for test compilation.)
   1.179 +# 	endif
   1.180 +# endif
   1.181 +# 
   1.182 +# # .PHONY: all
   1.183 +# # all: main
   1.184 +# 
   1.185 +# # don't delete .o files!
   1.186 +# .PRECIOUS: %.o
   1.187 +# 
   1.188 +# 
   1.189 +# SRC_DIRS ?= ./src
   1.190 +# 
   1.191 +# SRCS := $(wildcard src/*.cc) $(wildcard src/*/*.cc)
   1.192 +# OBJS := $(addsuffix .o,$(basename $(SRCS)))
   1.193 +# DEPS := $(OBJS:.o=.d)
   1.194 +# 
   1.195 +# CPPFLAGS += -I./include -MMD -MP
   1.196 +# 
   1.197 +# #	$(CC) $(LDFLAGS) $(OBJS) -o $@ $(LOADLIBES) $(LDLIBS)
   1.198 +# $(TARGET): $(OBJS)
   1.199 +# 	$(CXX) $(CXXFLAGS) $^ $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@
   1.200 +# 
   1.201 +# 
   1.202 +# .PHONY: test_home_
   1.203 +# test_home_: 
   1.204 +# 	mkdir -p $(TEST_HOME)
   1.205 +# 
   1.206 +# # .PHONY: clean
   1.207 +# # clean:
   1.208 +# # 	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) msg4.asc msg_encrypt_for_self.asc
   1.209 +# 
   1.210 +# 
   1.211 +# .PHONY: clean
   1.212 +# clean:
   1.213 +# 	$(RM) $(TARGET) $(OBJS) $(DEPS)
   1.214 +# 
   1.215 +# -include $(DEPS)
   1.216 +# 
   1.217 +# # .PHONY: main
   1.218 +# # main: TestDriver
   1.219 +# # 	
   1.220 +# # TestDriver : src/TestDriver
   1.221 +# # 	$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LDLIBS) $(TESTOBJ) $(SUITEOBJ) -o TestDriver
   1.222 +# # 
   1.223 +# # .PHONY: testfiles
   1.224 +# # testfiles : $(TESTOBJ)
   1.225 +# # 	$(CXX) -c $(CXXFLAGS) $^ $(LDFLAGS) $(LDLIBS)
   1.226 +# # 
   1.227 +# # .PHONY: suitefiles	
   1.228 +# # suitefiles : $(SUITEOBJ)
   1.229 +# # 	$(CXX) -c $(CXXFLAGS) $^ $(LDFLAGS) $(LDLIBS)
   1.230 +# #  
   1.231 +# # # %_test : %_test.o test_util.o
   1.232 +# # # 	$(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@
   1.233 +# # # 
   1.234 +# # # %_run : % test_home_
   1.235 +# # # 	$(TEST_CMD_PFX) ./$<
   1.236 +# # # 
   1.237 +# # # %_lldb : % test_home_
   1.238 +# # # 	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
   1.239 +# # # 
   1.240 +# # # %_valgrind : % test_home_
   1.241 +# # # 	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
   1.242 +# # # 
   1.243 +# # # %_gdb : % test_home_
   1.244 +# # # 	$(TEST_CMD_PFX) gdb ./$<
   1.245 +# # 
   1.246 +# # # .PHONY: unit_tests
   1.247 +# # # unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
   1.248 +# # 
   1.249 +# # # .PHONY: compile
   1.250 +# # # compile: $(UNIT_TESTS) $(TARGET)
   1.251 +# # 
   1.252 +# # # Installs the engine, not the test binaries
   1.253 +# # .PHONY: install
   1.254 +# # install:
   1.255 +# # 	$(MAKE) -C .. install