Makefile (14447B)
1 MBEDTLS_TEST_PATH = . 2 include ../scripts/common.make 3 4 # Set this to -v to see the details of failing test cases 5 TEST_FLAGS ?= $(if $(filter-out 0 OFF Off off NO No no FALSE False false N n,$(CTEST_OUTPUT_ON_FAILURE)),-v,) 6 7 # Also include library headers, for the sake of invasive tests. 8 LOCAL_CFLAGS += -I../library 9 10 # Enable definition of various functions used throughout the testsuite 11 # (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless 12 # on non-POSIX platforms. 13 LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L 14 15 ifdef RECORD_PSA_STATUS_COVERAGE_LOG 16 LOCAL_CFLAGS += -Werror -DRECORD_PSA_STATUS_COVERAGE_LOG 17 endif 18 19 GENERATED_BIGNUM_DATA_FILES := $(patsubst tests/%,%,$(shell \ 20 $(PYTHON) ../framework/scripts/generate_bignum_tests.py --list || \ 21 echo FAILED \ 22 )) 23 ifeq ($(GENERATED_BIGNUM_DATA_FILES),FAILED) 24 $(error "$(PYTHON) ../framework/scripts/generate_bignum_tests.py --list" failed) 25 endif 26 GENERATED_DATA_FILES += $(GENERATED_BIGNUM_DATA_FILES) 27 28 GENERATED_CONFIG_DATA_FILES := $(patsubst tests/%,%,$(shell \ 29 $(PYTHON) ../framework/scripts/generate_config_tests.py --list || \ 30 echo FAILED \ 31 )) 32 ifeq ($(GENERATED_CONFIG_DATA_FILES),FAILED) 33 $(error "$(PYTHON) ../framework/scripts/generate_config_tests.py --list" failed) 34 endif 35 GENERATED_DATA_FILES += $(GENERATED_CONFIG_DATA_FILES) 36 37 GENERATED_ECP_DATA_FILES := $(patsubst tests/%,%,$(shell \ 38 $(PYTHON) ../framework/scripts/generate_ecp_tests.py --list || \ 39 echo FAILED \ 40 )) 41 ifeq ($(GENERATED_ECP_DATA_FILES),FAILED) 42 $(error "$(PYTHON) ../framework/scripts/generate_ecp_tests.py --list" failed) 43 endif 44 GENERATED_DATA_FILES += $(GENERATED_ECP_DATA_FILES) 45 46 GENERATED_PSA_DATA_FILES := $(patsubst tests/%,%,$(shell \ 47 $(PYTHON) ../framework/scripts/generate_psa_tests.py --list || \ 48 echo FAILED \ 49 )) 50 ifeq ($(GENERATED_PSA_DATA_FILES),FAILED) 51 $(error "$(PYTHON) ../framework/scripts/generate_psa_tests.py --list" failed) 52 endif 53 GENERATED_DATA_FILES += $(GENERATED_PSA_DATA_FILES) 54 55 GENERATED_FILES = $(GENERATED_DATA_FILES) 56 GENERATED_FILES += include/test/test_keys.h include/test/test_certs.h 57 58 # Generated files needed to (fully) run ssl-opt.sh 59 .PHONY: ssl-opt 60 61 opt-testcases/handshake-generated.sh: ../framework/scripts/mbedtls_framework/tls_test_case.py 62 opt-testcases/handshake-generated.sh: ../framework/scripts/generate_tls_handshake_tests.py 63 echo " Gen $@" 64 $(PYTHON) ../framework/scripts/generate_tls_handshake_tests.py -o $@ 65 GENERATED_FILES += opt-testcases/handshake-generated.sh 66 ssl-opt: opt-testcases/handshake-generated.sh 67 68 opt-testcases/tls13-compat.sh: ../framework/scripts/generate_tls13_compat_tests.py 69 echo " Gen $@" 70 $(PYTHON) ../framework/scripts/generate_tls13_compat_tests.py -o $@ 71 GENERATED_FILES += opt-testcases/tls13-compat.sh 72 ssl-opt: opt-testcases/tls13-compat.sh 73 74 .PHONY: generated_files 75 generated_files: $(GENERATED_FILES) 76 77 # generate_bignum_tests.py and generate_psa_tests.py spend more time analyzing 78 # inputs than generating outputs. Its inputs are the same no matter which files 79 # are being generated. 80 # It's rare not to want all the outputs. So always generate all of its outputs. 81 # Use an intermediate phony dependency so that parallel builds don't run 82 # a separate instance of the recipe for each output file. 83 $(GENERATED_BIGNUM_DATA_FILES): $(gen_file_dep) generated_bignum_test_data 84 generated_bignum_test_data: ../framework/scripts/generate_bignum_tests.py 85 generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_common.py 86 generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_core.py 87 generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_mod_raw.py 88 generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_mod.py 89 generated_bignum_test_data: ../framework/scripts/mbedtls_framework/test_case.py 90 generated_bignum_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py 91 generated_bignum_test_data: 92 echo " Gen $(GENERATED_BIGNUM_DATA_FILES)" 93 $(PYTHON) ../framework/scripts/generate_bignum_tests.py 94 .SECONDARY: generated_bignum_test_data 95 96 # We deliberately omit the configuration files (mbedtls_config.h, 97 # crypto_config.h) from the depenency list because during development 98 # and on the CI, we often edit those in a way that doesn't change the 99 # output, to comment out certain options, or even to remove certain 100 # lines which do affect the output negatively (it will miss the 101 # corresponding test cases). 102 $(GENERATED_CONFIG_DATA_FILES): $(gen_file_dep) generated_config_test_data 103 generated_config_test_data: ../framework/scripts/generate_config_tests.py 104 generated_config_test_data: ../scripts/config.py 105 generated_config_test_data: ../framework/scripts/mbedtls_framework/test_case.py 106 generated_config_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py 107 generated_config_test_data: 108 echo " Gen $(GENERATED_CONFIG_DATA_FILES)" 109 $(PYTHON) ../framework/scripts/generate_config_tests.py 110 .SECONDARY: generated_config_test_data 111 112 $(GENERATED_ECP_DATA_FILES): $(gen_file_dep) generated_ecp_test_data 113 generated_ecp_test_data: ../framework/scripts/generate_ecp_tests.py 114 generated_ecp_test_data: ../framework/scripts/mbedtls_framework/bignum_common.py 115 generated_ecp_test_data: ../framework/scripts/mbedtls_framework/ecp.py 116 generated_ecp_test_data: ../framework/scripts/mbedtls_framework/test_case.py 117 generated_ecp_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py 118 generated_ecp_test_data: 119 echo " Gen $(GENERATED_ECP_DATA_FILES)" 120 $(PYTHON) ../framework/scripts/generate_ecp_tests.py 121 .SECONDARY: generated_ecp_test_data 122 123 $(GENERATED_PSA_DATA_FILES): $(gen_file_dep) generated_psa_test_data 124 generated_psa_test_data: ../framework/scripts/generate_psa_tests.py 125 generated_psa_test_data: ../framework/scripts/mbedtls_framework/crypto_data_tests.py 126 generated_psa_test_data: ../framework/scripts/mbedtls_framework/crypto_knowledge.py 127 generated_psa_test_data: ../framework/scripts/mbedtls_framework/macro_collector.py 128 generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_information.py 129 generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_storage.py 130 generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_test_case.py 131 generated_psa_test_data: ../framework/scripts/mbedtls_framework/test_case.py 132 generated_psa_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py 133 ## The generated file only depends on the options that are present in 134 ## crypto_config.h, not on which options are set. To avoid regenerating this 135 ## file all the time when switching between configurations, don't declare 136 ## crypto_config.h as a dependency. Remove this file from your working tree 137 ## if you've just added or removed an option in crypto_config.h. 138 #generated_psa_test_data: ../include/psa/crypto_config.h 139 generated_psa_test_data: ../include/psa/crypto_values.h 140 generated_psa_test_data: ../include/psa/crypto_extra.h 141 generated_psa_test_data: suites/test_suite_psa_crypto_metadata.data 142 generated_psa_test_data: 143 echo " Gen $(GENERATED_PSA_DATA_FILES) ..." 144 $(PYTHON) ../framework/scripts/generate_psa_tests.py 145 .SECONDARY: generated_psa_test_data 146 147 # A test application is built for each suites/test_suite_*.data file. 148 # Application name is same as .data file's base name and can be 149 # constructed by stripping path 'suites/' and extension .data. 150 DATA_FILES := $(wildcard suites/test_suite_*.data) 151 # Make sure that generated data files are included even if they don't 152 # exist yet when the makefile is parsed. 153 DATA_FILES += $(filter-out $(DATA_FILES),$(GENERATED_DATA_FILES)) 154 APPS = $(basename $(subst suites/,,$(DATA_FILES))) 155 156 # Construct executable name by adding OS specific suffix $(EXEXT). 157 BINARIES := $(addsuffix $(EXEXT),$(APPS)) 158 159 .SILENT: 160 161 .PHONY: all check test clean 162 163 all: $(BINARIES) 164 165 mbedtls_test: $(MBEDTLS_TEST_OBJS) 166 167 include/test/test_certs.h: ../framework/scripts/generate_test_cert_macros.py \ 168 $($(PYTHON) ../framework/scripts/generate_test_cert_macros.py --list-dependencies) 169 echo " Gen $@" 170 $(PYTHON) ../framework/scripts/generate_test_cert_macros.py --output $@ 171 172 include/test/test_keys.h: ../framework/scripts/generate_test_keys.py 173 echo " Gen $@" 174 $(PYTHON) ../framework/scripts/generate_test_keys.py --output $@ 175 176 TEST_OBJS_DEPS = $(wildcard include/test/*.h include/test/*/*.h) 177 ifdef RECORD_PSA_STATUS_COVERAGE_LOG 178 # Explicitly depend on this header because on a clean copy of the source tree, 179 # it doesn't exist yet and must be generated as part of the build, and 180 # therefore the wildcard enumeration above doesn't include it. 181 TEST_OBJS_DEPS += ../framework/tests/include/test/instrument_record_status.h 182 endif 183 TEST_OBJS_DEPS += include/test/test_certs.h include/test/test_keys.h 184 185 # Rule to compile common test C files in framework 186 ../framework/tests/src/%.o : ../framework/tests/src/%.c $(TEST_OBJS_DEPS) 187 echo " CC $<" 188 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $< 189 190 ../framework/tests/src/drivers/%.o : ../framework/tests/src/drivers/%.c 191 echo " CC $<" 192 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $< 193 194 # Rule to compile common test C files in src folder 195 src/%.o : src/%.c $(TEST_OBJS_DEPS) 196 echo " CC $<" 197 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $< 198 199 src/test_helpers/%.o : src/test_helpers/%.c 200 echo " CC $<" 201 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $< 202 203 C_FILES := $(addsuffix .c,$(APPS)) 204 c: $(C_FILES) 205 206 # Wildcard target for test code generation: 207 # A .c file is generated for each .data file in the suites/ directory. Each .c 208 # file depends on a .data and .function file from suites/ directory. Following 209 # nameing convention is followed: 210 # 211 # C file | Depends on 212 #----------------------------------------------------------------------------- 213 # foo.c | suites/foo.function suites/foo.data 214 # foo.bar.c | suites/foo.function suites/foo.bar.data 215 # 216 # Note above that .c and .data files have same base name. 217 # However, corresponding .function file's base name is the word before first 218 # dot in .c file's base name. 219 # 220 .SECONDEXPANSION: 221 %.c: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data ../framework/scripts/generate_test_code.py suites/helpers.function suites/main_test.function suites/host_test.function 222 echo " Gen $@" 223 $(PYTHON) ../framework/scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \ 224 -d suites/$*.data \ 225 -t suites/main_test.function \ 226 -p suites/host_test.function \ 227 -s suites \ 228 --helpers-file suites/helpers.function \ 229 -o . 230 231 232 $(BINARIES): %$(EXEXT): %.c $(MBEDLIBS) $(TEST_OBJS_DEPS) $(MBEDTLS_TEST_OBJS) 233 echo " CC $<" 234 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ 235 236 clean: 237 ifndef WINDOWS 238 rm -rf $(BINARIES) *.c *.datax 239 rm -f src/*.o src/test_helpers/*.o src/libmbed* 240 rm -f ../framework/tests/src/*.o ../framework/tests/src/drivers/*.o 241 rm -f ../framework/tests/include/test/instrument_record_status.h 242 rm -f ../framework/tests/include/alt-extra/*/*_alt.h 243 rm -rf libtestdriver1 244 rm -f ../library/libtestdriver1.a 245 else 246 if exist *.c del /Q /F *.c 247 if exist *.exe del /Q /F *.exe 248 if exist *.datax del /Q /F *.datax 249 if exist src/*.o del /Q /F src/*.o 250 if exist src/test_helpers/*.o del /Q /F src/test_helpers/*.o 251 if exist src/libmbed* del /Q /F src/libmbed* 252 if exist ../framework/tests/src/*.o del /Q /F ../framework/tests/src/*.o 253 if exist ../framework/tests/src/drivers/*.o del /Q /F ../framework/tests/src/drivers/*.o 254 if exist ../framework/tests/include/test/instrument_record_status.h del /Q /F ../framework/tests/include/test/instrument_record_status.h 255 endif 256 257 # Test suites caught by SKIP_TEST_SUITES are built but not executed. 258 check: $(BINARIES) 259 perl scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES) 260 261 test: check 262 263 # Generate variants of some headers for testing 264 ../framework/tests/include/alt-extra/%_alt.h: ../include/%.h 265 perl -p -e 's/^(# *(define|ifndef) +\w+_)H\b/$${1}ALT_H/' $< >$@ 266 267 # Generate test library 268 269 # Perl code that is executed to transform each original line from a library 270 # source file into the corresponding line in the test driver copy of the 271 # library. Add a LIBTESTDRIVER1_/libtestdriver1_ to mbedtls_xxx and psa_xxx 272 # symbols. 273 define libtestdriver1_rewrite := 274 s!^(\s*#\s*include\s*[\"<])(mbedtls|psa)/!$${1}libtestdriver1/include/$${2}/!; \ 275 next if /^\s*#\s*include/; \ 276 s/\b(?=MBEDTLS_|PSA_)/LIBTESTDRIVER1_/g; \ 277 s/\b(?=mbedtls_|psa_)/libtestdriver1_/g; 278 endef 279 280 libtestdriver1.a: export MBEDTLS_PATH := $(patsubst ../..//%,/%,../../$(MBEDTLS_PATH)) 281 libtestdriver1.a: 282 # Copy the library and fake a 3rdparty Makefile include. 283 rm -Rf ./libtestdriver1 284 mkdir ./libtestdriver1 285 cp -Rf ../library ./libtestdriver1 286 cp -Rf ../include ./libtestdriver1 287 cp -Rf ../scripts ./libtestdriver1 288 mkdir ./libtestdriver1/3rdparty 289 touch ./libtestdriver1/3rdparty/Makefile.inc 290 291 # Set the test driver base (minimal) configuration. 292 cp configs/config_test_driver.h ./libtestdriver1/include/mbedtls/mbedtls_config.h 293 294 # Set the PSA cryptography configuration for the test library. 295 # It is set from the copied include/psa/crypto_config.h of the Mbed TLS 296 # library the test library is intended to be linked with extended by 297 # configs/crypto_config_test_driver_extension.h to mirror the PSA_ACCEL_* 298 # macros. 299 mv ./libtestdriver1/include/psa/crypto_config.h ./libtestdriver1/include/psa/crypto_config.h.bak 300 head -n -1 ./libtestdriver1/include/psa/crypto_config.h.bak > ./libtestdriver1/include/psa/crypto_config.h 301 cat configs/crypto_config_test_driver_extension.h >> ./libtestdriver1/include/psa/crypto_config.h 302 echo "#endif /* PSA_CRYPTO_CONFIG_H */" >> ./libtestdriver1/include/psa/crypto_config.h 303 304 # Prefix MBEDTLS_* PSA_* symbols with LIBTESTDRIVER1_ as well as 305 # mbedtls_* psa_* symbols with libtestdriver1_ to avoid symbol clash 306 # when this test driver library is linked with the Mbed TLS library. 307 perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/library/*.[ch] 308 perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/include/*/*.h 309 310 $(MAKE) -C ./libtestdriver1/library CFLAGS="-I../../ $(CFLAGS)" LDFLAGS="$(LDFLAGS)" libmbedcrypto.a 311 cp ./libtestdriver1/library/libmbedcrypto.a ../library/libtestdriver1.a 312 313 ifdef RECORD_PSA_STATUS_COVERAGE_LOG 314 ../framework/tests/include/test/instrument_record_status.h: ../include/psa/crypto.h Makefile 315 echo " Gen $@" 316 sed <../include/psa/crypto.h >$@ -n 's/^psa_status_t \([A-Za-z0-9_]*\)(.*/#define \1(...) RECORD_STATUS("\1", \1(__VA_ARGS__))/p' 317 endif