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 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 51 # This list of binaries determes what gets built and run. Add each new test binary here. 52 BINARIES=\ 53 auth_token_table_test 54 55 .PHONY: coverage memcheck massif clean run 56 57 %.run: % 58 ./$< 59 touch $@ 60 61 run: $(BINARIES:=.run) 62 63 auth_token_table_test: auth_token_table_test.o \ 64 ../auth_token_table.o \ 65 $(GTEST)/src/gtest-all.o \ 66 $(KEYMASTER)/authorization_set.o \ 67 $(KEYMASTER)/logger.o \ 68 $(KEYMASTER)/serializable.o 69 70 coverage: coverage.info 71 genhtml coverage.info --output-directory coverage 72 73 coverage.info: run 74 lcov --capture --directory=. --directory=.. -b . --output-file coverage.info 75 76 %.coverage : % 77 $(MAKE) clean && $(MAKE) $< 78 ./$< 79 lcov --capture --directory=. --output-file coverage.info 80 genhtml coverage.info --output-directory coverage 81 #UNINIT_OPTS=--track-origins=yes 82 UNINIT_OPTS=--undef-value-errors=no 83 84 MEMCHECK_OPTS=--leak-check=full \ 85 --show-reachable=yes \ 86 --vgdb=full \ 87 $(UNINIT_OPTS) \ 88 --error-exitcode=1 89 90 MASSIF_OPTS=--tool=massif \ 91 --stacks=yes 92 93 %.memcheck : % 94 valgrind $(MEMCHECK_OPTS) ./$< && \ 95 touch $@ 96 97 %.massif : % 98 valgrind $(MASSIF_OPTS) --massif-out-file=$@ ./$< 99 100 memcheck: $(BINARIES:=.memcheck) 101 102 massif: $(BINARIES:=.massif) 103 104 OBJS=$(CPPSRCS:.cpp=.o) 105 DEPS=$(CPPSRCS:.cpp=.d) 106 GCOV=$(CPPSRCS:.cpp=.gcov) $(CPPSRCS:.cpp=.gcda) $(CPPSRCS:.cpp=.gcno) 107 108 clean: 109 rm -f $(OBJS) $(DEPS) $(BINARIES) $(GCOV) \ 110 $(BINARIES:=.run) $(BINARIES:=.memcheck) $(BINARIES:=.massif) \ 111 *gcov *gcno *gcda coverage.info 112 rm -rf coverage 113 114 -include $(CPPSRCS:.cpp=.d) 115 -include $(CCSRCS:.cc=.d) 116 117