summaryrefslogtreecommitdiff
path: root/testing/hstox/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'testing/hstox/Makefile')
-rw-r--r--testing/hstox/Makefile97
1 files changed, 97 insertions, 0 deletions
diff --git a/testing/hstox/Makefile b/testing/hstox/Makefile
new file mode 100644
index 00000000..ec02719c
--- /dev/null
+++ b/testing/hstox/Makefile
@@ -0,0 +1,97 @@
1# Don't bind to a CPU core. afl-fuzz doesn't release them again.
2export AFL_NO_AFFINITY := 1
3
4CFLAGS := \
5 -std=gnu99 \
6 -Wall \
7 -g3 \
8 -DCONFIGURED=1 \
9 -Imsgpack-c/include \
10 -I../../toxcore \
11
12LDFLAGS := -pthread -lsodium
13ifeq ($(shell echo 'int main(){}' | $(CC) -lrt -xc -o /dev/null - && echo true),true)
14LDFLAGS += -lrt
15endif
16
17SOURCES := $(filter-out %_main.c,$(wildcard *.c msgpack-c/src/*.c ../../toxcore/*.c))
18HEADERS := $(shell find . -name "*.h")
19
20ifeq ($(wildcard test-findings/master/fuzzer_stats),)
21TEST_INPUTS := test-inputs
22else
23TEST_INPUTS := -
24endif
25
26# All the possible test flavours.
27PROGRAMS := \
28 test_main-cov \
29 test_main-cov-asan \
30 test_main-vanilla \
31 test_main-vanilla-asan
32
33ifneq ($(shell which afl-clang),)
34AFL_CLANG := afl-clang
35endif
36
37ifneq ($(shell which afl-clang-fast),)
38AFL_CLANG := afl-clang-fast
39endif
40
41ifneq ($(AFL_CLANG),)
42PROGRAMS += \
43 fuzz_main-afl \
44 fuzz_main-afl-asan
45endif
46
47all: $(PROGRAMS)
48
49check: test_main-sut
50 ./$< ./$<
51
52master: fuzz_main-afl test-findings
53 afl-fuzz -i$(TEST_INPUTS) -o test-findings -M master ./$<
54
55slave%: fuzz_main-afl test-findings
56 afl-fuzz -i test-inputs -o test-findings -S slave$* ./$<
57
58%-afl: %.c $(SOURCES) $(HEADERS)
59 $(AFL_CLANG) $(CFLAGS) -O3 $(filter %.c,$^) $(LDFLAGS) -o $@
60
61%-afl-asan: %.c $(SOURCES) $(HEADERS)
62 $(AFL_CLANG) $(CFLAGS) -O3 -fsanitize=address $(filter %.c,$^) $(LDFLAGS) -o $@
63
64%-cov: %.c $(SOURCES) $(HEADERS)
65 $(CC) $(CFLAGS) -fprofile-arcs -ftest-coverage $(filter %.c,$^) $(LDFLAGS) -o $@
66
67%-cov-asan: %.c $(SOURCES) $(HEADERS)
68 $(CC) $(CFLAGS) -fprofile-arcs -ftest-coverage -fsanitize=address $(filter %.c,$^) $(LDFLAGS) -o $@
69
70%-vanilla: %.c $(SOURCES) $(HEADERS)
71 $(CC) $(CFLAGS) $(filter %.c,$^) $(LDFLAGS) -o $@
72
73%-vanilla-asan: %.c $(SOURCES) $(HEADERS)
74 $(CC) $(CFLAGS) -fsanitize=address $(filter %.c,$^) $(LDFLAGS) -o $@
75
76%-sut: toxcore-sut.hs %.c $(SOURCES) $(HEADERS)
77 ghc -package hstox $< \
78 $(filter %.c,$^) \
79 $(foreach f,$(CFLAGS),-optc $f) \
80 $(foreach f,$(LDFLAGS),-optl $f) \
81 -o $@
82
83ifneq ($(wildcard /Volumes),)
84test-findings: /Volumes/RAM\ Disk
85 mkdir -p "$</$@"
86 ln -sf "$</$@" $@
87
88/Volumes/RAM\ Disk:
89 diskutil erasevolume HFS+ 'RAM Disk' `hdiutil attach -nomount ram://204800`
90else
91test-findings: /dev/shm
92 mkdir -p "$</$@"
93 test -d $@ || ln -sf "$</$@" $@
94endif
95
96clean:
97 rm -rf $(wildcard *_main-* *.dSYM *.gcno *.gcda *.o *.hi test-findings/*)