@@ -167,17 +167,65 @@ if [ "$RUN_CHECK_DEPS" = "true" ]; then
167167 " ${BASE_ROOT_DIR} /contrib/devtools/check-deps.sh" " ${BASE_BUILD_DIR} "
168168fi
169169
170+ function get_interfaces()
171+ {
172+ set -o pipefail
173+ ifconfig | awk -F ' :| ' ' /^[^[:space:]]/ { if (!match($1, /^lo/)) { print $1 } }'
174+ set +o pipefail
175+ }
176+
177+ function tcpdump_file()
178+ {
179+ echo " /tmp/tcpdump_$1 _$2 "
180+ }
181+
182+ function traffic_monitor_begin()
183+ {
184+ test_name=" $1 "
185+ for ifname in $( get_interfaces) ; do
186+ tcpdump -nU -i " $ifname " -w " $( tcpdump_file " $test_name " " $ifname " ) " &
187+ done
188+ }
189+
190+ function traffic_monitor_end()
191+ {
192+ test_name=" $1 "
193+
194+ for ifname in $( get_interfaces) ; do
195+ f=$( tcpdump_file " $test_name " " $ifname " )
196+ if [ ! -e " $f " ] && [ " $CI_TCPDUMP_OK_TO_FAIL " = " 1" ] ; then
197+ # In some CI environments this script is not running as root and so the
198+ # tcpdump errors and does not create $f. Skip silently those, but we
199+ # need at least one where tcpdump can run and this is the ASAN one. So
200+ # treat the absence of $f as an error only on the ASAN task.
201+ continue
202+ fi
203+ # We are running as root and those files are created with owner:group =
204+ # tcpdump:tcpdump and then `tcpdump -r` refuses to read them with an error
205+ # "permission denied" if they are not owned by root:root.
206+ chown root:root " $f "
207+ out=" $( tcpdump -n -r " $f " --direction=out tcp or udp) "
208+ if [ -n " $out " ] ; then
209+ echo " Error: outbound TCP or UDP packets on the non loopback interface generated during $test_name tests:" >&2
210+ tcpdump -n -r " $f " tcp or udp
211+ fi
212+ done
213+ }
214+
170215if [ " $RUN_UNIT_TESTS " = " true" ]; then
216+ traffic_monitor_begin " unit"
171217 DIR_UNIT_TEST_DATA=" ${DIR_UNIT_TEST_DATA} " \
172218 LD_LIBRARY_PATH=" ${DEPENDS_DIR} /${HOST} /lib" \
173219 CTEST_OUTPUT_ON_FAILURE=ON \
174220 ctest --test-dir " ${BASE_BUILD_DIR} " \
175221 --stop-on-failure \
176222 " ${MAKEJOBS} " \
177223 --timeout $(( TEST_RUNNER_TIMEOUT_FACTOR * 60 ))
224+ traffic_monitor_end " unit"
178225fi
179226
180227if [ " $RUN_FUNCTIONAL_TESTS " = " true" ]; then
228+ traffic_monitor_begin " functional"
181229 # parses TEST_RUNNER_EXTRA as an array which allows for multiple arguments such as TEST_RUNNER_EXTRA='--exclude "rpc_bind.py --ipv6"'
182230 eval " TEST_RUNNER_EXTRA=($TEST_RUNNER_EXTRA )"
183231 LD_LIBRARY_PATH=" ${DEPENDS_DIR} /${HOST} /lib" \
@@ -190,9 +238,11 @@ if [ "$RUN_FUNCTIONAL_TESTS" = "true" ]; then
190238 " ${TEST_RUNNER_EXTRA[@]} " \
191239 --quiet \
192240 --failfast
241+ traffic_monitor_end " functional"
193242fi
194243
195244if [ " ${RUN_TIDY} " = " true" ]; then
245+ traffic_monitor_begin " tidy"
196246 cmake -B /tidy-build -DLLVM_DIR=/usr/lib/llvm-" ${TIDY_LLVM_V} " /cmake -DCMAKE_BUILD_TYPE=Release -S " ${BASE_ROOT_DIR} " /contrib/devtools/bitcoin-tidy
197247 cmake --build /tidy-build " $MAKEJOBS "
198248 cmake --build /tidy-build --target bitcoin-tidy-tests " $MAKEJOBS "
@@ -219,9 +269,11 @@ if [ "${RUN_TIDY}" = "true" ]; then
219269 cd " ${BASE_ROOT_DIR} /src"
220270 python3 " /include-what-you-use/fix_includes.py" --nosafe_headers < /tmp/iwyu_ci.out
221271 git --no-pager diff
272+ traffic_monitor_end " tidy"
222273fi
223274
224275if [ " $RUN_FUZZ_TESTS " = " true" ]; then
276+ traffic_monitor_begin " fuzz"
225277 # shellcheck disable=SC2086
226278 LD_LIBRARY_PATH=" ${DEPENDS_DIR} /${HOST} /lib" \
227279 " ${BASE_BUILD_DIR} /test/fuzz/test_runner.py" \
@@ -230,4 +282,5 @@ if [ "$RUN_FUZZ_TESTS" = "true" ]; then
230282 -l DEBUG \
231283 " ${DIR_FUZZ_IN} " \
232284 --empty_min_time=60
285+ traffic_monitor_end " fuzz"
233286fi
0 commit comments