blob: dee011f91a7320f754245e3c3cfbdbf6f5376d09 [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 Kinnunen83078022019-09-25 16:10:04 +030019endif
20
21LOCAL_CFLAGS = $(WARNING_CFLAGS) $(INCLUDE_DIR) -D_FILE_OFFSET_BITS=64
Arto Kinnunen83078022019-09-25 16:10:04 +030022
23LOCAL_LDFLAGS = -L$(LIBRARY_DIR) \
Manuel Pégourié-Gonnard21e1ac22015-06-25 08:45:12 +020024 -lmbedtls$(SHARED_SUFFIX) \
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020025 -lmbedx509$(SHARED_SUFFIX) \
Manuel Pégourié-Gonnard21e1ac22015-06-25 08:45:12 +020026 -lmbedcrypto$(SHARED_SUFFIX)
Paul Bakker0049c2f2009-07-11 19:15:43 +000027
Nicholas Wilson61fa4362018-06-25 12:10:00 +010028# Enable definition of various functions used throughout the testsuite
29# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
30# on non-POSIX platforms.
31LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
32
Paul Bakker674e0b02014-03-26 13:26:52 +010033ifndef SHARED
Arto Kinnunen83078022019-09-25 16:10:04 +030034DEP=$(LIBRARY_DIR)/libmbedcrypto.a $(LIBRARY_DIR)/libmbedx509.a $(LIBRARY_DIR)/libmbedtls.a
Paul Bakker674e0b02014-03-26 13:26:52 +010035else
Arto Kinnunen83078022019-09-25 16:10:04 +030036DEP=$(LIBRARY_DIR)/libmbedcrypto.$(DLEXT) $(LIBRARY_DIR)/libmbedx509.$(DLEXT) $(LIBRARY_DIR)/libmbedtls.$(DLEXT)
Paul Bakker674e0b02014-03-26 13:26:52 +010037endif
38
Paul Bakkerc7ffd362012-04-05 12:08:29 +000039ifdef DEBUG
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020040LOCAL_CFLAGS += -g3
Paul Bakkerc7ffd362012-04-05 12:08:29 +000041endif
42
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020043# if we're running on Windows, build for Windows
Paul Bakkercd5b5292012-05-10 20:49:10 +000044ifdef WINDOWS
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020045WINDOWS_BUILD=1
46endif
47
48ifdef WINDOWS_BUILD
49DLEXT=dll
50EXEXT=.exe
Alon Bar-Levada41052015-02-18 17:47:52 +020051LOCAL_LDFLAGS += -lws2_32
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020052ifdef SHARED
53SHARED_SUFFIX=.$(DLEXT)
54endif
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010055PYTHON ?= python
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020056else
Andres Amaya Garcia420f0cc2018-03-27 19:17:21 +010057DLEXT ?= so
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020058EXEXT=
59SHARED_SUFFIX=
Mohammad Azim Khan8a3628f2018-06-26 17:30:16 +010060# python2 for POSIX since FreeBSD has only python2 as default.
61PYTHON ?= python2
Paul Bakkercd5b5292012-05-10 20:49:10 +000062endif
63
Paul Bakker2770fbd2012-07-03 13:30:23 +000064# Zlib shared library extensions:
65ifdef ZLIB
Alon Bar-Levada41052015-02-18 17:47:52 +020066LOCAL_LDFLAGS += -lz
Paul Bakker2770fbd2012-07-03 13:30:23 +000067endif
68
Hanno Beckerfa37d072019-05-28 16:38:18 +010069# Pthread shared library extension
70ifdef PTHREAD
71LOCAL_LDFLAGS += -lpthread
72endif
73
Azim Khan27a35e72018-06-29 12:39:19 +010074# A test application is built for each suites/test_suite_*.data file.
75# Application name is same as .data file's base name and can be
76# constructed by stripping path 'suites/' and extension .data.
77APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data)))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000078
Hanno Beckerd687ef02019-05-29 13:05:55 +010079ifndef PTHREAD
80APPS := $(filter-out test_suite_x509parse_pthread, $(APPS))
81endif
82
Azim Khan27a35e72018-06-29 12:39:19 +010083# Construct executable name by adding OS specific suffix $(EXEXT).
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000084BINARIES := $(addsuffix $(EXEXT),$(APPS))
85
Paul Bakker0049c2f2009-07-11 19:15:43 +000086.SILENT:
87
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020088.PHONY: all check test clean
89
Azim Khan1de892b2017-06-09 15:02:36 +010090all: $(BINARIES)
91
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020092$(DEP):
Arto Kinnunen83078022019-09-25 16:10:04 +030093 $(MAKE) -C $(LIBRARY_DIR) $(INCLUDE_DIR)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020094
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000095C_FILES := $(addsuffix .c,$(APPS))
96
Azim Khan27a35e72018-06-29 12:39:19 +010097# Wildcard target for test code generation:
98# A .c file is generated for each .data file in the suites/ directory. Each .c
99# file depends on a .data and .function file from suites/ directory. Following
100# nameing convention is followed:
101#
102# C file | Depends on
103#-----------------------------------------------------------------------------
104# foo.c | suites/foo.function suites/foo.data
105# foo.bar.c | suites/foo.function suites/foo.bar.data
106#
107# Note above that .c and .data files have same base name.
108# However, corresponding .function file's base name is the word before first
109# dot in .c file's base name.
110#
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000111.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100112%.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 +0100113 echo " Gen $@"
Azim Khan27a35e72018-06-29 12:39:19 +0100114 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100115 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100116 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100117 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100118 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100119 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100120 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200121
Paul Bakker286bf3c2013-04-08 18:09:51 +0200122
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000123$(BINARIES): %$(EXEXT): %.c $(DEP)
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100124 echo " CC $<"
Alon Bar-Levf7a9f302015-02-18 17:55:05 +0200125 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200126
Paul Bakker286bf3c2013-04-08 18:09:51 +0200127
Paul Bakker0049c2f2009-07-11 19:15:43 +0000128clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000129ifndef WINDOWS
Manuel Pégourié-Gonnard80eaddf2019-07-30 14:59:54 +0200130 rm -rf $(BINARIES) *.c *.su *.datax TESTS
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200131else
Manuel Pégourié-Gonnard80eaddf2019-07-30 14:59:54 +0200132 del /Q /F *.c *.su *.exe *.datax
Azim Khan27a35e72018-06-29 12:39:19 +0100133ifneq ($(wildcard TESTS/.*),)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000134 rmdir /Q /S TESTS
Paul Bakker62f88dc2012-05-10 21:26:28 +0000135endif
Azim Khan27a35e72018-06-29 12:39:19 +0100136endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000137
Gilles Peskineac372cc2018-11-29 10:15:06 +0000138# Test suites caught by SKIP_TEST_SUITES are built but not executed.
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000139check: $(BINARIES)
Gilles Peskineac372cc2018-11-29 10:15:06 +0000140 perl scripts/run-test-suites.pl --skip=$(SKIP_TEST_SUITES)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200141
142test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000143
Azim Khan1de892b2017-06-09 15:02:36 +0100144# Create separate targets for generating embedded tests.
145EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000146
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100147# Generate test code for target.
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000148
149.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100150$(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 +0100151 echo " Gen ./TESTS/mbedtls/$*/$*.c"
Azim Khan27a35e72018-06-29 12:39:19 +0100152 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000153 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100154 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100155 -p suites/target_test.function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000156 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100157 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100158 -o ./TESTS/mbedtls/$*
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000159
Mohammad Azim Khanff560f22018-06-28 11:43:17 +0100160generate-target-tests: $(EMBEDDED_TESTS)