test/Makefile
author Damiano Boppart <damiano@pep-security.net>
Tue, 19 Sep 2017 14:50:07 +0200
branchENGINE-259
changeset 2074 817d6f5e8f48
parent 2073 b4126ce1af67
child 2075 92b8a67735e0
permissions -rw-r--r--
Fix recursive variable assignment
     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 ../Makefile.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)
    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 
    62 ifneq ($(MAKECMDGOALS),clean)
    63     ifneq (,$(findstring -DNDEBUG,$(CFLAGS)))
    64         $(error The macro NDEBUG must not be defined for test compilation.)
    65     endif
    66 endif
    67 
    68 .PHONY: all
    69 all: $(TARGET) $(UNIT_TESTS)
    70 
    71 # don't delete .o files!
    72 .PRECIOUS: %.o
    73 
    74 .PHONY: test_home_
    75 test_home_: 
    76 	-gpgconf --kill gpg-agent
    77 	-HOME=$(TEST_HOME) gpgconf --kill gpg-agent
    78 	-killall gpg-agent
    79 	rm -rf $(TEST_HOME)
    80 	mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
    81 	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
    82 
    83 .PHONY: clean
    84 clean:
    85 	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
    86 	rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
    87 
    88 .PHONY: test
    89 test: $(TARGET) test_home_
    90 	$(TEST_CMD_PFX) ./$<
    91 
    92 %_test : %_test.o test_util.o
    93 	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
    94 
    95 %_run : % test_home_
    96 	$(TEST_CMD_PFX) ./$<
    97 
    98 %_lldb : % test_home_
    99 	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
   100 
   101 %_valgrind : % test_home_
   102 	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
   103 
   104 %_gdb : % test_home_
   105 	$(TEST_CMD_PFX) gdb ./$<
   106 
   107 .PHONY: unit_tests
   108 unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
   109 
   110 .PHONY: compile
   111 compile: $(UNIT_TESTS) $(TARGET)
   112 
   113 # Installs the engine, not the test binaries
   114 .PHONY: install
   115 install:
   116 	$(MAKE) -C .. install