1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-11 05:17:44 +03:00

Merge pull request #21081 from mrc0mmand/even-more-coverage-tweaks

test: collect even more coverage
This commit is contained in:
Yu Watanabe 2021-10-22 04:48:40 +09:00 committed by GitHub
commit aee21f7f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 5 deletions

View File

@ -20,6 +20,7 @@ check_result_qemu() {
cryptsetup luksOpen "${LOOPDEV:?}p2" varcrypt <"$TESTDIR/keyfile"
mount /dev/mapper/varcrypt "$initdir/var"
save_journal "$initdir/var/log/journal"
check_coverage_reports "${initdir:?}" || ret=5
_umount_dir "$initdir/var"
_umount_dir "$initdir"
cryptsetup luksClose /dev/mapper/varcrypt
@ -28,7 +29,6 @@ check_result_qemu() {
echo "${JOURNAL_LIST:-No journals were saved}"
test -s "$TESTDIR/failed" && ret=1
check_coverage_reports "${initdir:?}" || ret=5
return $ret
}

View File

@ -238,7 +238,16 @@ is_built_with_asan() {
fi
}
is_built_with_coverage() {
if get_bool "${NO_BUILD:=}" || ! command -v meson >/dev/null; then
return 1
fi
meson configure "${BUILD_DIR:?}" | grep 'b_coverage' | awk '{ print $2 }' | grep -q 'true'
}
IS_BUILT_WITH_ASAN=$(is_built_with_asan && echo yes || echo no)
IS_BUILT_WITH_COVERAGE=$(is_built_with_coverage && echo yes || echo no)
if get_bool "$IS_BUILT_WITH_ASAN"; then
STRIP_BINARIES=no
@ -1015,7 +1024,7 @@ install_compiled_systemd() {
# If we are doing coverage runs, copy over the binary notes files, as lcov expects to
# find them in the same directory as the runtime data counts
if meson configure "${BUILD_DIR:?}" | grep 'b_coverage' | awk '{ print $2 }' | grep -q 'true'; then
if get_bool "$IS_BUILT_WITH_COVERAGE"; then
mkdir -p "${initdir}/${BUILD_DIR:?}/"
rsync -am --include='*/' --include='*.gcno' --exclude='*' "${BUILD_DIR:?}/" "${initdir}/${BUILD_DIR:?}/"
fi
@ -1098,7 +1107,7 @@ install_systemd() {
fi
# remove unneeded documentation
rm -fr "$initdir"/usr/share/{man,doc}
rm -fr "${initdir:?}"/usr/share/{man,doc}
# enable debug logging in PID1
echo LogLevel=debug >>"$initdir/etc/systemd/system.conf"
@ -1107,6 +1116,13 @@ install_systemd() {
# Propagate SYSTEMD_UNIT_PATH to user systemd managers
mkdir "$initdir/etc/systemd/system/user@.service.d/"
echo -e "[Service]\nPassEnvironment=SYSTEMD_UNIT_PATH\n" >"$initdir/etc/systemd/system/user@.service.d/override.conf"
# When built with gcov, disable ProtectSystem= in the test images, since
# it prevents gcov to write the coverage reports (*.gcda files)
if get_bool "$IS_BUILT_WITH_COVERAGE"; then
mkdir -p "$initdir/etc/systemd/system/service.d/"
echo -e "[Service]\nProtectSystem=no\n" >"$initdir/etc/systemd/system/service.d/override.conf"
fi
}
get_ldpath() {
@ -1177,7 +1193,7 @@ create_empty_image() {
if meson configure "${BUILD_DIR:?}" | grep 'link-.*-shared' | awk '{ print $2 }' | grep -q 'false'; then
size=$((size+=200))
fi
if meson configure "${BUILD_DIR:?}" | grep 'b_coverage' | awk '{ print $2 }' | grep -q 'true'; then
if get_bool "$IS_BUILT_WITH_COVERAGE"; then
size=$((size+=250))
fi
fi
@ -1288,7 +1304,7 @@ check_coverage_reports() {
if get_bool "$NO_BUILD"; then
return 0
fi
if meson configure "${BUILD_DIR:?}" | grep 'b_coverage' | awk '{ print $2 }' | grep -q 'false'; then
if ! get_bool "$IS_BUILT_WITH_COVERAGE"; then
return 0
fi

View File

@ -3,6 +3,7 @@
# systemd-networkd tests
import argparse
import errno
import itertools
import os
import re
@ -42,6 +43,7 @@ env = {}
asan_options=None
lsan_options=None
ubsan_options=None
with_coverage=False
running_units = []
@ -304,6 +306,8 @@ def setUpModule():
drop_in += ['SystemCallFilter=']
if use_valgrind or asan_options or lsan_options or ubsan_options:
drop_in += ['MemoryDenyWriteExecute=no']
if with_coverage:
drop_in += ['ProtectSystem=no']
os.makedirs('/run/systemd/system/systemd-networkd.service.d', exist_ok=True)
with open('/run/systemd/system/systemd-networkd.service.d/00-override.conf', mode='w') as f:
@ -330,6 +334,8 @@ def setUpModule():
drop_in += ['SystemCallFilter=']
if use_valgrind or asan_options or lsan_options or ubsan_options:
drop_in += ['MemoryDenyWriteExecute=no']
if with_coverage:
drop_in += ['ProtectSystem=no']
os.makedirs('/run/systemd/system/systemd-resolved.service.d', exist_ok=True)
with open('/run/systemd/system/systemd-resolved.service.d/00-override.conf', mode='w') as f:
@ -483,6 +489,15 @@ def stop_by_pid_file(pid_file):
with open(pid_file, 'r') as f:
pid = f.read().rstrip(' \t\r\n\0')
os.kill(int(pid), signal.SIGTERM)
for _ in range(25):
try:
os.kill(int(pid), 0)
print(f"PID {pid} is still alive, waiting...")
time.sleep(.2)
except OSError as e:
if e.errno == errno.ESRCH:
break
print(f"Unexpected exception when waiting for {pid} to die: {e.errno}")
os.remove(pid_file)
@ -5027,6 +5042,7 @@ if __name__ == '__main__':
parser.add_argument('--asan-options', help='ASAN options', dest='asan_options')
parser.add_argument('--lsan-options', help='LSAN options', dest='lsan_options')
parser.add_argument('--ubsan-options', help='UBSAN options', dest='ubsan_options')
parser.add_argument('--with-coverage', help='Loosen certain sandbox restrictions to make gcov happy', dest='with_coverage', type=bool, nargs='?', const=True, default=with_coverage)
ns, args = parser.parse_known_args(namespace=unittest)
if ns.build_dir:
@ -5060,6 +5076,7 @@ if __name__ == '__main__':
asan_options = ns.asan_options
lsan_options = ns.lsan_options
ubsan_options = ns.ubsan_options
with_coverage = ns.with_coverage
if use_valgrind:
networkctl_cmd = ['valgrind', '--track-origins=yes', '--leak-check=full', '--show-leak-kinds=all', networkctl_bin]