test/Makefile
author Krista Bennett <krista@pep-project.org>
Fri, 01 Jun 2018 10:30:19 +0200
branchENGINE-233
changeset 2727 b8b0443804da
parent 2021 c15acce7cee9
child 2062 4a97ad19141e
permissions -rw-r--r--
close branch
     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 .PHONY: all
    61 all: $(TARGET) $(UNIT_TESTS)
    62 
    63 # don't delete .o files!
    64 .PRECIOUS: %.o
    65 
    66 .PHONY: test_home_
    67 test_home_: 
    68 	-gpgconf --kill gpg-agent
    69 	-HOME=$(TEST_HOME) gpgconf --kill gpg-agent
    70 	-killall gpg-agent
    71 	rm -rf $(TEST_HOME)
    72 	mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
    73 	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
    74 
    75 .PHONY: clean
    76 clean:
    77 	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
    78 	rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
    79 
    80 .PHONY: test
    81 test: $(TARGET) test_home_
    82 	$(TEST_CMD_PFX) ./$<
    83 
    84 %_test : %_test.o test_util.o
    85 	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
    86 
    87 %_run : % test_home_
    88 	$(TEST_CMD_PFX) ./$<
    89 
    90 %_lldb : % test_home_
    91 	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
    92 
    93 %_valgrind : % test_home_
    94 	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
    95 
    96 %_gdb : % test_home_
    97 	$(TEST_CMD_PFX) gdb ./$<
    98 
    99 .PHONY: unit_tests
   100 unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
   101 
   102 .PHONY: compile
   103 compile: $(UNIT_TESTS) $(TARGET)
   104 
   105 # Installs the engine, not the test binaries
   106 .PHONY: install
   107 install:
   108 	$(MAKE) -C .. install