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
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
51# This list of binaries determes what gets built and run.  Add each new test binary here.
52BINARIES=\
53	auth_token_table_test
54
55.PHONY: coverage memcheck massif clean run
56
57%.run: %
58	./$<
59	touch $@
60
61run: $(BINARIES:=.run)
62
63auth_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
70coverage: coverage.info
71	genhtml coverage.info --output-directory coverage
72
73coverage.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
82UNINIT_OPTS=--undef-value-errors=no
83
84MEMCHECK_OPTS=--leak-check=full \
85	--show-reachable=yes \
86	--vgdb=full \
87	$(UNINIT_OPTS) \
88	--error-exitcode=1
89
90MASSIF_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
100memcheck: $(BINARIES:=.memcheck)
101
102massif: $(BINARIES:=.massif)
103
104OBJS=$(CPPSRCS:.cpp=.o)
105DEPS=$(CPPSRCS:.cpp=.d)
106GCOV=$(CPPSRCS:.cpp=.gcov) $(CPPSRCS:.cpp=.gcda) $(CPPSRCS:.cpp=.gcno)
107
108clean:
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