Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1n4o7d-00025H-Or for mharc-grub-devel@gnu.org; Tue, 04 Jan 2022 13:01:21 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39064) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n4o7a-000203-O4 for grub-devel@gnu.org; Tue, 04 Jan 2022 13:01:18 -0500 Received: from [2607:f8b0:4864:20::829] (port=37613 helo=mail-qt1-x829.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n4o7X-0003R3-GQ for grub-devel@gnu.org; Tue, 04 Jan 2022 13:01:18 -0500 Received: by mail-qt1-x829.google.com with SMTP id f9so34915879qtk.4 for ; Tue, 04 Jan 2022 10:01:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/Rk9XypBNLh6JttivjqGL9oKv3ykIApJ2u8rWnxUxxY=; b=GjbCbJY1ag/UWz+eHPd+JSnnDXCWtZMGETGrL+pV3T1owhx5SGL1Pde5J2YaB7/7hL mBkzxjOoK+J6VEwILnY228cJuLT91OCMLgv7YGbOV3wIuwfvN42K89lJPxzoAcSaXQVB ljJXlHUzNnxbfHbJHUrcs72kV6ghe8AHEtupDpBVucjkw3ARuwS54AAxL9CTJcDdEU1a /njkdleRV7oa/pkI5PMkl9zvyfNvNPcOjUsOKqFClO6pVTjSEBvG3YoF93zXx1p8eQZC fhx08CioOaNASdfS3vWQJ+tOb9/ic0jt0eWOlFBz/z8AnFJd88Mor9b6Mr0K+wvPxlOk co8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/Rk9XypBNLh6JttivjqGL9oKv3ykIApJ2u8rWnxUxxY=; b=EqX/zlvf9Jp4PoNmE7WJ6zO/6doAXdW3jb6Vj36kbKHKHQusE21pu/dDYaJocXceFV GAYVImPwwl/HKrf23BPgMcVUReN6EaGxw3VW5CqQf8BJCgKdFlPqKEZ4Cpibj5aHFHBz aPPjRunTe/B4/1FWD2xZkdXDc3sE8bPyH6M1d7v8IfypckXADL36S5gxlkRHN1F9eebG x3DDTXatSUozlxLDBPIuY8+xO5pYhDkOF+s0Hyg2OnP95rao9dLykKERgMiHY14YA5w0 F4qDTm4Vmgwbdj5m2sWen+rXGh3YunEkN8I/7H02XjlVglSI/HMXQP1+zDJHeEKPJUzA CC4g== X-Gm-Message-State: AOAM533iaOAURpc987+hspaLM7+KR0ud5O5J5wdt7CJ/UwxO6KLyKxvT A6yeErZU1TErgy3uy7wWScwBQg== X-Google-Smtp-Source: ABdhPJy650bcBwYgv9AfuhzaMvgN+YmSFRtKK9PjZysCwhJQfORNQvWreLkUj+OsyRUlK7J5puBaTw== X-Received: by 2002:a05:622a:24a:: with SMTP id c10mr45005074qtx.209.1641319273955; Tue, 04 Jan 2022 10:01:13 -0800 (PST) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id l22sm31884862qtj.68.2022.01.04.10.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 10:01:13 -0800 (PST) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Glenn Washburn Subject: [LOCAL-CI v2 1/3] scripts: Add general scripts to aid automated testing Date: Tue, 4 Jan 2022 12:00:44 -0600 Message-Id: <0d7f2be8555e9b41fbd150c9f313cec5f92a00e3.1641317423.git.development@efficientek.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::829 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::829; envelope-from=development@efficientek.com; helo=mail-qt1-x829.google.com X-Spam_score_int: 8 X-Spam_score: 0.8 X-Spam_bar: / X-Spam_report: (0.8 / 5.0 requ) DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Jan 2022 18:01:19 -0000 Signed-off-by: Glenn Washburn --- scripts/ci/build.sh | 67 ++++++++++++++++++++ scripts/ci/functions.sh | 33 ++++++++++ scripts/ci/make-images.sh | 86 +++++++++++++++++++++++++ scripts/ci/process-tests.sh | 111 +++++++++++++++++++++++++++++++++ scripts/ci/test.sh | 121 ++++++++++++++++++++++++++++++++++++ 5 files changed, 418 insertions(+) create mode 100755 scripts/ci/build.sh create mode 100644 scripts/ci/functions.sh create mode 100755 scripts/ci/make-images.sh create mode 100755 scripts/ci/process-tests.sh create mode 100755 scripts/ci/test.sh diff --git a/scripts/ci/build.sh b/scripts/ci/build.sh new file mode 100755 index 000000000..723dc292f --- /dev/null +++ b/scripts/ci/build.sh @@ -0,0 +1,67 @@ +#!/bin/bash + +set -eo pipefail + +# Environment variables +# JOBS: Number of concurrent jobs while building, defaults to number of +# processors plus 1, unless number of processors is 1 in which case its 2. +# SRCDIR: Path to source files +# BUILDDIR: Directory in which to place the build +# INSTALLDIR: Directory to install binaries +# ARCH: Architecture to build for +# PLATFORM: Platform to build for +# CONFIGURE_OPTS: Extra configure options +# FONT_SOURCE: Path to unicode font named "unifont." where ext is one of: +# pcf pcf.gz bdf bdf.gz ttf ttf.gz +# DJVU_FONT_SOURCE: Path to DejaVu font named "DejaVuSans." where ext is +# one of: pcf pcf.gz bdf bdf.gz ttf ttf.gz +# SHELL_TRACE: Set to 'y' to enable shell tracing + +[ "x${SHELL_TRACE}" = "xy" ] && set -x + +[ -f "$(dirname "$0")/functions.sh" ] && +. "$(dirname "$0")/functions.sh" + +[ -f "$(dirname "$0")/functions.$CI_TYPE.sh" ] && +. "$(dirname "$0")/functions.$CI_TYPE.sh" + +JOBS=${JOBS:-`getconf _NPROCESSORS_ONLN 2> /dev/null || echo 2`} +[ "$JOBS" = 1 ] || JOBS=$(($JOBS + 1)) + +TARGET="${ARCH}-${PLATFORM}" + +mkdir -pv ${BUILDDIR} + +RET=0 +cd ${BUILDDIR} + +if test -f "$FONT_SOURCE"; then + ln -svf "$(realpath -e "$FONT_SOURCE")" ./ +fi + +if test -f "$DJVU_FONT_SOURCE"; then + ln -svf "$(realpath -e "$DJVU_FONT_SOURCE")" ./ +fi + +start_log -c -n "configure-$TARGET" "Configuring $TARGET" +[ -x "$SRCDIR/configure" ] && $SRCDIR/configure --help +$SRCDIR/configure --target=$ARCH --with-platform=$PLATFORM \ + --prefix=${INSTALLDIR} $CONFIGURE_OPTS || RET=$? +end_log -n "configure-$TARGET" + +if [ "$RET" -ne 0 ]; then + start_log -c -n "showlogs-$TARGET" "Configuring $TARGET failed, showing logs" + cat ${BUILDDIR}/config.log + end_log -n "showlogs-$TARGET" + exit $RET +fi + +start_log -c -n "build-$TARGET" "Building $TARGET" +make ${JOBS:+-j$JOBS} || RET=$? +end_log -n "build-$TARGET" +[ "$RET" -ne 0 ] && exit $RET + +start_log -c -n "install-$TARGET" "Installing $TARGET" +make ${JOBS:+-j$JOBS} install || RET=$? +end_log -n "install-$TARGET" +exit $RET diff --git a/scripts/ci/functions.sh b/scripts/ci/functions.sh new file mode 100644 index 000000000..2f4cecaa1 --- /dev/null +++ b/scripts/ci/functions.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +TXT_RED="\e[31m" +TXT_YELLOW="\e[33m" +TXT_CLEAR="\e[0m" +TXT_LOG_COLOR="\e[97;100m" + +function start_log() { + local LOG_COLLAPSE LOG_NAME + while [ "$#" -gt 0 ]; do + case "$1" in + -c) LOG_COLLAPSE=1; shift;; + -n) LOG_NAME="$2"; shift;; + *) [ "$#" -eq 1 ] && LOG_MSG="$1"; shift;; + esac + done + + echo -e "Start:${LOG_NAME} ${LOG_MSG}" +} + +function end_log() { + local LOG_NAME + while [ "$#" -gt 0 ]; do + case "$1" in + -n) LOG_NAME=$2; shift;; + *) shift;; + esac + done + + echo -e "End:${LOG_NAME}" +} + +:; diff --git a/scripts/ci/make-images.sh b/scripts/ci/make-images.sh new file mode 100755 index 000000000..d156af46f --- /dev/null +++ b/scripts/ci/make-images.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +set -eo pipefail + +# Environment variables +# SRCDIR: Path to source files +# BUILDDIR: Directory in which to place the build +# TARGET: Target to test +# MAKE_ALL_IMAGE_TARGETS: If set to 'y', then all image targets, even disabled +# ones, will be run. +# DISABLED_IMAGES: String of target formats to disable when building grub +# images delimited by new lines. +# SHELL_TRACE: Set to 'y' to enable shell tracing +# NUM_FAILED_LOG_LINES: Set to integer number of log lines to display from the +# end of a failed log file + +if [ "x${SHELL_TRACE}" = "xy" ]; then + # If we export SHELL_OPTS, then all shells will be traced, most of which we do not want + SHELL_OPTS="-x" + set -x +fi + +[ -f "$(dirname "$0")/functions.sh" ] && +. "$(dirname "$0")/functions.sh" + +[ -f "$(dirname "$0")/functions.$CI_TYPE.sh" ] && +. "$(dirname "$0")/functions.$CI_TYPE.sh" + +start_log -c -n "images-$TARGET" "Making images for $TARGET" + +if [ ! -x "${BUILDDIR}/grub-mkimage" ]; then + echo "Aborting, no grub-mkimage found in builddir" + exit 1 +fi + +function build_tformat() { + TARGET=$1 + FORMATS=$2 + for fmt in $FORMATS; do + if [ -z "${fmt%~*}" ]; then + echo "${TARGET}" + else + echo "${TARGET}-${fmt}" + fi + done +} + +tformats="~" +case "$TARGET" in + mipsel-loongson) + tformats="mipsel-loongson-elf mipsel-yeeloong-flash mipsel-fuloong2f-flash" ;; + *) + case "$TARGET" in + i386-pc) tformats="~ pxe eltorito" ;; + sparc64-ieee1275) tformats="aout cdcore raw" ;; + mips-qemu_mips | \ + mipsel-qemu_mips) tformats="elf flash" ;; + arm-coreboot) tformats="vexpress veyron" ;; + esac + tformats=$(build_tformat "${TARGET}" "$tformats") + ;; +esac + +RET=0 +mkdir -pv "${BUILDDIR}/images" +for tfmt in $tformats; do + if [ "x${MAKE_ALL_IMAGE_TARGETS}" != "xy" ] && ( echo "${DISABLED_IMAGES}" | grep -qE "^\s*${tfmt}$" ); then + echo "Image build disabled for target format $tfmt" + continue + fi + + echo "Making image for target format: ${tfmt}" + ${BUILDDIR}/grub-mkimage -v -p / -O "${tfmt}" -o "${BUILDDIR}/images/grub-${tfmt}.img" echo reboot normal > "${BUILDDIR}/grub-mkimage-${tfmt}.log" 2>&1 || _RET=$? + [ "${_RET:-0}" -ne 0 ] && RET=$_RET + + if [ "$RET" -ne 0 ]; then + echo -e "${TXT_RED}Failed to build image for target format ${tfmt}: ${TESTNAME}$TXT_CLEAR" + echo -e -n "$TXT_LOG_COLOR" + echo "Last ${NUM_FAILED_LOG_LINES} lines of grub-mkimage verbose log" + tail -n "${NUM_FAILED_LOG_LINES}" "${BUILDDIR}/grub-mkimage-${tfmt}.log" + echo -e -n "$TXT_CLEAR" + fi +done + +end_log -n "images-$TARGET" +exit $RET diff --git a/scripts/ci/process-tests.sh b/scripts/ci/process-tests.sh new file mode 100755 index 000000000..9bf763502 --- /dev/null +++ b/scripts/ci/process-tests.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +set -eo pipefail + +# Environment variables +# SRCDIR: Path to source files +# BUILDDIR: Directory in which to place the build +# TARGET: Target to process +# TEST_ALL_TARGETS: If set to 'y', then all tests, even disabled ones will be +# processed. +# DISABLED_TESTS: String of disabled tests delimited by new lines. +# SHELL_TRACE: Set to 'y' to enable shell tracing +# EXPECTED_FAILURES: Multi-line string where each line contains a testname or +# target:testname indicating an expected failure. Lines whose first non-space +# character is '#' are ignored. +# EXPECTED_FUNCTIONAL_FAILURES: Same format as EXPECTED_FAILURES applied to the +# functional test suite (grub_func_test). +# FAIL_ON_HARD_ERRORS: Set to 'y' to fail on hard as well as normal errors. +# IGNORE_TIMEDOUT_TEST_FAILURE: Set to 'y' to ignore test failures due to +# test timing out. +# NUM_FAILED_LOG_LINES: Set to integer number of log lines to display from the +# end of a failed log file + +[ "x${SHELL_TRACE}" = "xy" ] && set -x + +[ -f "$(dirname "$0")/functions.sh" ] && +. "$(dirname "$0")/functions.sh" + +[ -f "$(dirname "$0")/functions.$CI_TYPE.sh" ] && +. "$(dirname "$0")/functions.$CI_TYPE.sh" + +# TARGET="${ARCH}-${PLATFORM}" +NUM_FAILED_LOG_LINES=${NUM_FAILED_LOG_LINES:-100} + +if [ -f ${BUILDDIR}/test.success ]; then + echo "Not processing test logs because make check ran successfully" + exit 0 +elif [ "x${TEST_ALL_TARGETS}" != "xy" ] && ( echo "${DISABLED_TESTS}" | grep -qE "^\s*${TARGET}$" ); then + echo "No test output processing because testing was disabled" + exit 0 +fi; + +start_log -c -n "process-test-$TARGET" "Processing test output of $TARGET" +: >${BUILDDIR}/test-results.log +if [ -f ${BUILDDIR}/test-suite.log ]; then + ( grep -E "^(FAIL|ERROR|SKIP):" ${BUILDDIR}/test-suite.log || ':' ) | + while read STATUS TESTNAME; do + STATUS=${STATUS%%:} + + if [ "$STATUS" = "SKIP" ]; then + TYPE=skip + elif tail -n1 "${BUILDDIR}/${TESTNAME}.log" | grep -qE 'exit status: (124|137)'; then + if [ "x${IGNORE_TIMEDOUT_TEST_FAILURE}" = "xy" ]; then + echo -e "${TXT_RED}Ignoring Timed-out test: ${TESTNAME}$TXT_CLEAR" + echo -e -n "$TXT_LOG_COLOR" + echo "Test failed due to a timeout. This is likely due to" + echo "insufficient host resources, and NOT a real failure." + echo -e -n "$TXT_CLEAR" + fi + TYPE=timeout + elif [ "$STATUS" = "ERROR" ]; then + TYPE=error + elif echo "${EXPECTED_FAILURES}" | grep -qE "^\s*(${TESTNAME}|${TARGET}:${TESTNAME})$"; then + echo "Expected failed test: $TESTNAME" + TYPE=expected + # If any unexpected failures in the functional tests, count a failure in + # grub_func_test as a true failure. + elif [ "$TESTNAME" = "grub_func_test" ]; then + grep -E ': FAIL' ${BUILDDIR}/${TESTNAME}.log | sort -u | + while read FTESTNAME STATUS; do + FTESTNAME=${FTESTNAME%:*} + if echo "${EXPECTED_FUNCTIONAL_FAILURES}" | grep -qE "^\s*(${FTESTNAME}|${TARGET}:${FTESTNAME})$"; then + echo "Expected failed functional test: $FTESTNAME" + TYPE=expected + else + echo -e "${TXT_RED}Unexpected failed functional test: ${FTESTNAME}$TXT_CLEAR" + TYPE=unexpected + fi + echo "${TARGET}:${TYPE}:${TESTNAME}:${FTESTNAME}" >> ${BUILDDIR}/test-results.log + done + continue + else + echo -e "${TXT_RED}Unexpected failed test: ${TESTNAME}$TXT_CLEAR" + echo -e -n "$TXT_LOG_COLOR" + echo "Last ${NUM_FAILED_LOG_LINES} lines of ${BUILDDIR}/${TESTNAME}.log" + tail -n "${NUM_FAILED_LOG_LINES}" "${BUILDDIR}/${TESTNAME}.log" + echo -e -n "$TXT_CLEAR" + TYPE=unexpected + fi + echo "${TARGET}:${TYPE}:${TESTNAME}" >> ${BUILDDIR}/test-results.log + done +else + echo "No success canary and no test-suite.log, perhaps tests were not run or was killed." + RET=2 +fi + +# If there are any unexpected errors return exit with error +FAILCOND="unexpected" +if [ "x${FAIL_ON_HARD_ERRORS}" = "xy" ]; then + FAILCOND="${FAILCOND}|error" +fi; +if [ "x${IGNORE_TIMEDOUT_TEST_FAILURE}" != "xy" ]; then + FAILCOND="${FAILCOND}|timeout" +fi; +FAILCOND="${TARGET}:(${FAILCOND})" + +if grep -E -qs "${FAILCOND}" ${BUILDDIR}/test-results.log; then + RET=1 +fi +end_log -n "process-test-$TARGET" +exit ${RET:-0} diff --git a/scripts/ci/test.sh b/scripts/ci/test.sh new file mode 100755 index 000000000..833912587 --- /dev/null +++ b/scripts/ci/test.sh @@ -0,0 +1,121 @@ +#!/bin/bash + +set -eo pipefail + +# Environment variables +# SRCDIR: Path to source files +# BUILDDIR: Directory in which to place the build +# TARGET: Target to test +# TEST_ALL_TARGETS: If set to 'y', then all tests, even disabled ones will be +# run. +# DISABLED_TESTS: String of disabled tests delimited by new lines. +# TESTS_TIMEOUT: Maximum timeout to allow for 'make check'. Set this slightly +# below total job timeout to allow for cleanup and log packaging code. +# TEST_VERBOSITY: Number to set verbosity level to +# TEST_DATA_PREFIX: Filename prefix to use when saving test data. If not set, +# test data will not be saved. +# STRACE_TESTS: Set to 'y' to strace each test +# SHELL_TRACE: Set to 'y' to enable shell tracing +# JOBS: Number of concurrent jobs while building, defaults to number of +# processors plus 1, unless number of processors is 1 in which case its 2. + + +if [ "x${SHELL_TRACE}" = "xy" ]; then + # If we export SHELL_OPTS, then all shells will be traced, most of which we do not want + SHELL_OPTS="-x" + set -x +fi + +[ -f "${0%/*}/functions.sh" ] && +. "${0%/*}/functions.sh" + +[ -f "${0%/*}/functions.$CI_TYPE.sh" ] && +. "${0%/*}/functions.$CI_TYPE.sh" + +if [ "x${TEST_ALL_TARGETS}" != "xy" ] && ( echo "${DISABLED_TESTS}" | grep -qE "^\s*${TARGET}$" ); then + echo "Tests are disabled for target $TARGET" + exit 0 +fi + +start_log -c -n "test-$TARGET" "Testing $TARGET" + +if [ "${TEST_VERBOSITY:-0}" -gt 0 ]; then + export GRUB_SHELL_DEFAULT_DEBUG=${TEST_VERBOSITY} + export GRUB_TEST_DEFAULT_DEBUG=${TEST_VERBOSITY} +fi + +JOBS="${JOBS:-`getconf _NPROCESSORS_ONLN 2> /dev/null || echo 2`}" +TESTTMPDIR="${TESTTMPDIR:-${TMPDIR:-/tmp}/grub-test-$TARGET}" +COMP=xz +STRACE_LOG="${BUILDDIR}/xxx.strace.$COMP" + +if [ "x${STRACE_TESTS}" = "xy" ]; then + STRACE="strace -y -yy -f -v -s4096 -o >($COMP -9 > $STRACE_LOG)" +fi + +cat >${BUILDDIR}/log-tester.sh <