From 747cd3aa097ebacc302f6257a4a6cd3c4122eb61 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Tue, 24 Sep 2024 12:43:46 +0200 Subject: [PATCH 1/5] ref: remove CIRRUS_TAG Cirrus-CI is no longer used. Signed-off-by: Matthieu Baerts (NGI0) --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 6ea55b7..193cac7 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1341,7 +1341,7 @@ _print_summary_header() { echo "== Summary ==" echo - echo "Ref: ${GITHUB_REF_NAME:-${CIRRUS_TAG:-$(git describe --tags 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo "Unknown")}}${GITHUB_SHA:+ (${GITHUB_SHA})}" + echo "Ref: ${GITHUB_REF_NAME:-$(git describe --tags 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo "Unknown")}${GITHUB_SHA:+ (${GITHUB_SHA})}" echo "Mode: ${mode}" echo "Extra kconfig: ${*:-/}" echo From 6f9614757518a57c781bb1847c5f817c94b42354 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Tue, 24 Sep 2024 18:50:13 +0200 Subject: [PATCH 2/5] run: ability to change the CPUs Useful when running syzkaller reproducers for example. Signed-off-by: Matthieu Baerts (NGI0) --- run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/run.sh b/run.sh index 0ff9234..629d47d 100755 --- a/run.sh +++ b/run.sh @@ -37,6 +37,7 @@ docker run \ -e "INPUT_PACKETDRILL_STABLE=${VIRTME_PACKETDRILL_STABLE:-0}" \ -e "INPUT_EXPECT_TIMEOUT" \ -e "INPUT_EXTRA_ENV" \ + -e "INPUT_CPUS" \ -e "VIRTME_ARCH" \ -e "COMPILER" \ --privileged \ From c10f22ddb7d0d0bd467c6e8af72ec18841fb8b99 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Tue, 24 Sep 2024 18:51:14 +0200 Subject: [PATCH 3/5] kmemleak: scan if available Not only in debug mode. Just in case it is enabled in another mode. Signed-off-by: Matthieu Baerts (NGI0) --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 193cac7..8e6d692 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1027,7 +1027,7 @@ has_call_trace() { } kmemleak_scan() { - if [ "${mode}" = "debug" ]; then + if [ -e /sys/kernel/debug/kmemleak ]; then echo scan > /sys/kernel/debug/kmemleak cat /sys/kernel/debug/kmemleak > "${KMEMLEAK}" fi From f652127466e276d351de8ea21d85f346b9c16006 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Tue, 24 Sep 2024 18:53:44 +0200 Subject: [PATCH 4/5] ref: extract to a dedicated helper It will be re-used in the following commit. Signed-off-by: Matthieu Baerts (NGI0) --- entrypoint.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 8e6d692..8877eac 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1278,6 +1278,10 @@ _print_line() { echo "==========================================" } +_get_ref() { + echo "${GITHUB_REF_NAME:-$(git describe --tags 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo "Unknown")}" +} + decode_stacktrace() { ./scripts/decode_stacktrace.sh "${VIRTME_BUILD_DIR}/vmlinux" "${KERNEL_SRC}" "${VIRTME_BUILD_DIR}/.virtme_mods" } @@ -1341,7 +1345,7 @@ _print_summary_header() { echo "== Summary ==" echo - echo "Ref: ${GITHUB_REF_NAME:-$(git describe --tags 2>/dev/null || git rev-parse --short HEAD 2>/dev/null || echo "Unknown")}${GITHUB_SHA:+ (${GITHUB_SHA})}" + echo "Ref: $(_get_ref)${GITHUB_SHA:+ (${GITHUB_SHA})}" echo "Mode: ${mode}" echo "Extra kconfig: ${*:-/}" echo From 023ce27f532e84ceee728f9ed5580c1d9f7e9a27 Mon Sep 17 00:00:00 2001 From: "Matthieu Baerts (NGI0)" Date: Tue, 24 Sep 2024 19:01:49 +0200 Subject: [PATCH 5/5] gcov: add GCOV support When launched with INPUT_GCOV=1, the kernel will be compiled with GCOV support. At the end of the tests, lcov will be used to extract the required info. In the analysis phase, an HTML report will be generated, only for net/mptcp. Note that -fprofile-update=atomic is used to avoid corrupted counters, but still, some can be negative, and '--rc geninfo_unexecuted_blocks=1' is then needed. The HTML report can be directly displayed, and the .lcov file can be used to track the evolution. Signed-off-by: Matthieu Baerts (NGI0) --- Dockerfile | 2 +- entrypoint.sh | 43 ++++++++++++++++++++++++++++++++++++++++++- run.sh | 1 + 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0ceed4a..82d6f63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ RUN apt-get update && \ iptables ebtables nftables vim psmisc bash-completion less jq \ gettext-base libevent-dev libtraceevent-dev libnewt0.52 libslang2 libutempter0 python3-newt tmux \ libdwarf-dev libbfd-dev libnuma-dev libzstd-dev libunwind-dev libdw-dev libslang2-dev python3-dev python3-setuptools binutils-dev libiberty-dev libbabeltrace-dev systemtap-sdt-dev libperl-dev python3-docutils \ - libtap-formatter-junit-perl \ + libtap-formatter-junit-perl lcov libjson-xs-perl \ zstd \ wget xz-utils lftp cpio u-boot-tools \ cscope \ diff --git a/entrypoint.sh b/entrypoint.sh index 8877eac..f52bd7e 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -55,6 +55,7 @@ set_trace_on : "${INPUT_SELFTESTS_MPTCP_LIB_OVERRIDE_FLAKY:=0}" : "${INPUT_SELFTESTS_MPTCP_LIB_COLOR_FORCE:=1}" : "${INPUT_CPUS:=""}" +: "${INPUT_GCOV:=""}" : "${INPUT_CI_RESULTS_DIR:=""}" : "${INPUT_CI_PRINT_EXIT_CODE:=1}" : "${INPUT_CI_TIMEOUT_SEC:=7200}" @@ -150,6 +151,8 @@ OUTPUT_VIRTME= TESTS_SUMMARY= CONCLUSION= KMEMLEAK= +LCOV_FILE= +LCOV_HTML= EXIT_STATUS=0 EXIT_REASONS=() @@ -222,6 +225,7 @@ setup_env() { local mode net=() mkdir -p "${RESULTS_DIR}" : "${INPUT_CPUS:=$(nproc)}" # use all available resources + : "${INPUT_GCOV:=1}" EXIT_TITLE="${EXIT_TITLE}: ${mode}" # only one mode @@ -241,6 +245,7 @@ setup_env() { local mode net=() mkdir -p "${RESULTS_DIR}" : "${INPUT_CPUS:=2}" # limit to 2 cores for now + : "${INPUT_GCOV:=0}" # add net support, can be useful, but delay the start of the tests (~1 sec?) net=("--net") @@ -256,6 +261,8 @@ setup_env() { local mode net=() TESTS_SUMMARY="${RESULTS_DIR}/summary.txt" CONCLUSION="${RESULTS_DIR}/conclusion.txt" KMEMLEAK="${RESULTS_DIR}/kmemleak.txt" + LCOV_FILE="${RESULTS_DIR}/kernel.lcov" + LCOV_HTML="${RESULTS_DIR}/lcov" KVERSION=$(make -C "${KERNEL_SRC}" -s kernelversion) ## 5.17.0 or 5.17.0-rc8 KVER_MAJ=${KVERSION%%.*} ## 5 @@ -429,6 +436,11 @@ gen_kconfig() { local mode kconfig=() vck rc=0 kconfig+=(-e DEBUG_INFO_REDUCED -e DEBUG_INFO_SPLIT) fi + # GCov for the CI + if [ "${INPUT_GCOV}" = 1 ]; then + kconfig+=(-e GCOV_KERNEL -e GCOV_PROFILE_MPTCP) + fi + # Debug tools for developers kconfig+=( -e DYNAMIC_DEBUG --set-val CONSOLE_LOGLEVEL_DEFAULT 8 @@ -491,7 +503,11 @@ gen_kconfig() { local mode kconfig=() vck rc=0 build_kernel() { local rc=0 log_section_start "Build kernel" - _make_o || rc=${?} + if [ "${INPUT_GCOV}" = 1 ]; then + KCFLAGS="-fprofile-update=atomic" _make_o || rc=${?} + else + _make_o || rc=${?} + fi # virtme will mount a tmpfs there + symlink to .virtme_mods mkdir -p /lib/modules @@ -1033,6 +1049,14 @@ kmemleak_scan() { fi } +gcov_extract() { + if [ -d /sys/kernel/debug/gcov ]; then + lcov --capture --keep-going --rc geninfo_unexecuted_blocks=1 \ + --function-coverage --branch-coverage \ + -b "${VIRTME_BUILD_DIR}" -j "${INPUT_CPUS}" -o "${LCOV_FILE}" + fi +} + # \$1: max iterations (<1 means no limit) ; args: what needs to be executed run_loop_n() { local i tdir rc=0 n=\${1} @@ -1106,6 +1130,7 @@ fi cd "${KERNEL_SRC}" kmemleak_scan +gcov_extract # To run commands before executing the tests if [ -f "${VIRTME_EXEC_POST}" ]; then @@ -1338,6 +1363,13 @@ _print_kmemleak() { echo "KMemLeak detected" } +_lcov_to_html() { + mkdir -p "${LCOV_HTML}" + genhtml -j "$(nproc)" -t "$(_get_ref)" --dark-mode \ + --include '/net/mptcp/' \ + -o "${LCOV_HTML}" "${LCOV_FILE}" &> "${LCOV_HTML}/gen.log" +} + # $1: mode, rest: args for kconfig _print_summary_header() { local mode="${1}" @@ -1484,6 +1516,15 @@ analyze() { EXIT_STATUS=1 fi + if [ "${INPUT_GCOV}" = 1 ]; then + if ! _lcov_to_html; then + echo "Unable to generate HTML from LCOV data" | tee -a "${TESTS_SUMMARY}" + tee -a "${TESTS_SUMMARY}" < "${LCOV_HTML}/gen.log" + _register_issue "Critical" "${mode}" "LCOV" + EXIT_STATUS=1 + fi + fi + echo -ne "${COLOR_RESET}" if [ "${EXIT_STATUS}" = "1" ]; then diff --git a/run.sh b/run.sh index 629d47d..1bc14c0 100755 --- a/run.sh +++ b/run.sh @@ -38,6 +38,7 @@ docker run \ -e "INPUT_EXPECT_TIMEOUT" \ -e "INPUT_EXTRA_ENV" \ -e "INPUT_CPUS" \ + -e "INPUT_GCOV" \ -e "VIRTME_ARCH" \ -e "COMPILER" \ --privileged \