• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2021 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16################################################################################
17
18case $SANITIZER in
19  address) SANITIZERS_ARGS="-DENABLE_ASAN=ON" ;;
20  undefined) SANITIZERS_ARGS="-DENABLE_UB_SANITIZER=ON" ;;
21  *) SANITIZERS_ARGS="" ;;
22esac
23
24: ${LD:="${CXX}"}
25: ${LDFLAGS:="${CXXFLAGS}"}  # to make sure we link with sanitizer runtime
26
27cmake_args=(
28    # Specific to Tarantool
29    -DENABLE_FUZZER=ON
30    -DOSS_FUZZ=ON
31    $SANITIZERS_ARGS
32
33    # C compiler
34    -DCMAKE_C_COMPILER="${CC}"
35    -DCMAKE_C_FLAGS="${CFLAGS}"
36
37    # C++ compiler
38    -DCMAKE_CXX_COMPILER="${CXX}"
39    -DCMAKE_CXX_FLAGS="${CXXFLAGS}"
40
41    # Linker
42    -DCMAKE_LINKER="${LD}"
43    -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}"
44    -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}"
45    -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}"
46)
47
48# Build the project and fuzzers.
49[[ -e build ]] && rm -rf build
50cmake "${cmake_args[@]}" -S . -B build
51make -j$(nproc) VERBOSE=1 -C build fuzzers
52
53# Archive and copy to $OUT seed corpus if the build succeeded.
54for f in $(ls build/test/fuzz/*_fuzzer);
55do
56  name=$(basename $f);
57  module=$(echo $name | sed 's/_fuzzer//')
58  corpus_dir="test/static/corpus/$module"
59  echo "Copying for $module";
60  cp $f $OUT/
61  [[ -e $corpus_dir ]] && zip -j $OUT/"$module"_fuzzer_seed_corpus.zip $corpus_dir/*
62done
63