test/Makefile
author Edouard Tisserant <edouard@pep-project.org>
Fri, 07 Jul 2017 16:17:10 +0200
changeset 1911 db8b70e61f55
parent 1910 8a1cf9cf1b87
child 1913 57585bd12bd1
permissions -rw-r--r--
tests: less gpg-agent killings when using netpgp
     1 
     2 # This file is under GNU General Public License 3.0
     3 # see LICENSE.txt
     4 
     5 HERE := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
     6 
     7 include ../Makefile.conf
     8 
     9 CC?=g++ -std=gnu++11 -pthread
    10 CXX?=g++ -std=gnu++11 -pthread
    11 LD?=$(CXX)
    12 LDFLAGS?=-L$(HOME)/lib
    13 LDLIBS?=-letpan -lpEpEngine -lstdc++ -L../asn.1 -lasn1
    14 ifeq ($(BUILD_FOR),Linux)
    15 	LDLIBS+= -luuid
    16 endif
    17 CXXFLAGS?=-std=c++11 -g -O0 -I../src -I../asn.1
    18 # CXXFLAGS=-O3 -DNDEBUG
    19 
    20 ifeq ("$(OPENPGP)","NETPGP")
    21 	LDLIBS+= -lnetpgp
    22 endif
    23 
    24 TARGET=pEpEngineTest
    25 
    26 UNIT_TESTS_SOURCE=$(wildcard *_test.cc)
    27 UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE))
    28 UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE))
    29 
    30 all: $(TARGET) $(UNIT_TESTS)
    31 
    32 .PHONY: clean
    33 
    34 # don't delete .o files!
    35 .PRECIOUS: %.o
    36 
    37 unexport GNUPGHOME;
    38 TEST_HOME=$(HERE)/test_home
    39 TEST_HOME_SKEL=$(TEST_HOME)_skel
    40 TEST_GNUPGHOME_SKEL=$(TEST_HOME)_skel/.gnupg
    41 
    42 ifeq ($(shell uname), Darwin)
    43     LIBPATH = DYLD_LIBRARY_PATH
    44     LLDB_BIN = /Applications/Xcode.app/Contents/Developer/usr/bin/lldb
    45 else
    46     LIBPATH = LD_LIBRARY_PATH
    47     LLDB_BIN = lldb
    48 endif
    49 
    50 TEST_CMD_PFX = $(LIBPATH)=$(HOME)/lib:../src HOME=$(TEST_HOME)
    51 
    52 define killgpg =
    53 	gpgconf --kill gpg-agent
    54 	HOME=$(TEST_HOME) gpgconf --kill gpg-agent
    55 	HOME=$(TEST_HOME_SKEL) gpgconf --kill gpg-agent
    56 endef
    57 ifeq ("$(OPENPGP)","NETPGP")
    58     killgpg_if_using_it =
    59 else
    60     killgpg_if_using_it = $(killgpg)
    61 endif
    62 
    63 test_home_skel:
    64 	$(killgpg)
    65 	mkdir -p test_home_skel
    66 	-cat 0x*.asc *_sec.asc | gpg2 --import --homedir $(TEST_GNUPGHOME_SKEL)
    67 	$(killgpg)
    68 
    69 test_home_: test_home_skel
    70 	$(killgpg_if_using_it)
    71 	rm -rf test_home
    72 	cp -a test_home_skel test_home
    73 
    74 clean:
    75 	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
    76 	rm -Rf *.dSYM test_home test_home_skel pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
    77 
    78 test: pEpEngineTest test_home_
    79 	$(TEST_CMD_PFX) ./pEpEngineTest
    80 
    81 %_test : %_test.o test_util.o
    82 	 $(LD) $(LDFLAGS) -o $@ $^ $(LDLIBS)
    83 
    84 %_run : % test_home_
    85 	$(TEST_CMD_PFX) ./$<
    86 
    87 %_lldb : % test_home_
    88 	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
    89 
    90 %_valgrind : % test_home_
    91 	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
    92 
    93 %_gdb : % test_home_
    94 	$(TEST_CMD_PFX) gdb ./$<
    95 
    96 unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
    97 
    98 install:
    99 	make -C .. install