4 # DO NOT EDIT THIS FILE IN MASTER. ONLY EDIT IT IN THE OLDEST SUPPORTED
5 # BRANCH, THEN MERGE FORWARD.
8 # This script is used to build Tor for continuous integration. It should
9 # be kept the same for all supported Tor versions.
11 # It's subject to the regular Tor license; see LICENSE for copying
17 # Options for this script.
18 DEBUG_CI
="${DEBUG_CI:-no}"
19 COLOR_CI
="${COLOR_CI:-yes}"
21 # Options for which CI system this is.
22 ON_GITLAB
="${ON_GITLAB:-yes}"
24 # Options for things we usually won't want to skip.
25 RUN_STAGE_CONFIGURE
="${RUN_STAGE_CONFIGURE:-yes}"
26 RUN_STAGE_BUILD
="${RUN_STAGE_BUILD:-yes}"
27 RUN_STAGE_TEST
="${RUN_STAGE_TEST:-yes}"
29 # Options for how to build Tor. All should be yes/no.
30 FATAL_WARNINGS
="${FATAL_WARNINGS:-yes}"
31 HARDENING
="${HARDENING:-no}"
32 COVERAGE
="${COVERAGE:-no}"
33 DOXYGEN
="${DOXYGEN:-no}"
34 ASCIIDOC
="${ASCIIDOC:-no}"
35 TRACING
="${TRACING:-no}"
36 ALL_BUGS_ARE_FATAL
="${ALL_BUGS_ARE_FATAL:-no}"
37 DISABLE_DIRAUTH
="${DISABLE_DIRAUTH:-no}"
38 DISABLE_RELAY
="${DISABLE_RELAY:-no}"
41 # Options for which tests to run. All should be yes/no.
44 CHUTNEY
="${CHUTNEY:-no}"
45 DISTCHECK
="${DISTCHECK:-no}"
47 # Options for where the Tor source is.
48 CI_SRCDIR
="${CI_SRCDIR:-.}"
50 # Options for where to build.
51 CI_BUILDDIR
="${CI_BUILDDIR:-./build}"
53 # How parallel should we run make?
54 MAKE_J_OPT
="${MAKE_J_OPT:--j4}"
55 # Should we stop after make finds an error?
56 MAKE_K_OPT
="${MAKE_K_OPT:--k}"
58 # What make target should we use for chutney?
59 CHUTNEY_MAKE_TARGET
="${CHUTNEY_MAKE_TARGET:-test-network}"
61 # Where do we find our additional testing tools?
62 CHUTNEY_PATH
="${CHUTNEY_PATH:-}"
63 STEM_PATH
="${STEM_PATH:-}"
65 #############################################################################
66 # Preliminary functions.
68 # Terminal coloring/emphasis stuff.
69 if [[ "${COLOR_CI}" == "yes" ]]; then
70 T_RED
=$
(tput setaf
1 || true
)
71 T_GREEN
=$
(tput setaf
2 || true
)
72 T_YELLOW
=$
(tput setaf
3 || true
)
73 T_DIM
=$
(tput dim || true
)
74 T_BOLD
=$
(tput bold || true
)
75 T_RESET
=$
(tput sgr0 || true
)
87 echo "${T_BOLD}${T_RED}ERROR:${T_RESET} $*" 1>&2
92 echo "${T_BOLD}${T_RED}FATAL ERROR:${T_RESET} $*" 1>&2
98 echo "${T_BOLD}${T_YELLOW}Skipping $*${T_RESET}"
103 echo "${T_BOLD}${T_GREEN}$*${T_RESET}"
106 if [[ "${DEBUG_CI}" == "yes" ]]; then
109 echo "${T_DIM}(debug): $*${T_RESET}"
121 local value
="${!varname}"
122 debug
"${varname} is ${value}"
123 if [[ "${value}" != 'yes' && "${value}" != 'no' ]]; then
124 die
"${varname} must be 'yes' or 'no'. Got unexpected value ${value}".
128 function incompatible
()
132 local val1
="${!varname1}"
133 local val2
="${!varname2}"
134 if [[ "${val1}" = 'yes' && "${val2}" = 'yes' ]]; then
135 die
"Cannot set both ${varname1} and ${varname2}: they are incompatible."
141 echo "${T_BOLD}\$ $*${T_RESET}"
143 error
"command '$*' has failed."
148 function show_git_version
()
152 local version
="?????"
153 if [[ -e "$dir/.git" ]] ; then
154 version
=$
(cd "$dir"; git rev-parse HEAD
)
156 echo "${T_BOLD}$tool:${T_RESET} $version"
159 if [[ "${ON_GITLAB}" == "yes" ]]; then
160 function start_section
()
165 printf "section_start:%s:%s\r\e[0K" "$stamp" "$label"
166 echo "${T_BOLD}${T_GREEN}========= $label${T_RESET}"
168 function end_section
()
173 printf "section_end:%s:%s\r\e[0K" "$stamp" "$label"
176 function start_section
()
180 function end_section
()
186 #############################################################################
189 debug Validating inputs
193 yes_or_no FATAL_WARNINGS
199 yes_or_no ALL_BUGS_ARE_FATAL
200 yes_or_no DISABLE_DIRAUTH
201 yes_or_no DISABLE_RELAY
204 yes_or_no RUN_STAGE_CONFIGURE
205 yes_or_no RUN_STAGE_BUILD
206 yes_or_no RUN_STAGE_TEST
212 incompatible DISTCHECK CHECK
213 incompatible DISTCHECK CHUTNEY
214 incompatible DISTCHECK STEM
215 incompatible DISTCHECK COVERAGE
216 incompatible DISTCHECK DOXYGEN
218 if [[ "${CHUTNEY}" = yes && "${CHUTNEY_PATH}" = '' ]] ; then
219 die
"CHUTNEY is set to 'yes', but CHUTNEY_PATH was not specified."
222 if [[ "${STEM}" = yes && "${STEM_PATH}" = '' ]] ; then
223 die
"STEM is set to 'yes', but STEM_PATH was not specified."
226 #############################################################################
227 # Set up options for make and configure.
230 if [[ "$MAKE_J_OPT" != "" ]]; then
231 make_options
+=("$MAKE_J_OPT")
233 if [[ "$MAKE_K_OPT" != "" ]]; then
234 make_options
+=("$MAKE_K_OPT")
238 if [[ "$FATAL_WARNINGS" == "yes" ]]; then
239 configure_options
+=("--enable-fatal-warnings")
241 if [[ "$HARDENING" == "yes" ]]; then
242 configure_options
+=("--enable-fragile-hardening")
244 if [[ "$COVERAGE" == "yes" ]]; then
245 configure_options
+=("--enable-coverage")
247 if [[ "$ASCIIDOC" != "yes" ]]; then
248 configure_options
+=("--disable-asciidoc")
250 if [[ "$TRACING" == "yes" ]]; then
251 configure_options
+=("--enable-tracing-instrumentation-lttng")
253 if [[ "$ALL_BUGS_ARE_FATAL" == "yes" ]]; then
254 configure_options
+=("--enable-all-bugs-are-fatal")
256 if [[ "$DISABLE_DIRAUTH" == "yes" ]]; then
257 configure_options
+=("--disable-module-dirauth")
259 if [[ "$DISABLE_RELAY" == "yes" ]]; then
260 configure_options
+=("--disable-module-relay")
262 if [[ "$NSS" == "yes" ]]; then
263 configure_options
+=("--enable-nss")
266 #############################################################################
267 # Tell the user about our versions of different tools and packages.
271 python
-V ||
echo "no 'python' binary."
273 python3
-V ||
echo "no 'python3' binary."
275 show_git_version Tor
"${CI_SRCDIR}"
276 if [[ "${STEM}" = "yes" ]]; then
277 show_git_version Stem
"${STEM_PATH}"
279 if [[ "${CHUTNEY}" = "yes" ]]; then
280 show_git_version Chutney
"${CHUTNEY_PATH}"
283 #############################################################################
284 # Determine the version of Tor.
286 TOR_VERSION
=$
(grep -m 1 AC_INIT
"${CI_SRCDIR}"/configure.ac |
sed -e 's/.*\[//; s/\].*//;')
288 # Use variables like these when we need to behave differently depending on
289 # Tor version. Only create the variables we need.
290 TOR_VER_AT_LEAST_043
=no
291 TOR_VER_AT_LEAST_044
=no
293 # These are the currently supported Tor versions; no need to work with anything
294 # ancient in this script.
295 case "$TOR_VERSION" in
297 TOR_VER_AT_LEAST_043
=yes
298 TOR_VER_AT_LEAST_044
=yes
301 TOR_VER_AT_LEAST_043
=yes
302 TOR_VER_AT_LEAST_044
=yes
305 TOR_VER_AT_LEAST_043
=yes
306 TOR_VER_AT_LEAST_044
=yes
310 #############################################################################
311 # Make sure the directories are all there.
313 # Make sure CI_SRCDIR exists and has a file we expect.
314 if [[ ! -d "$CI_SRCDIR" ]] ; then
315 die
"CI_SRCDIR=${CI_SRCDIR} is not a directory"
317 if [[ ! -f "$CI_SRCDIR/src/core/or/or.h" ]] ; then
318 die
"CI_SRCDIR=${CI_SRCDIR} does not look like a Tor directory."
321 # Make CI_SRCDIR absolute.
322 CI_SRCDIR
=$
(cd "$CI_SRCDIR" && pwd)
324 # Create an "artifacts" directory to copy artifacts into.
327 if [[ "$RUN_STAGE_CONFIGURE" = "yes" ]]; then
329 start_section
"Autogen"
330 runcmd
cd "${CI_SRCDIR}"
332 runcmd mkdir
-p "${CI_BUILDDIR}"
333 runcmd
cd "${CI_BUILDDIR}"
334 end_section
"Autogen"
336 # make the builddir absolute too.
339 start_section
"Configure"
340 if ! runcmd
"${CI_SRCDIR}"/configure
"${configure_options[@]}" ; then
341 error
"Here is the end of config.log:"
342 runcmd
tail config.log
343 die
"Unable to continue"
345 end_section
"Configure"
347 debug
"Skipping configure stage. Making sure that ${CI_BUILDDIR}/config.log exists."
348 if [[ ! -d "${CI_BUILDDIR}" ]]; then
349 die
"Build directory ${CI_BUILDDIR} did not exist!"
351 if [[ ! -f "${CI_BUILDDIR}/config.log" ]]; then
352 die
"Tor was not configured in ${CI_BUILDDIR}!"
355 cp config.log
"${CI_SRCDIR}"/artifacts
357 runcmd
cd "${CI_BUILDDIR}"
361 ###############################
364 if [[ "$RUN_STAGE_BUILD" = "yes" ]] ; then
365 if [[ "$DISTCHECK" = "no" ]]; then
366 start_section
"Build"
367 runcmd
make "${make_options[@]}" all
368 cp src
/app
/tor
"${CI_SRCDIR}"/artifacts
371 export DISTCHECK_CONFIGURE_FLAGS
="${configure_options[*]}"
372 # XXXX Set make options?
373 start_section Distcheck
374 if runcmd
make "${make_options[@]}" distcheck
; then
375 hooray
"Distcheck was successful. Nothing further will be done."
376 # We have to exit early here, since we can't do any other tests.
377 cp tor-
*.
tar.gz
"${CI_SRCDIR}"/artifacts
381 runcmd
make show-distdir-testlog || true
382 runcmd
make show-distdir-core || true
383 die
"Unable to continue."
385 end_section Distcheck
389 ##############################
392 if [[ "$RUN_STAGE_TEST" == "no" ]]; then
393 echo "Skipping tests. Exiting now."
399 if [[ "${DOXYGEN}" = 'yes' ]]; then
400 start_section Doxygen
401 if [[ "${TOR_VER_AT_LEAST_043}" = 'yes' ]]; then
402 if runcmd
make doxygen
; then
403 hooray
"make doxygen has succeeded."
405 FAILED_TESTS
="${FAILED_TESTS} doxygen"
408 skipping
"make doxygen: doxygen is broken for Tor < 0.4.3"
413 if [[ "${ASCIIDOC}" = 'yes' ]]; then
414 start_section Asciidoc
415 if runcmd
make manpages
; then
416 hooray
"make manpages has succeeded."
418 FAILED_TESTS
="${FAILED_TESTS} asciidoc"
423 if [[ "${CHECK}" = "yes" ]]; then
424 start_section
"Check"
425 if runcmd
make "${make_options[@]}" check
; then
426 hooray
"make check has succeeded."
428 error
"Here are the contents of the test suite output:"
429 runcmd
cat test-suite.log || true
430 FAILED_TESTS
="${FAILED_TESTS} check"
435 if [[ "${CHUTNEY}" = "yes" ]]; then
436 start_section
"Chutney"
437 export CHUTNEY_TOR_SANDBOX
=0
438 export CHUTNEY_ALLOW_FAILURES
=2
439 # Send 5MB for every verify check.
440 export CHUTNEY_DATA_BYTES
=5000000
441 if runcmd
make "${CHUTNEY_MAKE_TARGET}"; then
442 hooray
"Chutney tests have succeeded"
444 error
"Chutney says:"
445 export CHUTNEY_DATA_DIR
="${CHUTNEY_PATH}/net"
446 runcmd
"${CHUTNEY_PATH}"/tools
/diagnostics.sh || true
447 # XXXX These next two should be part of a make target.
448 runcmd
ls test_network_log || true
449 runcmd
head -n -0 test_network_log
/* || true
450 FAILED_TESTS
="${FAILED_TESTS} chutney"
452 end_section
"Chutney"
455 if [[ "${STEM}" = "yes" ]]; then
457 # 0.3.5 and onward have now disabled onion service v2 so we need to exclude
458 # these Stem tests from now on.
459 EXCLUDE_TESTS
="--exclude-test control.controller.test_ephemeral_hidden_services_v2 --exclude-test control.controller.test_hidden_services_conf --exclude-test control.controller.test_with_ephemeral_hidden_services_basic_auth --exclude-test control.controller.test_without_ephemeral_hidden_services --exclude-test control.controller.test_with_ephemeral_hidden_services_basic_auth_no_credentials"
460 if [[ "${TOR_VER_AT_LEAST_044}" = 'yes' ]]; then
461 # XXXX This should probably be part of some test-stem make target.
463 # Disable the check around EXCLUDE_TESTS that requires double quote. We
464 # need it to be expanded.
465 # shellcheck disable=SC2086
466 if runcmd timelimit
-p -t 520 -s USR1
-T 30 -S ABRT \
467 python3
"${STEM_PATH}/run_tests.py" \
469 --integ --test control.controller \
471 --test control.base_controller \
474 --log-file stem.log
; then
475 hooray
"Stem tests have succeeded"
478 runcmd
tail -1000 "${STEM_PATH}"/test
/data
/tor_log
479 runcmd
grep -v "SocketClosed" stem.log |
tail -1000
480 FAILED_TESTS
="${FAILED_TESTS} stem"
483 skipping
"Stem: broken with <= 0.4.3. See bug tor#40077"
490 if [[ "${FAILED_TESTS}" != "" ]]; then
491 die
"Failed tests: ${FAILED_TESTS}"
494 hooray
"Everything seems fine."