test/Makefile
author Damiano Boppart <damiano@pep-security.net>
Sun, 27 Aug 2017 14:33:36 +0000
branchENGINE-229
changeset 2002 6b465132be58
parent 1994 9e3f25c1644f
child 2021 c15acce7cee9
permissions -rw-r--r--
Use -lsqlite3 for compiling tests when SQLITE3_FROM_OS
damiano@1960
     1
# Copyright 2017, pEp Foundation
damiano@1958
     2
# This file is part of pEpEngine
damiano@1958
     3
# This file may be used under the terms of the GNU General Public License version 3
vb@1517
     4
# see LICENSE.txt
vb@1517
     5
damiano@1958
     6
HERE:=$(CURDIR)
vb@2
     7
edouard@1844
     8
include ../Makefile.conf
vb@1422
     9
damiano@1970
    10
TARGET=pEpEngineTest
damiano@1970
    11
damiano@1970
    12
unexport GNUPGHOME
damiano@1970
    13
TEST_HOME=$(HERE)/test_home
damiano@1970
    14
TEST_GNUPGHOME=$(TEST_HOME)/.gnupg
damiano@1970
    15
damiano@1970
    16
LDFLAGS+= $(ETPAN_LIB) -L../asn.1 -L../src
damiano@1970
    17
LDLIBS+= -letpan -lpEpEngine -lstdc++ -lasn1
damiano@1970
    18
krista@1989
    19
ifeq ($(BUILD_FOR),Linux)
damiano@1970
    20
    LDLIBS+= -luuid
krista@1989
    21
endif
krista@1988
    22
damiano@1972
    23
ifeq ($(OPENPGP),NETPGP)
damiano@1970
    24
    LDLIBS+= -lnetpgp
Edouard@178
    25
endif
Edouard@178
    26
damiano@2002
    27
ifdef SQLITE3_FROM_OS
damiano@2002
    28
    LDLIBS+= -lsqlite3
damiano@2002
    29
endif
damiano@2002
    30
damiano@1970
    31
ifeq ($(shell uname),Darwin)
damiano@1970
    32
    LIBPATH=DYLD_LIBRARY_PATH
damiano@1970
    33
    LLDB_BIN=/Applications/Xcode.app/Contents/Developer/usr/bin/lldb
damiano@1970
    34
else
damiano@1970
    35
    LIBPATH=LD_LIBRARY_PATH
damiano@1970
    36
    LLDB_BIN=lldb
Edouard@178
    37
endif
Edouard@178
    38
damiano@1972
    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.
damiano@1970
    40
# Note that += can not be used here, as it changes the amount of whitespace
damiano@1970
    41
EXTRA_LIB_PATHS=../src:
damiano@1970
    42
ifdef ETPAN_LIB
damiano@1970
    43
    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(ETPAN_LIB)):
damiano@1970
    44
endif
damiano@1970
    45
ifdef GPGME_LIB
damiano@1970
    46
    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(GPGME_LIB)):
damiano@1970
    47
endif
damiano@1970
    48
ifdef NETPGP_LIB
damiano@1970
    49
    EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS)$(patsubst -L%,%,$(NETPGP_LIB)):
damiano@1970
    50
endif
damiano@1970
    51
# Remove trailing ':'
damiano@1970
    52
EXTRA_LIB_PATHS:=$(EXTRA_LIB_PATHS::=)
damiano@1970
    53
damiano@1970
    54
TEST_CMD_PFX=$(LIBPATH)=$(EXTRA_LIB_PATHS) HOME=$(TEST_HOME)
vb@2
    55
vb@50
    56
UNIT_TESTS_SOURCE=$(wildcard *_test.cc)
vb@50
    57
UNIT_TESTS=$(subst .cc,,$(UNIT_TESTS_SOURCE))
krista@1617
    58
UNIT_TESTS_RUN=$(subst .cc,_run,$(UNIT_TESTS_SOURCE))
vb@2
    59
damiano@1970
    60
.PHONY: all
vb@48
    61
all: $(TARGET) $(UNIT_TESTS)
vb@2
    62
roker@1659
    63
# don't delete .o files!
roker@1659
    64
.PRECIOUS: %.o
roker@1659
    65
damiano@1970
    66
.PHONY: test_home_
edouard@1934
    67
test_home_: 
edouard@1941
    68
	-gpgconf --kill gpg-agent
edouard@1941
    69
	-HOME=$(TEST_HOME) gpgconf --kill gpg-agent
edouard@1941
    70
	-killall gpg-agent
edouard@1934
    71
	rm -rf $(TEST_HOME)
edouard@1934
    72
	mkdir -p $(TEST_GNUPGHOME)/private-keys-v1.d
edouard@1934
    73
	$(GPG_CMD) --import --batch --homedir $(TEST_GNUPGHOME) 0x*.asc *_sec.asc
edouard@1844
    74
damiano@1970
    75
.PHONY: clean
vb@2
    76
clean:
vb@458
    77
	rm -f *.o $(TARGET) *.a *~ $(UNIT_TESTS) pep_Dokument_Titel.pdf msg4.asc
edouard@1934
    78
	rm -Rf *.dSYM $(TEST_HOME) pubring.gpg secring.gpg random_seed *.conf trustdb.gpg
vb@2
    79
damiano@1970
    80
.PHONY: test
damiano@1970
    81
test: $(TARGET) test_home_
damiano@1970
    82
	$(TEST_CMD_PFX) ./$<
vb@2
    83
roker@1656
    84
%_test : %_test.o test_util.o
damiano@1994
    85
	$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
roker@1656
    86
edouard@1844
    87
%_run : % test_home_
edouard@1844
    88
	$(TEST_CMD_PFX) ./$<
Edouard@699
    89
edouard@1844
    90
%_lldb : % test_home_
edouard@1851
    91
	$(TEST_CMD_PFX) $(LLDB_BIN) ./$<
roker@1656
    92
edouard@1844
    93
%_valgrind : % test_home_
edouard@1844
    94
	$(TEST_CMD_PFX) valgrind --leak-check=yes ./$<
Edouard@745
    95
edouard@1844
    96
%_gdb : % test_home_
edouard@1844
    97
	$(TEST_CMD_PFX) gdb ./$<
Edouard@770
    98
damiano@1970
    99
.PHONY: unit_tests
Edouard@699
   100
unit_tests: $(UNIT_TESTS) $(UNIT_TESTS_RUN)
vb@142
   101
damiano@1994
   102
.PHONY: compile
damiano@1994
   103
compile: $(UNIT_TESTS) $(TARGET)
damiano@1994
   104
damiano@1970
   105
# Installs the engine, not the test binaries
damiano@1970
   106
.PHONY: install
vb@142
   107
install:
damiano@1970
   108
	$(MAKE) -C .. install