Home | History | Annotate | Line # | Download | only in fuzz
Makefile revision 1.1.1.4
      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 
      5 IMAGE		:= libfido2-coverage:1.8.0
      6 RUNNER		:= libfido2-runner
      7 PROFDATA	:= llvm-profdata-11
      8 COV		:= llvm-cov-11
      9 TARGETS		:= fuzz_assert fuzz_bio fuzz_cred fuzz_credman fuzz_hid \
     10 		   fuzz_largeblob fuzz_netlink fuzz_mgmt
     11 CORPORA		:= $(foreach f,${TARGETS},${f}/corpus)
     12 MINIFY		:= $(foreach f,${TARGETS},/minify/${f}/corpus)
     13 REMOTE		:= gs://libfido2-corpus.clusterfuzz-external.appspot.com
     14 .DEFAULT_GOAL	:= all
     15 
     16 all: ${TARGETS}
     17 
     18 build:
     19 	docker build -t ${IMAGE} - < Dockerfile
     20 
     21 run: build
     22 	-docker run -it -d --name ${RUNNER} ${IMAGE}
     23 	docker start ${RUNNER}
     24 
     25 sync: run
     26 	tar Ccf .. - src fuzz | docker exec -i ${RUNNER} tar Cxf /libfido2 -
     27 	docker exec ${RUNNER} make -C libfido2/build
     28 
     29 corpus: sync
     30 	docker exec ${RUNNER} /bin/sh -c 'cd /libfido2/fuzz && rm -rf ${TARGETS}'
     31 	docker exec ${RUNNER} tar Czxf /libfido2/fuzz /libfido2/fuzz/corpus.tgz
     32 
     33 ${TARGETS}: corpus sync
     34 	docker exec -e LLVM_PROFILE_FILE=/profraw/$@ ${RUNNER} \
     35 		/bin/sh -c 'rm -f /profraw/$@ && /libfido2/build/fuzz/$@ \
     36 		-runs=1 /libfido2/fuzz/$@'
     37 
     38 ${MINIFY}: /minify/%/corpus: %
     39 	docker exec ${RUNNER} /bin/sh -c 'rm -rf $@ && mkdir -p $@ && \
     40 		/libfido2/build/fuzz/$< -use_value_profile=1 -merge=1 $@ \
     41 		/libfido2/fuzz/$</corpus'
     42 
     43 corpus.tgz-: ${MINIFY}
     44 	docker exec -i ${RUNNER} tar Czcf /minify - ${TARGETS} > $@
     45 
     46 profdata: run
     47 	docker exec ${RUNNER} /bin/sh -c 'rm -f /$@ && ${PROFDATA} \
     48 		merge -sparse profraw/* -o $@'
     49 
     50 report.tgz: profdata
     51 	docker exec ${RUNNER} /bin/sh -c 'rm -rf /report && mkdir /report && \
     52 		${COV} show -format=html -tab-size=8 -instr-profile=/$< \
     53 		-output-dir=/report /libfido2/build/src/libfido2.so'
     54 	docker exec -i ${RUNNER} tar Czcf / - report > $@
     55 
     56 summary.txt: profdata
     57 	docker exec ${RUNNER} ${COV} report -use-color=false \
     58 		/libfido2/build/src/libfido2.so -instr-profile=/$< > $@
     59 
     60 functions.txt: profdata
     61 	docker exec ${RUNNER} /bin/sh -c '${COV} report -use-color=false \
     62 		-show-functions -instr-profile=/$< \
     63 		/libfido2/build/src/libfido2.so /libfido2/src/*.[ch]' > $@
     64 
     65 clean: run
     66 	docker exec ${RUNNER} /bin/sh -c 'rm -rf /profraw /profdata && \
     67 		make -C /libfido2/build clean'
     68 	-docker stop ${RUNNER}
     69 	rm -rf ${TARGETS}
     70 
     71 ${CORPORA}:
     72 	-mkdir -p $@
     73 	gsutil -q -m rsync -d -r ${REMOTE}/libFuzzer/libfido2_$(@:/corpus=) $@
     74 
     75 corpus.tgz: ${CORPORA}
     76 	tar zcf $@ ${TARGETS}
     77 
     78 .PHONY: build run sync corpus ${TARGETS} ${CORPORA}
     79 .PHONY: report.tgz summary.txt functions.txt
     80