build-and-test.sh 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #!/usr/bin/env bash
  2. # add 'x' for command tracing
  3. set -eu
  4. #-------------------------------------------------------------------------------
  5. #
  6. # Utilities
  7. #
  8. # For builds not triggered by a pull request TRAVIS_BRANCH is the name of the
  9. # branch currently being built; whereas for builds triggered by a pull request
  10. # it is the name of the branch targeted by the pull request (in many cases this
  11. # will be master).
  12. MAIN_BRANCH="0"
  13. if [[ $TRAVIS_BRANCH == "master" || $TRAVIS_BRANCH == "develop" ]]; then
  14. MAIN_BRANCH="1"
  15. fi
  16. if [[ "${BEAST_RETRY}" == "true" ]]; then
  17. JOBS=1
  18. elif [[ "${TRAVIS}" == "true" ]]; then
  19. JOBS="2"
  20. elif [[ $(uname -s) == "Linux" ]]; then
  21. # Physical cores
  22. JOBS=$(lscpu -p | grep -v '^#' | sort -u -t, -k 2,4 | wc -l)
  23. elif [[ $(uname) == "Darwin" ]]; then
  24. # Physical cores
  25. JOBS=$(sysctl -n hw.physicalcpu)
  26. else
  27. JOBS=1
  28. fi
  29. # run with a debugger
  30. function debug_run ()
  31. {
  32. if [[ $TRAVIS_OS_NAME == "osx" ]]; then
  33. # -o runs after loading the binary
  34. # -k runs after any crash
  35. # We use a ghetto appromixation of --return-child-result, exiting with
  36. # 1 on a crash
  37. lldb \
  38. --batch \
  39. -o 'run' \
  40. -k 'thread backtrace all' \
  41. -k 'script import os; os._exit(1)' \
  42. $@
  43. else
  44. gdb \
  45. --silent \
  46. --batch \
  47. --return-child-result \
  48. -ex="set print thread-events off" \
  49. -ex=run \
  50. -ex="thread apply all bt full" \
  51. --args $@
  52. fi
  53. }
  54. function valgrind_run ()
  55. {
  56. valgrind \
  57. --track-origins=yes \
  58. --max-stackframe=16000000 \
  59. --suppressions=$BOOST_ROOT/libs/beast/tools/valgrind.supp \
  60. --error-exitcode=1 \
  61. $@
  62. }
  63. function run_tests_with_debugger ()
  64. {
  65. find "$1" -name "$2" -print0 | while read -d $'\0' f
  66. do
  67. debug_run "$f"
  68. done
  69. }
  70. function run_tests_with_valgrind ()
  71. {
  72. find "$1" -name "$2" -print0 | while read -d $'\0' f
  73. do
  74. valgrind_run "$f"
  75. done
  76. }
  77. function run_tests ()
  78. {
  79. find "$1" -name "$2" -print0 | while read -d $'\0' f
  80. do
  81. "$f"
  82. done
  83. }
  84. #-------------------------------------------------------------------------------
  85. BIN_DIR="$BOOST_ROOT/bin.v2/libs/beast/test"
  86. LIB_DIR="$BOOST_ROOT/libs/beast"
  87. INC_DIR="$BOOST_ROOT/boost/beast"
  88. function build_bjam ()
  89. {
  90. if [[ $VARIANT == "beast_coverage" ]] || \
  91. [[ $VARIANT == "beast_valgrind" ]] || \
  92. [[ $VARIANT == "beast_ubasan" ]]; then
  93. b2 \
  94. define=BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 \
  95. cxxstd=$CXXSTD \
  96. libs/beast/test/beast/core//fat-tests \
  97. libs/beast/test/beast/http//fat-tests \
  98. libs/beast/test/beast/websocket//fat-tests \
  99. libs/beast/test/beast/zlib//fat-tests \
  100. toolset=$TOOLSET \
  101. variant=$VARIANT \
  102. -j${JOBS}
  103. elif [[ $VARIANT == "debug" ]]; then
  104. b2 \
  105. define=BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 \
  106. cxxstd=$CXXSTD \
  107. libs/beast/test//fat-tests \
  108. libs/beast/example \
  109. toolset=$TOOLSET \
  110. variant=$VARIANT \
  111. -j${JOBS}
  112. else
  113. b2 \
  114. define=BOOST_COROUTINES_NO_DEPRECATION_WARNING=1 \
  115. cxxstd=$CXXSTD \
  116. libs/beast/test//fat-tests \
  117. toolset=$TOOLSET \
  118. variant=$VARIANT \
  119. -j${JOBS}
  120. fi
  121. }
  122. build_bjam
  123. if [[ $VARIANT == "beast_coverage" ]]; then
  124. # for lcov to work effectively, the paths and includes
  125. # passed to the compiler should not contain "." or "..".
  126. # (this runs in $BOOST_ROOT)
  127. lcov --version
  128. find "$BOOST_ROOT" -name "*.gcda" | xargs rm -f
  129. rm -f "$BOOST_ROOT/*.info"
  130. lcov --no-external -c -i -d "$BOOST_ROOT" -o baseline.info > /dev/null
  131. run_tests "$BIN_DIR" fat-tests
  132. # https://bugs.launchpad.net/ubuntu/+source/lcov/+bug/1163758
  133. lcov --no-external -c -d "$BOOST_ROOT" -o testrun-all.info > /dev/null 2>&1
  134. lcov -a baseline.info -a testrun-all.info -o lcov-diff.info > /dev/null
  135. lcov -e "lcov-diff.info" "$INC_DIR/*" -o lcov.info > /dev/null
  136. lcov --remove "lcov.info" "$INC_DIR/_experimental/*" -o lcov.info > /dev/null
  137. ~/.local/bin/codecov -X gcov -f lcov.info
  138. find "$BOOST_ROOT" -name "*.gcda" | xargs rm -f
  139. elif [[ $VARIANT == "beast_valgrind" ]]; then
  140. run_tests_with_valgrind "$BIN_DIR" fat-tests
  141. else
  142. #run_tests_with_debugger "$BIN_DIR" fat-tests
  143. run_tests "$BIN_DIR" fat-tests
  144. fi