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 11 BASE=../../../.. 12 SUBS=system/core \ 13 system/keymaster\ 14 hardware/libhardware \ 15 external/gtest 16 GTEST=$(BASE)/external/gtest 17 KEYMASTER=$(BASE)/system/keymaster 18 19 INCLUDES=$(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. 25 ifdef USE_CLANG 26 CC=/usr/bin/clang 27 CXX=/usr/bin/clang 28 CLANG_TEST_DEFINE=-DKEYMASTER_CLANG_TEST_BUILD 29 COMPILER_SPECIFIC_ARGS=-std=c++11 $(CLANG_TEST_DEFINE) 30 else 31 COMPILER_SPECIFIC_ARGS=-std=c++0x -fprofile-arcs 32 endif 33 34 CPPFLAGS=$(INCLUDES) -g -O0 -MD -DHOST_BUILD 35 CXXFLAGS=-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 43 LDLIBS=-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). 47 CPPSRCS=\ 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 56 CCSRCS=$(GTEST)/src/gtest-all.cc 57 58 # This list of binaries determes what gets built and run. Add each new test binary here. 59 BINARIES=\ 60 auth_token_table_test 61 62 .PHONY: coverage memcheck massif clean run 63 64 %.run: % 65 ./$< 66 touch $@ 67 68 run: $(BINARIES:=.run) 69 70 GTEST_OBJS = $(GTEST)/src/gtest-all.o gtest_main.o 71 72 auth_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 80 coverage: coverage.info 81 genhtml coverage.info --output-directory coverage 82 83 coverage.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 92 UNINIT_OPTS=--undef-value-errors=no 93 94 MEMCHECK_OPTS=--leak-check=full \ 95 --show-reachable=yes \ 96 --vgdb=full \ 97 $(UNINIT_OPTS) \ 98 --error-exitcode=1 99 100 MASSIF_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 110 memcheck: $(BINARIES:=.memcheck) 111 112 massif: $(BINARIES:=.massif) 113 114 OBJS=$(CPPSRCS:.cpp=.o) 115 DEPS=$(CPPSRCS:.cpp=.d) 116 GCOV=$(CPPSRCS:.cpp=.gcov) $(CPPSRCS:.cpp=.gcda) $(CPPSRCS:.cpp=.gcno) 117 118 clean: 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