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 $(BASE)/libnativehelper/include/nativehelper \ 21 -I $(GTEST) -Iinclude 22 23# Add USE_CLANG=1 to the make command line to build with clang, which has better error 24# reporting and diagnoses some conditions that GCC doesn't. 25ifdef USE_CLANG 26CC=/usr/bin/clang 27CXX=/usr/bin/clang 28CLANG_TEST_DEFINE=-DKEYMASTER_CLANG_TEST_BUILD 29COMPILER_SPECIFIC_ARGS=-std=c++11 $(CLANG_TEST_DEFINE) 30else 31COMPILER_SPECIFIC_ARGS=-std=c++0x -fprofile-arcs 32endif 33 34CPPFLAGS=$(INCLUDES) -g -O0 -MD -DHOST_BUILD 35CXXFLAGS=-Wall -Werror -Wno-unused -Winit-self -Wpointer-arith -Wunused-parameter \ 36 -Werror=sign-compare -Wmissing-declarations -ftest-coverage -fno-permissive \ 37 -Wno-deprecated-declarations -fno-exceptions -DKEYMASTER_NAME_TAGS \ 38 $(COMPILER_SPECIFIC_ARGS) 39 40# Uncomment to enable debug logging. 41# CXXFLAGS += -DDEBUG 42 43LDLIBS=-lpthread -lstdc++ -lgcov 44 45# This list of sources is used for dependency generation and cleanup. Add each new source 46# file here (not headers). 47CPPSRCS=\ 48 ../auth_token_table.cpp \ 49 auth_token_table_test.cpp \ 50 gtest_main.cpp \ 51 $(KEYMASTER)/authorization_set.cpp \ 52 $(KEYMASTER)/keymaster_tags.cpp \ 53 $(KEYMASTER)/logger.cpp \ 54 $(KEYMASTER)/serializable.cpp 55 56CCSRCS=$(GTEST)/src/gtest-all.cc 57 58# This list of binaries determes what gets built and run. Add each new test binary here. 59BINARIES=\ 60 auth_token_table_test 61 62.PHONY: coverage memcheck massif clean run 63 64%.run: % 65 ./$< 66 touch $@ 67 68run: $(BINARIES:=.run) 69 70GTEST_OBJS = $(GTEST)/src/gtest-all.o gtest_main.o 71 72auth_token_table_test: auth_token_table_test.o \ 73 ../auth_token_table.o \ 74 $(GTEST_OBJS) \ 75 $(KEYMASTER)/authorization_set.o \ 76 $(KEYMASTER)/keymaster_tags.o \ 77 $(KEYMASTER)/logger.o \ 78 $(KEYMASTER)/serializable.o 79 80coverage: coverage.info 81 genhtml coverage.info --output-directory coverage 82 83coverage.info: run 84 lcov --capture --directory=. --directory=.. -b . --output-file coverage.info 85 86%.coverage : % 87 $(MAKE) clean && $(MAKE) $< 88 ./$< 89 lcov --capture --directory=. --output-file coverage.info 90 genhtml coverage.info --output-directory coverage 91#UNINIT_OPTS=--track-origins=yes 92UNINIT_OPTS=--undef-value-errors=no 93 94MEMCHECK_OPTS=--leak-check=full \ 95 --show-reachable=yes \ 96 --vgdb=full \ 97 $(UNINIT_OPTS) \ 98 --error-exitcode=1 99 100MASSIF_OPTS=--tool=massif \ 101 --stacks=yes 102 103%.memcheck : % 104 valgrind $(MEMCHECK_OPTS) ./$< && \ 105 touch $@ 106 107%.massif : % 108 valgrind $(MASSIF_OPTS) --massif-out-file=$@ ./$< 109 110memcheck: $(BINARIES:=.memcheck) 111 112massif: $(BINARIES:=.massif) 113 114OBJS=$(CPPSRCS:.cpp=.o) 115DEPS=$(CPPSRCS:.cpp=.d) 116GCOV=$(CPPSRCS:.cpp=.gcov) $(CPPSRCS:.cpp=.gcda) $(CPPSRCS:.cpp=.gcno) 117 118clean: 119 rm -f $(OBJS) $(DEPS) $(BINARIES) $(GCOV) \ 120 $(BINARIES:=.run) $(BINARIES:=.memcheck) $(BINARIES:=.massif) \ 121 *gcov *gcno *gcda coverage.info 122 rm -rf coverage 123 124-include $(CPPSRCS:.cpp=.d) 125-include $(CCSRCS:.cc=.d) 126 127