• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#####
2# Local unit test Makefile
3#
4# This makefile builds and runs the keymaster unit tests locally on the development
5# machine, not on an Android device.  Android.mk builds the same tests into the
6# "keymaster_tests" binary for execution on-device, but this Makefile runs them locally,
7# for a very fast edit/build/test development cycle.
8#
9# To build and run these tests, one pre-requisite must be manually installed: BoringSSL.
10# This Makefile expects to find BoringSSL in a directory adjacent to $ANDROID_BUILD_TOP.
11# To get and build it, first install the Ninja build tool (e.g. apt-get install
12# ninja-build), then do:
13#
14# cd $ANDROID_BUILD_TOP/..
15# git clone https://boringssl.googlesource.com/boringssl
16# cd boringssl
17# mdkir build
18# cd build
19# cmake -GNinja ..
20# ninja
21#
22# Then return to $ANDROID_BUILD_TOP/system/keymaster and run "make".
23#####
24
25BASE=../..
26SUBS=system/core \
27	hardware/libhardware \
28	external/gtest \
29	system/security/softkeymaster \
30	system/security/keystore
31GTEST=$(BASE)/external/gtest
32
33INCLUDES=$(foreach dir,$(SUBS),-I $(BASE)/$(dir)/include) \
34	-I $(BASE)/libnativehelper/include/nativehelper \
35	-I $(GTEST) -Iinclude -I$(BASE)/../boringssl/include
36
37ifdef FORCE_32_BIT
38ARCH_FLAGS = -m32
39endif
40
41ifdef USE_CLANG
42CC=/usr/bin/clang
43CXX=/usr/bin/clang
44CXXFLAGS +=-std=c++11 -DKEYMASTER_CLANG_TEST_BUILD
45CFLAGS += -DKEYMASTER_CLANG_TEST_BUILD
46else
47CXXFLAGS +=-std=c++0x -fprofile-arcs -ftest-coverage
48CFLAGS += -fprofile-arcs -ftest-coverage
49endif
50
51LDFLAGS += $(ARCH_FLAGS)
52CPPFLAGS = $(INCLUDES) -g -O0 -MD -MP
53CXXFLAGS += -Wall -Werror -Wno-unused -Winit-self -Wpointer-arith	-Wunused-parameter \
54	-Werror=sign-compare -Werror=return-type -fno-permissive \
55	-Wno-deprecated-declarations -fno-exceptions -DKEYMASTER_NAME_TAGS $(ARCH_FLAGS)
56CFLAGS += $(ARCH_FLAGS)
57
58# Uncomment to enable debug logging.
59# CXXFLAGS += -DDEBUG
60
61LDLIBS=-L$(BASE)/../boringssl/build/crypto -lcrypto -lpthread -lstdc++ -lgcov
62
63CPPSRCS=\
64	aes_key.cpp \
65	aes_operation.cpp \
66	android_keymaster.cpp \
67	android_keymaster_messages.cpp \
68	android_keymaster_messages_test.cpp \
69	android_keymaster_test.cpp \
70	android_keymaster_test_utils.cpp \
71	android_keymaster_utils.cpp \
72	asymmetric_key.cpp \
73	asymmetric_key_factory.cpp \
74	auth_encrypted_key_blob.cpp \
75	authorization_set.cpp \
76	authorization_set_test.cpp \
77	ec_key.cpp \
78	ec_key_factory.cpp \
79	ec_keymaster0_key.cpp \
80	ec_keymaster1_key.cpp \
81	ecdsa_keymaster1_operation.cpp \
82	ecdsa_operation.cpp \
83	gtest_main.cpp \
84	hkdf.cpp \
85	hkdf_test.cpp \
86	hmac.cpp \
87	hmac_key.cpp \
88	hmac_operation.cpp \
89	hmac_test.cpp \
90	integrity_assured_key_blob.cpp \
91	key.cpp \
92	key_blob_test.cpp \
93	keymaster0_engine.cpp \
94	keymaster1_engine.cpp \
95	keymaster_enforcement.cpp \
96	keymaster_enforcement_test.cpp \
97	logger.cpp \
98	ocb_utils.cpp \
99	openssl_err.cpp \
100	openssl_utils.cpp \
101	operation.cpp \
102	operation_table.cpp \
103	rsa_key.cpp \
104	rsa_key_factory.cpp \
105	rsa_keymaster0_key.cpp \
106	rsa_keymaster1_key.cpp \
107	rsa_keymaster1_operation.cpp \
108	rsa_operation.cpp \
109	serializable.cpp \
110	soft_keymaster_context.cpp \
111	soft_keymaster_device.cpp \
112	symmetric_key.cpp
113
114CCSRCS=$(GTEST)/src/gtest-all.cc
115CSRCS=ocb.c
116
117OBJS=$(CPPSRCS:.cpp=.o) $(CCSRCS:.cc=.o) $(CSRCS:.c=.o)
118DEPS=$(CPPSRCS:.cpp=.d) $(CCSRCS:.cc=.d) $(CSRCS:.c=.d)
119
120BINARIES = \
121	android_keymaster_messages_test \
122	android_keymaster_test \
123	authorization_set_test \
124	hkdf_test \
125	hmac_test \
126	key_blob_test \
127	keymaster_enforcement_test \
128
129.PHONY: coverage memcheck massif clean run
130
131%.run: %
132	./$<
133	touch $@
134
135run: $(BINARIES:=.run)
136
137coverage: coverage.info
138	genhtml coverage.info --output-directory coverage
139
140coverage.info: run
141	lcov --capture --directory=. --output-file coverage.info
142
143%.coverage : %
144	$(MAKE) clean && $(MAKE) $<
145	./$<
146	lcov --capture --directory=. --output-file coverage.info
147	genhtml coverage.info --output-directory coverage
148
149#UNINIT_OPTS=--track-origins=yes
150UNINIT_OPTS=--undef-value-errors=no
151
152MEMCHECK_OPTS=--leak-check=full \
153	--show-reachable=yes \
154	--vgdb=full \
155	$(UNINIT_OPTS) \
156	--error-exitcode=1 \
157	--suppressions=valgrind.supp \
158	--gen-suppressions=all
159
160MASSIF_OPTS=--tool=massif \
161	--stacks=yes
162
163%.memcheck : %
164	valgrind $(MEMCHECK_OPTS) ./$< && \
165	touch $@
166
167%.massif : %
168	valgrind $(MASSIF_OPTS) --massif-out-file=$@ ./$<
169
170memcheck: $(BINARIES:=.memcheck)
171
172massif: $(BINARIES:=.massif)
173
174GTEST_OBJS = $(GTEST)/src/gtest-all.o gtest_main.o
175
176hmac_test: hmac_test.o \
177	android_keymaster_test_utils.o \
178	android_keymaster_utils.o \
179	authorization_set.o \
180	hmac.o \
181	logger.o \
182	serializable.o \
183	$(GTEST_OBJS)
184
185hkdf_test: hkdf_test.o \
186	android_keymaster_test_utils.o \
187	android_keymaster_utils.o \
188	authorization_set.o \
189	hkdf.o \
190	hmac.o \
191	logger.o \
192	serializable.o \
193	$(GTEST_OBJS)
194
195authorization_set_test: authorization_set_test.o \
196	android_keymaster_test_utils.o \
197	authorization_set.o \
198	logger.o \
199	serializable.o \
200	$(GTEST_OBJS)
201
202key_blob_test: key_blob_test.o \
203	android_keymaster_test_utils.o \
204	android_keymaster_utils.o \
205	auth_encrypted_key_blob.o \
206	authorization_set.o \
207	integrity_assured_key_blob.o \
208	logger.o \
209	ocb.o \
210	ocb_utils.o \
211	openssl_err.o \
212	serializable.o \
213	$(GTEST_OBJS)
214
215android_keymaster_messages_test: android_keymaster_messages_test.o \
216	android_keymaster_messages.o \
217	android_keymaster_test_utils.o \
218	android_keymaster_utils.o \
219	authorization_set.o \
220	logger.o \
221	serializable.o \
222	$(GTEST_OBJS)
223
224android_keymaster_test: android_keymaster_test.o \
225	aes_key.o \
226	aes_operation.o \
227	android_keymaster.o \
228	android_keymaster_messages.o \
229	android_keymaster_test_utils.o \
230	android_keymaster_utils.o \
231	asymmetric_key.o \
232	asymmetric_key_factory.o \
233	auth_encrypted_key_blob.o \
234	authorization_set.o \
235	ec_key.o \
236	ec_key_factory.o \
237	ec_keymaster0_key.o \
238	ec_keymaster1_key.o \
239	ecdsa_keymaster1_operation.o \
240	ecdsa_operation.o \
241	hmac_key.o \
242	hmac_operation.o \
243	integrity_assured_key_blob.o \
244	key.o \
245	keymaster0_engine.o \
246	keymaster1_engine.o \
247	keymaster_enforcement.o \
248	logger.o \
249	ocb.o \
250	ocb_utils.o \
251	openssl_err.o \
252	openssl_utils.o \
253	operation.o \
254	operation_table.o \
255	rsa_key.o \
256	rsa_key_factory.o \
257	rsa_keymaster0_key.o \
258	rsa_keymaster1_key.o \
259	rsa_keymaster1_operation.o \
260	rsa_operation.o \
261	serializable.o \
262	soft_keymaster_context.o \
263	soft_keymaster_device.o \
264	symmetric_key.o \
265	$(BASE)/system/security/softkeymaster/keymaster_openssl.o \
266	$(BASE)/system/security/keystore/keyblob_utils.o \
267	$(GTEST_OBJS)
268
269keymaster_enforcement_test: keymaster_enforcement_test.o \
270	android_keymaster_messages.o \
271	android_keymaster_test_utils.o \
272	android_keymaster_utils.o \
273	authorization_set.o \
274	keymaster_enforcement.o \
275	logger.o \
276	serializable.o \
277	$(GTEST_OBJS)
278
279$(GTEST)/src/gtest-all.o: CXXFLAGS:=$(subst -Wmissing-declarations,,$(CXXFLAGS))
280
281clean:
282	rm -f $(OBJS) $(DEPS) $(BINARIES) \
283		$(BINARIES:=.run) $(BINARIES:=.memcheck) $(BINARIES:=.massif) \
284		*gcov *gcno *gcda coverage.info
285	rm -rf coverage
286
287-include $(CPPSRCS:.cpp=.d)
288-include $(CCSRCS:.cc=.d)
289
290