blob: 88d91ef265a0a613621472e020ff7d7a080cb49f [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
Nicholas Wilson61fa4362018-06-25 12:10:00 +010015# Enable definition of various functions used throughout the testsuite
16# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
17# on non-POSIX platforms.
18LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
19
Paul Bakker674e0b02014-03-26 13:26:52 +010020ifndef SHARED
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020021DEP=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
Paul Bakker674e0b02014-03-26 13:26:52 +010022else
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020023DEP=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
Paul Bakker674e0b02014-03-26 13:26:52 +010024endif
25
Paul Bakkerc7ffd362012-04-05 12:08:29 +000026ifdef DEBUG
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020027LOCAL_CFLAGS += -g3
Paul Bakkerc7ffd362012-04-05 12:08:29 +000028endif
29
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020030# if we're running on Windows, build for Windows
Paul Bakkercd5b5292012-05-10 20:49:10 +000031ifdef WINDOWS
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020032WINDOWS_BUILD=1
33endif
34
35ifdef WINDOWS_BUILD
36DLEXT=dll
37EXEXT=.exe
Alon Bar-Levada41052015-02-18 17:47:52 +020038LOCAL_LDFLAGS += -lws2_32
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020039ifdef SHARED
40SHARED_SUFFIX=.$(DLEXT)
41endif
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010042PYTHON ?= python
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020043else
Andres Amaya Garcia420f0cc2018-03-27 19:17:21 +010044DLEXT ?= so
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020045EXEXT=
46SHARED_SUFFIX=
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010047# python2 for POSIX since FreeBSD has only python2 as default.
48PYTHON ?= python2
Paul Bakkercd5b5292012-05-10 20:49:10 +000049endif
50
Paul Bakker2770fbd2012-07-03 13:30:23 +000051# Zlib shared library extensions:
52ifdef ZLIB
Alon Bar-Levada41052015-02-18 17:47:52 +020053LOCAL_LDFLAGS += -lz
Paul Bakker2770fbd2012-07-03 13:30:23 +000054endif
55
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000056APPS = test_suite_aes.ecb test_suite_aes.cbc \
57 test_suite_aes.cfb test_suite_aes.ofb \
58 test_suite_aes.xts \
59 test_suite_aes.rest test_suite_arc4 \
60 test_suite_aria test_suite_asn1write \
61 test_suite_base64 test_suite_blowfish \
62 test_suite_camellia test_suite_ccm \
63 test_suite_chacha20 test_suite_chachapoly \
64 test_suite_cmac \
65 test_suite_cipher.chachapoly \
66 test_suite_cipher.aes \
67 test_suite_cipher.arc4 test_suite_cipher.ccm \
68 test_suite_cipher.chacha20 \
69 test_suite_cipher.gcm \
70 test_suite_cipher.blowfish \
71 test_suite_cipher.camellia \
72 test_suite_cipher.des test_suite_cipher.null \
73 test_suite_cipher.padding \
74 test_suite_ctr_drbg test_suite_debug \
75 test_suite_des test_suite_dhm \
76 test_suite_ecdh test_suite_ecdsa \
77 test_suite_ecjpake test_suite_ecp \
78 test_suite_error test_suite_entropy \
79 test_suite_gcm.aes128_de \
80 test_suite_gcm.aes192_de \
81 test_suite_gcm.aes256_de \
82 test_suite_gcm.aes128_en \
83 test_suite_gcm.aes192_en \
84 test_suite_gcm.aes256_en \
85 test_suite_gcm.camellia \
86 test_suite_hkdf \
87 test_suite_hmac_drbg.misc \
88 test_suite_hmac_drbg.no_reseed \
89 test_suite_hmac_drbg.nopr \
90 test_suite_hmac_drbg.pr \
91 test_suite_md test_suite_mdx \
92 test_suite_memory_buffer_alloc \
93 test_suite_mpi \
94 test_suite_nist_kw \
95 test_suite_pem test_suite_pkcs1_v15 \
96 test_suite_pkcs1_v21 test_suite_pkcs5 \
97 test_suite_pkparse test_suite_pkwrite \
98 test_suite_pk \
99 test_suite_poly1305 \
100 test_suite_rsa test_suite_shax \
101 test_suite_ssl test_suite_timing \
102 test_suite_x509parse test_suite_x509write \
103 test_suite_xtea test_suite_version
104
105BINARIES := $(addsuffix $(EXEXT),$(APPS))
106
107# Look up for associated function files
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000108func.test_suite_aes.ecb := test_suite_aes
109func.test_suite_aes.cbc := test_suite_aes
110func.test_suite_aes.cfb := test_suite_aes
111func.test_suite_aes.ofb := test_suite_aes
112func.test_suite_aes.xts := test_suite_aes
113func.test_suite_aes.rest := test_suite_aes
114func.test_suite_arc4 := test_suite_arc4
115func.test_suite_aria := test_suite_aria
116func.test_suite_asn1write := test_suite_asn1write
117func.test_suite_base64 := test_suite_base64
118func.test_suite_blowfish := test_suite_blowfish
119func.test_suite_camellia := test_suite_camellia
120func.test_suite_ccm := test_suite_ccm
121func.test_suite_chacha20 := test_suite_chacha20
122func.test_suite_chachapoly := test_suite_chachapoly
123func.test_suite_cmac := test_suite_cmac
124func.test_suite_cipher.chachapoly := test_suite_cipher
125func.test_suite_cipher.aes := test_suite_cipher
126func.test_suite_cipher.arc4 := test_suite_cipher
127func.test_suite_cipher.ccm := test_suite_cipher
128func.test_suite_cipher.chacha20 := test_suite_cipher
129func.test_suite_cipher.gcm := test_suite_cipher
130func.test_suite_cipher.blowfish := test_suite_cipher
131func.test_suite_cipher.camellia := test_suite_cipher
132func.test_suite_cipher.des := test_suite_cipher
133func.test_suite_cipher.null := test_suite_cipher
134func.test_suite_cipher.padding := test_suite_cipher
135func.test_suite_ctr_drbg := test_suite_ctr_drbg
136func.test_suite_debug := test_suite_debug
137func.test_suite_des := test_suite_des
138func.test_suite_dhm := test_suite_dhm
139func.test_suite_ecdh := test_suite_ecdh
140func.test_suite_ecdsa := test_suite_ecdsa
141func.test_suite_ecjpake := test_suite_ecjpake
142func.test_suite_ecp := test_suite_ecp
143func.test_suite_error := test_suite_error
144func.test_suite_entropy := test_suite_entropy
145func.test_suite_gcm.aes128_de := test_suite_gcm
146func.test_suite_gcm.aes192_de := test_suite_gcm
147func.test_suite_gcm.aes256_de := test_suite_gcm
148func.test_suite_gcm.aes128_en := test_suite_gcm
149func.test_suite_gcm.aes192_en := test_suite_gcm
150func.test_suite_gcm.aes256_en := test_suite_gcm
151func.test_suite_gcm.camellia := test_suite_gcm
152func.test_suite_hkdf := test_suite_hkdf
153func.test_suite_hmac_drbg.misc := test_suite_hmac_drbg
154func.test_suite_hmac_drbg.no_reseed := test_suite_hmac_drbg
155func.test_suite_hmac_drbg.nopr := test_suite_hmac_drbg
156func.test_suite_hmac_drbg.pr := test_suite_hmac_drbg
157func.test_suite_md := test_suite_md
158func.test_suite_mdx := test_suite_mdx
159func.test_suite_memory_buffer_alloc := test_suite_memory_buffer_alloc
160func.test_suite_mpi := test_suite_mpi
161func.test_suite_nist_kw := test_suite_nist_kw
162func.test_suite_pem := test_suite_pem
163func.test_suite_pkcs1_v15 := test_suite_pkcs1_v15
164func.test_suite_pkcs1_v21 := test_suite_pkcs1_v21
165func.test_suite_pkcs5 := test_suite_pkcs5
166func.test_suite_pkparse := test_suite_pkparse
167func.test_suite_pkwrite := test_suite_pkwrite
168func.test_suite_pk := test_suite_pk
169func.test_suite_rsa := test_suite_rsa
170func.test_suite_shax := test_suite_shax
171func.test_suite_ssl := test_suite_ssl
172func.test_suite_timing := test_suite_timing
173func.test_suite_x509parse := test_suite_x509parse
174func.test_suite_x509write := test_suite_x509write
175func.test_suite_xtea := test_suite_xtea
176func.test_suite_version := test_suite_version
Paul Bakker0049c2f2009-07-11 19:15:43 +0000177
178.SILENT:
179
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200180.PHONY: all check test clean
181
Azim Khan1de892b2017-06-09 15:02:36 +0100182all: $(BINARIES)
183
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200184$(DEP):
Manuel Pégourié-Gonnardfc367082015-06-26 16:50:24 +0200185 $(MAKE) -C ../library
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200186
Manuel Pégourié-Gonnard6cacde22015-07-08 16:02:43 +0200187# invoke perl explicitly for the sake of mingw32-make
188
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000189C_FILES := $(addsuffix .c,$(APPS))
190
191.SECONDEXPANSION:
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000192$(C_FILES): %.c: suites/$$(func.$$*).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 +0100193 echo " Gen $@"
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000194 $(PYTHON) scripts/generate_test_code.py -f suites/$(func.$*).function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100195 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100196 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100197 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100198 -s suites \
199 --help-file suites/helpers.function \
200 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200201
Paul Bakker286bf3c2013-04-08 18:09:51 +0200202
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000203$(BINARIES): %$(EXEXT): %.c $(DEP)
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100204 echo " CC $<"
Alon Bar-Levf7a9f302015-02-18 17:55:05 +0200205 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200206
Paul Bakker286bf3c2013-04-08 18:09:51 +0200207
Paul Bakker0049c2f2009-07-11 19:15:43 +0000208clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000209ifndef WINDOWS
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100210 rm -rf $(APPS) *.c *.data TESTS
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200211else
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100212 del /Q /F *.c *.exe *.data
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000213 rmdir /Q /S TESTS
Paul Bakker62f88dc2012-05-10 21:26:28 +0000214endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000215
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000216check: $(BINARIES)
Manuel Pégourié-Gonnard85113842015-07-08 21:20:03 +0100217 perl scripts/run-test-suites.pl
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200218
219test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000220
Azim Khan1de892b2017-06-09 15:02:36 +0100221# Create separate targets for generating embedded tests.
222EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000223
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100224# Generate test code for target.
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000225
226.SECONDEXPANSION:
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000227$(EMBEDDED_TESTS): embedded_%: suites/$$(func.$$*).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 +0100228 echo " Gen ./TESTS/mbedtls/$*/$*.c"
Mohammad Azim Khan78befd92018-03-06 11:49:41 +0000229 $(PYTHON) scripts/generate_test_code.py -f suites/$(func.$*).function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000230 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100231 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100232 -p suites/target_test.function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000233 -s suites \
234 --help-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100235 -o ./TESTS/mbedtls/$*
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000236
Azim Khan1de892b2017-06-09 15:02:36 +0100237gen-embedded-test: $(EMBEDDED_TESTS)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000238