Blame view

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