blob: b6f2f8caff18920c522069692373914d43edd8be [file] [log] [blame]
Gilles Peskine570e5482024-01-02 18:11:10 +01001MBEDTLS_TEST_PATH = .
Gilles Peskinef3d1ae12023-12-22 11:40:58 +01002include ../scripts/common.make
Paul Bakker0049c2f2009-07-11 19:15:43 +00003
Gilles Peskine396853a2021-09-20 18:57:55 +02004# Set this to -v to see the details of failing test cases
5TEST_FLAGS ?= $(if $(filter-out 0 OFF Off off NO No no FALSE False false N n,$(CTEST_OUTPUT_ON_FAILURE)),-v,)
6
Ronald Cronc29afb62024-07-01 14:50:54 +02007# Also include private headers, for the sake of invasive tests.
Ronald Cron901a6752024-07-09 14:24:16 +02008LOCAL_CFLAGS += -I$(MBEDTLS_PATH)/library -I$(MBEDTLS_PATH)/tf-psa-crypto/core -I$(MBEDTLS_PATH)/tf-psa-crypto/drivers/builtin/src
Ronald Cron1451a762024-06-10 16:02:04 +02009
Nicholas Wilson61fa4362018-06-25 12:10:00 +010010# 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.
13LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
14
Gilles Peskine51681552019-05-20 19:35:37 +020015ifdef RECORD_PSA_STATUS_COVERAGE_LOG
16LOCAL_CFLAGS += -Werror -DRECORD_PSA_STATUS_COVERAGE_LOG
17endif
18
Ronald Cron901a6752024-07-09 14:24:16 +020019GENERATED_BIGNUM_DATA_FILES := $(addprefix ../tf-psa-crypto/,$(shell \
David Horstmannf6f3bca2024-05-29 17:57:08 +010020 $(PYTHON) ../framework/scripts/generate_bignum_tests.py --list || \
Werner Lewis8b2df742022-07-08 13:54:57 +010021 echo FAILED \
22))
23ifeq ($(GENERATED_BIGNUM_DATA_FILES),FAILED)
David Horstmannf6f3bca2024-05-29 17:57:08 +010024$(error "$(PYTHON) ../framework/scripts/generate_bignum_tests.py --list" failed)
Werner Lewis8b2df742022-07-08 13:54:57 +010025endif
Ronald Cron901a6752024-07-09 14:24:16 +020026GENERATED_CRYPTO_DATA_FILES += $(GENERATED_BIGNUM_DATA_FILES)
Gilles Peskineb0aa75e2024-05-23 16:38:07 +020027
Ronald Cron901a6752024-07-09 14:24:16 +020028GENERATED_CONFIG_DATA_FILES_RAW := $(patsubst tests/%,%,$(shell \
Gilles Peskinee154e6f2024-05-23 16:31:22 +020029 $(PYTHON) ../framework/scripts/generate_config_tests.py --list || \
30 echo FAILED \
31))
32ifeq ($(GENERATED_CONFIG_DATA_FILES),FAILED)
33$(error "$(PYTHON) ../framework/scripts/generate_config_tests.py --list" failed)
34endif
Ronald Cron901a6752024-07-09 14:24:16 +020035GENERATED_MBEDTLS_CONFIG_DATA_FILES := $(foreach file,$(GENERATED_CONFIG_DATA_FILES_RAW),$(if $(findstring mbedtls,$(file)),$(file),))
36GENERATED_PSA_CONFIG_DATA_FILES := $(foreach file,$(GENERATED_CONFIG_DATA_FILES_RAW),$(if $(findstring psa,$(file)),$(addprefix ../tf-psa-crypto/tests/,$(file)),))
37GENERATED_CONFIG_DATA_FILES := $(GENERATED_MBEDTLS_CONFIG_DATA_FILES)$(GENERATED_PSA_CONFIG_DATA_FILES)
38GENERATED_DATA_FILES += $(GENERATED_MBEDTLS_CONFIG_DATA_FILES)
39GENERATED_CRYPTO_DATA_FILES += $(GENERATED_PSA_CONFIG_DATA_FILES)
Gilles Peskinee154e6f2024-05-23 16:31:22 +020040
Ronald Cron901a6752024-07-09 14:24:16 +020041GENERATED_ECP_DATA_FILES := $(addprefix ../tf-psa-crypto/,$(shell \
David Horstmannf6f3bca2024-05-29 17:57:08 +010042 $(PYTHON) ../framework/scripts/generate_ecp_tests.py --list || \
Gabor Mezei95ecaaf2023-01-16 16:53:29 +010043 echo FAILED \
44))
45ifeq ($(GENERATED_ECP_DATA_FILES),FAILED)
David Horstmannf6f3bca2024-05-29 17:57:08 +010046$(error "$(PYTHON) ../framework/scripts/generate_ecp_tests.py --list" failed)
Gabor Mezei95ecaaf2023-01-16 16:53:29 +010047endif
Ronald Cron901a6752024-07-09 14:24:16 +020048GENERATED_CRYPTO_DATA_FILES += $(GENERATED_ECP_DATA_FILES)
Gilles Peskineb0aa75e2024-05-23 16:38:07 +020049
Ronald Cron901a6752024-07-09 14:24:16 +020050GENERATED_PSA_DATA_FILES := $(addprefix ../tf-psa-crypto/,$(shell \
David Horstmannf6f3bca2024-05-29 17:57:08 +010051 $(PYTHON) ../framework/scripts/generate_psa_tests.py --list || \
Gilles Peskinee9ad95a2021-07-13 18:36:05 +020052 echo FAILED \
53))
Werner Lewis8b2df742022-07-08 13:54:57 +010054ifeq ($(GENERATED_PSA_DATA_FILES),FAILED)
David Horstmannf6f3bca2024-05-29 17:57:08 +010055$(error "$(PYTHON) ../framework/scripts/generate_psa_tests.py --list" failed)
Gilles Peskinee9ad95a2021-07-13 18:36:05 +020056endif
Ronald Cron901a6752024-07-09 14:24:16 +020057GENERATED_CRYPTO_DATA_FILES += $(GENERATED_PSA_DATA_FILES)
Gilles Peskineb0aa75e2024-05-23 16:38:07 +020058
Ronald Cron901a6752024-07-09 14:24:16 +020059GENERATED_FILES = $(GENERATED_DATA_FILES) $(GENERATED_CRYPTO_DATA_FILES)
Ronald Cron27a1ac72024-12-12 11:04:03 +010060GENERATED_FILES += ../framework/tests/include/test/test_keys.h \
61 ../tf-psa-crypto/framework/tests/include/test/test_keys.h \
62 src/test_certs.h
Gilles Peskineb0aa75e2024-05-23 16:38:07 +020063
Gilles Peskine870ed2a2024-09-25 10:27:47 +020064# Generated files needed to (fully) run ssl-opt.sh
65.PHONY: ssl-opt
66
Gilles Peskine47733332025-03-01 14:28:20 +010067opt-testcases/handshake-generated.sh: ../framework/scripts/mbedtls_framework/tls_test_case.py
68opt-testcases/handshake-generated.sh: ../framework/scripts/generate_tls_handshake_tests.py
69 echo " Gen $@"
70 $(PYTHON) ../framework/scripts/generate_tls_handshake_tests.py -o $@
71GENERATED_FILES += opt-testcases/handshake-generated.sh
72ssl-opt: opt-testcases/handshake-generated.sh
73
Elena Uziunaiteb74c3ea2024-10-08 13:02:48 +010074opt-testcases/tls13-compat.sh: ../framework/scripts/generate_tls13_compat_tests.py
Gilles Peskine907e4952024-09-19 19:09:33 +020075 echo " Gen $@"
Elena Uziunaiteb74c3ea2024-10-08 13:02:48 +010076 $(PYTHON) ../framework/scripts/generate_tls13_compat_tests.py -o $@
Gilles Peskine3943a1a2024-09-13 15:57:44 +020077GENERATED_FILES += opt-testcases/tls13-compat.sh
Gilles Peskine870ed2a2024-09-25 10:27:47 +020078ssl-opt: opt-testcases/tls13-compat.sh
Gilles Peskine3943a1a2024-09-13 15:57:44 +020079
Gilles Peskineb0aa75e2024-05-23 16:38:07 +020080.PHONY: generated_files
81generated_files: $(GENERATED_FILES)
Gilles Peskine687d1ab2021-04-22 01:01:56 +020082
Werner Lewis8b2df742022-07-08 13:54:57 +010083# generate_bignum_tests.py and generate_psa_tests.py spend more time analyzing
84# inputs than generating outputs. Its inputs are the same no matter which files
85# are being generated.
Gilles Peskine5df77c62021-07-13 17:22:58 +020086# It's rare not to want all the outputs. So always generate all of its outputs.
87# Use an intermediate phony dependency so that parallel builds don't run
88# a separate instance of the recipe for each output file.
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020089$(GENERATED_BIGNUM_DATA_FILES): $(gen_file_dep) generated_bignum_test_data
David Horstmannf6f3bca2024-05-29 17:57:08 +010090generated_bignum_test_data: ../framework/scripts/generate_bignum_tests.py
David Horstmanncd84bb22024-05-03 14:36:12 +010091generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_common.py
92generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_core.py
93generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_mod_raw.py
94generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_mod.py
95generated_bignum_test_data: ../framework/scripts/mbedtls_framework/test_case.py
96generated_bignum_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py
Werner Lewis8b2df742022-07-08 13:54:57 +010097generated_bignum_test_data:
98 echo " Gen $(GENERATED_BIGNUM_DATA_FILES)"
Ronald Cron901a6752024-07-09 14:24:16 +020099 $(PYTHON) ../framework/scripts/generate_bignum_tests.py --directory ../tf-psa-crypto/tests/suites
Gilles Peskineb0aa75e2024-05-23 16:38:07 +0200100.SECONDARY: generated_bignum_test_data
Werner Lewis8b2df742022-07-08 13:54:57 +0100101
Gilles Peskinee154e6f2024-05-23 16:31:22 +0200102# We deliberately omit the configuration files (mbedtls_config.h,
103# crypto_config.h) from the depenency list because during development
104# and on the CI, we often edit those in a way that doesn't change the
105# output, to comment out certain options, or even to remove certain
106# lines which do affect the output negatively (it will miss the
107# corresponding test cases).
108$(GENERATED_CONFIG_DATA_FILES): $(gen_file_dep) generated_config_test_data
109generated_config_test_data: ../framework/scripts/generate_config_tests.py
110generated_config_test_data: ../scripts/config.py
111generated_config_test_data: ../framework/scripts/mbedtls_framework/test_case.py
112generated_config_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py
113generated_config_test_data:
114 echo " Gen $(GENERATED_CONFIG_DATA_FILES)"
Ronald Cron901a6752024-07-09 14:24:16 +0200115 $(PYTHON) ../framework/scripts/generate_config_tests.py $(GENERATED_MBEDTLS_CONFIG_DATA_FILES)
116 $(PYTHON) ../framework/scripts/generate_config_tests.py --directory ../tf-psa-crypto/tests/suites $(GENERATED_PSA_CONFIG_DATA_FILES)
Gilles Peskinee154e6f2024-05-23 16:31:22 +0200117.SECONDARY: generated_config_test_data
Werner Lewis8b2df742022-07-08 13:54:57 +0100118
Gilles Peskine0b62b7a2023-09-08 16:19:13 +0200119$(GENERATED_ECP_DATA_FILES): $(gen_file_dep) generated_ecp_test_data
David Horstmannf6f3bca2024-05-29 17:57:08 +0100120generated_ecp_test_data: ../framework/scripts/generate_ecp_tests.py
David Horstmanncd84bb22024-05-03 14:36:12 +0100121generated_ecp_test_data: ../framework/scripts/mbedtls_framework/bignum_common.py
122generated_ecp_test_data: ../framework/scripts/mbedtls_framework/ecp.py
123generated_ecp_test_data: ../framework/scripts/mbedtls_framework/test_case.py
124generated_ecp_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py
Gabor Mezei95ecaaf2023-01-16 16:53:29 +0100125generated_ecp_test_data:
126 echo " Gen $(GENERATED_ECP_DATA_FILES)"
Ronald Cron901a6752024-07-09 14:24:16 +0200127 $(PYTHON) ../framework/scripts/generate_ecp_tests.py --directory ../tf-psa-crypto/tests/suites
Gilles Peskineb0aa75e2024-05-23 16:38:07 +0200128.SECONDARY: generated_ecp_test_data
Gabor Mezei95ecaaf2023-01-16 16:53:29 +0100129
Gilles Peskine0b62b7a2023-09-08 16:19:13 +0200130$(GENERATED_PSA_DATA_FILES): $(gen_file_dep) generated_psa_test_data
David Horstmannf6f3bca2024-05-29 17:57:08 +0100131generated_psa_test_data: ../framework/scripts/generate_psa_tests.py
David Horstmanncd84bb22024-05-03 14:36:12 +0100132generated_psa_test_data: ../framework/scripts/mbedtls_framework/crypto_data_tests.py
133generated_psa_test_data: ../framework/scripts/mbedtls_framework/crypto_knowledge.py
134generated_psa_test_data: ../framework/scripts/mbedtls_framework/macro_collector.py
135generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_information.py
136generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_storage.py
Gilles Peskinea074fe42024-12-17 18:54:12 +0100137generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_test_case.py
David Horstmanncd84bb22024-05-03 14:36:12 +0100138generated_psa_test_data: ../framework/scripts/mbedtls_framework/test_case.py
139generated_psa_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py
Gilles Peskine1411c7c2021-04-22 14:50:16 +0200140## The generated file only depends on the options that are present in
141## crypto_config.h, not on which options are set. To avoid regenerating this
142## file all the time when switching between configurations, don't declare
143## crypto_config.h as a dependency. Remove this file from your working tree
144## if you've just added or removed an option in crypto_config.h.
Ronald Cronc7e9e362024-06-10 09:41:49 +0200145#generated_psa_test_data: ../tf-psa-crypto/include/psa/crypto_config.h
146generated_psa_test_data: ../tf-psa-crypto/include/psa/crypto_values.h
147generated_psa_test_data: ../tf-psa-crypto/include/psa/crypto_extra.h
Ronald Cron901a6752024-07-09 14:24:16 +0200148generated_psa_test_data: ../tf-psa-crypto/tests/suites/test_suite_psa_crypto_metadata.data
Gilles Peskine5df77c62021-07-13 17:22:58 +0200149generated_psa_test_data:
Werner Lewis8b2df742022-07-08 13:54:57 +0100150 echo " Gen $(GENERATED_PSA_DATA_FILES) ..."
Ronald Cron901a6752024-07-09 14:24:16 +0200151 $(PYTHON) ../framework/scripts/generate_psa_tests.py --directory ../tf-psa-crypto/tests/suites
Gilles Peskineb0aa75e2024-05-23 16:38:07 +0200152.SECONDARY: generated_psa_test_data
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200153
Azim Khan27a35e72018-06-29 12:39:19 +0100154# A test application is built for each suites/test_suite_*.data file.
155# Application name is same as .data file's base name and can be
156# constructed by stripping path 'suites/' and extension .data.
Ronald Cron901a6752024-07-09 14:24:16 +0200157DATA_FILES = $(filter-out $(GENERATED_DATA_FILES), $(wildcard suites/test_suite_*.data))
158CRYPTO_DATA_FILES = $(filter-out $(GENERATED_CRYPTO_DATA_FILES), $(wildcard ../tf-psa-crypto/tests/suites/test_suite_*.data))
159
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200160# Make sure that generated data files are included even if they don't
161# exist yet when the makefile is parsed.
Ronald Cron901a6752024-07-09 14:24:16 +0200162DATA_FILES += $(GENERATED_DATA_FILES)
163CRYPTO_DATA_FILES += $(GENERATED_CRYPTO_DATA_FILES)
164
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200165APPS = $(basename $(subst suites/,,$(DATA_FILES)))
Ronald Cron901a6752024-07-09 14:24:16 +0200166CRYPTO_APPS = $(basename $(subst suites/,,$(CRYPTO_DATA_FILES)))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000167
Azim Khan27a35e72018-06-29 12:39:19 +0100168# Construct executable name by adding OS specific suffix $(EXEXT).
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000169BINARIES := $(addsuffix $(EXEXT),$(APPS))
Ronald Cron901a6752024-07-09 14:24:16 +0200170CRYPTO_BINARIES := $(addsuffix $(EXEXT),$(CRYPTO_APPS))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000171
Paul Bakker0049c2f2009-07-11 19:15:43 +0000172.SILENT:
173
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200174.PHONY: all check test clean
175
Ronald Cron901a6752024-07-09 14:24:16 +0200176all: $(BINARIES) $(CRYPTO_BINARIES)
Azim Khan1de892b2017-06-09 15:02:36 +0100177
Ronald Cronddaf99c2020-06-19 11:27:26 +0200178mbedtls_test: $(MBEDTLS_TEST_OBJS)
179
David Horstmannf6f3bca2024-05-29 17:57:08 +0100180src/test_certs.h: ../framework/scripts/generate_test_cert_macros.py \
181 $($(PYTHON) ../framework/scripts/generate_test_cert_macros.py --list-dependencies)
Gilles Peskine907e4952024-09-19 19:09:33 +0200182 echo " Gen $@"
David Horstmannf6f3bca2024-05-29 17:57:08 +0100183 $(PYTHON) ../framework/scripts/generate_test_cert_macros.py --output $@
Valerio Setti8284f3d2024-04-08 17:52:12 +0200184
Ronald Cronf6eee5a2024-12-09 09:10:51 +0100185../framework/tests/include/test/test_keys.h: ../framework/scripts/generate_test_keys.py
Gilles Peskine907e4952024-09-19 19:09:33 +0200186 echo " Gen $@"
David Horstmannf6f3bca2024-05-29 17:57:08 +0100187 $(PYTHON) ../framework/scripts/generate_test_keys.py --output $@
Valerio Setti8284f3d2024-04-08 17:52:12 +0200188
Ronald Cron27a1ac72024-12-12 11:04:03 +0100189../tf-psa-crypto/framework/tests/include/test/test_keys.h: ../tf-psa-crypto/framework/scripts/generate_test_keys.py
190 echo " Gen $@"
191 $(PYTHON) ../tf-psa-crypto/framework/scripts/generate_test_keys.py --output $@
192
Gilles Peskinee1d51bd2021-01-20 19:47:23 +0100193TEST_OBJS_DEPS = $(wildcard include/test/*.h include/test/*/*.h)
Gilles Peskined71539f2020-11-25 18:17:17 +0100194ifdef RECORD_PSA_STATUS_COVERAGE_LOG
Gilles Peskine75829a42021-01-25 13:46:14 +0100195# Explicitly depend on this header because on a clean copy of the source tree,
196# it doesn't exist yet and must be generated as part of the build, and
197# therefore the wildcard enumeration above doesn't include it.
David Horstmannd9626802024-11-08 10:59:21 +0000198TEST_OBJS_DEPS += ../framework/tests/include/test/instrument_record_status.h
Gilles Peskined71539f2020-11-25 18:17:17 +0100199endif
Ronald Cron27a1ac72024-12-12 11:04:03 +0100200TEST_OBJS_DEPS += src/test_certs.h ../framework/tests/include/test/test_keys.h \
201 ../tf-psa-crypto/framework/tests/include/test/test_keys.h
Gilles Peskined71539f2020-11-25 18:17:17 +0100202
David Horstmann69b12ee2024-11-05 14:45:50 +0000203# Rule to compile common test C files in framework
204../framework/tests/src/%.o : ../framework/tests/src/%.c $(TEST_OBJS_DEPS)
Ronald Cronb6d6d4c2020-06-03 10:11:18 +0200205 echo " CC $<"
206 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
207
David Horstmann69b12ee2024-11-05 14:45:50 +0000208../framework/tests/src/drivers/%.o : ../framework/tests/src/drivers/%.c
209 echo " CC $<"
210 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
211
212# Rule to compile common test C files in src folder
213src/%.o : src/%.c $(TEST_OBJS_DEPS)
Steven Cooremana70d5882020-07-16 20:26:18 +0200214 echo " CC $<"
215 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
216
Yanray Wangb458b8c2022-10-28 11:49:33 +0800217src/test_helpers/%.o : src/test_helpers/%.c
218 echo " CC $<"
219 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
220
Ronald Cron901a6752024-07-09 14:24:16 +0200221C_FILES := $(addsuffix .c,$(APPS)) $(addsuffix .c,$(CRYPTO_APPS))
Gilles Peskine1d7cc082022-11-10 19:50:34 +0100222c: $(C_FILES)
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000223
Azim Khan27a35e72018-06-29 12:39:19 +0100224# Wildcard target for test code generation:
225# A .c file is generated for each .data file in the suites/ directory. Each .c
226# file depends on a .data and .function file from suites/ directory. Following
227# nameing convention is followed:
228#
229# C file | Depends on
230#-----------------------------------------------------------------------------
231# foo.c | suites/foo.function suites/foo.data
232# foo.bar.c | suites/foo.function suites/foo.bar.data
233#
234# Note above that .c and .data files have same base name.
235# However, corresponding .function file's base name is the word before first
236# dot in .c file's base name.
237#
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000238.SECONDEXPANSION:
Ronald Cron901a6752024-07-09 14:24:16 +0200239
Gilles Peskine88a6baa2024-08-08 14:07:24 +0200240# First handle the tf-psa-crypto case, which has different paths from
241# the local case. In GNU Make >=3.82, the shortest match applies regardless
242# of the order in the makefile. In GNU Make <=3.81, the first matching rule
243# applies.
Ronald Cron901a6752024-07-09 14:24:16 +0200244../tf-psa-crypto/tests/%.c: ../tf-psa-crypto/tests/suites/$$(firstword $$(subst ., ,$$*)).function ../tf-psa-crypto/tests/suites/%.data ../framework/scripts/generate_test_code.py ../tf-psa-crypto/tests/suites/helpers.function ../tf-psa-crypto/tests/suites/main_test.function ../tf-psa-crypto/tests/suites/host_test.function
245 echo " Gen $@"
246 cd ../tf-psa-crypto/tests && $(PYTHON) ../../framework/scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
247 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100248 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100249 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100250 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100251 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100252 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200253
Gilles Peskine88a6baa2024-08-08 14:07:24 +0200254%.c: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data ../framework/scripts/generate_test_code.py ../tf-psa-crypto/tests/suites/helpers.function ../tf-psa-crypto/tests/suites/main_test.function ../tf-psa-crypto/tests/suites/host_test.function
255 echo " Gen $@"
256 $(PYTHON) ../framework/scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
257 -d suites/$*.data \
258 -t ../tf-psa-crypto/tests/suites/main_test.function \
259 -p ../tf-psa-crypto/tests/suites/host_test.function \
260 -s suites \
261 --helpers-file ../tf-psa-crypto/tests/suites/helpers.function \
262 -o .
263
Gilles Peskined71539f2020-11-25 18:17:17 +0100264$(BINARIES): %$(EXEXT): %.c $(MBEDLIBS) $(TEST_OBJS_DEPS) $(MBEDTLS_TEST_OBJS)
Ronald Cron901a6752024-07-09 14:24:16 +0200265 echo " CC $<"
Gilles Peskine4ad57332023-12-22 11:30:30 +0100266 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200267
David Horstmann1b457a92024-11-04 15:53:42 +0000268LOCAL_CRYPTO_CFLAGS = $(patsubst -I./include, -I../../tests/include, $(patsubst -I../%,-I../../%, $(LOCAL_CFLAGS)))
Ronald Cron901a6752024-07-09 14:24:16 +0200269LOCAL_CRYPTO_LDFLAGS = $(patsubst -L../library, -L../../library, \
270 $(patsubst -L../tests/%, -L../../tests/%, \
David Horstmanncbab2ff2024-11-05 15:10:56 +0000271 $(patsubst ./src/%,../../tests/src/%, \
David Horstmanned91f882024-11-19 17:15:30 +0000272 $(patsubst ../framework/tests/src/%,../../framework/tests/src/%, \
David Horstmanncbab2ff2024-11-05 15:10:56 +0000273 $(LOCAL_LDFLAGS)))))
Ronald Cron901a6752024-07-09 14:24:16 +0200274$(CRYPTO_BINARIES): %$(EXEXT): %.c $(MBEDLIBS) $(TEST_OBJS_DEPS) $(MBEDTLS_TEST_OBJS)
275 echo " CC $<"
276 cd ../tf-psa-crypto/tests && $(CC) $(LOCAL_CRYPTO_CFLAGS) $(CFLAGS) $(subst $(EXEXT),,$(@F)).c $(LOCAL_CRYPTO_LDFLAGS) $(LDFLAGS) -o $(@F)
277
Paul Bakker0049c2f2009-07-11 19:15:43 +0000278clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000279ifndef WINDOWS
Valerio Setti09172652024-06-27 08:00:54 +0200280 $(MAKE) -C psa-client-server/psasim clean
Gilles Peskined0254222021-09-14 11:28:22 +0200281 rm -rf $(BINARIES) *.c *.datax
Ronald Cron901a6752024-07-09 14:24:16 +0200282 rm -rf $(CRYPTO_BINARIES) ../tf-psa-crypto/tests/*.c ../tf-psa-crypto/tests/*.datax
David Horstmann8a8d56a2024-11-06 15:53:14 +0000283 rm -f src/*.o src/test_helpers/*.o src/libmbed*
284 rm -f ../framework/tests/src/*.o ../framework/tests/src/drivers/*.o
David Horstmann07712532024-11-13 10:45:42 +0000285 rm -f ../framework/tests/include/test/instrument_record_status.h
David Horstmanndc459512024-11-07 17:08:11 +0000286 rm -f ../framework/tests/include/alt-extra/*/*_alt.h
Ronald Cron72b25da2021-04-28 18:29:24 +0200287 rm -rf libtestdriver1
Valerio Settid1b6ef12024-05-07 16:00:21 +0200288 rm -rf libpsaclient libpsaserver
Manuel Pégourié-Gonnard85101052022-12-29 16:04:35 +0100289 rm -f ../library/libtestdriver1.a
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200290else
Darryl Green6c0f94c2018-10-17 16:12:33 +0100291 if exist *.c del /Q /F *.c
292 if exist *.exe del /Q /F *.exe
293 if exist *.datax del /Q /F *.datax
Ronald Cron901a6752024-07-09 14:24:16 +0200294 if exist ../tf-psa-crypto/tests/*.c del /Q /F ../tf-psa-crypto/tests/*.c
295 if exist ../tf-psa-crypto/tests/*.exe del /Q /F ../tf-psa-crypto/tests/*.exe
296 if exist ../tf-psa-crypto/tests/*.datax del /Q /F ../tf-psa-crypto/tests/*.datax
Ronald Cronb6d6d4c2020-06-03 10:11:18 +0200297 if exist src/*.o del /Q /F src/*.o
Yanray Wangb458b8c2022-10-28 11:49:33 +0800298 if exist src/test_helpers/*.o del /Q /F src/test_helpers/*.o
David Horstmanndcc78ee2024-08-28 16:28:46 +0100299 if exist src/libmbed* del /Q /F src/libmbed*
David Horstmann8a8d56a2024-11-06 15:53:14 +0000300 if exist ../framework/tests/src/*.o del /Q /F ../framework/tests/src/*.o
301 if exist ../framework/tests/src/drivers/*.o del /Q /F ../framework/tests/src/drivers/*.o
David Horstmann07712532024-11-13 10:45:42 +0000302 if exist ../framework/tests/include/test/instrument_record_status.h del /Q /F ../framework/tests/include/test/instrument_record_status.h
Azim Khan27a35e72018-06-29 12:39:19 +0100303endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000304
Gilles Peskineac372cc2018-11-29 10:15:06 +0000305# Test suites caught by SKIP_TEST_SUITES are built but not executed.
Ronald Cron901a6752024-07-09 14:24:16 +0200306check: $(BINARIES) $(CRYPTO_BINARIES)
Gilles Peskine396853a2021-09-20 18:57:55 +0200307 perl scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200308
309test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000310
Gilles Peskinedf6e84a2023-02-22 22:09:51 +0100311# Generate variants of some headers for testing
David Horstmanndc459512024-11-07 17:08:11 +0000312../framework/tests/include/alt-extra/%_alt.h: ../include/%.h
Gilles Peskinedf6e84a2023-02-22 22:09:51 +0100313 perl -p -e 's/^(# *(define|ifndef) +\w+_)H\b/$${1}ALT_H/' $< >$@
David Horstmanndc459512024-11-07 17:08:11 +0000314../framework/tests/include/alt-extra/%_alt.h: ../tf-psa-crypto/include/%.h
Ronald Cronc7e9e362024-06-10 09:41:49 +0200315 perl -p -e 's/^(# *(define|ifndef) +\w+_)H\b/$${1}ALT_H/' $< >$@
David Horstmanndc459512024-11-07 17:08:11 +0000316../framework/tests/include/alt-extra/%_alt.h: ../tf-psa-crypto/drivers/builtin/include/%.h
Ronald Cron3d817ad2024-06-14 08:43:28 +0200317 perl -p -e 's/^(# *(define|ifndef) +\w+_)H\b/$${1}ALT_H/' $< >$@
Gilles Peskinedf6e84a2023-02-22 22:09:51 +0100318
Ronald Cron72b25da2021-04-28 18:29:24 +0200319# Generate test library
320
321# Perl code that is executed to transform each original line from a library
322# source file into the corresponding line in the test driver copy of the
323# library. Add a LIBTESTDRIVER1_/libtestdriver1_ to mbedtls_xxx and psa_xxx
324# symbols.
325define libtestdriver1_rewrite :=
Ronald Cron52cc8582024-06-17 17:26:39 +0200326 s!^(\s*#\s*include\s*[\"<])mbedtls/build_info.h!$${1}libtestdriver1/include/mbedtls/build_info.h!; \
327 s!^(\s*#\s*include\s*[\"<])mbedtls/mbedtls_config.h!$${1}libtestdriver1/include/mbedtls/mbedtls_config.h!; \
Ronald Cron52cc8582024-06-17 17:26:39 +0200328 s!^(\s*#\s*include\s*[\"<])mbedtls/config_adjust_x509.h!$${1}libtestdriver1/include/mbedtls/config_adjust_x509.h!; \
329 s!^(\s*#\s*include\s*[\"<])mbedtls/config_adjust_ssl.h!$${1}libtestdriver1/include/mbedtls/config_adjust_ssl.h!; \
330 s!^(\s*#\s*include\s*[\"<])mbedtls/check_config.h!$${1}libtestdriver1/include/mbedtls/check_config.h!; \
331 s!^(\s*#\s*include\s*[\"<])mbedtls/!$${1}libtestdriver1/tf-psa-crypto/drivers/builtin/include/mbedtls/!; \
Ronald Cron1451a762024-06-10 16:02:04 +0200332 s!^(\s*#\s*include\s*[\"<])psa/!$${1}libtestdriver1/tf-psa-crypto/include/psa/!; \
Ronald Cronf6d17ca2024-11-06 14:11:15 +0100333 s!^(\s*#\s*include\s*[\"<])tf-psa-crypto/!$${1}libtestdriver1/tf-psa-crypto/include/tf-psa-crypto/!; \
Ronald Cron72b25da2021-04-28 18:29:24 +0200334 next if /^\s*#\s*include/; \
Ronald Cronf6d17ca2024-11-06 14:11:15 +0100335 s/\b(?=MBEDTLS_|PSA_|TF_PSA_CRYPTO_)/LIBTESTDRIVER1_/g; \
336 s/\b(?=mbedtls_|psa_|tf_psa_crypto_)/libtestdriver1_/g;
Ronald Cron72b25da2021-04-28 18:29:24 +0200337endef
338
339libtestdriver1.a:
Ronald Cron72b25da2021-04-28 18:29:24 +0200340 rm -Rf ./libtestdriver1
341 mkdir ./libtestdriver1
Ronald Croncec78c32024-12-05 11:01:06 +0100342 mkdir ./libtestdriver1/framework
Ronald Cron4cc77a12024-07-02 08:52:26 +0200343 mkdir ./libtestdriver1/tf-psa-crypto
344 mkdir ./libtestdriver1/tf-psa-crypto/drivers
345 mkdir ./libtestdriver1/tf-psa-crypto/drivers/everest
346 mkdir ./libtestdriver1/tf-psa-crypto/drivers/p256-m
347 touch ./libtestdriver1/tf-psa-crypto/drivers/everest/Makefile.inc
348 touch ./libtestdriver1/tf-psa-crypto/drivers/p256-m/Makefile.inc
Ronald Croncec78c32024-12-05 11:01:06 +0100349 cp -Rf ../framework/scripts ./libtestdriver1/framework
Ronald Cron72b25da2021-04-28 18:29:24 +0200350 cp -Rf ../library ./libtestdriver1
351 cp -Rf ../include ./libtestdriver1
Ronald Cron6a2cbe72024-11-13 09:20:30 +0100352 cp -Rf ../scripts ./libtestdriver1
Ronald Cron4cc77a12024-07-02 08:52:26 +0200353 cp -Rf ../tf-psa-crypto/core ./libtestdriver1/tf-psa-crypto
354 cp -Rf ../tf-psa-crypto/include ./libtestdriver1/tf-psa-crypto
355 cp -Rf ../tf-psa-crypto/drivers/builtin ./libtestdriver1/tf-psa-crypto/drivers
Ronald Cron6a2cbe72024-11-13 09:20:30 +0100356 cp -Rf ../tf-psa-crypto/scripts ./libtestdriver1/tf-psa-crypto
Ronald Cron72b25da2021-04-28 18:29:24 +0200357
358 # Set the test driver base (minimal) configuration.
Ronald Crone0ebf552024-11-19 14:59:09 +0100359 cp ../tf-psa-crypto/tests/configs/config_test_driver.h ./libtestdriver1/include/mbedtls/mbedtls_config.h
Minos Galanakis23452f52024-11-28 17:48:14 +0000360 cp ../tf-psa-crypto/tests/configs/crypto_config_test_driver.h ./libtestdriver1/tf-psa-crypto/include/psa/crypto_config.h
Ronald Cron72b25da2021-04-28 18:29:24 +0200361
362 # Set the PSA cryptography configuration for the test library.
Minos Galanakis23452f52024-11-28 17:48:14 +0000363 # The configuration is created by joining the base
364 # ../tf-psa-crypto/tests/configs/crypto_config_test_driver.h,
365 # with the the library's PSA_WANT_* macros extracted from
366 # ./tf-psa-crypto/include/psa/crypto_config.h
367 # and then extended with entries of
368 # ../tf-psa-crypto/tests/configs/crypto_config_test_driver_extension.h
369 # to mirror the PSA_ACCEL_* macros.
370
Ronald Cron1451a762024-06-10 16:02:04 +0200371 mv ./libtestdriver1/tf-psa-crypto/include/psa/crypto_config.h ./libtestdriver1/tf-psa-crypto/include/psa/crypto_config.h.bak
372 head -n -1 ./libtestdriver1/tf-psa-crypto/include/psa/crypto_config.h.bak > ./libtestdriver1/tf-psa-crypto/include/psa/crypto_config.h
Minos Galanakis23452f52024-11-28 17:48:14 +0000373 grep '^#define PSA_WANT_*' ../tf-psa-crypto/include/psa/crypto_config.h >> ./libtestdriver1/tf-psa-crypto/include/psa/crypto_config.h
Ronald Crone0ebf552024-11-19 14:59:09 +0100374 cat ../tf-psa-crypto/tests/configs/crypto_config_test_driver_extension.h >> ./libtestdriver1/tf-psa-crypto/include/psa/crypto_config.h
Ronald Cron1451a762024-06-10 16:02:04 +0200375 echo "#endif /* PSA_CRYPTO_CONFIG_H */" >> ./libtestdriver1/tf-psa-crypto/include/psa/crypto_config.h
Ronald Cron72b25da2021-04-28 18:29:24 +0200376
377 # Prefix MBEDTLS_* PSA_* symbols with LIBTESTDRIVER1_ as well as
378 # mbedtls_* psa_* symbols with libtestdriver1_ to avoid symbol clash
379 # when this test driver library is linked with the Mbed TLS library.
380 perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/library/*.[ch]
381 perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/include/*/*.h
Ronald Cronb2bdb782024-07-02 07:59:11 +0200382 perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/tf-psa-crypto/core/*.[ch]
Ronald Cron1451a762024-06-10 16:02:04 +0200383 perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/tf-psa-crypto/include/*/*.h
Ronald Cron52cc8582024-06-17 17:26:39 +0200384 perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/tf-psa-crypto/drivers/builtin/include/*/*.h
Ronald Cronb2bdb782024-07-02 07:59:11 +0200385 perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/tf-psa-crypto/drivers/builtin/src/*.[ch]
Ronald Cron72b25da2021-04-28 18:29:24 +0200386
387 $(MAKE) -C ./libtestdriver1/library CFLAGS="-I../../ $(CFLAGS)" LDFLAGS="$(LDFLAGS)" libmbedcrypto.a
388 cp ./libtestdriver1/library/libmbedcrypto.a ../library/libtestdriver1.a
389
Gilles Peskine51681552019-05-20 19:35:37 +0200390ifdef RECORD_PSA_STATUS_COVERAGE_LOG
David Horstmannd9626802024-11-08 10:59:21 +0000391../framework/tests/include/test/instrument_record_status.h: ../tf-psa-crypto/include/psa/crypto.h Makefile
Gilles Peskined71539f2020-11-25 18:17:17 +0100392 echo " Gen $@"
Ronald Cronc7e9e362024-06-10 09:41:49 +0200393 sed <../tf-psa-crypto/include/psa/crypto.h >$@ -n 's/^psa_status_t \([A-Za-z0-9_]*\)(.*/#define \1(...) RECORD_STATUS("\1", \1(__VA_ARGS__))/p'
Gilles Peskine51681552019-05-20 19:35:37 +0200394endif