blob: 72c734324e8db99cac8fcc71299d27f223b7eef5 [file] [log] [blame]
Paul Bakker0049c2f2009-07-11 19:15:43 +00001
2# To compile on SunOS: add "-lsocket -lnsl" to LDFLAGS
Paul Bakker43b7e352011-01-18 15:27:19 +00003# To compile with PKCS11: add "-lpkcs11-helper" to LDFLAGS
Paul Bakker0049c2f2009-07-11 19:15:43 +00004
Mohammad Azim Khan95402612017-07-19 10:15:54 +01005CFLAGS ?= -O2
Alon Bar-Levf7a9f302015-02-18 17:55:05 +02006WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement -Wno-unused-function -Wno-unused-value
Alon Bar-Levada41052015-02-18 17:47:52 +02007LDFLAGS ?=
Paul Bakker0049c2f2009-07-11 19:15:43 +00008
Alon Bar-Levf7a9f302015-02-18 17:55:05 +02009LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -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 -lmbedtls$(SHARED_SUFFIX) \
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020012 -lmbedx509$(SHARED_SUFFIX) \
Manuel Pégourié-Gonnard21e1ac22015-06-25 08:45:12 +020013 -lmbedcrypto$(SHARED_SUFFIX)
Paul Bakker0049c2f2009-07-11 19:15:43 +000014
Jaeden Amero30b340a2018-10-25 17:37:00 +010015ifdef USE_CRYPTO_SUBMODULE
16LOCAL_LDFLAGS += -L../crypto/library
Jaeden Amerob1c48d32018-11-23 14:45:43 +000017LOCAL_CFLAGS += -I../crypto/include
Jaeden Amero30b340a2018-10-25 17:37:00 +010018CRYPTO := ../crypto/library/
19else
20CRYPTO := ../library/
21endif
22
Nicholas Wilson61fa4362018-06-25 12:10:00 +010023# Enable definition of various functions used throughout the testsuite
24# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
25# on non-POSIX platforms.
26LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
27
Paul Bakker674e0b02014-03-26 13:26:52 +010028ifndef SHARED
Jaeden Amero30b340a2018-10-25 17:37:00 +010029DEP=$(CRYPTO)libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
Paul Bakker674e0b02014-03-26 13:26:52 +010030else
Jaeden Amero30b340a2018-10-25 17:37:00 +010031DEP=$(CRYPTO)libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
Paul Bakker674e0b02014-03-26 13:26:52 +010032endif
33
Paul Bakkerc7ffd362012-04-05 12:08:29 +000034ifdef DEBUG
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020035LOCAL_CFLAGS += -g3
Paul Bakkerc7ffd362012-04-05 12:08:29 +000036endif
37
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020038# if we're running on Windows, build for Windows
Paul Bakkercd5b5292012-05-10 20:49:10 +000039ifdef WINDOWS
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020040WINDOWS_BUILD=1
41endif
42
43ifdef WINDOWS_BUILD
44DLEXT=dll
45EXEXT=.exe
Alon Bar-Levada41052015-02-18 17:47:52 +020046LOCAL_LDFLAGS += -lws2_32
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020047ifdef SHARED
48SHARED_SUFFIX=.$(DLEXT)
49endif
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010050PYTHON ?= python
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020051else
Andres Amaya Garcia420f0cc2018-03-27 19:17:21 +010052DLEXT ?= so
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020053EXEXT=
54SHARED_SUFFIX=
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010055# python2 for POSIX since FreeBSD has only python2 as default.
56PYTHON ?= python2
Paul Bakkercd5b5292012-05-10 20:49:10 +000057endif
58
Paul Bakker2770fbd2012-07-03 13:30:23 +000059# Zlib shared library extensions:
60ifdef ZLIB
Alon Bar-Levada41052015-02-18 17:47:52 +020061LOCAL_LDFLAGS += -lz
Paul Bakker2770fbd2012-07-03 13:30:23 +000062endif
63
Azim Khan27a35e72018-06-29 12:39:19 +010064# A test application is built for each suites/test_suite_*.data file.
65# Application name is same as .data file's base name and can be
66# constructed by stripping path 'suites/' and extension .data.
67APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data)))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000068
Jaeden Amerob78b3002018-10-29 15:15:41 +000069ifdef USE_CRYPTO_SUBMODULE
70APPS := $(filter-out \
71 test_suite_aes.cbc \
72 test_suite_aes.cfb \
73 test_suite_aes.ecb \
74 test_suite_aes.ofb \
75 test_suite_aes.rest \
76 test_suite_aes.xts \
77 test_suite_arc4 \
78 test_suite_aria \
79 test_suite_asn1write \
80 test_suite_base64 \
81 test_suite_blowfish \
82 test_suite_camellia \
83 test_suite_ccm \
84 test_suite_chacha20 \
85 test_suite_chachapoly \
86 test_suite_cipher.aes \
87 test_suite_cipher.arc4 \
88 test_suite_cipher.blowfish \
89 test_suite_cipher.camellia \
90 test_suite_cipher.ccm \
91 test_suite_cipher.chacha20 \
92 test_suite_cipher.chachapoly \
93 test_suite_cipher.des \
94 test_suite_cipher.gcm \
95 test_suite_cipher.misc \
96 test_suite_cipher.null \
97 test_suite_cipher.padding \
98 test_suite_cmac \
99 test_suite_ctr_drbg \
100 test_suite_des \
101 test_suite_dhm \
102 test_suite_ecdh \
103 test_suite_ecdsa \
104 test_suite_ecjpake \
105 test_suite_ecp \
106 test_suite_entropy \
107 test_suite_error \
108 test_suite_gcm.aes128_de \
109 test_suite_gcm.aes128_en \
110 test_suite_gcm.aes192_de \
111 test_suite_gcm.aes192_en \
112 test_suite_gcm.aes256_de \
113 test_suite_gcm.aes256_en \
114 test_suite_gcm.camellia \
115 test_suite_gcm.misc \
116 test_suite_hkdf \
117 test_suite_hmac_drbg.misc \
118 test_suite_hmac_drbg.nopr \
119 test_suite_hmac_drbg.no_reseed \
120 test_suite_hmac_drbg.pr \
121 test_suite_md \
122 test_suite_mdx \
123 test_suite_memory_buffer_alloc \
124 test_suite_mpi \
125 test_suite_nist_kw \
126 test_suite_pem \
127 test_suite_pk \
128 test_suite_pkcs1_v15 \
129 test_suite_pkcs1_v21 \
130 test_suite_pkcs5 \
131 test_suite_pkparse \
132 test_suite_pkwrite \
133 test_suite_poly1305 \
134 test_suite_rsa \
135 test_suite_shax \
136 test_suite_timing \
137 test_suite_xtea \
138 ,$(APPS))
139endif
140
Azim Khan27a35e72018-06-29 12:39:19 +0100141# Construct executable name by adding OS specific suffix $(EXEXT).
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000142BINARIES := $(addsuffix $(EXEXT),$(APPS))
143
Paul Bakker0049c2f2009-07-11 19:15:43 +0000144.SILENT:
145
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200146.PHONY: all check test clean
147
Azim Khan1de892b2017-06-09 15:02:36 +0100148all: $(BINARIES)
149
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200150$(DEP):
Manuel Pégourié-Gonnardfc367082015-06-26 16:50:24 +0200151 $(MAKE) -C ../library
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200152
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000153C_FILES := $(addsuffix .c,$(APPS))
154
Azim Khan27a35e72018-06-29 12:39:19 +0100155# Wildcard target for test code generation:
156# A .c file is generated for each .data file in the suites/ directory. Each .c
157# file depends on a .data and .function file from suites/ directory. Following
158# nameing convention is followed:
159#
160# C file | Depends on
161#-----------------------------------------------------------------------------
162# foo.c | suites/foo.function suites/foo.data
163# foo.bar.c | suites/foo.function suites/foo.bar.data
164#
165# Note above that .c and .data files have same base name.
166# However, corresponding .function file's base name is the word before first
167# dot in .c file's base name.
168#
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000169.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100170%.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 +0100171 echo " Gen $@"
Azim Khan27a35e72018-06-29 12:39:19 +0100172 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100173 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100174 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100175 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100176 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100177 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100178 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200179
Paul Bakker286bf3c2013-04-08 18:09:51 +0200180
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000181$(BINARIES): %$(EXEXT): %.c $(DEP)
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100182 echo " CC $<"
Alon Bar-Levf7a9f302015-02-18 17:55:05 +0200183 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200184
Paul Bakker286bf3c2013-04-08 18:09:51 +0200185
Paul Bakker0049c2f2009-07-11 19:15:43 +0000186clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000187ifndef WINDOWS
Gilles Peskine2561a502018-09-26 13:42:26 +0200188 rm -rf $(BINARIES) *.c *.datax TESTS
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200189else
Mohammad Azim Khan00c4b092018-06-28 13:10:19 +0100190 del /Q /F *.c *.exe *.datax
Azim Khan27a35e72018-06-29 12:39:19 +0100191ifneq ($(wildcard TESTS/.*),)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000192 rmdir /Q /S TESTS
Paul Bakker62f88dc2012-05-10 21:26:28 +0000193endif
Azim Khan27a35e72018-06-29 12:39:19 +0100194endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000195
Gilles Peskineac372cc2018-11-29 10:15:06 +0000196# Test suites caught by SKIP_TEST_SUITES are built but not executed.
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000197check: $(BINARIES)
Gilles Peskineac372cc2018-11-29 10:15:06 +0000198 perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200199
200test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000201
Azim Khan1de892b2017-06-09 15:02:36 +0100202# Create separate targets for generating embedded tests.
203EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000204
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100205# Generate test code for target.
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000206
207.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100208$(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 +0100209 echo " Gen ./TESTS/mbedtls/$*/$*.c"
Azim Khan27a35e72018-06-29 12:39:19 +0100210 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000211 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100212 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100213 -p suites/target_test.function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000214 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100215 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100216 -o ./TESTS/mbedtls/$*
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000217
Mohammad Azim Khanff560f22018-06-28 11:43:17 +0100218generate-target-tests: $(EMBEDDED_TESTS)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000219