blob: 103c4fe9dbe8c0811d01538b62426440d25bda92 [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
Gilles Peskinef5c5ce72023-12-22 11:36:53 +01007# Also include library headers, for the sake of invasive tests.
8LOCAL_CFLAGS += -I../library
Paul Bakker0049c2f2009-07-11 19:15:43 +00009
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
Werner Lewis8b2df742022-07-08 13:54:57 +010019GENERATED_BIGNUM_DATA_FILES := $(patsubst tests/%,%,$(shell \
David Horstmannea091522024-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 Horstmannea091522024-05-29 17:57:08 +010024$(error "$(PYTHON) ../framework/scripts/generate_bignum_tests.py --list" failed)
Werner Lewis8b2df742022-07-08 13:54:57 +010025endif
Gilles Peskine26d279e2024-05-23 16:38:07 +020026GENERATED_DATA_FILES += $(GENERATED_BIGNUM_DATA_FILES)
27
Gilles Peskine06fb1802024-05-23 16:31:22 +020028GENERATED_CONFIG_DATA_FILES := $(patsubst tests/%,%,$(shell \
29 $(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
35GENERATED_DATA_FILES += $(GENERATED_CONFIG_DATA_FILES)
36
Gabor Mezei95ecaaf2023-01-16 16:53:29 +010037GENERATED_ECP_DATA_FILES := $(patsubst tests/%,%,$(shell \
David Horstmannea091522024-05-29 17:57:08 +010038 $(PYTHON) ../framework/scripts/generate_ecp_tests.py --list || \
Gabor Mezei95ecaaf2023-01-16 16:53:29 +010039 echo FAILED \
40))
41ifeq ($(GENERATED_ECP_DATA_FILES),FAILED)
David Horstmannea091522024-05-29 17:57:08 +010042$(error "$(PYTHON) ../framework/scripts/generate_ecp_tests.py --list" failed)
Gabor Mezei95ecaaf2023-01-16 16:53:29 +010043endif
Gilles Peskine26d279e2024-05-23 16:38:07 +020044GENERATED_DATA_FILES += $(GENERATED_ECP_DATA_FILES)
45
Werner Lewis8b2df742022-07-08 13:54:57 +010046GENERATED_PSA_DATA_FILES := $(patsubst tests/%,%,$(shell \
David Horstmannea091522024-05-29 17:57:08 +010047 $(PYTHON) ../framework/scripts/generate_psa_tests.py --list || \
Gilles Peskinee9ad95a2021-07-13 18:36:05 +020048 echo FAILED \
49))
Werner Lewis8b2df742022-07-08 13:54:57 +010050ifeq ($(GENERATED_PSA_DATA_FILES),FAILED)
David Horstmannea091522024-05-29 17:57:08 +010051$(error "$(PYTHON) ../framework/scripts/generate_psa_tests.py --list" failed)
Gilles Peskinee9ad95a2021-07-13 18:36:05 +020052endif
Gilles Peskine26d279e2024-05-23 16:38:07 +020053GENERATED_DATA_FILES += $(GENERATED_PSA_DATA_FILES)
54
55GENERATED_FILES = $(GENERATED_DATA_FILES)
Ronald Cronf810d442025-02-14 15:43:22 +010056GENERATED_FILES += include/test/test_keys.h include/test/test_certs.h
Gilles Peskine26d279e2024-05-23 16:38:07 +020057
Gilles Peskineae7e1c72024-09-25 10:27:47 +020058# Generated files needed to (fully) run ssl-opt.sh
59.PHONY: ssl-opt
60
Gilles Peskine28f953c2025-03-01 14:28:20 +010061opt-testcases/handshake-generated.sh: ../framework/scripts/mbedtls_framework/tls_test_case.py
62opt-testcases/handshake-generated.sh: ../framework/scripts/generate_tls_handshake_tests.py
63 echo " Gen $@"
64 $(PYTHON) ../framework/scripts/generate_tls_handshake_tests.py -o $@
65GENERATED_FILES += opt-testcases/handshake-generated.sh
66ssl-opt: opt-testcases/handshake-generated.sh
67
Elena Uziunaite1d8a2252024-10-08 13:02:48 +010068opt-testcases/tls13-compat.sh: ../framework/scripts/generate_tls13_compat_tests.py
Gilles Peskine8ca70ac2024-09-19 19:09:33 +020069 echo " Gen $@"
Elena Uziunaite1d8a2252024-10-08 13:02:48 +010070 $(PYTHON) ../framework/scripts/generate_tls13_compat_tests.py -o $@
Gilles Peskine0e9ba082024-09-13 15:57:44 +020071GENERATED_FILES += opt-testcases/tls13-compat.sh
Gilles Peskineae7e1c72024-09-25 10:27:47 +020072ssl-opt: opt-testcases/tls13-compat.sh
Gilles Peskine0e9ba082024-09-13 15:57:44 +020073
Gilles Peskine26d279e2024-05-23 16:38:07 +020074.PHONY: generated_files
75generated_files: $(GENERATED_FILES)
Gilles Peskine687d1ab2021-04-22 01:01:56 +020076
Werner Lewis8b2df742022-07-08 13:54:57 +010077# 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.
Gilles Peskine5df77c62021-07-13 17:22:58 +020080# 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.
Gilles Peskine0b62b7a2023-09-08 16:19:13 +020083$(GENERATED_BIGNUM_DATA_FILES): $(gen_file_dep) generated_bignum_test_data
David Horstmannea091522024-05-29 17:57:08 +010084generated_bignum_test_data: ../framework/scripts/generate_bignum_tests.py
David Horstmann9638ca32024-05-03 14:36:12 +010085generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_common.py
86generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_core.py
87generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_mod_raw.py
88generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_mod.py
89generated_bignum_test_data: ../framework/scripts/mbedtls_framework/test_case.py
90generated_bignum_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py
Werner Lewis8b2df742022-07-08 13:54:57 +010091generated_bignum_test_data:
92 echo " Gen $(GENERATED_BIGNUM_DATA_FILES)"
David Horstmannea091522024-05-29 17:57:08 +010093 $(PYTHON) ../framework/scripts/generate_bignum_tests.py
Gilles Peskine26d279e2024-05-23 16:38:07 +020094.SECONDARY: generated_bignum_test_data
Werner Lewis8b2df742022-07-08 13:54:57 +010095
Gilles Peskine06fb1802024-05-23 16:31:22 +020096# 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
103generated_config_test_data: ../framework/scripts/generate_config_tests.py
104generated_config_test_data: ../scripts/config.py
105generated_config_test_data: ../framework/scripts/mbedtls_framework/test_case.py
106generated_config_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py
107generated_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
Gilles Peskine0b62b7a2023-09-08 16:19:13 +0200112$(GENERATED_ECP_DATA_FILES): $(gen_file_dep) generated_ecp_test_data
David Horstmannea091522024-05-29 17:57:08 +0100113generated_ecp_test_data: ../framework/scripts/generate_ecp_tests.py
David Horstmann9638ca32024-05-03 14:36:12 +0100114generated_ecp_test_data: ../framework/scripts/mbedtls_framework/bignum_common.py
115generated_ecp_test_data: ../framework/scripts/mbedtls_framework/ecp.py
116generated_ecp_test_data: ../framework/scripts/mbedtls_framework/test_case.py
117generated_ecp_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py
Gabor Mezei95ecaaf2023-01-16 16:53:29 +0100118generated_ecp_test_data:
119 echo " Gen $(GENERATED_ECP_DATA_FILES)"
David Horstmannea091522024-05-29 17:57:08 +0100120 $(PYTHON) ../framework/scripts/generate_ecp_tests.py
Gilles Peskine26d279e2024-05-23 16:38:07 +0200121.SECONDARY: generated_ecp_test_data
Gabor Mezei95ecaaf2023-01-16 16:53:29 +0100122
Gilles Peskine0b62b7a2023-09-08 16:19:13 +0200123$(GENERATED_PSA_DATA_FILES): $(gen_file_dep) generated_psa_test_data
David Horstmannea091522024-05-29 17:57:08 +0100124generated_psa_test_data: ../framework/scripts/generate_psa_tests.py
David Horstmann9638ca32024-05-03 14:36:12 +0100125generated_psa_test_data: ../framework/scripts/mbedtls_framework/crypto_data_tests.py
126generated_psa_test_data: ../framework/scripts/mbedtls_framework/crypto_knowledge.py
127generated_psa_test_data: ../framework/scripts/mbedtls_framework/macro_collector.py
128generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_information.py
129generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_storage.py
Gilles Peskineedb89ff2024-11-21 22:11:44 +0100130generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_test_case.py
David Horstmann9638ca32024-05-03 14:36:12 +0100131generated_psa_test_data: ../framework/scripts/mbedtls_framework/test_case.py
132generated_psa_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py
Gilles Peskine1411c7c2021-04-22 14:50:16 +0200133## 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.
Gilles Peskine5df77c62021-07-13 17:22:58 +0200138#generated_psa_test_data: ../include/psa/crypto_config.h
139generated_psa_test_data: ../include/psa/crypto_values.h
140generated_psa_test_data: ../include/psa/crypto_extra.h
141generated_psa_test_data: suites/test_suite_psa_crypto_metadata.data
142generated_psa_test_data:
Werner Lewis8b2df742022-07-08 13:54:57 +0100143 echo " Gen $(GENERATED_PSA_DATA_FILES) ..."
David Horstmannea091522024-05-29 17:57:08 +0100144 $(PYTHON) ../framework/scripts/generate_psa_tests.py
Gilles Peskine26d279e2024-05-23 16:38:07 +0200145.SECONDARY: generated_psa_test_data
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200146
Azim Khan27a35e72018-06-29 12:39:19 +0100147# 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.
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200150DATA_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.
Gilles Peskine26d279e2024-05-23 16:38:07 +0200153DATA_FILES += $(filter-out $(DATA_FILES),$(GENERATED_DATA_FILES))
Gilles Peskine687d1ab2021-04-22 01:01:56 +0200154APPS = $(basename $(subst suites/,,$(DATA_FILES)))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000155
Azim Khan27a35e72018-06-29 12:39:19 +0100156# Construct executable name by adding OS specific suffix $(EXEXT).
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000157BINARIES := $(addsuffix $(EXEXT),$(APPS))
158
Paul Bakker0049c2f2009-07-11 19:15:43 +0000159.SILENT:
160
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200161.PHONY: all check test clean
162
Azim Khan1de892b2017-06-09 15:02:36 +0100163all: $(BINARIES)
164
Ronald Cronddaf99c2020-06-19 11:27:26 +0200165mbedtls_test: $(MBEDTLS_TEST_OBJS)
166
Ronald Cronf810d442025-02-14 15:43:22 +0100167include/test/test_certs.h: ../framework/scripts/generate_test_cert_macros.py \
David Horstmannea091522024-05-29 17:57:08 +0100168 $($(PYTHON) ../framework/scripts/generate_test_cert_macros.py --list-dependencies)
Gilles Peskine8ca70ac2024-09-19 19:09:33 +0200169 echo " Gen $@"
David Horstmannea091522024-05-29 17:57:08 +0100170 $(PYTHON) ../framework/scripts/generate_test_cert_macros.py --output $@
Valerio Settia607a1b2024-04-08 17:52:12 +0200171
Ronald Cronf810d442025-02-14 15:43:22 +0100172include/test/test_keys.h: ../framework/scripts/generate_test_keys.py
Gilles Peskine8ca70ac2024-09-19 19:09:33 +0200173 echo " Gen $@"
David Horstmannea091522024-05-29 17:57:08 +0100174 $(PYTHON) ../framework/scripts/generate_test_keys.py --output $@
Valerio Settia607a1b2024-04-08 17:52:12 +0200175
Gilles Peskinee1d51bd2021-01-20 19:47:23 +0100176TEST_OBJS_DEPS = $(wildcard include/test/*.h include/test/*/*.h)
Gilles Peskined71539f2020-11-25 18:17:17 +0100177ifdef RECORD_PSA_STATUS_COVERAGE_LOG
Gilles Peskine75829a42021-01-25 13:46:14 +0100178# 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.
David Horstmannc54f0b32024-11-08 10:59:21 +0000181TEST_OBJS_DEPS += ../framework/tests/include/test/instrument_record_status.h
Gilles Peskined71539f2020-11-25 18:17:17 +0100182endif
Ronald Cronf810d442025-02-14 15:43:22 +0100183TEST_OBJS_DEPS += include/test/test_certs.h include/test/test_keys.h
Gilles Peskined71539f2020-11-25 18:17:17 +0100184
David Horstmann45c83ca2024-11-05 14:45:50 +0000185# Rule to compile common test C files in framework
186../framework/tests/src/%.o : ../framework/tests/src/%.c $(TEST_OBJS_DEPS)
Ronald Cronb6d6d4c2020-06-03 10:11:18 +0200187 echo " CC $<"
188 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
189
David Horstmann45c83ca2024-11-05 14:45:50 +0000190../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
195src/%.o : src/%.c $(TEST_OBJS_DEPS)
Steven Cooremana70d5882020-07-16 20:26:18 +0200196 echo " CC $<"
197 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
198
Yanray Wangb458b8c2022-10-28 11:49:33 +0800199src/test_helpers/%.o : src/test_helpers/%.c
200 echo " CC $<"
201 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $<
202
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000203C_FILES := $(addsuffix .c,$(APPS))
Gilles Peskine1d7cc082022-11-10 19:50:34 +0100204c: $(C_FILES)
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000205
Azim Khan27a35e72018-06-29 12:39:19 +0100206# 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#
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000220.SECONDEXPANSION:
David Horstmannea091522024-05-29 17:57:08 +0100221%.c: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data ../framework/scripts/generate_test_code.py suites/helpers.function suites/main_test.function suites/host_test.function
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100222 echo " Gen $@"
David Horstmannea091522024-05-29 17:57:08 +0100223 $(PYTHON) ../framework/scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100224 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100225 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100226 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100227 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100228 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100229 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200230
Paul Bakker286bf3c2013-04-08 18:09:51 +0200231
Gilles Peskined71539f2020-11-25 18:17:17 +0100232$(BINARIES): %$(EXEXT): %.c $(MBEDLIBS) $(TEST_OBJS_DEPS) $(MBEDTLS_TEST_OBJS)
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100233 echo " CC $<"
Gilles Peskine4ad57332023-12-22 11:30:30 +0100234 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200235
Paul Bakker0049c2f2009-07-11 19:15:43 +0000236clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000237ifndef WINDOWS
Gilles Peskined0254222021-09-14 11:28:22 +0200238 rm -rf $(BINARIES) *.c *.datax
David Horstmann61b7b1e2024-11-06 15:53:14 +0000239 rm -f src/*.o src/test_helpers/*.o src/libmbed*
240 rm -f ../framework/tests/src/*.o ../framework/tests/src/drivers/*.o
David Horstmannb25eaca2024-11-13 10:45:42 +0000241 rm -f ../framework/tests/include/test/instrument_record_status.h
David Horstmannb19374f2024-11-07 17:08:11 +0000242 rm -f ../framework/tests/include/alt-extra/*/*_alt.h
Ronald Cron72b25da2021-04-28 18:29:24 +0200243 rm -rf libtestdriver1
Manuel Pégourié-Gonnard85101052022-12-29 16:04:35 +0100244 rm -f ../library/libtestdriver1.a
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200245else
Darryl Green6c0f94c2018-10-17 16:12:33 +0100246 if exist *.c del /Q /F *.c
247 if exist *.exe del /Q /F *.exe
248 if exist *.datax del /Q /F *.datax
Ronald Cronb6d6d4c2020-06-03 10:11:18 +0200249 if exist src/*.o del /Q /F src/*.o
Yanray Wangb458b8c2022-10-28 11:49:33 +0800250 if exist src/test_helpers/*.o del /Q /F src/test_helpers/*.o
David Horstmann204c4b42024-08-28 16:28:46 +0100251 if exist src/libmbed* del /Q /F src/libmbed*
David Horstmann61b7b1e2024-11-06 15:53:14 +0000252 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
David Horstmannb25eaca2024-11-13 10:45:42 +0000254 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 +0100255endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000256
Gilles Peskineac372cc2018-11-29 10:15:06 +0000257# Test suites caught by SKIP_TEST_SUITES are built but not executed.
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000258check: $(BINARIES)
Gilles Peskine396853a2021-09-20 18:57:55 +0200259 perl scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200260
261test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000262
Gilles Peskinedf6e84a2023-02-22 22:09:51 +0100263# Generate variants of some headers for testing
David Horstmannb19374f2024-11-07 17:08:11 +0000264../framework/tests/include/alt-extra/%_alt.h: ../include/%.h
Gilles Peskinedf6e84a2023-02-22 22:09:51 +0100265 perl -p -e 's/^(# *(define|ifndef) +\w+_)H\b/$${1}ALT_H/' $< >$@
266
Ronald Cron72b25da2021-04-28 18:29:24 +0200267# 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.
273define 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;
278endef
279
Gilles Peskine1c13aa72024-03-04 11:06:56 +0100280libtestdriver1.a: export MBEDTLS_PATH := $(patsubst ../..//%,/%,../../$(MBEDTLS_PATH))
Ronald Cron72b25da2021-04-28 18:29:24 +0200281libtestdriver1.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.
Ronald Cron83d21cc2024-11-20 08:25:55 +0100292 cp configs/config_test_driver.h ./libtestdriver1/include/mbedtls/mbedtls_config.h
Ronald Cron72b25da2021-04-28 18:29:24 +0200293
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
Ronald Cron83d21cc2024-11-20 08:25:55 +0100297 # configs/crypto_config_test_driver_extension.h to mirror the PSA_ACCEL_*
298 # macros.
Ronald Cron72b25da2021-04-28 18:29:24 +0200299 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
Ronald Cron83d21cc2024-11-20 08:25:55 +0100301 cat configs/crypto_config_test_driver_extension.h >> ./libtestdriver1/include/psa/crypto_config.h
Ronald Cron72b25da2021-04-28 18:29:24 +0200302 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
Gilles Peskine51681552019-05-20 19:35:37 +0200313ifdef RECORD_PSA_STATUS_COVERAGE_LOG
David Horstmannc54f0b32024-11-08 10:59:21 +0000314../framework/tests/include/test/instrument_record_status.h: ../include/psa/crypto.h Makefile
Gilles Peskined71539f2020-11-25 18:17:17 +0100315 echo " Gen $@"
Gilles Peskine51681552019-05-20 19:35:37 +0200316 sed <../include/psa/crypto.h >$@ -n 's/^psa_status_t \([A-Za-z0-9_]*\)(.*/#define \1(...) RECORD_STATUS("\1", \1(__VA_ARGS__))/p'
317endif