blob: 2720b0f87a6109c1330ad85bc3f474a9dd27f85c [file] [log] [blame]
Shawn Willden489dfe12015-03-17 10:13:27 -06001##########
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
Shawn Willden47d26162016-03-16 08:32:39 -060034CPPFLAGS=$(INCLUDES) -g -O0 -MD -DHOST_BUILD
Shawn Willden489dfe12015-03-17 10:13:27 -060035CXXFLAGS=-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 \
Shawn Willden47d26162016-03-16 08:32:39 -060049 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
Shawn Willden489dfe12015-03-17 10:13:27 -060057
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
Shawn Willden47d26162016-03-16 08:32:39 -060070GTEST_OBJS = $(GTEST)/src/gtest-all.o gtest_main.o
71
Shawn Willden489dfe12015-03-17 10:13:27 -060072auth_token_table_test: auth_token_table_test.o \
73 ../auth_token_table.o \
Shawn Willden47d26162016-03-16 08:32:39 -060074 $(GTEST_OBJS) \
Shawn Willden489dfe12015-03-17 10:13:27 -060075 $(KEYMASTER)/authorization_set.o \
Shawn Willden47d26162016-03-16 08:32:39 -060076 $(KEYMASTER)/keymaster_tags.o \
Shawn Willden489dfe12015-03-17 10:13:27 -060077 $(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