blob: 2c47634743696fff9360e11fa6d48bc757652e79 [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
Simon Butcherd3d8a642018-10-04 12:26:55 +01006WARNING_CFLAGS ?= -Wall -W -Wdeclaration-after-statement -Wunused
Alon Bar-Levada41052015-02-18 17:47:52 +02007LDFLAGS ?=
Paul Bakker0049c2f2009-07-11 19:15:43 +00008
Arto Kinnunen83078022019-09-25 16:10:04 +03009# Check test environment. If ../library is available then Mbed TLS is used.
10# Otherwise Mbed OS environment is used.
11DIR_FOR_MBED_TLS_ENV=../library
12ifneq "$(wildcard $(DIR_FOR_MBED_TLS_ENV) )" ""
13 LIBRARY_DIR=../library
14 INCLUDE_DIR=-I../include
15else
16 LIBRARY_DIR=../src
Arto Kinnunenc0d2fa72019-09-26 10:33:56 +030017 INCLUDE_DIR=-I../inc
18 CFLAGS += "-DMBEDTLS_CONFIG_FILE=\"mbedtls/test_config.h\""
Arto Kinnunen4ecfbd32019-10-24 15:48:47 +030019 CFLAGS += "-DTEST_ENV_MBED_OS"
Arto Kinnunen83078022019-09-25 16:10:04 +030020endif
21
22LOCAL_CFLAGS = $(WARNING_CFLAGS) $(INCLUDE_DIR) -D_FILE_OFFSET_BITS=64
Arto Kinnunen83078022019-09-25 16:10:04 +030023
24LOCAL_LDFLAGS = -L$(LIBRARY_DIR) \
Manuel Pégourié-Gonnard21e1ac22015-06-25 08:45:12 +020025 -lmbedtls$(SHARED_SUFFIX) \
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020026 -lmbedx509$(SHARED_SUFFIX) \
Manuel Pégourié-Gonnard21e1ac22015-06-25 08:45:12 +020027 -lmbedcrypto$(SHARED_SUFFIX)
Paul Bakker0049c2f2009-07-11 19:15:43 +000028
Nicholas Wilson61fa4362018-06-25 12:10:00 +010029# Enable definition of various functions used throughout the testsuite
30# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
31# on non-POSIX platforms.
32LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
33
Paul Bakker674e0b02014-03-26 13:26:52 +010034ifndef SHARED
Arto Kinnunen83078022019-09-25 16:10:04 +030035DEP=$(LIBRARY_DIR)/libmbedcrypto.a $(LIBRARY_DIR)/libmbedx509.a $(LIBRARY_DIR)/libmbedtls.a
Paul Bakker674e0b02014-03-26 13:26:52 +010036else
Arto Kinnunen83078022019-09-25 16:10:04 +030037DEP=$(LIBRARY_DIR)/libmbedcrypto.$(DLEXT) $(LIBRARY_DIR)/libmbedx509.$(DLEXT) $(LIBRARY_DIR)/libmbedtls.$(DLEXT)
Paul Bakker674e0b02014-03-26 13:26:52 +010038endif
39
Paul Bakkerc7ffd362012-04-05 12:08:29 +000040ifdef DEBUG
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020041LOCAL_CFLAGS += -g3
Paul Bakkerc7ffd362012-04-05 12:08:29 +000042endif
43
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020044# if we're running on Windows, build for Windows
Paul Bakkercd5b5292012-05-10 20:49:10 +000045ifdef WINDOWS
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020046WINDOWS_BUILD=1
47endif
48
49ifdef WINDOWS_BUILD
50DLEXT=dll
51EXEXT=.exe
Alon Bar-Levada41052015-02-18 17:47:52 +020052LOCAL_LDFLAGS += -lws2_32
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020053ifdef SHARED
54SHARED_SUFFIX=.$(DLEXT)
55endif
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010056PYTHON ?= python
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020057else
Andres Amaya Garcia420f0cc2018-03-27 19:17:21 +010058DLEXT ?= so
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020059EXEXT=
60SHARED_SUFFIX=
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010061# python2 for POSIX since FreeBSD has only python2 as default.
62PYTHON ?= python2
Paul Bakkercd5b5292012-05-10 20:49:10 +000063endif
64
Paul Bakker2770fbd2012-07-03 13:30:23 +000065# Zlib shared library extensions:
66ifdef ZLIB
Alon Bar-Levada41052015-02-18 17:47:52 +020067LOCAL_LDFLAGS += -lz
Paul Bakker2770fbd2012-07-03 13:30:23 +000068endif
69
Hanno Beckerfa37d072019-05-28 16:38:18 +010070# Pthread shared library extension
71ifdef PTHREAD
72LOCAL_LDFLAGS += -lpthread
73endif
74
Azim Khan27a35e72018-06-29 12:39:19 +010075# A test application is built for each suites/test_suite_*.data file.
76# Application name is same as .data file's base name and can be
77# constructed by stripping path 'suites/' and extension .data.
78APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data)))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000079
Hanno Beckerd687ef02019-05-29 13:05:55 +010080ifndef PTHREAD
81APPS := $(filter-out test_suite_x509parse_pthread, $(APPS))
82endif
83
Azim Khan27a35e72018-06-29 12:39:19 +010084# Construct executable name by adding OS specific suffix $(EXEXT).
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000085BINARIES := $(addsuffix $(EXEXT),$(APPS))
86
Paul Bakker0049c2f2009-07-11 19:15:43 +000087.SILENT:
88
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020089.PHONY: all check test clean
90
Azim Khan1de892b2017-06-09 15:02:36 +010091all: $(BINARIES)
92
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020093$(DEP):
Arto Kinnunen83078022019-09-25 16:10:04 +030094 $(MAKE) -C $(LIBRARY_DIR) $(INCLUDE_DIR)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020095
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000096C_FILES := $(addsuffix .c,$(APPS))
97
Azim Khan27a35e72018-06-29 12:39:19 +010098# Wildcard target for test code generation:
99# A .c file is generated for each .data file in the suites/ directory. Each .c
100# file depends on a .data and .function file from suites/ directory. Following
101# nameing convention is followed:
102#
103# C file | Depends on
104#-----------------------------------------------------------------------------
105# foo.c | suites/foo.function suites/foo.data
106# foo.bar.c | suites/foo.function suites/foo.bar.data
107#
108# Note above that .c and .data files have same base name.
109# However, corresponding .function file's base name is the word before first
110# dot in .c file's base name.
111#
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000112.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100113%.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 +0100114 echo " Gen $@"
Azim Khan27a35e72018-06-29 12:39:19 +0100115 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100116 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100117 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100118 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100119 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100120 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100121 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200122
Paul Bakker286bf3c2013-04-08 18:09:51 +0200123
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000124$(BINARIES): %$(EXEXT): %.c $(DEP)
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100125 echo " CC $<"
Alon Bar-Levf7a9f302015-02-18 17:55:05 +0200126 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200127
Paul Bakker286bf3c2013-04-08 18:09:51 +0200128
Paul Bakker0049c2f2009-07-11 19:15:43 +0000129clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000130ifndef WINDOWS
Manuel Pégourié-Gonnard80eaddf2019-07-30 14:59:54 +0200131 rm -rf $(BINARIES) *.c *.su *.datax TESTS
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200132else
Manuel Pégourié-Gonnard80eaddf2019-07-30 14:59:54 +0200133 del /Q /F *.c *.su *.exe *.datax
Azim Khan27a35e72018-06-29 12:39:19 +0100134ifneq ($(wildcard TESTS/.*),)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000135 rmdir /Q /S TESTS
Paul Bakker62f88dc2012-05-10 21:26:28 +0000136endif
Azim Khan27a35e72018-06-29 12:39:19 +0100137endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000138
Gilles Peskineac372cc2018-11-29 10:15:06 +0000139# Test suites caught by SKIP_TEST_SUITES are built but not executed.
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000140check: $(BINARIES)
Gilles Peskineac372cc2018-11-29 10:15:06 +0000141 perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200142
143test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000144
Azim Khan1de892b2017-06-09 15:02:36 +0100145# Create separate targets for generating embedded tests.
146EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000147
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100148# Generate test code for target.
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000149
150.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100151$(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 +0100152 echo " Gen ./TESTS/mbedtls/$*/$*.c"
Azim Khan27a35e72018-06-29 12:39:19 +0100153 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000154 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100155 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100156 -p suites/target_test.function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000157 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100158 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100159 -o ./TESTS/mbedtls/$*
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000160
Mohammad Azim Khanff560f22018-06-28 11:43:17 +0100161generate-target-tests: $(EMBEDDED_TESTS)