blob: f7505b602a6216b09b6566cd14cf4ccf36750def [file] [log] [blame]
Paul Bakker0049c2f2009-07-11 19:15:43 +00001
2# To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS
Paul Bakker0049c2f2009-07-11 19:15:43 +00003
Mohammad Azim Khan95402612017-07-19 10:15:54 +01004CFLAGS ?= -O2
Gilles Peskine1e657712019-07-02 20:05:20 +02005WARNING_CFLAGS ?= -Wall -Wextra
Alon Bar-Levada41052015-02-18 17:47:52 +02006LDFLAGS ?=
Paul Bakker0049c2f2009-07-11 19:15:43 +00007
Jaeden Amero120d5712019-03-07 15:32:49 +00008CRYPTO_INCLUDES ?= -I../include
9LOCAL_CFLAGS = $(WARNING_CFLAGS) $(CRYPTO_INCLUDES) -I../library -D_FILE_OFFSET_BITS=64
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000010LOCAL_LDFLAGS = -L../library \
Manuel Pégourié-Gonnard21e1ac22015-06-25 08:45:12 +020011 -lmbedcrypto$(SHARED_SUFFIX)
Paul Bakker0049c2f2009-07-11 19:15:43 +000012
Christoph M. Wintersteiger6ea2dea12019-01-21 17:26:19 +000013include ../3rdparty/Makefile.inc
14LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
Christoph M. Wintersteigerd5fd7662018-10-25 12:47:03 +010015
Nicholas Wilson61fa4362018-06-25 12:10:00 +010016# 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.
19LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
20
Paul Bakker674e0b02014-03-26 13:26:52 +010021ifndef SHARED
Jaeden Amero8298d702018-11-02 10:11:31 +000022DEP=../library/libmbedcrypto.a
Paul Bakker674e0b02014-03-26 13:26:52 +010023else
Jaeden Amero8298d702018-11-02 10:11:31 +000024DEP=../library/libmbedcrypto.$(DLEXT)
Paul Bakker674e0b02014-03-26 13:26:52 +010025endif
26
Paul Bakkerc7ffd362012-04-05 12:08:29 +000027ifdef DEBUG
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020028LOCAL_CFLAGS += -g3
Paul Bakkerc7ffd362012-04-05 12:08:29 +000029endif
30
Gilles Peskine51681552019-05-20 19:35:37 +020031ifdef RECORD_PSA_STATUS_COVERAGE_LOG
32LOCAL_CFLAGS += -Werror -DRECORD_PSA_STATUS_COVERAGE_LOG
33endif
34
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020035# if we're running on Windows, build for Windows
Paul Bakkercd5b5292012-05-10 20:49:10 +000036ifdef WINDOWS
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020037WINDOWS_BUILD=1
38endif
39
40ifdef WINDOWS_BUILD
41DLEXT=dll
42EXEXT=.exe
Alon Bar-Levada41052015-02-18 17:47:52 +020043LOCAL_LDFLAGS += -lws2_32
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020044ifdef SHARED
45SHARED_SUFFIX=.$(DLEXT)
46endif
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010047PYTHON ?= python
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020048else
Andres Amaya Garcia420f0cc2018-03-27 19:17:21 +010049DLEXT ?= so
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020050EXEXT=
51SHARED_SUFFIX=
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010052# python2 for POSIX since FreeBSD has only python2 as default.
53PYTHON ?= python2
Paul Bakkercd5b5292012-05-10 20:49:10 +000054endif
55
Azim Khan27a35e72018-06-29 12:39:19 +010056# 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.
59APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data)))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000060
Jaeden Amero1264c2a2019-03-07 16:01:11 +000061# When this project is used as a submodule, exclude the following list of
62# tests, which will be run from the parent module instead.
63ifdef USE_CRYPTO_SUBMODULE
64APPS := $(filter-out \
65 test_suite_version \
66 ,$(APPS))
67endif
68
69
Azim Khan27a35e72018-06-29 12:39:19 +010070# Construct executable name by adding OS specific suffix $(EXEXT).
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000071BINARIES := $(addsuffix $(EXEXT),$(APPS))
72
Paul Bakker0049c2f2009-07-11 19:15:43 +000073.SILENT:
74
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020075.PHONY: all check test clean
76
Azim Khan1de892b2017-06-09 15:02:36 +010077all: $(BINARIES)
78
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020079$(DEP):
Manuel Pégourié-Gonnardfc367082015-06-26 16:50:24 +020080 $(MAKE) -C ../library
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020081
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000082C_FILES := $(addsuffix .c,$(APPS))
83
Azim Khan27a35e72018-06-29 12:39:19 +010084# 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 Khan94aefaf2017-03-23 12:32:54 +000098.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +010099%.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é-Gonnard78ec2b02015-07-08 22:12:06 +0100100 echo " Gen $@"
Azim Khan27a35e72018-06-29 12:39:19 +0100101 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100102 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100103 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100104 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100105 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100106 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100107 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200108
Paul Bakker286bf3c2013-04-08 18:09:51 +0200109
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000110$(BINARIES): %$(EXEXT): %.c $(DEP)
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100111 echo " CC $<"
Alon Bar-Levf7a9f302015-02-18 17:55:05 +0200112 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200113
Gilles Peskine1d102572019-06-20 17:23:58 +0200114# Some test suites require additional header files.
Gilles Peskine1838e822019-06-20 12:40:56 +0200115$(filter test_suite_psa_crypto%, $(BINARIES)): psa_crypto_helpers.h
Gilles Peskine1d102572019-06-20 17:23:58 +0200116$(addprefix embedded_,$(filter test_suite_psa_crypto%, $(APPS))): embedded_%: TESTS/mbedtls/%/psa_crypto_helpers.h
Gilles Peskine3cff7682019-06-20 12:54:43 +0200117$(filter test_suite_psa_%, $(BINARIES)): psa_helpers.h
Gilles Peskine1d102572019-06-20 17:23:58 +0200118$(addprefix embedded_,$(filter test_suite_psa_%, $(APPS))): embedded_%: TESTS/mbedtls/%/psa_helpers.h
Paul Bakker286bf3c2013-04-08 18:09:51 +0200119
Paul Bakker0049c2f2009-07-11 19:15:43 +0000120clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000121ifndef WINDOWS
Gilles Peskine15965542018-09-26 13:42:26 +0200122 rm -rf $(BINARIES) *.c *.datax TESTS
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200123else
Darryl Green6c0f94c2018-10-17 16:12:33 +0100124 if exist *.c del /Q /F *.c
125 if exist *.exe del /Q /F *.exe
126 if exist *.datax del /Q /F *.datax
Azim Khan27a35e72018-06-29 12:39:19 +0100127ifneq ($(wildcard TESTS/.*),)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000128 rmdir /Q /S TESTS
Paul Bakker62f88dc2012-05-10 21:26:28 +0000129endif
Azim Khan27a35e72018-06-29 12:39:19 +0100130endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000131
Gilles Peskineac372cc2018-11-29 10:15:06 +0000132# Test suites caught by SKIP_TEST_SUITES are built but not executed.
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000133check: $(BINARIES)
Gilles Peskineac372cc2018-11-29 10:15:06 +0000134 perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200135
136test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000137
Azim Khan1de892b2017-06-09 15:02:36 +0100138# Create separate targets for generating embedded tests.
139EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000140
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100141# Generate test code for target.
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000142
143.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100144$(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 Khanfff49042017-03-28 01:48:31 +0100145 echo " Gen ./TESTS/mbedtls/$*/$*.c"
Azim Khan27a35e72018-06-29 12:39:19 +0100146 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000147 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100148 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100149 -p suites/target_test.function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000150 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100151 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100152 -o ./TESTS/mbedtls/$*
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000153
Mohammad Azim Khanff560f22018-06-28 11:43:17 +0100154generate-target-tests: $(EMBEDDED_TESTS)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000155
Gilles Peskine1d102572019-06-20 17:23:58 +0200156define copy_header_to_target
157TESTS/mbedtls/$(1)/$(2): $(2)
158 echo " Copy ./$$@"
159ifndef WINDOWS
160 mkdir -p $$(@D)
161 cp $$< $$@
162else
163 mkdir $$(@D)
164 copy $$< $$@
165endif
166
167endef
168$(foreach app, $(APPS), $(foreach file, $(wildcard *.h), \
169 $(eval $(call copy_header_to_target,$(app),$(file)))))
Gilles Peskine51681552019-05-20 19:35:37 +0200170
171ifdef RECORD_PSA_STATUS_COVERAGE_LOG
172$(BINARIES): instrument_record_status.h
173instrument_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'
175endif