test/Makefile
author Krista Bennett <krista@pep-project.org>
Tue, 06 Feb 2018 18:48:45 +0100
branchENGINE-250
changeset 2478 0460dfb7f3dc
parent 2477 45e8ed722fec
child 2495 ce2a95430d2d
permissions -rw-r--r--
ENGINE-250: fixed some things, am screaming at others. Have overcome the 'insert or update' issue at least, probably.
     1 # Copyright 2017, pEp Foundation
     2 # This file is part of pEpEngine
     3 # This file may be used under the terms of the GNU General Public License version 3
     4 # see LICENSE.txt
     5 
     6 HERE:=$(CURDIR)
     7 
     8 include ../default.conf
     9 
    10 TARGET=pEpEngineTest
    11 
    12 unexport GNUPGHOME
    13 TEST_HOME=$(HERE)test_home
    14 TEST_GNUPGHOME=$(TEST_HOME)/gnupg
    15 
    16 LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -L../src
    17 LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
    18 
    19 ifeq ($(BUILD_FOR),Linux)
    20     LDLIBS+= -luuid
    21 endif
    22 
    23 ifeq ($(OPENPGP),NETPGP)
    24     LDLIBS+= -lnetpgp
    25 endif
    26 
    27 ifdef SQLITE3_FROM_OS
    28     LDLIBS+= -lsqlite3
    29 endif
    30 
    31 ifeq ($(shell uname),Darwin)
    32     LIBPATH=DYLD_LIBRARY_PATH
    33     LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
    34 else
    35     LIBPATH=LD_LIBRARY_PATH
    36     LLDB_BIN=lldb
    37 endif
    38 
    39 # 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.
    40 # Note that += can not be used here, as it changes the amount of whitespace
    41 EXTRA_LIB_PATHS=../src:
    42 ifdef ETPAN_LIB
    43     EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
    44 endif
    45 ifdef GPGME_LIB
    46     EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
    47 endif
    48 ifdef NETPGP_LIB
    49     EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
    50 endif
    51 # Remove trailing ':'
    52 EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
    53 
    54 TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) HOME=$(TEST_HOME) GNUPGHOME=$(TEST_GNUPGHOME)
    55 
    56 UNIT_TESTS_SOURCE=$(wildcard *_test.cc)
    57 UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE))
    58 UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE))
    59 
    60 CFLAGS:=$(filter-out -DNDEBUG,$(CFLAGS))
    61 ifneq ($(MAKECMDGOALS),clean)
    62     ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
    63         $(error The macro NDEBUG must not be defined for test compilation.)
    64     endif
    65 endif
    66 
    67 CXXFLAGS:=$(filter-out -DNDEBUG,$(CXXFLAGS))
    68 ifneq ($(MAKECMDGOALS),clean)
    69     ifneq (,$(findstring -DNDEBUG,$(CXXFLAGS)))
    70         $(error The macro NDEBUG must not be defined for test compilation.)
    71     endif
    72 endif
    73 
    74 .PHONY: all
    75 all: $(TARGET) $(UNIT_TESTS)
    76 
    77 # don't delete .o files!
    78 .PRECIOUS: %.o
    79 
    80 .PHONY: test_home_
    81 test_home_: 
    82 	-GNUPGHOME=$(TEST_GNUPGHOME) gpgconf --kill gpg-agent
    83 	rm -rf $(TEST_HOME)
    84 	mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
    85 	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
    86 
    87 .PHONY: clean
    88 clean:
    89 	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc msg_encrypt_for_self.asc
    90 	rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
    91 
    92 .PHONY: test
    93 test: $(TARGET) test_home_
    94 	$(TEST_CMD_PFX) ./$<
    95 
    96 %_test : %_test.o test_util.o
    97 	$(CXX) $^ $(LDFLAGS) $(LDLIBS) -o $@
    98 
    99 %_run : % test_home_
   100 	$(TEST_CMD_PFX) ./$<
   101 
   102 %_lldb : % test_home_
   103 	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
   104 
   105 %_valgrind : % test_home_
   106 	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
   107 
   108 %_gdb : % test_home_
   109 	$(TEST_CMD_PFX) gdb ./$<
   110 
   111 .PHONY: unit_tests
   112 unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
   113 
   114 .PHONY: compile
   115 compile: $(UNIT_TESTS) $(TARGET)
   116 
   117 # Installs the engine, not the test binaries
   118 .PHONY: install
   119 install:
   120 	$(MAKE) -C .. install