Debian Codegraph @

fuzz/Makefile

raw
1 # Copyright (c) 2019-2023 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 # SPDX-License-Identifier: BSD-2-Clause
5
6 IMAGE := libfido2-coverage:1.17.0
7 RUNNER := libfido2-runner
8 PROFDATA := llvm-profdata
9 COV := llvm-cov
10 TARGETS := fuzz_assert fuzz_attobj fuzz_bio fuzz_cred fuzz_credman \
11 fuzz_hid fuzz_largeblob fuzz_netlink fuzz_mgmt fuzz_pcsc
12 CORPORA := $(foreach f,${TARGETS},${f}/corpus)
13 MINIFY := $(foreach f,${TARGETS},/minify/${f}/corpus)
14 REMOTE := gs://libfido2-corpus.clusterfuzz-external.appspot.com
15 .DEFAULT_GOAL := all
16
17 all: ${TARGETS}
18
19 build:
20 docker build -t ${IMAGE} - < Dockerfile
21
22 run: build
23 -docker run -it -d --name ${RUNNER} ${IMAGE}
24 docker start ${RUNNER}
25
26 sync: run
27 [ -e corpus.tgz ] # required
28 tar Ccf .. - src fuzz | docker exec -i ${RUNNER} tar Cxf /libfido2 -
29 docker exec ${RUNNER} make -C /libfido2/build
30
31 corpus: sync
32 docker exec ${RUNNER} /bin/sh -c 'cd /libfido2/fuzz && rm -rf ${TARGETS}'
33 docker exec ${RUNNER} tar Czxf /libfido2/fuzz /libfido2/fuzz/corpus.tgz
34
35 ${TARGETS}: corpus sync
36 docker exec -e LLVM_PROFILE_FILE=/profraw/$@ ${RUNNER} \
37 /bin/sh -c 'rm -f /profraw/$@ && /libfido2/build/fuzz/$@ \
38 -runs=1 /libfido2/fuzz/$@'
39
40 ${MINIFY}: /minify/%/corpus: %
41 docker exec ${RUNNER} /bin/sh -c 'rm -rf $@ && mkdir -p $@ && \
42 /libfido2/build/fuzz/$< -use_value_profile=1 -merge=1 $@ \
43 /libfido2/fuzz/$</corpus'
44
45 corpus.tgz-: ${MINIFY}
46 docker exec -i ${RUNNER} tar Czcf /minify - ${TARGETS} > $@
47
48 profdata: run
49 docker exec ${RUNNER} /bin/sh -c 'rm -f /$@ && ${PROFDATA} \
50 merge -sparse /profraw/* -o /$@'
51
52 report.tgz: profdata
53 docker exec ${RUNNER} /bin/sh -c 'rm -rf /report && mkdir /report && \
54 ${COV} show -format=html -tab-size=8 -instr-profile=/$< \
55 -ignore-filename-regex=pcsclite.h --show-branch-summary=false \
56 -output-dir=/report /libfido2/build/src/libfido2.so'
57 docker exec -i ${RUNNER} tar Czcf / - report > $@
58
59 summary.txt: profdata
60 docker exec ${RUNNER} ${COV} report -use-color=false \
61 -ignore-filename-regex=pcsclite.h --show-branch-summary=false \
62 /libfido2/build/src/libfido2.so -instr-profile=/$< > $@
63
64 functions.txt: profdata
65 docker exec ${RUNNER} /bin/sh -c '${COV} report -use-color=false \
66 -ignore-filename-regex=pcsclite.h -show-functions \
67 --show-branch-summary=false -instr-profile=/$< \
68 /libfido2/build/src/libfido2.so /libfido2/src/*.[ch]' > $@
69
70 clean: run
71 docker exec ${RUNNER} /bin/sh -c 'rm -rf /profraw /profdata && \
72 make -C /libfido2/build clean'
73 -docker stop ${RUNNER}
74 rm -rf ${TARGETS}
75
76 ${CORPORA}:
77 -mkdir -p $@
78 gsutil -q -m rsync -d -r ${REMOTE}/libFuzzer/libfido2_$(@:/corpus=) $@
79
80 fetch-oss-fuzz: ${CORPORA}
81 find ${TARGETS} -type f -size +8192c -print0 | xargs -0 rm
82
83 fetch-franz:
84 ssh franz tar -C corpus -cf- . | tar -xf-
85
86 corpus.tgz:
87 tar zcf $@ ${TARGETS}
88
89 .PHONY: build run sync corpus ${TARGETS} ${CORPORA}
90 .PHONY: report.tgz summary.txt functions.txt
91 .PHONY: fetch-oss-fuzz fetch-franz corpus.tgz