1#
2# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License").
5# You may not use this file except in compliance with the License.
6# A copy of the License is located at
7#
8#  http://aws.amazon.com/apache2.0
9#
10# or in the "license" file accompanying this file. This file is distributed
11# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12# express or implied. See the License for the specific language governing
13# permissions and limitations under the License.
14#
15
16SRCS=$(wildcard *.c)
17OBJS=$(SRCS:.c=.o)
18TESTS=$(SRCS:.c=)
19CRYPTO_LDFLAGS = -L$(LIBCRYPTO_ROOT)/lib
20SHELL:=/bin/bash
21
22
23ifndef LIBFUZZER_ROOT
24    export LIBFUZZER_ROOT = $(shell echo "../../fuzz_dependencies")
25endif
26
27ifndef FUZZ_TIMEOUT_SEC
28    export FUZZ_TIMEOUT_SEC=120
29endif
30
31ifndef FUZZ_TESTS
32    export FUZZ_TESTS=${TESTS}
33endif
34
35.PHONY : all
36all : run_tests
37
38include ../../s2n.mk
39
40CRUFT += $(wildcard *_test) $(wildcard fuzz-*.log) $(wildcard *_test_output.txt) $(wildcard *_test_results.txt) $(wildcard LD_PRELOAD/*.so) $(wildcard *.prof*)
41
42CFLAGS += -Wno-unreachable-code -O0 -I$(LIBCRYPTO_ROOT)/include/ -I../
43LIBS += -L../testlib/ -ltests2n -L../../lib/ -ls2n
44LDFLAGS += $(LIBFUZZER_ROOT)/lib/libFuzzer.a -lstdc++
45LDFLAGS += ${CRYPTO_LDFLAGS} ${LIBS} ${CRYPTO_LIBS} -lm -ldl -lrt -pthread
46
47DYLD_LIBRARY_PATH="../../lib/:../testlib/:$(LIBCRYPTO_ROOT)/lib:$$DYLD_LIBRARY_PATH"
48LD_LIBRARY_PATH="../../lib/:../testlib/:$(LIBCRYPTO_ROOT)/lib:$$LD_LIBRARY_PATH"
49
50ifdef AFL_FUZZ
51    ifneq ($(FUZZ_COVERAGE), true)
52        CFLAGS += $(LIBFUZZER_ROOT)/FuzzingEngine.a
53    endif
54endif
55
56
57ld-preload :
58	${MAKE} -C LD_PRELOAD
59
60$(TESTS)::
61	@${CC} ${CFLAGS} $@.c -o $@  ${LDFLAGS}
62
63run_tests:: $(FUZZ_TESTS) ld-preload
64	{ set -e; \
65	for test_name in ${FUZZ_TESTS} ; do \
66	export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}; \
67	export DYLD_LIBRARY_PATH=${DYLD_LIBRARY_PATH}; \
68	export LIBCRYPTO_ROOT=${LIBCRYPTO_ROOT}; \
69	./runFuzzTest.sh $${test_name} ${FUZZ_TIMEOUT_SEC}; done; \
70	}
71	./calcTotalCov.sh
72
73.PHONY : clean
74clean: decruft
75	${MAKE} -C LD_PRELOAD decruft
76	rm -rf profiles
77