generate_corpus.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. set -e
  3. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  4. BASE_DIR="$( cd "$DIR/../../" && pwd )"
  5. BUILD_DIR_FUZZ_MODE="$DIR/../../build_fuzz"
  6. if [ ! -d "$BUILD_DIR_FUZZ_MODE" ]; then
  7. mkdir $BUILD_DIR_FUZZ_MODE
  8. fi
  9. BUILD_DIR_FUZZ_MODE="$( cd "$DIR/../../build_fuzz" && pwd )"
  10. BUILD_DIR_CORPUS="$DIR/../../build_corpus"
  11. if [ ! -d "$BUILD_DIR_CORPUS" ]; then
  12. mkdir $BUILD_DIR_CORPUS
  13. fi
  14. BUILD_DIR_CORPUS="$( cd "$DIR/../../build_corpus" && pwd )"
  15. cd $BUILD_DIR_CORPUS
  16. if [ -d "$BUILD_DIR_CORPUS/corpus" ]; then
  17. rm -rf "$BUILD_DIR_CORPUS/corpus"
  18. fi
  19. if [ $TRAVIS = true ]; then
  20. export CC=clang-3.9
  21. export CXX=clang++-3.9
  22. else
  23. export CC=clang-5.0
  24. export CXX=clang++-5.0
  25. fi
  26. # First build and run the unit tests without any specific fuzz settings
  27. cmake -DUA_BUILD_FUZZING_CORPUS=ON -DUA_BUILD_UNIT_TESTS=ON ..
  28. make -j && make test ARGS="-V"
  29. if [ $? -ne 0 ] ; then exit 1 ; fi
  30. # Run our special generator
  31. $BUILD_DIR_CORPUS/bin/corpus_generator
  32. if [ $? -ne 0 ] ; then exit 1 ; fi
  33. # Now build the fuzzer executables
  34. cd $BUILD_DIR_FUZZ_MODE
  35. cmake -DUA_BUILD_FUZZING=ON ..
  36. make -j
  37. if [ $? -ne 0 ] ; then exit 1 ; fi
  38. merge_corpus() {
  39. local fuzzer="$1"
  40. local corpus_existing="$2"
  41. local corpus_new="$3"
  42. if [ -d "$corpus_existing" ]; then
  43. echo "Merging ${corpus_existing} into ${corpus_new}"
  44. "$fuzzer" -merge=1 "$corpus_existing" "${corpus_new}"
  45. else
  46. echo "Copying ${corpus_new} into ${corpus_existing}"
  47. cp -r ${corpus_new} ${corpus_existing}
  48. fi
  49. }
  50. merge_corpus $BUILD_DIR_FUZZ_MODE/bin/fuzz_binary_message $BASE_DIR/tests/fuzz/fuzz_binary_message_corpus/generated $BUILD_DIR_CORPUS/corpus
  51. if [ $? -ne 0 ] ; then exit 1 ; fi