blob: 0da3748f18e8f246d8ad2858afd14d6aa88780c4 [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
Gilles Peskine24180ac2021-09-20 18:57:55 +02009# Set this to -v to see the details of failing test cases
10TEST_FLAGS ?= $(if $(filter-out 0 OFF Off off NO No no FALSE False false N n,$(CTEST_OUTPUT_ON_FAILURE)),-v,)
11
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020012LOCAL_CFLAGS = $(WARNING_CFLAGS) -I../include -D_FILE_OFFSET_BITS=64
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000013LOCAL_LDFLAGS = -L../library \
Manuel Pégourié-Gonnard21e1ac22015-06-25 08:45:12 +020014 -lmbedtls$(SHARED_SUFFIX) \
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020015 -lmbedx509$(SHARED_SUFFIX) \
Manuel Pégourié-Gonnard21e1ac22015-06-25 08:45:12 +020016 -lmbedcrypto$(SHARED_SUFFIX)
Paul Bakker0049c2f2009-07-11 19:15:43 +000017
Nicholas Wilson61fa4362018-06-25 12:10:00 +010018# Enable definition of various functions used throughout the testsuite
19# (gethostname, strdup, fileno...) even when compiling with -std=c99. Harmless
20# on non-POSIX platforms.
21LOCAL_CFLAGS += -D_POSIX_C_SOURCE=200809L
22
Paul Bakker674e0b02014-03-26 13:26:52 +010023ifndef SHARED
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020024DEP=../library/libmbedcrypto.a ../library/libmbedx509.a ../library/libmbedtls.a
Paul Bakker674e0b02014-03-26 13:26:52 +010025else
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020026DEP=../library/libmbedcrypto.$(DLEXT) ../library/libmbedx509.$(DLEXT) ../library/libmbedtls.$(DLEXT)
Paul Bakker674e0b02014-03-26 13:26:52 +010027endif
28
Paul Bakkerc7ffd362012-04-05 12:08:29 +000029ifdef DEBUG
Alon Bar-Levf7a9f302015-02-18 17:55:05 +020030LOCAL_CFLAGS += -g3
Paul Bakkerc7ffd362012-04-05 12:08:29 +000031endif
32
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020033# if we're running on Windows, build for Windows
Paul Bakkercd5b5292012-05-10 20:49:10 +000034ifdef WINDOWS
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020035WINDOWS_BUILD=1
36endif
37
38ifdef WINDOWS_BUILD
39DLEXT=dll
40EXEXT=.exe
Alon Bar-Levada41052015-02-18 17:47:52 +020041LOCAL_LDFLAGS += -lws2_32
Alon Bar-Lev18ba0cc2015-02-14 01:04:58 +020042ifdef SHARED
43SHARED_SUFFIX=.$(DLEXT)
44endif
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020045else
Andres Amaya Garcia420f0cc2018-03-27 19:17:21 +010046DLEXT ?= so
Manuel Pégourié-Gonnard8d4a6132015-06-24 12:16:20 +020047EXEXT=
48SHARED_SUFFIX=
Gilles Peskinecf3c4492021-07-13 18:14:25 +020049endif
50
51ifdef WINDOWS
52PYTHON ?= python
53else
Gilles Peskine99705a62021-04-22 00:21:58 +020054PYTHON ?= $(shell if type python3 >/dev/null 2>/dev/null; then echo python3; else echo python; fi)
Paul Bakkercd5b5292012-05-10 20:49:10 +000055endif
56
Paul Bakker2770fbd2012-07-03 13:30:23 +000057# Zlib shared library extensions:
58ifdef ZLIB
Alon Bar-Levada41052015-02-18 17:47:52 +020059LOCAL_LDFLAGS += -lz
Paul Bakker2770fbd2012-07-03 13:30:23 +000060endif
61
Azim Khan27a35e72018-06-29 12:39:19 +010062# A test application is built for each suites/test_suite_*.data file.
63# Application name is same as .data file's base name and can be
64# constructed by stripping path 'suites/' and extension .data.
65APPS = $(basename $(subst suites/,,$(wildcard suites/test_suite_*.data)))
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000066
Azim Khan27a35e72018-06-29 12:39:19 +010067# Construct executable name by adding OS specific suffix $(EXEXT).
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000068BINARIES := $(addsuffix $(EXEXT),$(APPS))
69
Paul Bakker0049c2f2009-07-11 19:15:43 +000070.SILENT:
71
Gilles Peskine3c546f72021-05-06 15:07:29 +020072.PHONY: all c_files check test clean
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020073
Azim Khan1de892b2017-06-09 15:02:36 +010074all: $(BINARIES)
75
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020076$(DEP):
Manuel Pégourié-Gonnardfc367082015-06-26 16:50:24 +020077 $(MAKE) -C ../library
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +020078
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000079C_FILES := $(addsuffix .c,$(APPS))
Gilles Peskine3c546f72021-05-06 15:07:29 +020080c_files: $(C_FILES)
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000081
Azim Khan27a35e72018-06-29 12:39:19 +010082# Wildcard target for test code generation:
83# A .c file is generated for each .data file in the suites/ directory. Each .c
84# file depends on a .data and .function file from suites/ directory. Following
85# nameing convention is followed:
86#
87# C file | Depends on
88#-----------------------------------------------------------------------------
89# foo.c | suites/foo.function suites/foo.data
90# foo.bar.c | suites/foo.function suites/foo.bar.data
91#
92# Note above that .c and .data files have same base name.
93# However, corresponding .function file's base name is the word before first
94# dot in .c file's base name.
95#
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +000096.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +010097%.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 +010098 echo " Gen $@"
Azim Khan27a35e72018-06-29 12:39:19 +010099 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100100 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100101 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100102 -p suites/host_test.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100103 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100104 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100105 -o .
Paul Bakker286bf3c2013-04-08 18:09:51 +0200106
Paul Bakker286bf3c2013-04-08 18:09:51 +0200107
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000108$(BINARIES): %$(EXEXT): %.c $(DEP)
Manuel Pégourié-Gonnard78ec2b02015-07-08 22:12:06 +0100109 echo " CC $<"
Alon Bar-Levf7a9f302015-02-18 17:55:05 +0200110 $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@
Paul Bakker286bf3c2013-04-08 18:09:51 +0200111
Paul Bakker286bf3c2013-04-08 18:09:51 +0200112
Paul Bakker0049c2f2009-07-11 19:15:43 +0000113clean:
Paul Bakker62f88dc2012-05-10 21:26:28 +0000114ifndef WINDOWS
Gilles Peskine2561a502018-09-26 13:42:26 +0200115 rm -rf $(BINARIES) *.c *.datax TESTS
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200116else
Mohammad Azim Khan00c4b092018-06-28 13:10:19 +0100117 del /Q /F *.c *.exe *.datax
Azim Khan27a35e72018-06-29 12:39:19 +0100118ifneq ($(wildcard TESTS/.*),)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000119 rmdir /Q /S TESTS
Paul Bakker62f88dc2012-05-10 21:26:28 +0000120endif
Azim Khan27a35e72018-06-29 12:39:19 +0100121endif
Paul Bakker0049c2f2009-07-11 19:15:43 +0000122
Gilles Peskineac372cc2018-11-29 10:15:06 +0000123# Test suites caught by SKIP_TEST_SUITES are built but not executed.
Mohammad Azim Khan94aefaf2017-03-23 12:32:54 +0000124check: $(BINARIES)
Gilles Peskine24180ac2021-09-20 18:57:55 +0200125 perl scripts/run-test-suites.pl $(TEST_FLAGS) --skip=$(SKIP_TEST_SUITES)
Manuel Pégourié-Gonnard5c59a4f2015-06-24 13:06:24 +0200126
127test: check
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000128
Azim Khan1de892b2017-06-09 15:02:36 +0100129# Create separate targets for generating embedded tests.
130EMBEDDED_TESTS := $(addprefix embedded_,$(APPS))
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000131
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100132# Generate test code for target.
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000133
134.SECONDEXPANSION:
Azim Khan27a35e72018-06-29 12:39:19 +0100135$(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 +0100136 echo " Gen ./TESTS/mbedtls/$*/$*.c"
Azim Khan27a35e72018-06-29 12:39:19 +0100137 $(PYTHON) scripts/generate_test_code.py -f suites/$(firstword $(subst ., ,$*)).function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000138 -d suites/$*.data \
Azim Khan1de892b2017-06-09 15:02:36 +0100139 -t suites/main_test.function \
Mohammad Azim Khan95402612017-07-19 10:15:54 +0100140 -p suites/target_test.function \
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000141 -s suites \
Azim Khane3b26af2018-06-29 02:36:57 +0100142 --helpers-file suites/helpers.function \
Mohammad Azim Khanfff49042017-03-28 01:48:31 +0100143 -o ./TESTS/mbedtls/$*
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000144
Mohammad Azim Khanff560f22018-06-28 11:43:17 +0100145generate-target-tests: $(EMBEDDED_TESTS)
Mohammad Azim Khan1f29be72017-03-20 22:21:22 +0000146