David Benjamin | fd06601 | 2016-11-15 00:47:17 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright (c) 2016, Google Inc. |
| 3 | # |
| 4 | # Permission to use, copy, modify, and/or distribute this software for any |
| 5 | # purpose with or without fee is hereby granted, provided that the above |
| 6 | # copyright notice and this permission notice appear in all copies. |
| 7 | # |
| 8 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 11 | # SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 13 | # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 14 | # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | |
| 16 | set -ex |
| 17 | |
| 18 | if [[ $# -ne 2 ]]; then |
| 19 | echo "Usage: $0 fuzzer_mode_build_dir no_fuzzer_mode_build_dir" |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
| 23 | fuzzer_mode_build_dir=$1 |
| 24 | no_fuzzer_mode_build_dir=$2 |
| 25 | |
| 26 | |
| 27 | # Sanity-check the build directories. |
| 28 | |
| 29 | if ! grep -q '^FUZZ:' "$fuzzer_mode_build_dir/CMakeCache.txt"; then |
| 30 | echo "$fuzzer_mode_build_dir was not built with -DFUZZ=1" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | if grep -q '^NO_FUZZER_MODE:' "$fuzzer_mode_build_dir/CMakeCache.txt"; then |
| 35 | echo "$fuzzer_mode_build_dir was built with -DNO_FUZZER_MODE=1" |
| 36 | exit 1 |
| 37 | fi |
| 38 | |
| 39 | if ! grep -q '^FUZZ:' "$no_fuzzer_mode_build_dir/CMakeCache.txt"; then |
| 40 | echo "$no_fuzzer_mode_build_dir was not built with -DFUZZ=1" |
| 41 | exit 1 |
| 42 | fi |
| 43 | |
| 44 | if ! grep -q '^NO_FUZZER_MODE:' "$no_fuzzer_mode_build_dir/CMakeCache.txt"; then |
| 45 | echo "$no_fuzzer_mode_build_dir was not built with -DNO_FUZZER_MODE=1" |
| 46 | exit 1 |
| 47 | fi |
| 48 | |
| 49 | |
| 50 | # Sanity-check the current working directory. |
| 51 | |
| 52 | assert_directory() { |
| 53 | if [[ ! -d $1 ]]; then |
| 54 | echo "$1 not found." |
| 55 | exit 1 |
| 56 | fi |
| 57 | } |
| 58 | |
| 59 | assert_directory client_corpus |
| 60 | assert_directory client_corpus_no_fuzzer_mode |
| 61 | assert_directory server_corpus |
| 62 | assert_directory server_corpus_no_fuzzer_mode |
| 63 | |
| 64 | |
| 65 | # Gather new transcripts. Ignore errors in running the tests. |
| 66 | |
| 67 | fuzzer_mode_shim=$(readlink -f "$fuzzer_mode_build_dir/ssl/test/bssl_shim") |
| 68 | no_fuzzer_mode_shim=$(readlink -f \ |
| 69 | "$no_fuzzer_mode_build_dir/ssl/test/bssl_shim") |
| 70 | |
| 71 | fuzzer_mode_transcripts=$(mktemp -d '/tmp/boringssl-transcript.XXXXXX') |
| 72 | no_fuzzer_mode_transcripts=$(mktemp -d '/tmp/boringssl-transcript.XXXXXX') |
| 73 | |
| 74 | echo Recording fuzzer-mode transcripts |
| 75 | (cd ../ssl/test/runner/ && go test \ |
| 76 | -shim-path "$fuzzer_mode_shim" \ |
| 77 | -transcript-dir "$fuzzer_mode_transcripts" \ |
| 78 | -fuzzer \ |
| 79 | -deterministic) || true |
| 80 | |
| 81 | echo Recording non-fuzzer-mode transcripts |
| 82 | (cd ../ssl/test/runner/ && go test \ |
| 83 | -shim-path "$no_fuzzer_mode_shim" \ |
| 84 | -transcript-dir "$no_fuzzer_mode_transcripts" \ |
| 85 | -deterministic) || true |
| 86 | |
| 87 | |
| 88 | # Minimize the existing corpora. |
| 89 | |
| 90 | minimize_corpus() { |
| 91 | local fuzzer="$1" |
| 92 | local corpus="$2" |
| 93 | |
| 94 | echo "Minimizing ${corpus}" |
| 95 | mv "$corpus" "${corpus}_old" |
| 96 | mkdir "$corpus" |
| 97 | "$fuzzer" -max_len=50000 -merge=1 "$corpus" "${corpus}_old" |
| 98 | rm -Rf "${corpus}_old" |
| 99 | } |
| 100 | |
| 101 | minimize_corpus "$fuzzer_mode_build_dir/fuzz/client" client_corpus |
| 102 | minimize_corpus "$fuzzer_mode_build_dir/fuzz/server" server_corpus |
| 103 | minimize_corpus "$no_fuzzer_mode_build_dir/fuzz/client" client_corpus_no_fuzzer_mode |
| 104 | minimize_corpus "$no_fuzzer_mode_build_dir/fuzz/server" server_corpus_no_fuzzer_mode |
| 105 | |
| 106 | |
| 107 | # Incorporate the new transcripts. |
| 108 | |
| 109 | "$fuzzer_mode_build_dir/fuzz/client" -max_len=50000 -merge=1 client_corpus "${fuzzer_mode_transcripts}/tls/client" |
| 110 | "$fuzzer_mode_build_dir/fuzz/server" -max_len=50000 -merge=1 server_corpus "${fuzzer_mode_transcripts}/tls/server" |
| 111 | "$no_fuzzer_mode_build_dir/fuzz/client" -max_len=50000 -merge=1 client_corpus_no_fuzzer_mode "${no_fuzzer_mode_transcripts}/tls/client" |
| 112 | "$no_fuzzer_mode_build_dir/fuzz/server" -max_len=50000 -merge=1 server_corpus_no_fuzzer_mode "${no_fuzzer_mode_transcripts}/tls/server" |