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 25 BASE=../.. 26 SUBS=system/core \ 27 hardware/libhardware \ 28 external/gtest \ 29 system/security/softkeymaster \ 30 system/security/keystore 31 GTEST=$(BASE)/external/gtest 32 33 INCLUDES=$(foreach dir,$(SUBS),-I $(BASE)/$(dir)/include) \ 34 -I $(BASE)/libnativehelper/include/nativehelper \ 35 -I $(GTEST) -Iinclude -I$(BASE)/../boringssl/include 36 37 ifdef FORCE_32_BIT 38 ARCH_FLAGS = -m32 39 endif 40 41 ifdef USE_CLANG 42 CC=/usr/bin/clang 43 CXX=/usr/bin/clang 44 CXXFLAGS +=-std=c++11 -DKEYMASTER_CLANG_TEST_BUILD 45 CFLAGS += -DKEYMASTER_CLANG_TEST_BUILD 46 else 47 CXXFLAGS +=-std=c++0x -fprofile-arcs 48 CFLAGS += -fprofile-arcs 49 endif 50 51 LDFLAGS += $(ARCH_FLAGS) 52 CPPFLAGS = $(INCLUDES) -g -O0 -MD -MP 53 CXXFLAGS += -Wall -Werror -Wno-unused -Winit-self -Wpointer-arith -Wunused-parameter \ 54 -Werror=sign-compare -ftest-coverage -fno-permissive \ 55 -Wno-deprecated-declarations -fno-exceptions -DKEYMASTER_NAME_TAGS $(ARCH_FLAGS) 56 CFLAGS += $(ARCH_FLAGS) 57 58 # Uncomment to enable debug logging. 59 # CXXFLAGS += -DDEBUG 60 61 LDLIBS=-L$(BASE)/../boringssl/build/crypto -lcrypto -lpthread -lstdc++ -lgcov 62 63 CPPSRCS=\ 64 aead_mode_operation.cpp \ 65 aes_key.cpp \ 66 aes_operation.cpp \ 67 android_keymaster.cpp \ 68 android_keymaster_messages.cpp \ 69 android_keymaster_messages_test.cpp \ 70 android_keymaster_test.cpp \ 71 android_keymaster_test_utils.cpp \ 72 android_keymaster_utils.cpp \ 73 asymmetric_key.cpp \ 74 asymmetric_key_factory.cpp \ 75 auth_encrypted_key_blob.cpp \ 76 authorization_set.cpp \ 77 authorization_set_test.cpp \ 78 ec_key.cpp \ 79 ec_key_factory.cpp \ 80 ec_keymaster0_key.cpp \ 81 ecdsa_operation.cpp \ 82 gtest_main.cpp \ 83 hkdf.cpp \ 84 hkdf_test.cpp \ 85 hmac.cpp \ 86 hmac_key.cpp \ 87 hmac_operation.cpp \ 88 hmac_test.cpp \ 89 integrity_assured_key_blob.cpp \ 90 key.cpp \ 91 key_blob_test.cpp \ 92 keymaster0_engine.cpp \ 93 keymaster_enforcement.cpp \ 94 keymaster_enforcement_test.cpp \ 95 logger.cpp \ 96 ocb_utils.cpp \ 97 openssl_err.cpp \ 98 openssl_utils.cpp \ 99 operation.cpp \ 100 operation_table.cpp \ 101 rsa_key.cpp \ 102 rsa_key_factory.cpp \ 103 rsa_keymaster0_key.cpp \ 104 rsa_operation.cpp \ 105 serializable.cpp \ 106 soft_keymaster_context.cpp \ 107 soft_keymaster_device.cpp \ 108 symmetric_key.cpp 109 110 CCSRCS=$(GTEST)/src/gtest-all.cc 111 CSRCS=ocb.c 112 113 OBJS=$(CPPSRCS:.cpp=.o) $(CCSRCS:.cc=.o) $(CSRCS:.c=.o) 114 DEPS=$(CPPSRCS:.cpp=.d) $(CCSRCS:.cc=.d) $(CSRCS:.c=.d) 115 116 BINARIES = \ 117 android_keymaster_messages_test \ 118 android_keymaster_test \ 119 authorization_set_test \ 120 hkdf_test \ 121 hmac_test \ 122 key_blob_test \ 123 keymaster_enforcement_test \ 124 125 .PHONY: coverage memcheck massif clean run 126 127 %.run: % 128 ./$< 129 touch $@ 130 131 run: $(BINARIES:=.run) 132 133 coverage: coverage.info 134 genhtml coverage.info --output-directory coverage 135 136 coverage.info: run 137 lcov --capture --directory=. --output-file coverage.info 138 139 %.coverage : % 140 $(MAKE) clean && $(MAKE) $< 141 ./$< 142 lcov --capture --directory=. --output-file coverage.info 143 genhtml coverage.info --output-directory coverage 144 145 #UNINIT_OPTS=--track-origins=yes 146 UNINIT_OPTS=--undef-value-errors=no 147 148 MEMCHECK_OPTS=--leak-check=full \ 149 --show-reachable=yes \ 150 --vgdb=full \ 151 $(UNINIT_OPTS) \ 152 --error-exitcode=1 \ 153 --suppressions=valgrind.supp \ 154 --gen-suppressions=all 155 156 MASSIF_OPTS=--tool=massif \ 157 --stacks=yes 158 159 %.memcheck : % 160 valgrind $(MEMCHECK_OPTS) ./$< && \ 161 touch $@ 162 163 %.massif : % 164 valgrind $(MASSIF_OPTS) --massif-out-file=$@ ./$< 165 166 memcheck: $(BINARIES:=.memcheck) 167 168 massif: $(BINARIES:=.massif) 169 170 GTEST_OBJS = $(GTEST)/src/gtest-all.o gtest_main.o 171 172 hmac_test: hmac_test.o \ 173 android_keymaster_test_utils.o \ 174 android_keymaster_utils.o \ 175 authorization_set.o \ 176 hmac.o \ 177 logger.o \ 178 serializable.o \ 179 $(GTEST_OBJS) 180 181 hkdf_test: hkdf_test.o \ 182 android_keymaster_test_utils.o \ 183 android_keymaster_utils.o \ 184 authorization_set.o \ 185 hkdf.o \ 186 hmac.o \ 187 logger.o \ 188 serializable.o \ 189 $(GTEST_OBJS) 190 191 authorization_set_test: authorization_set_test.o \ 192 android_keymaster_test_utils.o \ 193 authorization_set.o \ 194 logger.o \ 195 serializable.o \ 196 $(GTEST_OBJS) 197 198 key_blob_test: key_blob_test.o \ 199 android_keymaster_test_utils.o \ 200 android_keymaster_utils.o \ 201 auth_encrypted_key_blob.o \ 202 authorization_set.o \ 203 integrity_assured_key_blob.o \ 204 logger.o \ 205 ocb.o \ 206 ocb_utils.o \ 207 openssl_err.o \ 208 serializable.o \ 209 $(GTEST_OBJS) 210 211 android_keymaster_messages_test: android_keymaster_messages_test.o \ 212 android_keymaster_messages.o \ 213 android_keymaster_test_utils.o \ 214 android_keymaster_utils.o \ 215 authorization_set.o \ 216 logger.o \ 217 serializable.o \ 218 $(GTEST_OBJS) 219 220 android_keymaster_test: android_keymaster_test.o \ 221 aes_key.o \ 222 aes_operation.o \ 223 android_keymaster.o \ 224 android_keymaster_messages.o \ 225 android_keymaster_test_utils.o \ 226 android_keymaster_utils.o \ 227 asymmetric_key.o \ 228 asymmetric_key_factory.o \ 229 auth_encrypted_key_blob.o \ 230 authorization_set.o \ 231 ec_key.o \ 232 ec_key_factory.o \ 233 ec_keymaster0_key.o \ 234 ecdsa_operation.o \ 235 hmac_key.o \ 236 hmac_operation.o \ 237 integrity_assured_key_blob.o \ 238 key.o \ 239 keymaster0_engine.o \ 240 keymaster_enforcement.o \ 241 logger.o \ 242 ocb.o \ 243 ocb_utils.o \ 244 openssl_err.o \ 245 openssl_utils.o \ 246 operation.o \ 247 operation_table.o \ 248 rsa_key.o \ 249 rsa_key_factory.o \ 250 rsa_keymaster0_key.o \ 251 rsa_operation.o \ 252 serializable.o \ 253 soft_keymaster_context.o \ 254 soft_keymaster_device.o \ 255 symmetric_key.o \ 256 $(BASE)/system/security/softkeymaster/keymaster_openssl.o \ 257 $(BASE)/system/security/keystore/keyblob_utils.o \ 258 $(GTEST_OBJS) 259 260 keymaster_enforcement_test: keymaster_enforcement_test.o \ 261 android_keymaster_messages.o \ 262 android_keymaster_test_utils.o \ 263 android_keymaster_utils.o \ 264 authorization_set.o \ 265 keymaster_enforcement.o \ 266 logger.o \ 267 serializable.o \ 268 $(GTEST_OBJS) 269 270 $(GTEST)/src/gtest-all.o: CXXFLAGS:=$(subst -Wmissing-declarations,,$(CXXFLAGS)) 271 272 clean: 273 rm -f $(OBJS) $(DEPS) $(BINARIES) \ 274 $(BINARIES:=.run) $(BINARIES:=.memcheck) $(BINARIES:=.massif) \ 275 *gcov *gcno *gcda coverage.info 276 rm -rf coverage 277 278 -include $(CPPSRCS:.cpp=.d) 279 -include $(CCSRCS:.cc=.d) 280 281