Merge "Add log directory option to functional tests"

This commit is contained in:
Zuul 2018-06-14 00:43:16 +00:00 committed by Gerrit Code Review
commit 3dff137b04

View File

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