Home | History | Annotate | Line # | Download | only in fuzz
Makefile revision 1.1.1.1
      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.3.0
      6 RUNNER		:= libfido2-runner
      7 PROFDATA	:= llvm-profdata-9
      8 COV		:= llvm-cov-9
      9 TARGETS		:= fuzz_assert fuzz_bio fuzz_cred fuzz_credman fuzz_mgmt
     10 CORPORA		:= $(foreach f,${TARGETS},${f}/corpus)
     11 MINIFY		:= $(foreach f,${TARGETS},/minify/${f}/corpus)
     12 REMOTE		:= gs://libfido2-corpus.clusterfuzz-external.appspot.com
     13 .DEFAULT_GOAL	:= all
     14 
     15 all: ${TARGETS}
     16 
     17 build:
     18 	docker build -t ${IMAGE} - < Dockerfile
     19 
     20 run: build
     21 	-docker run -it -d --name ${RUNNER} ${IMAGE}
     22 	docker start ${RUNNER}
     23 
     24 sync: run
     25 	tar Ccf .. - src fuzz | docker exec -i ${RUNNER} tar Cxf /libfido2 -
     26 	docker exec ${RUNNER} make -C libfido2/build
     27 
     28 corpus: 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 
     42 corpus.tgz-: ${MINIFY}
     43 	docker exec -i ${RUNNER} tar Czcf /minify - ${TARGETS} > $@
     44 
     45 profdata: run
     46 	docker exec ${RUNNER} /bin/bash -c 'rm -f /$@ && ${PROFDATA} \
     47 		merge -sparse profraw/* -o $@'
     48 
     49 report.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 
     55 summary.txt: profdata
     56 	docker exec ${RUNNER} ${COV} report -use-color=false \
     57 		/libfido2/build/src/libfido2.so -instr-profile=/$< > $@
     58 
     59 functions.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 
     64 clean: 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 
     74 corpus.tgz: ${CORPORA}
     75 	tar zcf $@ ${TARGETS}
     76 
     77 .PHONY: build run sync corpus ${TARGETS} ${CORPORA}
     78 .PHONY: report.tgz summary.txt functions.txt
     79