do_build.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/bin/bash
  2. set -eu
  3. readonly FuzzTestingDir=$(dirname "$(echo $0 | sed -e "s,^\([^/]\),$(pwd)/\1,")")
  4. printUsage() {
  5. NAME=$(basename "${0}")
  6. cat << EOF
  7. usage: ${NAME} [OPTIONS]
  8. This script builds (and can run) the fuzz tests.
  9. OPTIONS:
  10. General:
  11. -h, --help
  12. Show this message
  13. --debug-only
  14. Just build the 'debug' configuration.
  15. --release-only
  16. Just build the 'release' configuration.
  17. --both
  18. Build both the 'debug' and 'release' configurations. This is
  19. the default.
  20. --run-regressions, --run
  21. After building, also run all the fuzz tests against the known fail
  22. cases.
  23. EOF
  24. }
  25. FUZZ_TESTS=(
  26. "FuzzBinary"
  27. "FuzzBinaryDelimited"
  28. "FuzzAsyncMessageSequence"
  29. "FuzzJSON"
  30. "FuzzTextFormat"
  31. )
  32. RUN_TESTS="yes"
  33. CHECK_REGRESSIONS="no"
  34. # Default to both
  35. CMD_CONFIGS=("debug" "release")
  36. while [[ $# != 0 ]]; do
  37. case "${1}" in
  38. -h | --help )
  39. printUsage
  40. exit 0
  41. ;;
  42. --debug-only )
  43. CMD_CONFIGS=("debug")
  44. ;;
  45. --release-only )
  46. CMD_CONFIGS=("release")
  47. ;;
  48. --both )
  49. CMD_CONFIGS=("debug" "release")
  50. ;;
  51. --run-regressions | --run )
  52. CHECK_REGRESSIONS="yes"
  53. ;;
  54. --skip-tests )
  55. RUN_TESTS="no"
  56. ;;
  57. -*)
  58. echo "ERROR: Unknown option: ${1}" 1>&2
  59. printUsage
  60. exit 1
  61. ;;
  62. *)
  63. echo "ERROR: Unknown argument: ${1}" 1>&2
  64. printUsage
  65. exit 1
  66. ;;
  67. esac
  68. shift
  69. done
  70. cd "${FuzzTestingDir}"
  71. if [[ "${RUN_TESTS}" == "yes" ]] ; then
  72. echo "------------------------------------------------------------------------------------------"
  73. echo "Testing: swift test"
  74. swift test
  75. fi
  76. declare -a CMD_BASE
  77. if [ "$(uname)" == "Darwin" ]; then
  78. CMD_BASE=(
  79. xcrun
  80. --toolchain swift
  81. swift build -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library
  82. )
  83. else
  84. CMD_BASE=(
  85. swift build -Xswiftc -sanitize=fuzzer,address -Xswiftc -parse-as-library
  86. )
  87. fi
  88. for CMD_CONFIG in "${CMD_CONFIGS[@]}"; do
  89. echo "------------------------------------------------------------------------------------------"
  90. echo "Building: ${CMD_CONFIG}"
  91. echo "${CMD_BASE[@]}" -c "${CMD_CONFIG}"
  92. "${CMD_BASE[@]}" -c "${CMD_CONFIG}"
  93. if [[ "${CHECK_REGRESSIONS}" == "yes" ]] ; then
  94. for FUZZ_TEST in "${FUZZ_TESTS[@]}"; do
  95. # Don't worry about running the test cases against the right binaries, they should
  96. # all be able to handle any input.
  97. echo "------------------------------------------------------------------------------------------"
  98. echo "Regressing: ${FUZZ_TEST}"
  99. ".build/${CMD_CONFIG}/${FUZZ_TEST}" FailCases/*
  100. done
  101. fi
  102. done