1#!/bin/bash
2# Copyright 2016 The BoringSSL Authors
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#     https://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
16set -e
17
18buildDir=../build
19if [ $# -gt 0 ]; then
20  buildDir=$1
21fi
22
23for testSource in $(ls -1 *.cc); do
24  test=$(echo $testSource | sed -e 's/\.cc$//')
25  if [ ! -x $buildDir/fuzz/$test ] ; then
26    echo "Failed to find binary for $test"
27    exit 1
28  fi
29  if [ ! -d ${test}_corpus ]; then
30    echo "Failed to find corpus directory for $test"
31    exit 1
32  fi
33  if [ -d ${test}_corpus_old ]; then
34    echo "Old corpus directory for $test already exists"
35    exit 1
36  fi
37done
38
39for testSource in $(ls -1 *.cc); do
40  test=$(echo $testSource | sed -e 's/\.cc$//')
41  mv ${test}_corpus ${test}_corpus_old
42  mkdir ${test}_corpus
43  $buildDir/fuzz/$test -max_len=50000 -merge=1 ${test}_corpus ${test}_corpus_old
44  rm -Rf ${test}_corpus_old
45done
46