]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | #!/usr/bin/env bash |
2 | # We use set -e to bail on first non zero exit code of any processes launched | |
3 | # and -x to exit upon any unbound variable. -x will output command lines used | |
4 | # (with variable expansion) | |
5 | set -eux | |
6 | ||
7 | # brew install bash (4) to get this working on OSX! | |
8 | shopt -s globstar | |
9 | ||
10 | ################################## ENVIRONMENT ################################# | |
11 | ||
12 | # If not CI, then set some defaults | |
13 | if [[ "${CI:-}" == "" ]]; then | |
14 | TRAVIS_BRANCH=${TRAVIS_BRANCH:-feature} | |
15 | CC=${CC:-gcc} | |
16 | ADDRESS_MODEL=${ADDRESS_MODEL:-64} | |
17 | VARIANT=${VARIANT:-debug} | |
18 | # If running locally we assume we have lcov/valgrind on PATH | |
19 | else | |
20 | export PATH=$VALGRIND_ROOT/bin:$LCOV_ROOT/usr/bin:$PATH | |
21 | fi | |
22 | ||
23 | MAIN_BRANCH="0" | |
24 | # For builds not triggered by a pull request TRAVIS_BRANCH is the name of the | |
25 | # branch currently being built; whereas for builds triggered by a pull request | |
26 | # it is the name of the branch targeted by the pull request (in many cases this | |
27 | # will be master). | |
28 | if [[ $TRAVIS_BRANCH == "master" || $TRAVIS_BRANCH == "develop" ]]; then | |
29 | MAIN_BRANCH="1" | |
30 | fi | |
31 | ||
32 | num_jobs="1" | |
33 | if [[ $(uname) == "Darwin" ]]; then | |
34 | num_jobs=$(sysctl -n hw.physicalcpu) | |
35 | elif [[ $(uname -s) == "Linux" ]]; then | |
36 | # CircleCI returns 32 phys procs, but 2 virt proc | |
37 | num_proc_units=$(nproc) | |
38 | # Physical cores | |
39 | num_jobs=$(lscpu -p | grep -v '^#' | sort -u -t, -k 2,4 | wc -l) | |
40 | if ((${num_proc_units} < ${num_jobs})); then | |
41 | num_jobs=$num_proc_units | |
42 | fi | |
43 | if [[ "${TRAVIS}" == "true" && ${NUM_PROCESSORS:=2} > ${num_jobs} ]]; then | |
44 | num_jobs=$NUM_PROCESSORS | |
45 | fi | |
46 | fi | |
47 | ||
48 | echo "using toolset: $CC" | |
49 | echo "using variant: $VARIANT" | |
50 | echo "using address-model: $ADDRESS_MODEL" | |
51 | echo "using PATH: $PATH" | |
52 | echo "using MAIN_BRANCH: $MAIN_BRANCH" | |
53 | echo "using BOOST_ROOT: $BOOST_ROOT" | |
54 | ||
55 | #################################### HELPERS ################################### | |
56 | ||
57 | function run_tests_with_debugger { | |
58 | for x in bin/**/$VARIANT/**/*-tests; do | |
59 | scripts/run-with-debugger.sh "$x" | |
60 | done | |
61 | } | |
62 | ||
63 | function run_tests { | |
64 | for x in bin/**/$VARIANT/**/*-tests; do | |
65 | $x | |
66 | done | |
67 | } | |
68 | ||
69 | function run_tests_with_valgrind { | |
70 | for x in bin/**/$VARIANT/**/*-tests; do | |
71 | if [[ $(basename $x) == "bench-tests" ]]; then | |
72 | $x | |
73 | else | |
74 | # TODO --max-stackframe=8388608 | |
75 | # see: https://travis-ci.org/vinniefalco/Beast/jobs/132486245 | |
76 | valgrind --suppressions=./scripts/valgrind.supp --error-exitcode=1 "$x" | |
77 | fi | |
78 | done | |
79 | } | |
80 | ||
81 | function build_beast { | |
82 | $BOOST_ROOT/bjam toolset=$CC \ | |
83 | variant=$VARIANT \ | |
84 | address-model=$ADDRESS_MODEL \ | |
85 | -j${num_jobs} | |
86 | } | |
87 | ||
88 | function build_beast_cmake { | |
89 | mkdir -p build | |
90 | pushd build > /dev/null | |
91 | cmake -DVARIANT=${VARIANT} .. | |
92 | make -j${num_jobs} | |
93 | mkdir -p ../bin/$VARIANT | |
94 | find . -executable -type f -exec cp {} ../bin/$VARIANT/. \; | |
95 | popd > /dev/null | |
96 | } | |
97 | ||
98 | function run_autobahn_test_suite { | |
99 | # Run autobahn tests | |
100 | wsecho=$(find bin -name "websocket-echo" | grep /$VARIANT/) | |
101 | nohup $wsecho& | |
102 | ||
103 | # We need to wait a while so wstest can connect! | |
104 | sleep 5 | |
105 | # Show the output (if any) as it is generated | |
106 | tail -f nohup.out & | |
107 | cd scripts && wstest -m fuzzingclient | |
108 | cd .. | |
109 | rm nohup.out | |
110 | # Show what jobs are running | |
111 | jobs | |
112 | # Wait a while for things to wind down before issuing a kill | |
113 | sleep 5 | |
114 | # Kill it gracefully | |
115 | kill -INT %1 | |
116 | kill -INT %2 | |
117 | # Wait for all the jobs to finish | |
118 | wait | |
119 | # Parse the test results, with python>=2.5<3 script | |
120 | python scripts/parseautobahn.py scripts/autoresults/index.json | |
121 | } | |
122 | ||
123 | ##################################### BUILD #################################### | |
124 | ||
125 | if [[ ${BUILD_SYSTEM:-} == cmake ]]; then | |
126 | build_beast_cmake | |
127 | else | |
128 | build_beast | |
129 | fi | |
130 | ||
131 | ##################################### TESTS #################################### | |
132 | ||
133 | if [[ $VARIANT == "coverage" ]]; then | |
134 | find . -name "*.gcda" | xargs rm -f | |
135 | rm *.info -f | |
136 | # Create baseline coverage data file | |
137 | lcov --no-external -c -i -d . -o baseline.info > /dev/null | |
138 | ||
139 | # Perform test | |
140 | if [[ $MAIN_BRANCH == "1" ]]; then | |
141 | run_tests_with_valgrind | |
142 | # skip slow autobahn tests | |
143 | #run_autobahn_test_suite | |
144 | else | |
145 | echo "skipping autobahn/valgrind tests for feature branch build" | |
146 | run_tests | |
147 | fi | |
148 | ||
149 | # Create test coverage data file | |
150 | lcov --no-external -c -d . -o testrun.info > /dev/null | |
151 | ||
152 | # Combine baseline and test coverage data | |
153 | lcov -a baseline.info -a testrun.info -o lcov-all.info > /dev/null | |
154 | ||
155 | # Extract only include/beast, and don\'t report on examples/test | |
156 | lcov -e "lcov-all.info" "$PWD/include/beast/*" -o lcov.info > /dev/null | |
157 | ||
158 | ~/.local/bin/codecov -X gcov | |
159 | cat lcov.info | node_modules/.bin/coveralls | |
160 | ||
161 | # Clean up these stragglers so BOOST_ROOT cache is clean | |
162 | find $BOOST_ROOT/bin.v2 -name "*.gcda" | xargs rm -f | |
163 | else | |
164 | run_tests_with_debugger | |
165 | fi |