Skip to content

Commit

Permalink
runtests: show the results of executed cases if runtests was stopped …
Browse files Browse the repository at this point in the history
…by accident

As before runtests stopped by accident like ctrl+c, it will not show
the results of the execution that has already done.
Now add the cleanup function to show results of executed cases.

Signed-off-by: Pengfei Xu <[email protected]>
  • Loading branch information
xupengfe committed Apr 24, 2024
1 parent 2d99391 commit 3ac3765
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions runtests
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,56 @@ test_all() {
append_log "Test files: $CMDFILES" "$LOGFILE"
}

show_result() {
# Add the following print for the end of the case summary.
echo "--------------------------------------------------------" >> "$SUMMRY_LOG"

[[ -z "$LOGFILE" ]] || cat "$SUMMRY_LOG" >> "$LOGFILE"
cat "$SUMMRY_LOG"
echo "Dependence info in $DEP_LOG and runtests log in $LOGFILE"
}

# runtests_cleanup to show test result. TODO: restore the env if needed
runtests_cleanup() {
show_result
exit 0
}

run_tests() {
if [[ -z "$CMDFILES" ]] && [[ -z "$CMDLINE" ]]; then
usage
err "no test to run!"
fi

cat /dev/null > "$LOGFILE"

START_TIME="$(date +%Y-%m-%d_%H-%M-%S)"
SUMMRY_LOG="/tmp/lkvs_${START_TIME}_summary.log"
echo "Test Start Time: $START_TIME" > "$SUMMRY_LOG"
{
echo "--------------------------------------------------------"
printf "%-76s%-11s%-12s%-8s\n" "Testcase" "Result" "Exit Value" "Duration"
printf "%-76s%-11s%-12s%-8s\n" "--------" "------" "----------" "--------"
} >> "$SUMMRY_LOG"

init_dep_log "$DEP_LOG"

for cmdfile in $(tr "," " " <<< "$CMDFILES"); do
check_test_file_legal "$cmdfile" || continue

check_dep_feature "$cmdfile" || {
append_log "Skip $cmdfile due to dependece, please check $DEP_LOG" "$LOGFILE"
continue
}

runcmdfile "$cmdfile" "$LOGFILE"
done

if [[ -n "$CMDLINE" ]]; then
runtest "$CMDLINE" "$LOGFILE"
fi
}

# Default value
: "${LOGFILE:="./lkvs.log"}"
: CMDFILES=""
Expand Down Expand Up @@ -381,42 +431,6 @@ while getopts ":o:d:f:c:h" opt; do
esac
done

if [[ -z "$CMDFILES" ]] && [[ -z "$CMDLINE" ]]; then
usage
err "no test to run!"
fi

cat /dev/null > "$LOGFILE"

START_TIME="$(date +%Y-%m-%d_%H-%M-%S)"
SUMMRY_LOG="/tmp/lkvs_${START_TIME}_summary.log"
echo "Test Start Time: $START_TIME" > "$SUMMRY_LOG"
{
echo "--------------------------------------------------------"
printf "%-76s%-11s%-12s%-8s\n" "Testcase" "Result" "Exit Value" "Duration"
printf "%-76s%-11s%-12s%-8s\n" "--------" "------" "----------" "--------"
} >> "$SUMMRY_LOG"

init_dep_log "$DEP_LOG"

for cmdfile in $(tr "," " " <<< "$CMDFILES"); do
check_test_file_legal "$cmdfile" || continue

check_dep_feature "$cmdfile" || {
append_log "Skip $cmdfile due to dependece, please check $DEP_LOG" "$LOGFILE"
continue
}

runcmdfile "$cmdfile" "$LOGFILE"
done

if [[ -n "$CMDLINE" ]]; then
runtest "$CMDLINE" "$LOGFILE"
fi

# Add the following print for the end of the case summary.
echo "--------------------------------------------------------" >> "$SUMMRY_LOG"

[[ -z "$LOGFILE" ]] || cat "$SUMMRY_LOG" >> "$LOGFILE"
cat "$SUMMRY_LOG"
echo "Please check dependence info in $DEP_LOG"
trap runtests_cleanup SIGTERM SIGINT
run_tests
runtests_cleanup

0 comments on commit 3ac3765

Please sign in to comment.