blob: f5753818994e29dd77cb58eda0728b4eba64c7d9 [file] [log] [blame]
Andres Moralesb33c9b82015-09-08 17:56:07 -07001#####
2# Local unit test Makefile
3#
4# This makefile builds and runs the trusty_keymaster unit tests locally on the development
5# machine, not on an Android device.
6#
7# To build and run these tests, one pre-requisite must be manually installed: BoringSSL.
8# This Makefile expects to find BoringSSL in a directory adjacent to $ANDROID_BUILD_TOP.
9# To get and build it, first install the Ninja build tool (e.g. apt-get install
10# ninja-build), then do:
11#
12# cd $ANDROID_BUILD_TOP/..
13# git clone https://boringssl.googlesource.com/boringssl
14# cd boringssl
15# mdkir build
16# cd build
17# cmake -GNinja ..
18# ninja
19#
20# Then return to $ANDROID_BUILD_TOP/system/keymaster and run "make".
21#####
22
23BASE=../../../..
24SUBS=system/core \
25 system/keymaster \
26 hardware/libhardware \
27 external/gtest
28GTEST=$(BASE)/external/gtest
29KM=$(BASE)/system/keymaster
30
31INCLUDES=$(foreach dir,$(SUBS),-I $(BASE)/$(dir)/include) \
32 -I $(BASE)/libnativehelper/include/nativehelper \
33 -I ../tipc/include \
34 -I $(BASE)/system/keymaster \
35 -I $(GTEST) \
36 -I$(BASE)/../boringssl/include
37
38ifdef USE_CLANG
39CC=/usr/bin/clang
40CXX=/usr/bin/clang
41CLANG_TEST_DEFINE=-DKEYMASTER_CLANG_TEST_BUILD
42COMPILER_SPECIFIC_ARGS=-std=c++11 $(CLANG_TEST_DEFINE)
43else
44COMPILER_SPECIFIC_ARGS=-std=c++0x -fprofile-arcs
45endif
46
47CPPFLAGS=$(INCLUDES) -g -O0 -MD
48CXXFLAGS=-Wall -Werror -Wno-unused -Winit-self -Wpointer-arith -Wunused-parameter \
49 -Wmissing-declarations -ftest-coverage \
50 -Wno-deprecated-declarations -fno-exceptions -DKEYMASTER_NAME_TAGS \
51 $(COMPILER_SPECIFIC_ARGS)
52LDLIBS=-L$(BASE)/../boringssl/build/crypto -lcrypto -lpthread -lstdc++
53
54CPPSRCS=\
55 $(KM)/aead_mode_operation.cpp \
56 $(KM)/aes_key.cpp \
57 $(KM)/aes_operation.cpp \
58 $(KM)/android_keymaster.cpp \
59 $(KM)/android_keymaster_messages.cpp \
60 $(KM)/android_keymaster_messages_test.cpp \
61 $(KM)/android_keymaster_test.cpp \
62 $(KM)/android_keymaster_test_utils.cpp \
63 $(KM)/android_keymaster_utils.cpp \
64 $(KM)/asymmetric_key.cpp \
65 $(KM)/auth_encrypted_key_blob.cpp \
66 $(KM)/auth_encrypted_key_blob.cpp \
67 $(KM)/authorization_set.cpp \
68 $(KM)/authorization_set_test.cpp \
69 $(KM)/ec_key.cpp \
70 $(KM)/ec_keymaster0_key.cpp \
71 $(KM)/ecdsa_operation.cpp \
72 $(KM)/hmac_key.cpp \
73 $(KM)/hmac_operation.cpp \
74 $(KM)/integrity_assured_key_blob.cpp \
75 $(KM)/key.cpp \
76 $(KM)/key_blob_test.cpp \
77 $(KM)/keymaster0_engine.cpp \
78 $(KM)/logger.cpp \
79 $(KM)/ocb_utils.cpp \
80 $(KM)/openssl_err.cpp \
81 $(KM)/openssl_utils.cpp \
82 $(KM)/operation.cpp \
83 $(KM)/operation_table.cpp \
84 $(KM)/rsa_key.cpp \
85 $(KM)/rsa_keymaster0_key.cpp \
86 $(KM)/rsa_operation.cpp \
87 $(KM)/serializable.cpp \
88 $(KM)/soft_keymaster_context.cpp \
89 $(KM)/symmetric_key.cpp \
90 $(KM)/unencrypted_key_blob.cpp \
91 trusty_keymaster_device.cpp \
92 trusty_keymaster_device_test.cpp
93CCSRCS=$(GTEST)/src/gtest-all.cc
94CSRCS=ocb.c
95
96OBJS=$(CPPSRCS:.cpp=.o) $(CCSRCS:.cc=.o) $(CSRCS:.c=.o)
97DEPS=$(CPPSRCS:.cpp=.d) $(CCSRCS:.cc=.d) $(CSRCS:.c=.d)
98GCDA=$(CPPSRCS:.cpp=.gcda) $(CCSRCS:.cc=.gcda) $(CSRCS:.c=.gcda)
99GCNO=$(CPPSRCS:.cpp=.gcno) $(CCSRCS:.cc=.gcno) $(CSRCS:.c=.gcno)
100
101LINK.o=$(LINK.cc)
102
103BINARIES=trusty_keymaster_device_test
104
105ifdef TRUSTY
106BINARIES += trusty_keymaster_device_test
107endif # TRUSTY
108
109.PHONY: coverage memcheck massif clean run
110
111%.run: %
112 ./$<
113 touch $@
114
115run: $(BINARIES:=.run)
116
117coverage: coverage.info
118 genhtml coverage.info --output-directory coverage
119
120coverage.info: run
121 lcov --capture --directory=. --output-file coverage.info
122
123%.coverage : %
124 $(MAKE) clean && $(MAKE) $<
125 ./$<
126 lcov --capture --directory=. --output-file coverage.info
127 genhtml coverage.info --output-directory coverage
128
129#UNINIT_OPTS=--track-origins=yes
130UNINIT_OPTS=--undef-value-errors=no
131
132MEMCHECK_OPTS=--leak-check=full \
133 --show-reachable=yes \
134 --vgdb=full \
135 $(UNINIT_OPTS) \
136 --error-exitcode=1
137
138MASSIF_OPTS=--tool=massif \
139 --stacks=yes
140
141%.memcheck : %
142 valgrind $(MEMCHECK_OPTS) ./$< && \
143 touch $@
144
145%.massif : %
146 valgrind $(MASSIF_OPTS) --massif-out-file=$@ ./$<
147
148memcheck: $(BINARIES:=.memcheck)
149
150massif: $(BINARIES:=.massif)
151
152trusty_keymaster_device_test: trusty_keymaster_device_test.o \
153 trusty_keymaster_device.o \
154 $(KM)/aead_mode_operation.o \
155 $(KM)/aes_key.o \
156 $(KM)/aes_operation.o \
157 $(KM)/android_keymaster.o \
158 $(KM)/android_keymaster_messages.o \
159 $(KM)/android_keymaster_test_utils.o \
160 $(KM)/android_keymaster_utils.o \
161 $(KM)/asymmetric_key.o \
162 $(KM)/auth_encrypted_key_blob.o \
163 $(KM)/auth_encrypted_key_blob.o \
164 $(KM)/authorization_set.o \
165 $(KM)/ec_key.o \
166 $(KM)/ec_keymaster0_key.cpp \
167 $(KM)/ecdsa_operation.o \
168 $(KM)/hmac_key.o \
169 $(KM)/hmac_operation.o \
170 $(KM)/integrity_assured_key_blob.o \
171 $(KM)/key.o \
172 $(KM)/keymaster0_engine.o \
173 $(KM)/logger.o \
174 $(KM)/ocb.o \
175 $(KM)/ocb_utils.o \
176 $(KM)/openssl_err.o \
177 $(KM)/openssl_utils.o \
178 $(KM)/operation.o \
179 $(KM)/operation_table.o \
180 $(KM)/rsa_key.o \
181 $(KM)/rsa_keymaster0_key.o \
182 $(KM)/rsa_operation.o \
183 $(KM)/serializable.o \
184 $(KM)/soft_keymaster_context.o \
185 $(KM)/symmetric_key.o \
186 $(GTEST)/src/gtest-all.o
187
188$(GTEST)/src/gtest-all.o: CXXFLAGS:=$(subst -Wmissing-declarations,,$(CXXFLAGS))
189ocb.o: CFLAGS=$(CLANG_TEST_DEFINE)
190
191clean:
192 rm -f $(OBJS) $(DEPS) $(GCDA) $(GCNO) $(BINARIES) \
193 $(BINARIES:=.run) $(BINARIES:=.memcheck) $(BINARIES:=.massif) \
194 coverage.info
195 rm -rf coverage
196
197-include $(CPPSRCS:.cpp=.d)
198-include $(CCSRCS:.cc=.d)
199