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