1########## 2# This makefile builds local unit tests that run locally on the development machine. Note 3# that it may be necessary to install some libraries on the dev maching to make the tests 4# build. 5# 6# The same unit tests are also built by Android.mk to run on the target device. The tests 7# should always build and pass in both places. The on-device test is what really matters, 8# of course, but debugging is often somewhat easier on the dev platform. 9########## 10 11BASE=../../../.. 12SUBS=system/core \ 13 system/keymaster\ 14 hardware/libhardware \ 15 external/gtest 16GTEST=$(BASE)/external/gtest 17KEYMASTER=$(BASE)/system/keymaster 18 19INCLUDES=$(foreach dir,$(SUBS),-I $(BASE)/$(dir)/include) \ 20 -I $(GTEST) -Iinclude 21 22# Add USE_CLANG=1 to the make command line to build with clang, which has better error 23# reporting and diagnoses some conditions that GCC doesn't. 24ifdef USE_CLANG 25CC=/usr/bin/clang 26CXX=/usr/bin/clang 27CLANG_TEST_DEFINE=-DKEYMASTER_CLANG_TEST_BUILD 28COMPILER_SPECIFIC_ARGS=-std=c++11 $(CLANG_TEST_DEFINE) 29else 30COMPILER_SPECIFIC_ARGS=-std=c++0x -fprofile-arcs 31endif 32 33CPPFLAGS=$(INCLUDES) -g -O0 -MD -DHOST_BUILD 34CXXFLAGS=-Wall -Werror -Wno-unused -Winit-self -Wpointer-arith -Wunused-parameter \ 35 -Werror=sign-compare -Wmissing-declarations -ftest-coverage -fno-permissive \ 36 -Wno-deprecated-declarations -fno-exceptions -DKEYMASTER_NAME_TAGS \ 37 $(COMPILER_SPECIFIC_ARGS) 38 39# Uncomment to enable debug logging. 40# CXXFLAGS += -DDEBUG 41 42LDLIBS=-lpthread -lstdc++ -lgcov 43 44# This list of sources is used for dependency generation and cleanup. Add each new source 45# file here (not headers). 46CPPSRCS=\ 47 ../auth_token_table.cpp \ 48 auth_token_table_test.cpp \ 49 gtest_main.cpp \ 50 $(KEYMASTER)/authorization_set.cpp \ 51 $(KEYMASTER)/keymaster_tags.cpp \ 52 $(KEYMASTER)/logger.cpp \ 53 $(KEYMASTER)/serializable.cpp 54 55CCSRCS=$(GTEST)/src/gtest-all.cc 56 57# This list of binaries determes what gets built and run. Add each new test binary here. 58BINARIES=\ 59 auth_token_table_test 60 61.PHONY: coverage memcheck massif clean run 62 63%.run: % 64 ./$< 65 touch $@ 66 67run: $(BINARIES:=.run) 68 69GTEST_OBJS = $(GTEST)/src/gtest-all.o gtest_main.o 70 71auth_token_table_test: auth_token_table_test.o \ 72 ../auth_token_table.o \ 73 $(GTEST_OBJS) \ 74 $(KEYMASTER)/authorization_set.o \ 75 $(KEYMASTER)/keymaster_tags.o \ 76 $(KEYMASTER)/logger.o \ 77 $(KEYMASTER)/serializable.o 78 79coverage: coverage.info 80 genhtml coverage.info --output-directory coverage 81 82coverage.info: run 83 lcov --capture --directory=. --directory=.. -b . --output-file coverage.info 84 85%.coverage : % 86 $(MAKE) clean && $(MAKE) $< 87 ./$< 88 lcov --capture --directory=. --output-file coverage.info 89 genhtml coverage.info --output-directory coverage 90#UNINIT_OPTS=--track-origins=yes 91UNINIT_OPTS=--undef-value-errors=no 92 93MEMCHECK_OPTS=--leak-check=full \ 94 --show-reachable=yes \ 95 --vgdb=full \ 96 $(UNINIT_OPTS) \ 97 --error-exitcode=1 98 99MASSIF_OPTS=--tool=massif \ 100 --stacks=yes 101 102%.memcheck : % 103 valgrind $(MEMCHECK_OPTS) ./$< && \ 104 touch $@ 105 106%.massif : % 107 valgrind $(MASSIF_OPTS) --massif-out-file=$@ ./$< 108 109memcheck: $(BINARIES:=.memcheck) 110 111massif: $(BINARIES:=.massif) 112 113OBJS=$(CPPSRCS:.cpp=.o) 114DEPS=$(CPPSRCS:.cpp=.d) 115GCOV=$(CPPSRCS:.cpp=.gcov) $(CPPSRCS:.cpp=.gcda) $(CPPSRCS:.cpp=.gcno) 116 117clean: 118 rm -f $(OBJS) $(DEPS) $(BINARIES) $(GCOV) \ 119 $(BINARIES:=.run) $(BINARIES:=.memcheck) $(BINARIES:=.massif) \ 120 *gcov *gcno *gcda coverage.info 121 rm -rf coverage 122 123-include $(CPPSRCS:.cpp=.d) 124-include $(CCSRCS:.cc=.d) 125 126