xref: /netbsd-src/external/bsd/libfido2/dist/fuzz/Makefile (revision cef8759bd76c1b621f8eab8faa6f208faabc2e15)
1# Copyright (c) 2019 Yubico AB. All rights reserved.
2# Use of this source code is governed by a BSD-style
3# license that can be found in the LICENSE file.
4
5IMAGE		:= libfido2-coverage:1.3.0
6RUNNER		:= libfido2-runner
7PROFDATA	:= llvm-profdata-9
8COV		:= llvm-cov-9
9TARGETS		:= fuzz_assert fuzz_bio fuzz_cred fuzz_credman fuzz_mgmt
10CORPORA		:= $(foreach f,${TARGETS},${f}/corpus)
11MINIFY		:= $(foreach f,${TARGETS},/minify/${f}/corpus)
12REMOTE		:= gs://libfido2-corpus.clusterfuzz-external.appspot.com
13.DEFAULT_GOAL	:= all
14
15all: ${TARGETS}
16
17build:
18	docker build -t ${IMAGE} - < Dockerfile
19
20run: build
21	-docker run -it -d --name ${RUNNER} ${IMAGE}
22	docker start ${RUNNER}
23
24sync: run
25	tar Ccf .. - src fuzz | docker exec -i ${RUNNER} tar Cxf /libfido2 -
26	docker exec ${RUNNER} make -C libfido2/build
27
28corpus: sync
29	docker exec ${RUNNER} /bin/bash -c 'cd /libfido2/fuzz && rm -rf ${TARGETS}'
30	docker exec ${RUNNER} tar Czxf /libfido2/fuzz /libfido2/fuzz/corpus.tgz
31
32${TARGETS}: corpus sync
33	docker exec -e LLVM_PROFILE_FILE=/profraw/$@ ${RUNNER} \
34		/bin/bash -c 'rm -f /profraw/$@ && /libfido2/build/fuzz/$@ \
35		-runs=1 /libfido2/fuzz/$@'
36
37${MINIFY}: /minify/%/corpus: %
38	docker exec ${RUNNER} /bin/bash -c 'rm -rf $@ && mkdir -p $@ && \
39		/libfido2/build/fuzz/$< -use_value_profile=1 -merge=1 $@ \
40		/libfido2/fuzz/$</corpus'
41
42corpus.tgz-: ${MINIFY}
43	docker exec -i ${RUNNER} tar Czcf /minify - ${TARGETS} > $@
44
45profdata: run
46	docker exec ${RUNNER} /bin/bash -c 'rm -f /$@ && ${PROFDATA} \
47		merge -sparse profraw/* -o $@'
48
49report.tgz: profdata
50	docker exec ${RUNNER} /bin/bash -c 'rm -rf /report && mkdir /report && \
51		${COV} show -format=html -tab-size=8 -instr-profile=/$< \
52		-output-dir=/report /libfido2/build/src/libfido2.so'
53	docker exec -i ${RUNNER} tar Czcf / - report > $@
54
55summary.txt: profdata
56	docker exec ${RUNNER} ${COV} report -use-color=false \
57		/libfido2/build/src/libfido2.so -instr-profile=/$< > $@
58
59functions.txt: profdata
60	docker exec ${RUNNER} /bin/bash -c '${COV} report -use-color=false \
61		-show-functions -instr-profile=/$< \
62		/libfido2/build/src/libfido2.so /libfido2/src/*.[ch]' > $@
63
64clean: run
65	docker exec ${RUNNER} /bin/bash -c 'rm -rf /profraw /profdata && \
66		make -C /libfido2/build clean'
67	-docker stop ${RUNNER}
68	rm -rf ${TARGETS}
69
70${CORPORA}:
71	-mkdir -p $@
72	gsutil -q -m rsync -d -r ${REMOTE}/libFuzzer/libfido2_$(@:/corpus=) $@
73
74corpus.tgz: ${CORPORA}
75	tar zcf $@ ${TARGETS}
76
77.PHONY: build run sync corpus ${TARGETS} ${CORPORA}
78.PHONY: report.tgz summary.txt functions.txt
79