From bd54e0125ee26dc2f64baa7c9d41e59f20c2e8fc Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 23 May 2018 11:37:18 +1000 Subject: [PATCH] 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 --- tests/run_functests.sh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/tests/run_functests.sh b/tests/run_functests.sh index 6a965dfa..a51b860b 100755 --- a/tests/run_functests.sh +++ b/tests/run_functests.sh @@ -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] ..." @@ -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 " : 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