diff --git a/tests/Makefile b/tests/Makefile index 27ce33895..d5dd193b8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -112,9 +112,12 @@ BINARIES := $(addsuffix $(EXEXT),$(APPS)) .SILENT: -.PHONY: all check test clean +.PHONY: all check test clean fuzz -all: $(BINARIES) +all: $(BINARIES) fuzz + +fuzz: + $(MAKE) -C fuzz $(DEP): $(MAKE) -C ../library diff --git a/tests/fuzz/Makefile b/tests/fuzz/Makefile new file mode 100644 index 000000000..f2195d129 --- /dev/null +++ b/tests/fuzz/Makefile @@ -0,0 +1,72 @@ + +LOCAL_CFLAGS = -I../../include -D_FILE_OFFSET_BITS=64 +LOCAL_LDFLAGS = -L../../library \ + -lmbedtls$(SHARED_SUFFIX) \ + -lmbedx509$(SHARED_SUFFIX) \ + -lmbedcrypto$(SHARED_SUFFIX) + +LOCAL_LDFLAGS += -L../../crypto/library +LOCAL_CFLAGS += -I../../crypto/include +CRYPTO := ../../crypto/library/ + +ifndef SHARED +DEP=$(CRYPTO)libmbedcrypto.a ../../library/libmbedx509.a ../../library/libmbedtls.a +else +DEP=$(CRYPTO)libmbedcrypto.$(DLEXT) ../../library/libmbedx509.$(DLEXT) ../../library/libmbedtls.$(DLEXT) +endif + + +DLEXT ?= so +EXEXT= +SHARED_SUFFIX= +# python2 for POSIX since FreeBSD has only python2 as default. +PYTHON ?= python2 + +# Zlib shared library extensions: +ifdef ZLIB +LOCAL_LDFLAGS += -lz +endif + +ifdef FUZZINGENGINE +LOCAL_LDFLAGS += -lFuzzingEngine +endif + +# A test application is built for each suites/test_suite_*.data file. +# Application name is same as .data file's base name and can be +# constructed by stripping path 'suites/' and extension .data. +APPS = $(basename $(wildcard fuzz_*.c)) + +# Construct executable name by adding OS specific suffix $(EXEXT). +BINARIES := $(addsuffix $(EXEXT),$(APPS)) + +.SILENT: + +.PHONY: all check test clean + +all: $(BINARIES) + +$(DEP): + $(MAKE) -C ../../library + +C_FILES := $(addsuffix .c,$(APPS)) + +%.o: %.c + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c $< -o $@ + + +ifdef FUZZINGENGINE +$(BINARIES): %$(EXEXT): %.o common.o $(DEP) + echo " $(CC) common.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@" + $(CXX) common.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +else +$(BINARIES): %$(EXEXT): %.o common.o onefile.o $(DEP) + echo " $(CC) common.o onefile.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@" + $(CC) common.o onefile.o $< $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +endif + +clean: +ifndef WINDOWS + rm -rf $(BINARIES) *.o +else + del /Q /F *.o *.exe +endif diff --git a/tests/fuzz/README.md b/tests/fuzz/README.md index a779c29ac..2105ece49 100644 --- a/tests/fuzz/README.md +++ b/tests/fuzz/README.md @@ -24,7 +24,7 @@ You can use `undefined` sanitizer as well as `address` sanitizer And you can run any of the fuzz targets like `fuzz_client` To run the fuzz targets without oss-fuzz, you first need to install one libFuzzingEngine (libFuzzer for instance) -Then you need to compile the code +Then you need to compile the code with the compiler flags of the wished sanitizer ``` perl scripts/config.pl set MBEDTLS_PLATFORM_TIME_ALT mkdir build