Gilles Peskine | 570e548 | 2024-01-02 18:11:10 +0100 | [diff] [blame] | 1 | MBEDTLS_TEST_PATH = . |
Gilles Peskine | f3d1ae1 | 2023-12-22 11:40:58 +0100 | [diff] [blame] | 2 | include ../scripts/common.make |
Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 3 | |
Gilles Peskine | 396853a | 2021-09-20 18:57:55 +0200 | [diff] [blame] | 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 | |
Gilles Peskine | f5c5ce7 | 2023-12-22 11:36:53 +0100 | [diff] [blame] | 7 | # Also include library headers, for the sake of invasive tests. |
| 8 | LOCAL_CFLAGS += -I../library |
Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 9 | |
Nicholas Wilson | 61fa436 | 2018-06-25 12:10:00 +0100 | [diff] [blame] | 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 | |
Gilles Peskine | 5168155 | 2019-05-20 19:35:37 +0200 | [diff] [blame] | 15 | ifdef RECORD_PSA_STATUS_COVERAGE_LOG |
| 16 | LOCAL_CFLAGS += -Werror -DRECORD_PSA_STATUS_COVERAGE_LOG |
| 17 | endif |
| 18 | |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 19 | GENERATED_BIGNUM_DATA_FILES := $(patsubst tests/%,%,$(shell \ |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 20 | $(PYTHON) ../framework/scripts/generate_bignum_tests.py --list || \ |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 21 | echo FAILED \ |
| 22 | )) |
| 23 | ifeq ($(GENERATED_BIGNUM_DATA_FILES),FAILED) |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 24 | $(error "$(PYTHON) ../framework/scripts/generate_bignum_tests.py --list" failed) |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 25 | endif |
Gilles Peskine | 26d279e | 2024-05-23 16:38:07 +0200 | [diff] [blame] | 26 | GENERATED_DATA_FILES += $(GENERATED_BIGNUM_DATA_FILES) |
| 27 | |
Gilles Peskine | 06fb180 | 2024-05-23 16:31:22 +0200 | [diff] [blame] | 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 | |
Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame] | 37 | GENERATED_ECP_DATA_FILES := $(patsubst tests/%,%,$(shell \ |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 38 | $(PYTHON) ../framework/scripts/generate_ecp_tests.py --list || \ |
Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame] | 39 | echo FAILED \ |
| 40 | )) |
| 41 | ifeq ($(GENERATED_ECP_DATA_FILES),FAILED) |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 42 | $(error "$(PYTHON) ../framework/scripts/generate_ecp_tests.py --list" failed) |
Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame] | 43 | endif |
Gilles Peskine | 26d279e | 2024-05-23 16:38:07 +0200 | [diff] [blame] | 44 | GENERATED_DATA_FILES += $(GENERATED_ECP_DATA_FILES) |
| 45 | |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 46 | GENERATED_PSA_DATA_FILES := $(patsubst tests/%,%,$(shell \ |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 47 | $(PYTHON) ../framework/scripts/generate_psa_tests.py --list || \ |
Gilles Peskine | e9ad95a | 2021-07-13 18:36:05 +0200 | [diff] [blame] | 48 | echo FAILED \ |
| 49 | )) |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 50 | ifeq ($(GENERATED_PSA_DATA_FILES),FAILED) |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 51 | $(error "$(PYTHON) ../framework/scripts/generate_psa_tests.py --list" failed) |
Gilles Peskine | e9ad95a | 2021-07-13 18:36:05 +0200 | [diff] [blame] | 52 | endif |
Gilles Peskine | 26d279e | 2024-05-23 16:38:07 +0200 | [diff] [blame] | 53 | GENERATED_DATA_FILES += $(GENERATED_PSA_DATA_FILES) |
| 54 | |
| 55 | GENERATED_FILES = $(GENERATED_DATA_FILES) |
| 56 | GENERATED_FILES += src/test_keys.h src/test_certs.h |
| 57 | |
| 58 | .PHONY: generated_files |
| 59 | generated_files: $(GENERATED_FILES) |
Gilles Peskine | 687d1ab | 2021-04-22 01:01:56 +0200 | [diff] [blame] | 60 | |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 61 | # generate_bignum_tests.py and generate_psa_tests.py spend more time analyzing |
| 62 | # inputs than generating outputs. Its inputs are the same no matter which files |
| 63 | # are being generated. |
Gilles Peskine | 5df77c6 | 2021-07-13 17:22:58 +0200 | [diff] [blame] | 64 | # It's rare not to want all the outputs. So always generate all of its outputs. |
| 65 | # Use an intermediate phony dependency so that parallel builds don't run |
| 66 | # a separate instance of the recipe for each output file. |
Gilles Peskine | 0b62b7a | 2023-09-08 16:19:13 +0200 | [diff] [blame] | 67 | $(GENERATED_BIGNUM_DATA_FILES): $(gen_file_dep) generated_bignum_test_data |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 68 | generated_bignum_test_data: ../framework/scripts/generate_bignum_tests.py |
David Horstmann | 9638ca3 | 2024-05-03 14:36:12 +0100 | [diff] [blame] | 69 | generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_common.py |
| 70 | generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_core.py |
| 71 | generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_mod_raw.py |
| 72 | generated_bignum_test_data: ../framework/scripts/mbedtls_framework/bignum_mod.py |
| 73 | generated_bignum_test_data: ../framework/scripts/mbedtls_framework/test_case.py |
| 74 | generated_bignum_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 75 | generated_bignum_test_data: |
| 76 | echo " Gen $(GENERATED_BIGNUM_DATA_FILES)" |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 77 | $(PYTHON) ../framework/scripts/generate_bignum_tests.py |
Gilles Peskine | 26d279e | 2024-05-23 16:38:07 +0200 | [diff] [blame] | 78 | .SECONDARY: generated_bignum_test_data |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 79 | |
Gilles Peskine | 06fb180 | 2024-05-23 16:31:22 +0200 | [diff] [blame] | 80 | # We deliberately omit the configuration files (mbedtls_config.h, |
| 81 | # crypto_config.h) from the depenency list because during development |
| 82 | # and on the CI, we often edit those in a way that doesn't change the |
| 83 | # output, to comment out certain options, or even to remove certain |
| 84 | # lines which do affect the output negatively (it will miss the |
| 85 | # corresponding test cases). |
| 86 | $(GENERATED_CONFIG_DATA_FILES): $(gen_file_dep) generated_config_test_data |
| 87 | generated_config_test_data: ../framework/scripts/generate_config_tests.py |
| 88 | generated_config_test_data: ../scripts/config.py |
| 89 | generated_config_test_data: ../framework/scripts/mbedtls_framework/test_case.py |
| 90 | generated_config_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py |
| 91 | generated_config_test_data: |
| 92 | echo " Gen $(GENERATED_CONFIG_DATA_FILES)" |
| 93 | $(PYTHON) ../framework/scripts/generate_config_tests.py |
| 94 | .SECONDARY: generated_config_test_data |
| 95 | |
Gilles Peskine | 0b62b7a | 2023-09-08 16:19:13 +0200 | [diff] [blame] | 96 | $(GENERATED_ECP_DATA_FILES): $(gen_file_dep) generated_ecp_test_data |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 97 | generated_ecp_test_data: ../framework/scripts/generate_ecp_tests.py |
David Horstmann | 9638ca3 | 2024-05-03 14:36:12 +0100 | [diff] [blame] | 98 | generated_ecp_test_data: ../framework/scripts/mbedtls_framework/bignum_common.py |
| 99 | generated_ecp_test_data: ../framework/scripts/mbedtls_framework/ecp.py |
| 100 | generated_ecp_test_data: ../framework/scripts/mbedtls_framework/test_case.py |
| 101 | generated_ecp_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py |
Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame] | 102 | generated_ecp_test_data: |
| 103 | echo " Gen $(GENERATED_ECP_DATA_FILES)" |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 104 | $(PYTHON) ../framework/scripts/generate_ecp_tests.py |
Gilles Peskine | 26d279e | 2024-05-23 16:38:07 +0200 | [diff] [blame] | 105 | .SECONDARY: generated_ecp_test_data |
Gabor Mezei | 95ecaaf | 2023-01-16 16:53:29 +0100 | [diff] [blame] | 106 | |
Gilles Peskine | 0b62b7a | 2023-09-08 16:19:13 +0200 | [diff] [blame] | 107 | $(GENERATED_PSA_DATA_FILES): $(gen_file_dep) generated_psa_test_data |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 108 | generated_psa_test_data: ../framework/scripts/generate_psa_tests.py |
David Horstmann | 9638ca3 | 2024-05-03 14:36:12 +0100 | [diff] [blame] | 109 | generated_psa_test_data: ../framework/scripts/mbedtls_framework/crypto_data_tests.py |
| 110 | generated_psa_test_data: ../framework/scripts/mbedtls_framework/crypto_knowledge.py |
| 111 | generated_psa_test_data: ../framework/scripts/mbedtls_framework/macro_collector.py |
| 112 | generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_information.py |
| 113 | generated_psa_test_data: ../framework/scripts/mbedtls_framework/psa_storage.py |
| 114 | generated_psa_test_data: ../framework/scripts/mbedtls_framework/test_case.py |
| 115 | generated_psa_test_data: ../framework/scripts/mbedtls_framework/test_data_generation.py |
Gilles Peskine | 1411c7c | 2021-04-22 14:50:16 +0200 | [diff] [blame] | 116 | ## The generated file only depends on the options that are present in |
| 117 | ## crypto_config.h, not on which options are set. To avoid regenerating this |
| 118 | ## file all the time when switching between configurations, don't declare |
| 119 | ## crypto_config.h as a dependency. Remove this file from your working tree |
| 120 | ## if you've just added or removed an option in crypto_config.h. |
Gilles Peskine | 5df77c6 | 2021-07-13 17:22:58 +0200 | [diff] [blame] | 121 | #generated_psa_test_data: ../include/psa/crypto_config.h |
| 122 | generated_psa_test_data: ../include/psa/crypto_values.h |
| 123 | generated_psa_test_data: ../include/psa/crypto_extra.h |
| 124 | generated_psa_test_data: suites/test_suite_psa_crypto_metadata.data |
| 125 | generated_psa_test_data: |
Werner Lewis | 8b2df74 | 2022-07-08 13:54:57 +0100 | [diff] [blame] | 126 | echo " Gen $(GENERATED_PSA_DATA_FILES) ..." |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 127 | $(PYTHON) ../framework/scripts/generate_psa_tests.py |
Gilles Peskine | 26d279e | 2024-05-23 16:38:07 +0200 | [diff] [blame] | 128 | .SECONDARY: generated_psa_test_data |
Gilles Peskine | 687d1ab | 2021-04-22 01:01:56 +0200 | [diff] [blame] | 129 | |
Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 130 | # A test application is built for each suites/test_suite_*.data file. |
| 131 | # Application name is same as .data file's base name and can be |
| 132 | # constructed by stripping path 'suites/' and extension .data. |
Gilles Peskine | 687d1ab | 2021-04-22 01:01:56 +0200 | [diff] [blame] | 133 | DATA_FILES := $(wildcard suites/test_suite_*.data) |
| 134 | # Make sure that generated data files are included even if they don't |
| 135 | # exist yet when the makefile is parsed. |
Gilles Peskine | 26d279e | 2024-05-23 16:38:07 +0200 | [diff] [blame] | 136 | DATA_FILES += $(filter-out $(DATA_FILES),$(GENERATED_DATA_FILES)) |
Gilles Peskine | 687d1ab | 2021-04-22 01:01:56 +0200 | [diff] [blame] | 137 | APPS = $(basename $(subst suites/,,$(DATA_FILES))) |
Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 138 | |
Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 139 | # Construct executable name by adding OS specific suffix $(EXEXT). |
Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 140 | BINARIES := $(addsuffix $(EXEXT),$(APPS)) |
| 141 | |
Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 142 | .SILENT: |
| 143 | |
Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 144 | .PHONY: all check test clean |
| 145 | |
Azim Khan | 1de892b | 2017-06-09 15:02:36 +0100 | [diff] [blame] | 146 | all: $(BINARIES) |
| 147 | |
Ronald Cron | ddaf99c | 2020-06-19 11:27:26 +0200 | [diff] [blame] | 148 | mbedtls_test: $(MBEDTLS_TEST_OBJS) |
| 149 | |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 150 | src/test_certs.h: ../framework/scripts/generate_test_cert_macros.py \ |
| 151 | $($(PYTHON) ../framework/scripts/generate_test_cert_macros.py --list-dependencies) |
| 152 | $(PYTHON) ../framework/scripts/generate_test_cert_macros.py --output $@ |
Valerio Setti | a607a1b | 2024-04-08 17:52:12 +0200 | [diff] [blame] | 153 | |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 154 | src/test_keys.h: ../framework/scripts/generate_test_keys.py |
| 155 | $(PYTHON) ../framework/scripts/generate_test_keys.py --output $@ |
Valerio Setti | a607a1b | 2024-04-08 17:52:12 +0200 | [diff] [blame] | 156 | |
Gilles Peskine | e1d51bd | 2021-01-20 19:47:23 +0100 | [diff] [blame] | 157 | TEST_OBJS_DEPS = $(wildcard include/test/*.h include/test/*/*.h) |
Gilles Peskine | d71539f | 2020-11-25 18:17:17 +0100 | [diff] [blame] | 158 | ifdef RECORD_PSA_STATUS_COVERAGE_LOG |
Gilles Peskine | 75829a4 | 2021-01-25 13:46:14 +0100 | [diff] [blame] | 159 | # Explicitly depend on this header because on a clean copy of the source tree, |
| 160 | # it doesn't exist yet and must be generated as part of the build, and |
| 161 | # therefore the wildcard enumeration above doesn't include it. |
Gilles Peskine | d71539f | 2020-11-25 18:17:17 +0100 | [diff] [blame] | 162 | TEST_OBJS_DEPS += include/test/instrument_record_status.h |
| 163 | endif |
Valerio Setti | a607a1b | 2024-04-08 17:52:12 +0200 | [diff] [blame] | 164 | TEST_OBJS_DEPS += src/test_certs.h src/test_keys.h |
Gilles Peskine | d71539f | 2020-11-25 18:17:17 +0100 | [diff] [blame] | 165 | |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 166 | # Rule to compile common test C files in src folder |
Gilles Peskine | d71539f | 2020-11-25 18:17:17 +0100 | [diff] [blame] | 167 | src/%.o : src/%.c $(TEST_OBJS_DEPS) |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 168 | echo " CC $<" |
| 169 | $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $< |
| 170 | |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 171 | src/drivers/%.o : src/drivers/%.c |
| 172 | echo " CC $<" |
| 173 | $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $< |
| 174 | |
Yanray Wang | b458b8c | 2022-10-28 11:49:33 +0800 | [diff] [blame] | 175 | src/test_helpers/%.o : src/test_helpers/%.c |
| 176 | echo " CC $<" |
| 177 | $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -o $@ -c $< |
| 178 | |
Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 179 | C_FILES := $(addsuffix .c,$(APPS)) |
Gilles Peskine | 1d7cc08 | 2022-11-10 19:50:34 +0100 | [diff] [blame] | 180 | c: $(C_FILES) |
Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 181 | |
Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 182 | # Wildcard target for test code generation: |
| 183 | # A .c file is generated for each .data file in the suites/ directory. Each .c |
| 184 | # file depends on a .data and .function file from suites/ directory. Following |
| 185 | # nameing convention is followed: |
| 186 | # |
| 187 | # C file | Depends on |
| 188 | #----------------------------------------------------------------------------- |
| 189 | # foo.c | suites/foo.function suites/foo.data |
| 190 | # foo.bar.c | suites/foo.function suites/foo.bar.data |
| 191 | # |
| 192 | # Note above that .c and .data files have same base name. |
| 193 | # However, corresponding .function file's base name is the word before first |
| 194 | # dot in .c file's base name. |
| 195 | # |
Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 196 | .SECONDEXPANSION: |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 197 | %.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é-Gonnard | 78ec2b0 | 2015-07-08 22:12:06 +0100 | [diff] [blame] | 198 | echo " Gen $@" |
David Horstmann | ea09152 | 2024-05-29 17:57:08 +0100 | [diff] [blame] | 199 | $(PYTHON) ../framework/scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \ |
Mohammad Azim Khan | fff4904 | 2017-03-28 01:48:31 +0100 | [diff] [blame] | 200 | -d suites/$*.data \ |
Azim Khan | 1de892b | 2017-06-09 15:02:36 +0100 | [diff] [blame] | 201 | -t suites/main_test.function \ |
Mohammad Azim Khan | 9540261 | 2017-07-19 10:15:54 +0100 | [diff] [blame] | 202 | -p suites/host_test.function \ |
Mohammad Azim Khan | fff4904 | 2017-03-28 01:48:31 +0100 | [diff] [blame] | 203 | -s suites \ |
Azim Khan | e3b26af | 2018-06-29 02:36:57 +0100 | [diff] [blame] | 204 | --helpers-file suites/helpers.function \ |
Mohammad Azim Khan | fff4904 | 2017-03-28 01:48:31 +0100 | [diff] [blame] | 205 | -o . |
Paul Bakker | 286bf3c | 2013-04-08 18:09:51 +0200 | [diff] [blame] | 206 | |
Paul Bakker | 286bf3c | 2013-04-08 18:09:51 +0200 | [diff] [blame] | 207 | |
Gilles Peskine | d71539f | 2020-11-25 18:17:17 +0100 | [diff] [blame] | 208 | $(BINARIES): %$(EXEXT): %.c $(MBEDLIBS) $(TEST_OBJS_DEPS) $(MBEDTLS_TEST_OBJS) |
Manuel Pégourié-Gonnard | 78ec2b0 | 2015-07-08 22:12:06 +0100 | [diff] [blame] | 209 | echo " CC $<" |
Gilles Peskine | 4ad5733 | 2023-12-22 11:30:30 +0100 | [diff] [blame] | 210 | $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ |
Paul Bakker | 286bf3c | 2013-04-08 18:09:51 +0200 | [diff] [blame] | 211 | |
Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 212 | clean: |
Paul Bakker | 62f88dc | 2012-05-10 21:26:28 +0000 | [diff] [blame] | 213 | ifndef WINDOWS |
Gilles Peskine | d025422 | 2021-09-14 11:28:22 +0200 | [diff] [blame] | 214 | rm -rf $(BINARIES) *.c *.datax |
David Horstmann | 636367f | 2024-08-28 16:30:33 +0100 | [diff] [blame^] | 215 | rm -f src/*.o src/drivers/*.o src/test_helpers/*.o src/libmbed* |
Gilles Peskine | d71539f | 2020-11-25 18:17:17 +0100 | [diff] [blame] | 216 | rm -f include/test/instrument_record_status.h |
Gilles Peskine | df6e84a | 2023-02-22 22:09:51 +0100 | [diff] [blame] | 217 | rm -f include/alt-extra/*/*_alt.h |
Ronald Cron | 72b25da | 2021-04-28 18:29:24 +0200 | [diff] [blame] | 218 | rm -rf libtestdriver1 |
Manuel Pégourié-Gonnard | 8510105 | 2022-12-29 16:04:35 +0100 | [diff] [blame] | 219 | rm -f ../library/libtestdriver1.a |
Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 220 | else |
Darryl Green | 6c0f94c | 2018-10-17 16:12:33 +0100 | [diff] [blame] | 221 | if exist *.c del /Q /F *.c |
| 222 | if exist *.exe del /Q /F *.exe |
| 223 | if exist *.datax del /Q /F *.datax |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 224 | if exist src/*.o del /Q /F src/*.o |
Steven Cooreman | a70d588 | 2020-07-16 20:26:18 +0200 | [diff] [blame] | 225 | if exist src/drivers/*.o del /Q /F src/drivers/*.o |
Yanray Wang | b458b8c | 2022-10-28 11:49:33 +0800 | [diff] [blame] | 226 | if exist src/test_helpers/*.o del /Q /F src/test_helpers/*.o |
David Horstmann | 204c4b4 | 2024-08-28 16:28:46 +0100 | [diff] [blame] | 227 | if exist src/libmbed* del /Q /F src/libmbed* |
Gilles Peskine | d71539f | 2020-11-25 18:17:17 +0100 | [diff] [blame] | 228 | if exist include/test/instrument_record_status.h del /Q /F include/test/instrument_record_status.h |
Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 229 | endif |
Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 230 | |
Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 231 | # Test suites caught by SKIP_TEST_SUITES are built but not executed. |
Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 232 | check: $(BINARIES) |
Gilles Peskine | 396853a | 2021-09-20 18:57:55 +0200 | [diff] [blame] | 233 | perl scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES) |
Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 234 | |
| 235 | test: check |
Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 236 | |
Gilles Peskine | df6e84a | 2023-02-22 22:09:51 +0100 | [diff] [blame] | 237 | # Generate variants of some headers for testing |
| 238 | include/alt-extra/%_alt.h: ../include/%.h |
| 239 | perl -p -e 's/^(# *(define|ifndef) +\w+_)H\b/$${1}ALT_H/' $< >$@ |
| 240 | |
Ronald Cron | 72b25da | 2021-04-28 18:29:24 +0200 | [diff] [blame] | 241 | # Generate test library |
| 242 | |
| 243 | # Perl code that is executed to transform each original line from a library |
| 244 | # source file into the corresponding line in the test driver copy of the |
| 245 | # library. Add a LIBTESTDRIVER1_/libtestdriver1_ to mbedtls_xxx and psa_xxx |
| 246 | # symbols. |
| 247 | define libtestdriver1_rewrite := |
| 248 | s!^(\s*#\s*include\s*[\"<])(mbedtls|psa)/!$${1}libtestdriver1/include/$${2}/!; \ |
| 249 | next if /^\s*#\s*include/; \ |
| 250 | s/\b(?=MBEDTLS_|PSA_)/LIBTESTDRIVER1_/g; \ |
| 251 | s/\b(?=mbedtls_|psa_)/libtestdriver1_/g; |
| 252 | endef |
| 253 | |
Gilles Peskine | 1c13aa7 | 2024-03-04 11:06:56 +0100 | [diff] [blame] | 254 | libtestdriver1.a: export MBEDTLS_PATH := $(patsubst ../..//%,/%,../../$(MBEDTLS_PATH)) |
Ronald Cron | 72b25da | 2021-04-28 18:29:24 +0200 | [diff] [blame] | 255 | libtestdriver1.a: |
| 256 | # Copy the library and fake a 3rdparty Makefile include. |
| 257 | rm -Rf ./libtestdriver1 |
| 258 | mkdir ./libtestdriver1 |
| 259 | cp -Rf ../library ./libtestdriver1 |
| 260 | cp -Rf ../include ./libtestdriver1 |
| 261 | cp -Rf ../scripts ./libtestdriver1 |
| 262 | mkdir ./libtestdriver1/3rdparty |
| 263 | touch ./libtestdriver1/3rdparty/Makefile.inc |
| 264 | |
| 265 | # Set the test driver base (minimal) configuration. |
| 266 | cp ./include/test/drivers/config_test_driver.h ./libtestdriver1/include/mbedtls/mbedtls_config.h |
| 267 | |
| 268 | # Set the PSA cryptography configuration for the test library. |
| 269 | # It is set from the copied include/psa/crypto_config.h of the Mbed TLS |
| 270 | # library the test library is intended to be linked with extended by |
| 271 | # ./include/test/drivers/crypto_config_test_driver_extension.h to |
| 272 | # mirror the PSA_ACCEL_* macros. |
| 273 | mv ./libtestdriver1/include/psa/crypto_config.h ./libtestdriver1/include/psa/crypto_config.h.bak |
| 274 | head -n -1 ./libtestdriver1/include/psa/crypto_config.h.bak > ./libtestdriver1/include/psa/crypto_config.h |
| 275 | cat ./include/test/drivers/crypto_config_test_driver_extension.h >> ./libtestdriver1/include/psa/crypto_config.h |
| 276 | echo "#endif /* PSA_CRYPTO_CONFIG_H */" >> ./libtestdriver1/include/psa/crypto_config.h |
| 277 | |
| 278 | # Prefix MBEDTLS_* PSA_* symbols with LIBTESTDRIVER1_ as well as |
| 279 | # mbedtls_* psa_* symbols with libtestdriver1_ to avoid symbol clash |
| 280 | # when this test driver library is linked with the Mbed TLS library. |
| 281 | perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/library/*.[ch] |
| 282 | perl -pi -e '$(libtestdriver1_rewrite)' ./libtestdriver1/include/*/*.h |
| 283 | |
| 284 | $(MAKE) -C ./libtestdriver1/library CFLAGS="-I../../ $(CFLAGS)" LDFLAGS="$(LDFLAGS)" libmbedcrypto.a |
| 285 | cp ./libtestdriver1/library/libmbedcrypto.a ../library/libtestdriver1.a |
| 286 | |
Gilles Peskine | 5168155 | 2019-05-20 19:35:37 +0200 | [diff] [blame] | 287 | ifdef RECORD_PSA_STATUS_COVERAGE_LOG |
Ronald Cron | 02c78b7 | 2020-05-27 09:22:32 +0200 | [diff] [blame] | 288 | include/test/instrument_record_status.h: ../include/psa/crypto.h Makefile |
Gilles Peskine | d71539f | 2020-11-25 18:17:17 +0100 | [diff] [blame] | 289 | echo " Gen $@" |
Gilles Peskine | 5168155 | 2019-05-20 19:35:37 +0200 | [diff] [blame] | 290 | sed <../include/psa/crypto.h >$@ -n 's/^psa_status_t \([A-Za-z0-9_]*\)(.*/#define \1(...) RECORD_STATUS("\1", \1(__VA_ARGS__))/p' |
| 291 | endif |