Commit 97220c8a authored by Richard Neill's avatar Richard Neill Committed by Kamil Dzieżyk
Browse files

ewaol-tests: If a test suite fails, print the log-file to stdout for debugging

To do this, print the log from the generic run-* script that executes each test
suite. As this generic script doesn't know what test suite it will be running,
or what the user might customize that test suite's log file to be, use a
hard-coded temporary log-file placed in the same volatile runtime directory that
is used for storing the test PIDs, and log messages to that file simultaneously
with the normal logging procedure.

Also, this patch allows setting extra parameters to be passed to bats "run-.*"
scripts via the 'EWAOL_TEST_OPTIONS' build-time variable. Currently, it is set
to "--show-output-of-passing-tests" to give the user more information about
what the test suite is doing at run-time.

Furthermore, spaces are replaced with tabs in the 'run-test-suite' file to allow
better code readability with here-document indentions, along with two more
variables: 'TEST_RUNTIME_DIR' and 'EWAOL_TEST_BATS_OPTIONS', are set with the
e...
parent 340bf554
......@@ -12,6 +12,7 @@ RDEPENDS:${PN}:append = " bats runtime-integration-tests-common"
DEPENDS:append = " gettext-native"
EWAOL_TEST_ACCOUNT ??= "test"
EWAOL_TEST_BATS_OPTIONS ?= "--show-output-of-passing-tests"
TEST_DIR = "${datadir}/${BPN}"
TEST_SUITE_NAME = "${BPN}"
......@@ -23,12 +24,14 @@ SRC_URI = "${TEST_FILES} \
ENVSUBST_VARS = "\$TEST_SUITE_NAME \
\$EWAOL_TEST_ACCOUNT \
\$TEST_DIR \
\$EWAOL_GUEST_VM_HOSTNAME"
\$EWAOL_GUEST_VM_HOSTNAME \
\$EWAOL_TEST_BATS_OPTIONS"
export TEST_SUITE_NAME
export EWAOL_TEST_ACCOUNT
export TEST_DIR
export EWAOL_GUEST_VM_HOSTNAME
export EWAOL_TEST_BATS_OPTIONS
do_install[vardeps] += "\
ENVSUBST_VARS \
......@@ -36,6 +39,7 @@ do_install[vardeps] += "\
EWAOL_TEST_ACCOUNT \
TEST_DIR \
EWAOL_GUEST_VM_HOSTNAME \
EWAOL_TEST_BATS_OPTIONS \
"
do_install() {
......
......@@ -14,8 +14,6 @@ else
TEST_LOG_DIR="${CE_TEST_LOG_DIR}"
fi
TEST_RUNTIME_DIR="/var/run/ewaol-integration-tests"
export TEST_LOG_FILE="${TEST_LOG_DIR}/container-engine-integration-tests.log"
export TEST_STDERR_FILE="${TEST_LOG_DIR}/ce-stderr.log"
export TEST_RUN_FILE="${TEST_RUNTIME_DIR}/container-engine-integration-tests.pgid"
......
......@@ -4,6 +4,11 @@
#
# SPDX-License-Identifier: MIT
# In order to automatically print the log from a generic file that is common to
# the test suites, also store the log messages in the volatile runtime dir which
# doesn't change.
export TEST_TEMP_LOG_FILE="${TEST_RUNTIME_DIR}/latest-tests.log"
# Arg1: Type of message (INFO, DEBUG, PASS, FAIL, SKIP)
# Arg2: Message to log
#
......@@ -28,18 +33,18 @@ log() {
log_msg="${log_msg}:${*:2}"
fi
echo "${log_msg}" >> "${TEST_LOG_FILE}"
echo "${log_msg}"
echo "${log_msg}" | sudo -n tee -a "${TEST_LOG_FILE}" "${TEST_TEMP_LOG_FILE}"
if [ "${1}" == "FAIL" ]; then
# If the test failed, add additional debugging information
touch "${TEST_STDERR_FILE}"
stderr="$(cat "${TEST_STDERR_FILE}")"
debug_msg="${timestamp} DEBUG:${BATS_TEST_NAME}:${status:-}:${output:-}:${stderr}"
echo "${debug_msg}" >> "${TEST_LOG_FILE}"
echo "${debug_msg}"
echo "${debug_msg}" | sudo -n tee -a "${TEST_LOG_FILE}" \
"${TEST_TEMP_LOG_FILE}"
echo "DEBUG:Test log can be found at ${TEST_LOG_FILE}"
fi
}
......@@ -75,7 +80,10 @@ check_running_test_suite() {
# appropriately
BATS_TEST_NAME="check_prior_execution"
if pgid=$(cat "$1"); then
# If umask is set to 0027, then the access to the files under '/var/run/*'
# is restricted for 'others'. `sudo` is required because the owner of the
# '/var/run/*' files is 'root'.
if pgid=$(sudo -n cat "$1"); then
# A run file currently exists, therefore a previous execution didn't
# complete
log "DEBUG" "Found a run-file from an existing test execution: ${pgid}"
......@@ -117,7 +125,7 @@ check_running_test_suite() {
begin_test_suite() {
# shellcheck disable=SC2009
pgid="$(ps -o pid,pgid | grep -w "$$" | xargs | cut -d" " -f 2)"
sudo sh -c "echo ${pgid} > ${1}"
echo "${pgid}" | sudo -n tee "${1}" > /dev/null
}
# Remove the run-file if it contains the appropriate PGID
......@@ -127,13 +135,17 @@ finish_test_suite() {
# shellcheck disable=SC2009
pgid=$(ps -o pid,pgid | grep -w "$$" | xargs | cut -d" " -f 2)
file_pgid=$(cat "$1")
# If umask is set to 0027, then the access to the files under '/var/run/*'
# is restricted for 'others'. `sudo` is required because the owner of the
# '/var/run/*' files is 'root'.
file_pgid=$(sudo -n cat "$1")
if [ "${pgid}" -ne "${file_pgid}" ]; then
log "DEBUG" "When finishing test-suite execution, the PGID ${pgid}"
" did not match the PGID within the run-file ${file_pgid}"
else
sudo rm "${1}"
sudo -n rm "${1}"
fi
}
......@@ -153,11 +165,12 @@ finish_test_suite() {
test_suite_setup() {
# Clear and rebuild the logs
sudo -n rm -f "${TEST_TEMP_LOG_FILE}"
rm -f "${TEST_LOG_FILE}" "${TEST_STDERR_FILE}"
mkdir -p "${TEST_LOG_DIR}"
# Create volatile runtime directory.
sudo mkdir -p "${TEST_RUNTIME_DIR}"
sudo -n mkdir -p "${TEST_RUNTIME_DIR}"
_run check_running_test_suite "${TEST_RUN_FILE}"
if [ "${status}" -ne 0 ]; then
......
......@@ -9,14 +9,22 @@
# when we already switched to ${EWAOL_TEST_ACCOUNT} via the following sudo
# command.
if ! cd /home ; then
echo "FAIL:${TEST_SUITE_NAME}"
exit 1
echo "FAIL:${TEST_SUITE_NAME}"
exit 1
fi
if sudo -HEnu "${EWAOL_TEST_ACCOUNT}" bats "${TEST_DIR}/${TEST_SUITE_NAME}.bats"; then
echo "PASS:${TEST_SUITE_NAME}"
exit 0
if sudo -HEnu "${EWAOL_TEST_ACCOUNT}" bats "${EWAOL_TEST_BATS_OPTIONS}" "${TEST_DIR}/${TEST_SUITE_NAME}.bats"; then
echo "PASS:${TEST_SUITE_NAME}"
exit 0
else
echo "FAIL:${TEST_SUITE_NAME}"
exit 1
echo "FAIL:${TEST_SUITE_NAME}"
sudo -HEns <<-'EOF'
if [ -f "${TEST_RUNTIME_DIR}/latest-tests.log" ]; then
echo "DEBUG:Printing the contents of the log-file:"
cat "${TEST_RUNTIME_DIR}/latest-tests.log"
else
echo "DEBUG:Could not find a log-file."
fi
EOF
exit 1
fi
......@@ -14,8 +14,6 @@ else
TEST_LOG_DIR="${K3S_TEST_LOG_DIR}"
fi
TEST_RUNTIME_DIR="/var/run/ewaol-integration-tests"
export TEST_LOG_FILE="${TEST_LOG_DIR}/k3s-integration-tests.log"
export TEST_STDERR_FILE="${TEST_LOG_DIR}/k3s-stderr.log"
export TEST_RUN_FILE="${TEST_RUNTIME_DIR}/k3s-integration-tests.pgid"
......
......@@ -43,8 +43,8 @@ do_compile[noexec] = "1"
do_install() {
install -d "${D}/${TEST_COMMON_DIR}"
install --mode="644" "${WORKDIR}/integration-tests-common-funcs.sh" \
"${D}/${TEST_COMMON_DIR}"
envsubst '$TEST_RUNTIME_DIR' < "${WORKDIR}/integration-tests-common-funcs.sh" \
> "${D}/${TEST_COMMON_DIR}/integration-tests-common-funcs.sh"
install --mode="644" "${WORKDIR}/login-console-funcs.expect" \
"${D}/${TEST_COMMON_DIR}"
......
......@@ -3,8 +3,12 @@
# SPDX-License-Identifier: MIT
export TEST_COMMON_DIR = "${datadir}/runtime-integration-tests-common"
ENVSUBST_VARS:append = " \$TEST_COMMON_DIR"
export TEST_RUNTIME_DIR = "/var/run/ewaol-integration-tests"
ENVSUBST_VARS:append = " \$TEST_COMMON_DIR\
\$TEST_RUNTIME_DIR "
do_install[vardeps] += "\
TEST_COMMON_DIR \
TEST_RUNTIME_DIR \
"
......@@ -14,8 +14,6 @@ else
TEST_LOG_DIR="${UA_TEST_LOG_DIR}"
fi
TEST_RUNTIME_DIR="/var/run/ewaol-integration-tests"
export TEST_LOG_FILE="${TEST_LOG_DIR}/user-accounts-integration-tests.log"
export TEST_STDERR_FILE="${TEST_LOG_DIR}/ua-stderr.log"
export TEST_RUN_FILE="${TEST_RUNTIME_DIR}/user-accounts-integration-tests.pgid"
......
......@@ -15,8 +15,6 @@ else
TEST_LOG_DIR="${VIRT_TEST_LOG_DIR}"
fi
TEST_RUNTIME_DIR="/var/run/ewaol-integration-tests"
export TEST_LOG_FILE="${TEST_LOG_DIR}/virtualization-integration-tests.log"
export TEST_STDERR_FILE="${TEST_LOG_DIR}/virt-stderr.log"
export TEST_RUN_FILE="${TEST_RUNTIME_DIR}/virtualization-integration-tests.pgid"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment