blob: 3857778e7c42a5ba7bc4f7d4a8d26c35899bf66c [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
Gilles Peskine1e657712019-07-02 20:05:20 +02006WARNING_CFLAGS ?= -Wall -Wextra
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 +010015LOCAL_LDFLAGS += -L../crypto/library
Jaeden Amerob1c48d32018-11-23 14:45:43 +000016LOCAL_CFLAGS += -I../crypto/include
Jaeden Amero30b340a2018-10-25 17:37:00 +010017CRYPTO := ../crypto/library/
Jaeden Amero30b340a2018-10-25 17:37:00 +010018
Christoph M. Wintersteiger655ddab2019-01-21 17:26:19 +000019include ../3rdparty/Makefile.inc
20LOCAL_CFLAGS+=$(THIRDPARTY_INCLUDES)
Christoph M. Wintersteiger977d89a2018-10-25 12:47:03 +010021
Nicholas Wilson61fa4362018-06-25 12:10:00 +010022# Enable definition of various functions used throughout the testsuite
23# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
24# on non-POSIX platforms.
25LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
26
Paul Bakker674e0b02014-03-26 13:26:52 +010027ifndef SHARED
Jaeden Amero30b340a2018-10-25 17:37:00 +010028DEP=$(CRYPTO)libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
Paul Bakker674e0b02014-03-26 13:26:52 +010029else
Jaeden Amero30b340a2018-10-25 17:37:00 +010030DEP=$(CRYPTO)libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
Paul Bakker674e0b02014-03-26 13:26:52 +010031endif
32
Paul Bakkerc7ffd362012-04-05 12:08:29 +000033ifdef DEBUG
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020034LOCAL_CFLAGS += -g3
Paul Bakkerc7ffd362012-04-05 12:08:29 +000035endif
36
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020037# if we're running on Windows, build for Windows
Paul Bakkercd5b5292012-05-10 20:49:10 +000038ifdef WINDOWS
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020039WINDOWS_BUILD=1
40endif
41
42ifdef WINDOWS_BUILD
43DLEXT=dll
44EXEXT=.exe
Alon Bar-Levada41052015-02-18 17:47:52 +020045LOCAL_LDFLAGS += -lws2_32
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020046ifdef SHARED
47SHARED_SUFFIX=.$(DLEXT)
48endif
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010049PYTHON ?= python
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020050else
Andres Amaya Garcia420f0cc2018-03-27 19:17:21 +010051DLEXT ?= so
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020052EXEXT=
53SHARED_SUFFIX=
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010054# python2 for POSIX since FreeBSD has only python2 as default.
55PYTHON ?= python2
Paul Bakkercd5b5292012-05-10 20:49:10 +000056endif
57
Paul Bakker2770fbd2012-07-03 13:30:23 +000058# Zlib shared library extensions:
59ifdef ZLIB
Alon Bar-Levada41052015-02-18 17:47:52 +020060LOCAL_LDFLAGS += -lz
Paul Bakker2770fbd2012-07-03 13:30:23 +000061endif
62
Azim Khan27a35e72018-06-29 12:39:19 +010063# A test application is built for each suites/test_suite_*.data file.
64# Application name is same as .data file's base name and can be
65# constructed by stripping path 'suites/' and extension .data.
66APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data)))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000067
Jaeden Amerob78b3002018-10-29 15:15:41 +000068APPS := $(filter-out \
Jaeden Amero2184ef62019-03-13 14:50:00 +000069 test_suite_aes.% \
Jaeden Amerob78b3002018-10-29 15:15:41 +000070 test_suite_arc4 \
71 test_suite_aria \
72 test_suite_asn1write \
73 test_suite_base64 \
74 test_suite_blowfish \
75 test_suite_camellia \
76 test_suite_ccm \
77 test_suite_chacha20 \
78 test_suite_chachapoly \
Jaeden Amero2184ef62019-03-13 14:50:00 +000079 test_suite_cipher.% \
Jaeden Amerob78b3002018-10-29 15:15:41 +000080 test_suite_cmac \
81 test_suite_ctr_drbg \
82 test_suite_des \
83 test_suite_dhm \
84 test_suite_ecdh \
85 test_suite_ecdsa \
86 test_suite_ecjpake \
87 test_suite_ecp \
88 test_suite_entropy \
89 test_suite_error \
Jaeden Amero2184ef62019-03-13 14:50:00 +000090 test_suite_gcm.% \
Jaeden Amerob78b3002018-10-29 15:15:41 +000091 test_suite_hkdf \
Jaeden Amero2184ef62019-03-13 14:50:00 +000092 test_suite_hmac_drbg.% \
Jaeden Amerob78b3002018-10-29 15:15:41 +000093 test_suite_md \
94 test_suite_mdx \
95 test_suite_memory_buffer_alloc \
96 test_suite_mpi \
97 test_suite_nist_kw \
Jaeden Ameroc73fde72019-03-27 14:50:21 +000098 test_suite_oid \
Jaeden Amerob78b3002018-10-29 15:15:41 +000099 test_suite_pem \
100 test_suite_pk \
101 test_suite_pkcs1_v15 \
102 test_suite_pkcs1_v21 \
103 test_suite_pkcs5 \
104 test_suite_pkparse \
105 test_suite_pkwrite \
106 test_suite_poly1305 \
107 test_suite_rsa \
108 test_suite_shax \
109 test_suite_timing \
110 test_suite_xtea \
111 ,$(APPS))
Jaeden Amerob78b3002018-10-29 15:15:41 +0000112
Azim Khan27a35e72018-06-29 12:39:19 +0100113# Construct executable name by adding OS specific suffix $(EXEXT).
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000114BINARIES := $(addsuffix $(EXEXT),$(APPS))
115
Paul Bakker0049c2f2009-07-11 19:15:43 +0000116.SILENT:
117
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200118.PHONY: all check test clean
119
Azim Khan1de892b2017-06-09 15:02:36 +0100120all: $(BINARIES)
121
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200122$(DEP):
Manuel Pégourié-Gonnardfc367082015-06-26 16:50:24 +0200123 $(MAKE) -C ../library
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200124
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000125C_FILES := $(addsuffix .c,$(APPS))
126
Azim Khan27a35e72018-06-29 12:39:19 +0100127# Wildcard target for test code generation:
128# A .c file is generated for each .data file in the suites/ directory. Each .c
129# file depends on a .data and .function file from suites/ directory. Following
130# nameing convention is followed:
131#
132# C file | Depends on
133#-----------------------------------------------------------------------------
134# foo.c | suites/foo.function suites/foo.data
135# foo.bar.c | suites/foo.function suites/foo.bar.data
136#
137# Note above that .c and .data files have same base name.
138# However, corresponding .function file's base name is the word before first
139# dot in .c file's base name.
140#
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000141.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100142%.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 +0100143 echo " Gen $@"
Azim Khan27a35e72018-06-29 12:39:19 +0100144 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100145 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100146 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100147 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100148 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100149 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100150 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200151
Paul Bakker286bf3c2013-04-08 18:09:51 +0200152
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000153$(BINARIES): %$(EXEXT): %.c $(DEP)
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100154 echo " CC $<"
Alon Bar-Levf7a9f302015-02-18 17:55:05 +0200155 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200156
Paul Bakker286bf3c2013-04-08 18:09:51 +0200157
Paul Bakker0049c2f2009-07-11 19:15:43 +0000158clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000159ifndef WINDOWS
Gilles Peskine2561a502018-09-26 13:42:26 +0200160 rm -rf $(BINARIES) *.c *.datax TESTS
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200161else
Mohammad Azim Khan00c4b092018-06-28 13:10:19 +0100162 del /Q /F *.c *.exe *.datax
Azim Khan27a35e72018-06-29 12:39:19 +0100163ifneq ($(wildcard TESTS/.*),)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000164 rmdir /Q /S TESTS
Paul Bakker62f88dc2012-05-10 21:26:28 +0000165endif
Azim Khan27a35e72018-06-29 12:39:19 +0100166endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000167
Gilles Peskineac372cc2018-11-29 10:15:06 +0000168# Test suites caught by SKIP_TEST_SUITES are built but not executed.
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000169check: $(BINARIES)
Gilles Peskineac372cc2018-11-29 10:15:06 +0000170 perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200171
172test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000173
Azim Khan1de892b2017-06-09 15:02:36 +0100174# Create separate targets for generating embedded tests.
175EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000176
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100177# Generate test code for target.
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000178
179.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100180$(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 +0100181 echo " Gen ./TESTS/mbedtls/$*/$*.c"
Azim Khan27a35e72018-06-29 12:39:19 +0100182 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000183 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100184 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100185 -p suites/target_test.function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000186 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100187 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100188 -o ./TESTS/mbedtls/$*
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000189
Mohammad Azim Khanff560f22018-06-28 11:43:17 +0100190generate-target-tests: $(EMBEDDED_TESTS)