Add log directory option to functional tests

This option to the functional test runner outputs logs for each test
to ${LOGDIR}/${element}/${test_element}.log

Change-Id: I3bf5362bcda8acda1a03c1058728875a9a6c9711
This commit is contained in:
Ian Wienand 2018-05-23 11:37:18 +10:00
parent 8fb2f5cb55
commit bd54e0125e

View File

@ -6,7 +6,7 @@ set -o pipefail
BASE_DIR=$(cd $(dirname "$0")/.. && pwd)
# then execute tests for elements
export DIB_CMD=disk-image-create
export DIB_CMD="disk-image-create"
export DIB_ELEMENTS=$(python -c '
import diskimage_builder.paths
diskimage_builder.paths.show_path("elements")')
@ -114,6 +114,7 @@ function run_disk_element_test() {
local element=$2
local dont_use_tmp=$3
local output_format="$4"
local logfile="$5"
local use_tmp_flag=""
local dest_dir=$(mktemp -d)
@ -132,6 +133,7 @@ function run_disk_element_test() {
ELEMENTS_PATH=$DIB_ELEMENTS/$element/test-elements \
$DIB_CMD -x -t ${output_format} \
${use_tmp_flag} \
${logfile} \
-o $dest_dir/image -n $element $test_element 2>&1 \
| log_with_prefix "${element}/${test_element}"; then
@ -220,11 +222,12 @@ done
JOB_MAX_CNT=1
LOG_DATESTAMP=0
KEEP_OUTPUT=0
LOG_DIRECTORY=''
#
# Parse args
#
while getopts ":hlj:t" opt; do
while getopts ":hlj:tL:" opt; do
case $opt in
h)
echo "run_functests.sh [-h] [-l] <test> <test> ..."
@ -233,6 +236,7 @@ while getopts ":hlj:t" opt; do
echo " -j : parallel job count (default to 1)"
echo " -t : prefix log messages with timestamp"
echo " -k : keep output directories"
echo " -L : output logs into this directory"
echo " <test> : functional test to run"
echo " Special test 'all' will run all tests"
exit 0
@ -261,6 +265,9 @@ while getopts ":hlj:t" opt; do
k)
KEEP_OUTPUT=1
;;
L)
LOG_DIRECTORY=${OPTARG}
;;
\?)
echo "Invalid option: -$OPTARG"
exit 1
@ -305,6 +312,11 @@ else
done
fi
if [[ -n "${LOG_DIRECTORY}" ]]; then
mkdir -p "${LOG_DIRECTORY}"
export DIB_QUIET=1
fi
# print a little status info
echo "------"
echo ${title}
@ -365,8 +377,16 @@ for test in "${TESTS_TO_RUN[@]}"; do
element_output=$(cat ${element_output_override})
fi
log_argument=' '
if [[ -n "${LOG_DIRECTORY}" ]]; then
mkdir -p "${LOG_DIRECTORY}/${element}"
log_argument="--logfile ${LOG_DIRECTORY}/${element}/${test_element}.log"
fi
echo "Running $test ($element_type)"
run_${element_type}_element_test $test_element $element ${DONT_USE_TMP} "${element_output}" &
run_${element_type}_element_test \
$test_element $element \
${DONT_USE_TMP} "${element_output}" "$log_argument" &
done
# Wait for the rest of the jobs