| Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 1 |  | 
|  | 2 | # To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS | 
| Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 3 |  | 
| Mohammad Azim Khan | 9540261 | 2017-07-19 10:15:54 +0100 | [diff] [blame] | 4 | CFLAGS	?= -O2 | 
| Gilles Peskine | 1e65771 | 2019-07-02 20:05:20 +0200 | [diff] [blame] | 5 | WARNING_CFLAGS ?= -Wall -Wextra | 
| Alon Bar-Lev | ada4105 | 2015-02-18 17:47:52 +0200 | [diff] [blame] | 6 | LDFLAGS ?= | 
| Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 7 |  | 
| Jaeden Amero | 120d571 | 2019-03-07 15:32:49 +0000 | [diff] [blame] | 8 | CRYPTO_INCLUDES ?= -I../include | 
|  | 9 | LOCAL_CFLAGS = $(WARNING_CFLAGS) $(CRYPTO_INCLUDES) -I../library -D_FILE_OFFSET_BITS=64 | 
| Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 10 | LOCAL_LDFLAGS = -L../library			\ | 
| Manuel Pégourié-Gonnard | 21e1ac2 | 2015-06-25 08:45:12 +0200 | [diff] [blame] | 11 | -lmbedcrypto$(SHARED_SUFFIX) | 
| Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 12 |  | 
| Christoph M. Wintersteiger | 6ea2dea1 | 2019-01-21 17:26:19 +0000 | [diff] [blame] | 13 | include ../3rdparty/Makefile.inc | 
|  | 14 | LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES) | 
| Christoph M. Wintersteiger | d5fd766 | 2018-10-25 12:47:03 +0100 | [diff] [blame] | 15 |  | 
| Nicholas Wilson | 61fa436 | 2018-06-25 12:10:00 +0100 | [diff] [blame] | 16 | # Enable definition of various functions used throughout the testsuite | 
|  | 17 | # (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless | 
|  | 18 | # on non-POSIX platforms. | 
|  | 19 | LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L | 
|  | 20 |  | 
| Paul Bakker | 674e0b0 | 2014-03-26 13:26:52 +0100 | [diff] [blame] | 21 | ifndef SHARED | 
| Jaeden Amero | 8298d70 | 2018-11-02 10:11:31 +0000 | [diff] [blame] | 22 | DEP=../library/libmbedcrypto.a | 
| Paul Bakker | 674e0b0 | 2014-03-26 13:26:52 +0100 | [diff] [blame] | 23 | else | 
| Jaeden Amero | 8298d70 | 2018-11-02 10:11:31 +0000 | [diff] [blame] | 24 | DEP=../library/libmbedcrypto.$(DLEXT) | 
| Paul Bakker | 674e0b0 | 2014-03-26 13:26:52 +0100 | [diff] [blame] | 25 | endif | 
|  | 26 |  | 
| Paul Bakker | c7ffd36 | 2012-04-05 12:08:29 +0000 | [diff] [blame] | 27 | ifdef DEBUG | 
| Alon Bar-Lev | f7a9f30 | 2015-02-18 17:55:05 +0200 | [diff] [blame] | 28 | LOCAL_CFLAGS += -g3 | 
| Paul Bakker | c7ffd36 | 2012-04-05 12:08:29 +0000 | [diff] [blame] | 29 | endif | 
|  | 30 |  | 
| Gilles Peskine | 5168155 | 2019-05-20 19:35:37 +0200 | [diff] [blame^] | 31 | ifdef RECORD_PSA_STATUS_COVERAGE_LOG | 
|  | 32 | LOCAL_CFLAGS += -Werror -DRECORD_PSA_STATUS_COVERAGE_LOG | 
|  | 33 | endif | 
|  | 34 |  | 
| Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 35 | # if we're running on Windows, build for Windows | 
| Paul Bakker | cd5b529 | 2012-05-10 20:49:10 +0000 | [diff] [blame] | 36 | ifdef WINDOWS | 
| Alon Bar-Lev | 18ba0cc | 2015-02-14 01:04:58 +0200 | [diff] [blame] | 37 | WINDOWS_BUILD=1 | 
|  | 38 | endif | 
|  | 39 |  | 
|  | 40 | ifdef WINDOWS_BUILD | 
|  | 41 | DLEXT=dll | 
|  | 42 | EXEXT=.exe | 
| Alon Bar-Lev | ada4105 | 2015-02-18 17:47:52 +0200 | [diff] [blame] | 43 | LOCAL_LDFLAGS += -lws2_32 | 
| Alon Bar-Lev | 18ba0cc | 2015-02-14 01:04:58 +0200 | [diff] [blame] | 44 | ifdef SHARED | 
|  | 45 | SHARED_SUFFIX=.$(DLEXT) | 
|  | 46 | endif | 
| Mohammad Azim Khan | 8a3628f | 2018-06-26 17:30:16 +0100 | [diff] [blame] | 47 | PYTHON ?= python | 
| Manuel Pégourié-Gonnard | 8d4a613 | 2015-06-24 12:16:20 +0200 | [diff] [blame] | 48 | else | 
| Andres Amaya Garcia | 420f0cc | 2018-03-27 19:17:21 +0100 | [diff] [blame] | 49 | DLEXT ?= so | 
| Manuel Pégourié-Gonnard | 8d4a613 | 2015-06-24 12:16:20 +0200 | [diff] [blame] | 50 | EXEXT= | 
|  | 51 | SHARED_SUFFIX= | 
| Mohammad Azim Khan | 8a3628f | 2018-06-26 17:30:16 +0100 | [diff] [blame] | 52 | # python2 for POSIX since FreeBSD has only python2 as default. | 
|  | 53 | PYTHON ?= python2 | 
| Paul Bakker | cd5b529 | 2012-05-10 20:49:10 +0000 | [diff] [blame] | 54 | endif | 
|  | 55 |  | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 56 | # A test application is built for each suites/test_suite_*.data file. | 
|  | 57 | # Application name is same as .data file's base name and can be | 
|  | 58 | # constructed by stripping path 'suites/' and extension .data. | 
|  | 59 | APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data))) | 
| Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 60 |  | 
| Jaeden Amero | 1264c2a | 2019-03-07 16:01:11 +0000 | [diff] [blame] | 61 | # When this project is used as a submodule, exclude the following list of | 
|  | 62 | # tests, which will be run from the parent module instead. | 
|  | 63 | ifdef USE_CRYPTO_SUBMODULE | 
|  | 64 | APPS := $(filter-out \ | 
|  | 65 | test_suite_version \ | 
|  | 66 | ,$(APPS)) | 
|  | 67 | endif | 
|  | 68 |  | 
|  | 69 |  | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 70 | # Construct executable name by adding OS specific suffix $(EXEXT). | 
| Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 71 | BINARIES := $(addsuffix $(EXEXT),$(APPS)) | 
|  | 72 |  | 
| Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 73 | .SILENT: | 
|  | 74 |  | 
| Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 75 | .PHONY: all check test clean | 
|  | 76 |  | 
| Azim Khan | 1de892b | 2017-06-09 15:02:36 +0100 | [diff] [blame] | 77 | all: $(BINARIES) | 
|  | 78 |  | 
| Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 79 | $(DEP): | 
| Manuel Pégourié-Gonnard | fc36708 | 2015-06-26 16:50:24 +0200 | [diff] [blame] | 80 | $(MAKE) -C ../library | 
| Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 81 |  | 
| Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 82 | C_FILES := $(addsuffix .c,$(APPS)) | 
|  | 83 |  | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 84 | # Wildcard target for test code generation: | 
|  | 85 | # A .c file is generated for each .data file in the suites/ directory. Each .c | 
|  | 86 | # file depends on a .data and .function file from suites/ directory. Following | 
|  | 87 | # nameing convention is followed: | 
|  | 88 | # | 
|  | 89 | #     C file        |        Depends on | 
|  | 90 | #----------------------------------------------------------------------------- | 
|  | 91 | #  foo.c            | suites/foo.function suites/foo.data | 
|  | 92 | #  foo.bar.c        | suites/foo.function suites/foo.bar.data | 
|  | 93 | # | 
|  | 94 | # Note above that .c and .data files have same base name. | 
|  | 95 | # However, corresponding .function file's base name is the word before first | 
|  | 96 | # dot in .c file's base name. | 
|  | 97 | # | 
| Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 98 | .SECONDEXPANSION: | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 99 | %.c: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data 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] | 100 | echo "  Gen   $@" | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 101 | $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \ | 
| Mohammad Azim Khan | fff4904 | 2017-03-28 01:48:31 +0100 | [diff] [blame] | 102 | -d suites/$*.data \ | 
| Azim Khan | 1de892b | 2017-06-09 15:02:36 +0100 | [diff] [blame] | 103 | -t suites/main_test.function \ | 
| Mohammad Azim Khan | 9540261 | 2017-07-19 10:15:54 +0100 | [diff] [blame] | 104 | -p suites/host_test.function \ | 
| Mohammad Azim Khan | fff4904 | 2017-03-28 01:48:31 +0100 | [diff] [blame] | 105 | -s suites  \ | 
| Azim Khan | e3b26af | 2018-06-29 02:36:57 +0100 | [diff] [blame] | 106 | --helpers-file suites/helpers.function \ | 
| Mohammad Azim Khan | fff4904 | 2017-03-28 01:48:31 +0100 | [diff] [blame] | 107 | -o . | 
| Paul Bakker | 286bf3c | 2013-04-08 18:09:51 +0200 | [diff] [blame] | 108 |  | 
| Paul Bakker | 286bf3c | 2013-04-08 18:09:51 +0200 | [diff] [blame] | 109 |  | 
| Mohammad Azim Khan | 94aefaf | 2017-03-23 12:32:54 +0000 | [diff] [blame] | 110 | $(BINARIES): %$(EXEXT): %.c $(DEP) | 
| Manuel Pégourié-Gonnard | 78ec2b0 | 2015-07-08 22:12:06 +0100 | [diff] [blame] | 111 | echo "  CC    $<" | 
| Alon Bar-Lev | f7a9f30 | 2015-02-18 17:55:05 +0200 | [diff] [blame] | 112 | $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $<	$(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ | 
| Paul Bakker | 286bf3c | 2013-04-08 18:09:51 +0200 | [diff] [blame] | 113 |  | 
| Gilles Peskine | 1d10257 | 2019-06-20 17:23:58 +0200 | [diff] [blame] | 114 | # Some test suites require additional header files. | 
| Gilles Peskine | 1838e82 | 2019-06-20 12:40:56 +0200 | [diff] [blame] | 115 | $(filter test_suite_psa_crypto%, $(BINARIES)): psa_crypto_helpers.h | 
| Gilles Peskine | 1d10257 | 2019-06-20 17:23:58 +0200 | [diff] [blame] | 116 | $(addprefix embedded_,$(filter test_suite_psa_crypto%, $(APPS))): embedded_%: TESTS/mbedtls/%/psa_crypto_helpers.h | 
| Gilles Peskine | 3cff768 | 2019-06-20 12:54:43 +0200 | [diff] [blame] | 117 | $(filter test_suite_psa_%, $(BINARIES)): psa_helpers.h | 
| Gilles Peskine | 1d10257 | 2019-06-20 17:23:58 +0200 | [diff] [blame] | 118 | $(addprefix embedded_,$(filter test_suite_psa_%, $(APPS))): embedded_%: TESTS/mbedtls/%/psa_helpers.h | 
| Paul Bakker | 286bf3c | 2013-04-08 18:09:51 +0200 | [diff] [blame] | 119 |  | 
| Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 120 | clean: | 
| Paul Bakker | 62f88dc | 2012-05-10 21:26:28 +0000 | [diff] [blame] | 121 | ifndef WINDOWS | 
| Gilles Peskine | 1596554 | 2018-09-26 13:42:26 +0200 | [diff] [blame] | 122 | rm -rf $(BINARIES) *.c *.datax TESTS | 
| Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 123 | else | 
| Darryl Green | 6c0f94c | 2018-10-17 16:12:33 +0100 | [diff] [blame] | 124 | if exist *.c del /Q /F *.c | 
|  | 125 | if exist *.exe del /Q /F *.exe | 
|  | 126 | if exist *.datax del /Q /F *.datax | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 127 | ifneq ($(wildcard TESTS/.*),) | 
| Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 128 | rmdir /Q /S TESTS | 
| Paul Bakker | 62f88dc | 2012-05-10 21:26:28 +0000 | [diff] [blame] | 129 | endif | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 130 | endif | 
| Paul Bakker | 0049c2f | 2009-07-11 19:15:43 +0000 | [diff] [blame] | 131 |  | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 132 | # 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] | 133 | check: $(BINARIES) | 
| Gilles Peskine | ac372cc | 2018-11-29 10:15:06 +0000 | [diff] [blame] | 134 | perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES) | 
| Manuel Pégourié-Gonnard | 5c59a4f | 2015-06-24 13:06:24 +0200 | [diff] [blame] | 135 |  | 
|  | 136 | test: check | 
| Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 137 |  | 
| Azim Khan | 1de892b | 2017-06-09 15:02:36 +0100 | [diff] [blame] | 138 | # Create separate targets for generating embedded tests. | 
|  | 139 | EMBEDDED_TESTS := $(addprefix embedded_,$(APPS)) | 
| Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 140 |  | 
| Mohammad Azim Khan | 9540261 | 2017-07-19 10:15:54 +0100 | [diff] [blame] | 141 | # Generate test code for target. | 
| Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 142 |  | 
|  | 143 | .SECONDEXPANSION: | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 144 | $(EMBEDDED_TESTS): embedded_%: suites/$$(firstword $$(subst ., ,$$*)).function suites/%.data scripts/generate_test_code.py suites/helpers.function suites/main_test.function suites/target_test.function | 
| Mohammad Azim Khan | fff4904 | 2017-03-28 01:48:31 +0100 | [diff] [blame] | 145 | echo "  Gen  ./TESTS/mbedtls/$*/$*.c" | 
| Azim Khan | 27a35e7 | 2018-06-29 12:39:19 +0100 | [diff] [blame] | 146 | $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \ | 
| Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 147 | -d suites/$*.data \ | 
| Azim Khan | 1de892b | 2017-06-09 15:02:36 +0100 | [diff] [blame] | 148 | -t suites/main_test.function \ | 
| Mohammad Azim Khan | 9540261 | 2017-07-19 10:15:54 +0100 | [diff] [blame] | 149 | -p suites/target_test.function \ | 
| Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 150 | -s suites  \ | 
| Azim Khan | e3b26af | 2018-06-29 02:36:57 +0100 | [diff] [blame] | 151 | --helpers-file suites/helpers.function \ | 
| Mohammad Azim Khan | fff4904 | 2017-03-28 01:48:31 +0100 | [diff] [blame] | 152 | -o ./TESTS/mbedtls/$* | 
| Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 153 |  | 
| Mohammad Azim Khan | ff560f2 | 2018-06-28 11:43:17 +0100 | [diff] [blame] | 154 | generate-target-tests: $(EMBEDDED_TESTS) | 
| Mohammad Azim Khan | 1f29be7 | 2017-03-20 22:21:22 +0000 | [diff] [blame] | 155 |  | 
| Gilles Peskine | 1d10257 | 2019-06-20 17:23:58 +0200 | [diff] [blame] | 156 | define copy_header_to_target | 
|  | 157 | TESTS/mbedtls/$(1)/$(2): $(2) | 
|  | 158 | echo "  Copy ./$$@" | 
|  | 159 | ifndef WINDOWS | 
|  | 160 | mkdir -p $$(@D) | 
|  | 161 | cp $$< $$@ | 
|  | 162 | else | 
|  | 163 | mkdir $$(@D) | 
|  | 164 | copy $$< $$@ | 
|  | 165 | endif | 
|  | 166 |  | 
|  | 167 | endef | 
|  | 168 | $(foreach app, $(APPS), $(foreach file, $(wildcard *.h), \ | 
|  | 169 | $(eval $(call copy_header_to_target,$(app),$(file))))) | 
| Gilles Peskine | 5168155 | 2019-05-20 19:35:37 +0200 | [diff] [blame^] | 170 |  | 
|  | 171 | ifdef RECORD_PSA_STATUS_COVERAGE_LOG | 
|  | 172 | $(BINARIES): instrument_record_status.h | 
|  | 173 | instrument_record_status.h: ../include/psa/crypto.h Makefile | 
|  | 174 | sed <../include/psa/crypto.h >$@ -n 's/^psa_status_t \([A-Za-z0-9_]*\)(.*/#define \1(...) RECORD_STATUS("\1", \1(__VA_ARGS__))/p' | 
|  | 175 | endif |