1#!/bin/bash 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright(c) 2020, Mohana Datta Yelugoti 4 5# fail on any errors 6set -e 7 8print_usage() 9{ 10 cat <<EOFUSAGE 11usage: $0 [-f] 12 -f Build testbench with compiler provided by fuzzer 13 (default path: $HOME/sof/work/AFL/afl-gcc) 14EOFUSAGE 15} 16 17rebuild_testbench() 18{ 19 cd "$BUILD_TESTBENCH_DIR" 20 21 rm -rf build_testbench 22 23 mkdir build_testbench 24 cd build_testbench 25 26 cmake -DCMAKE_INSTALL_PREFIX=install .. 27 28 cmake --build . -- -j"$(nproc)" install 29} 30 31export_CC_with_afl() 32{ 33 printf 'export CC=%s\n' "${SOF_AFL}" 34 export CC=${SOF_AFL} 35} 36 37main() 38{ 39 SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd) 40 SOF_REPO=$(dirname "$SCRIPT_DIR") 41 BUILD_TESTBENCH_DIR="$SOF_REPO"/tools/testbench 42 : "${SOF_AFL:=$HOME/sof/work/AFL/afl-gcc}" 43 44 while getopts "fh" OPTION; do 45 case "$OPTION" in 46 f) export_CC_with_afl;; 47 h) print_usage; exit 1;; 48 *) print_usage; exit 1;; 49 esac 50 done 51 52 rebuild_testbench 53} 54 55main "$@" 56