12ccfa855SEd Maste# Copyright (c) 2019-2023 Yubico AB. All rights reserved. 20afa8e06SEd Maste# Use of this source code is governed by a BSD-style 30afa8e06SEd Maste# license that can be found in the LICENSE file. 42ccfa855SEd Maste# SPDX-License-Identifier: BSD-2-Clause 50afa8e06SEd Maste 6*60a517b6SEd MasteIMAGE := libfido2-coverage:1.14.0 70afa8e06SEd MasteRUNNER := libfido2-runner 82ccfa855SEd MastePROFDATA := llvm-profdata 92ccfa855SEd MasteCOV := llvm-cov 100afa8e06SEd MasteTARGETS := fuzz_assert fuzz_bio fuzz_cred fuzz_credman fuzz_hid \ 112ccfa855SEd Maste fuzz_largeblob fuzz_netlink fuzz_mgmt fuzz_pcsc 120afa8e06SEd MasteCORPORA := $(foreach f,${TARGETS},${f}/corpus) 130afa8e06SEd MasteMINIFY := $(foreach f,${TARGETS},/minify/${f}/corpus) 140afa8e06SEd MasteREMOTE := gs://libfido2-corpus.clusterfuzz-external.appspot.com 150afa8e06SEd Maste.DEFAULT_GOAL := all 160afa8e06SEd Maste 170afa8e06SEd Masteall: ${TARGETS} 180afa8e06SEd Maste 190afa8e06SEd Mastebuild: 200afa8e06SEd Maste docker build -t ${IMAGE} - < Dockerfile 210afa8e06SEd Maste 220afa8e06SEd Masterun: build 230afa8e06SEd Maste -docker run -it -d --name ${RUNNER} ${IMAGE} 240afa8e06SEd Maste docker start ${RUNNER} 250afa8e06SEd Maste 260afa8e06SEd Mastesync: run 270afa8e06SEd Maste tar Ccf .. - src fuzz | docker exec -i ${RUNNER} tar Cxf /libfido2 - 282ccfa855SEd Maste docker exec ${RUNNER} make -C /libfido2/build 290afa8e06SEd Maste 300afa8e06SEd Mastecorpus: sync 310afa8e06SEd Maste docker exec ${RUNNER} /bin/sh -c 'cd /libfido2/fuzz && rm -rf ${TARGETS}' 320afa8e06SEd Maste docker exec ${RUNNER} tar Czxf /libfido2/fuzz /libfido2/fuzz/corpus.tgz 330afa8e06SEd Maste 340afa8e06SEd Maste${TARGETS}: corpus sync 350afa8e06SEd Maste docker exec -e LLVM_PROFILE_FILE=/profraw/$@ ${RUNNER} \ 360afa8e06SEd Maste /bin/sh -c 'rm -f /profraw/$@ && /libfido2/build/fuzz/$@ \ 370afa8e06SEd Maste -runs=1 /libfido2/fuzz/$@' 380afa8e06SEd Maste 390afa8e06SEd Maste${MINIFY}: /minify/%/corpus: % 400afa8e06SEd Maste docker exec ${RUNNER} /bin/sh -c 'rm -rf $@ && mkdir -p $@ && \ 410afa8e06SEd Maste /libfido2/build/fuzz/$< -use_value_profile=1 -merge=1 $@ \ 420afa8e06SEd Maste /libfido2/fuzz/$</corpus' 430afa8e06SEd Maste 440afa8e06SEd Mastecorpus.tgz-: ${MINIFY} 450afa8e06SEd Maste docker exec -i ${RUNNER} tar Czcf /minify - ${TARGETS} > $@ 460afa8e06SEd Maste 470afa8e06SEd Masteprofdata: run 480afa8e06SEd Maste docker exec ${RUNNER} /bin/sh -c 'rm -f /$@ && ${PROFDATA} \ 492ccfa855SEd Maste merge -sparse /profraw/* -o /$@' 500afa8e06SEd Maste 510afa8e06SEd Mastereport.tgz: profdata 520afa8e06SEd Maste docker exec ${RUNNER} /bin/sh -c 'rm -rf /report && mkdir /report && \ 530afa8e06SEd Maste ${COV} show -format=html -tab-size=8 -instr-profile=/$< \ 542ccfa855SEd Maste -ignore-filename-regex=pcsclite.h --show-branch-summary=false \ 552ccfa855SEd Maste -output-dir=/report /libfido2/build/src/libfido2.so' 560afa8e06SEd Maste docker exec -i ${RUNNER} tar Czcf / - report > $@ 570afa8e06SEd Maste 580afa8e06SEd Mastesummary.txt: profdata 590afa8e06SEd Maste docker exec ${RUNNER} ${COV} report -use-color=false \ 602ccfa855SEd Maste -ignore-filename-regex=pcsclite.h --show-branch-summary=false \ 612ccfa855SEd Maste /libfido2/build/src/libfido2.so -instr-profile=/$< > $@ 620afa8e06SEd Maste 630afa8e06SEd Mastefunctions.txt: profdata 640afa8e06SEd Maste docker exec ${RUNNER} /bin/sh -c '${COV} report -use-color=false \ 652ccfa855SEd Maste -ignore-filename-regex=pcsclite.h -show-functions \ 662ccfa855SEd Maste --show-branch-summary=false -instr-profile=/$< \ 670afa8e06SEd Maste /libfido2/build/src/libfido2.so /libfido2/src/*.[ch]' > $@ 680afa8e06SEd Maste 690afa8e06SEd Masteclean: run 700afa8e06SEd Maste docker exec ${RUNNER} /bin/sh -c 'rm -rf /profraw /profdata && \ 710afa8e06SEd Maste make -C /libfido2/build clean' 720afa8e06SEd Maste -docker stop ${RUNNER} 730afa8e06SEd Maste rm -rf ${TARGETS} 740afa8e06SEd Maste 750afa8e06SEd Maste${CORPORA}: 760afa8e06SEd Maste -mkdir -p $@ 770afa8e06SEd Maste gsutil -q -m rsync -d -r ${REMOTE}/libFuzzer/libfido2_$(@:/corpus=) $@ 780afa8e06SEd Maste 792ccfa855SEd Mastefetch-oss-fuzz: ${CORPORA} 802ccfa855SEd Maste find ${TARGETS} -type f -size +8192c -print0 | xargs -0 rm 812ccfa855SEd Maste 822ccfa855SEd Mastefetch-franz: 832ccfa855SEd Maste ssh franz tar -C corpus -cf- . | tar -xf- 842ccfa855SEd Maste 852ccfa855SEd Mastecorpus.tgz: 860afa8e06SEd Maste tar zcf $@ ${TARGETS} 870afa8e06SEd Maste 880afa8e06SEd Maste.PHONY: build run sync corpus ${TARGETS} ${CORPORA} 890afa8e06SEd Maste.PHONY: report.tgz summary.txt functions.txt 902ccfa855SEd Maste.PHONY: fetch-oss-fuzz fetch-franz corpus.tgz 91