Merge pull request #745 from dcooper16/run_mass_testing_parallel2

More improvements to mass testing in parallel
This commit is contained in:
Dirk Wetter 2017-05-17 18:34:13 +02:00 committed by GitHub
commit a3c318655d

View File

@ -307,6 +307,7 @@ SERVER_COUNTER=0 # Counter for multiple servers
readonly PARALLEL_SLEEP=1 # Time to sleep after starting each test readonly PARALLEL_SLEEP=1 # Time to sleep after starting each test
readonly MAX_WAIT_TEST=1200 # Maximum time (in seconds) to wait for a test to complete readonly MAX_WAIT_TEST=1200 # Maximum time (in seconds) to wait for a test to complete
readonly MAX_PARALLEL=20 # Maximum number of tests to run in parallel readonly MAX_PARALLEL=20 # Maximum number of tests to run in parallel
# This value may be made larger on systems with faster processors
declare -a -i PARALLEL_TESTING_PID=() # process id for each child test (or 0 to indicate test has already completed) declare -a -i PARALLEL_TESTING_PID=() # process id for each child test (or 0 to indicate test has already completed)
declare -a PARALLEL_TESTING_CMDLINE=() # command line for each child test declare -a PARALLEL_TESTING_CMDLINE=() # command line for each child test
declare -i NR_PARALLEL_TESTS=0 # number of parallel tests run declare -i NR_PARALLEL_TESTS=0 # number of parallel tests run
@ -11353,15 +11354,17 @@ cleanup () {
# If parallel mass testing is being performed, then the child tests need # If parallel mass testing is being performed, then the child tests need
# to be killed before $TEMPDIR is deleted. Otherwise, error messages # to be killed before $TEMPDIR is deleted. Otherwise, error messages
# will be created if testssl.sh is stopped before all testing is complete. # will be created if testssl.sh is stopped before all testing is complete.
"$INTERACTIVE" && [[ $NR_PARALLEL_TESTS -gt 0 ]] && echo -en "\r \r" 1>&2
while [[ $NEXT_PARALLEL_TEST_TO_FINISH -lt $NR_PARALLEL_TESTS ]]; do while [[ $NEXT_PARALLEL_TEST_TO_FINISH -lt $NR_PARALLEL_TESTS ]]; do
if [[ ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} -ne 0 ]] && \ if [[ ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} -ne 0 ]] && \
ps ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >/dev/null ; then ps ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >/dev/null ; then
kill ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >&2 2>/dev/null kill ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >&2 2>/dev/null
wait ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} 2>/dev/null # make sure pid terminated, see wait(1p) wait ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} 2>/dev/null # make sure pid terminated, see wait(1p)
get_next_message_testing_parallel_result "stopped"
else else
# If a test had already completed, but its output wasn't yet processed, # If a test had already completed, but its output wasn't yet processed,
# then process it now. # then process it now.
get_next_message_testing_parallel_result get_next_message_testing_parallel_result "completed"
fi fi
NEXT_PARALLEL_TEST_TO_FINISH+=1 NEXT_PARALLEL_TEST_TO_FINISH+=1
done done
@ -12271,17 +12274,26 @@ run_mass_testing() {
return $? return $?
} }
# This function is called when it has been determined that the next child process has completed. # This function is called when it has been determined that the next child
# This process prints its output to the terminal and, if appropriate, adds any JSON, CSV, and HTML # process has completed or it has been stopped. If the child process completed,
# output it has created to the appropriate file. # then this process prints the child process's output to the terminal and, if
# appropriate, adds any JSON, CSV, and HTML output it has created to the
# appropriate file. If the child process was stopped, then a message indicating
# that is printed, but the incomplete results are not used.
get_next_message_testing_parallel_result() { get_next_message_testing_parallel_result() {
draw_line "=" $((TERM_WIDTH / 2)); outln; draw_line "=" $((TERM_WIDTH / 2)); outln;
outln "${PARALLEL_TESTING_CMDLINE[NEXT_PARALLEL_TEST_TO_FINISH]}" outln "${PARALLEL_TESTING_CMDLINE[NEXT_PARALLEL_TEST_TO_FINISH]}"
cat "$TEMPDIR/term_output_$(printf "%08d" $NEXT_PARALLEL_TEST_TO_FINISH).log" if [[ "$1" == "completed" ]]; then
[[ $NEXT_PARALLEL_TEST_TO_FINISH -gt 0 ]] && fileout_separator # this is needed for appended output, see #687 cat "$TEMPDIR/term_output_$(printf "%08d" $NEXT_PARALLEL_TEST_TO_FINISH).log"
"$JSONHEADER" && cat "$TEMPDIR/jsonfile_$(printf "%08d" $NEXT_PARALLEL_TEST_TO_FINISH).json" >> "$JSONFILE" [[ $NEXT_PARALLEL_TEST_TO_FINISH -gt 0 ]] && fileout_separator # this is needed for appended output, see #687
"$CSVHEADER" && cat "$TEMPDIR/csvfile_$(printf "%08d" $NEXT_PARALLEL_TEST_TO_FINISH).csv" >> "$CSVFILE" "$JSONHEADER" && cat "$TEMPDIR/jsonfile_$(printf "%08d" $NEXT_PARALLEL_TEST_TO_FINISH).json" >> "$JSONFILE"
"$HTMLHEADER" && cat "$TEMPDIR/htmlfile_$(printf "%08d" $NEXT_PARALLEL_TEST_TO_FINISH).html" >> "$HTMLFILE" "$CSVHEADER" && cat "$TEMPDIR/csvfile_$(printf "%08d" $NEXT_PARALLEL_TEST_TO_FINISH).csv" >> "$CSVFILE"
"$HTMLHEADER" && cat "$TEMPDIR/htmlfile_$(printf "%08d" $NEXT_PARALLEL_TEST_TO_FINISH).html" >> "$HTMLFILE"
elif [[ "$1" == "stopped" ]]; then
outln "\nTest was stopped before it completed.\n"
else
outln "\nTest timed out before it completed.\n"
fi
} }
#FIXME: not called/tested yet #FIXME: not called/tested yet
@ -12289,7 +12301,7 @@ run_mass_testing_parallel() {
local cmdline="" local cmdline=""
local -i i nr_active_tests=0 local -i i nr_active_tests=0
local -a -i start_time=() local -a -i start_time=()
local -i curr_time local -i curr_time wait_time
if [[ ! -r "$FNAME" ]] && $IKNOW_FNAME; then if [[ ! -r "$FNAME" ]] && $IKNOW_FNAME; then
fatal "Can't read file \"$FNAME\"" "2" fatal "Can't read file \"$FNAME\"" "2"
@ -12308,24 +12320,30 @@ run_mass_testing_parallel() {
"$JSONHEADER" && >"$TEMPDIR/jsonfile_$(printf "%08d" $NR_PARALLEL_TESTS).json" "$JSONHEADER" && >"$TEMPDIR/jsonfile_$(printf "%08d" $NR_PARALLEL_TESTS).json"
PARALLEL_TESTING_CMDLINE[NR_PARALLEL_TESTS]="$(create_cmd_line_string "$0" "${MASS_TESTING_CMDLINE[@]}")" PARALLEL_TESTING_CMDLINE[NR_PARALLEL_TESTS]="$(create_cmd_line_string "$0" "${MASS_TESTING_CMDLINE[@]}")"
if [[ -z "$(which "$0")" ]]; then if [[ -z "$(which "$0")" ]]; then
CHILD_MASS_TESTING=true "$RUN_DIR/$PROG_NAME" "${MASS_TESTING_CMDLINE[@]}" > "$TEMPDIR/term_output_$(printf "%08d" $NR_PARALLEL_TESTS).log" & CHILD_MASS_TESTING=true "$RUN_DIR/$PROG_NAME" "${MASS_TESTING_CMDLINE[@]}" > "$TEMPDIR/term_output_$(printf "%08d" $NR_PARALLEL_TESTS).log" 2>&1 &
else else
CHILD_MASS_TESTING=true "$0" "${MASS_TESTING_CMDLINE[@]}" > "$TEMPDIR/term_output_$(printf "%08d" $NR_PARALLEL_TESTS).log" & CHILD_MASS_TESTING=true "$0" "${MASS_TESTING_CMDLINE[@]}" > "$TEMPDIR/term_output_$(printf "%08d" $NR_PARALLEL_TESTS).log" 2>&1 &
fi fi
PARALLEL_TESTING_PID[NR_PARALLEL_TESTS]=$! PARALLEL_TESTING_PID[NR_PARALLEL_TESTS]=$!
start_time[NR_PARALLEL_TESTS]=$(date +%s) start_time[NR_PARALLEL_TESTS]=$(date +%s)
debugme echo "Started test #$NR_PARALLEL_TESTS" if "$INTERACTIVE"; then
echo -en "\r \r" 1>&2
echo -n "Started test #$NR_PARALLEL_TESTS" 1>&2
[[ $NEXT_PARALLEL_TEST_TO_FINISH -lt $NR_PARALLEL_TESTS ]] && \
echo -n " (waiting for test #$NEXT_PARALLEL_TEST_TO_FINISH to finish)" 1>&2
fi
NR_PARALLEL_TESTS+=1 NR_PARALLEL_TESTS+=1
nr_active_tests+=1 nr_active_tests+=1
sleep $PARALLEL_SLEEP sleep $PARALLEL_SLEEP
# Get the results of any completed tests # Get the results of any completed tests
while [[ $NEXT_PARALLEL_TEST_TO_FINISH -lt $NR_PARALLEL_TESTS ]]; do while [[ $NEXT_PARALLEL_TEST_TO_FINISH -lt $NR_PARALLEL_TESTS ]]; do
if [[ ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} -eq 0 ]]; then if [[ ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} -eq 0 ]]; then
get_next_message_testing_parallel_result "$INTERACTIVE" && echo -en "\r \r" 1>&2
get_next_message_testing_parallel_result "completed"
NEXT_PARALLEL_TEST_TO_FINISH+=1 NEXT_PARALLEL_TEST_TO_FINISH+=1
elif ! ps ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >/dev/null ; then elif ! ps ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >/dev/null ; then
debugme echo "Test #$NEXT_PARALLEL_TEST_TO_FINISH complete" "$INTERACTIVE" && echo -en "\r \r" 1>&2
get_next_message_testing_parallel_result get_next_message_testing_parallel_result "completed"
NEXT_PARALLEL_TEST_TO_FINISH+=1 NEXT_PARALLEL_TEST_TO_FINISH+=1
nr_active_tests=$nr_active_tests-1 nr_active_tests=$nr_active_tests-1
else else
@ -12341,7 +12359,6 @@ run_mass_testing_parallel() {
! ps ${PARALLEL_TESTING_PID[i]} >/dev/null ; then ! ps ${PARALLEL_TESTING_PID[i]} >/dev/null ; then
PARALLEL_TESTING_PID[i]=0 PARALLEL_TESTING_PID[i]=0
nr_active_tests=$nr_active_tests-1 nr_active_tests=$nr_active_tests-1
debugme echo "Test #$i complete"
break break
fi fi
done done
@ -12351,14 +12368,32 @@ run_mass_testing_parallel() {
# start will be killed. # start will be killed.
kill ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >&2 2>/dev/null kill ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >&2 2>/dev/null
wait ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} 2>/dev/null # make sure pid terminated, see wait(1p) wait ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} 2>/dev/null # make sure pid terminated, see wait(1p)
debugme echo "Test #$NEXT_PARALLEL_TEST_TO_FINISH stopped" "$INTERACTIVE" && echo -en "\r \r" 1>&2
get_next_message_testing_parallel_result "timeout"
NEXT_PARALLEL_TEST_TO_FINISH+=1 NEXT_PARALLEL_TEST_TO_FINISH+=1
nr_active_tests=$nr_active_tests-1 nr_active_tests=$nr_active_tests-1
break break
fi fi
debugme echo "Waiting for test #$NEXT_PARALLEL_TEST_TO_FINISH" # Wake up to increment the counter every second (so that the counter
sleep 1 # appears to users as if it is operating smoothly), but check the
curr_time+=1 # status of the $MAX_PARALLEL active processes less often, since the
# ps command is expensive.
for (( i=0; i <= $((MAX_PARALLEL/5)); i++ )); do
wait_time=$((curr_time-start_time[NEXT_PARALLEL_TEST_TO_FINISH]))
[[ $wait_time -gt $MAX_WAIT_TEST ]] && wait_time=$MAX_WAIT_TEST
if "$INTERACTIVE"; then
echo -en "\r \r" 1>&2
echo -n "Waiting for test #$NEXT_PARALLEL_TEST_TO_FINISH to finish"
if [[ $((MAX_WAIT_TEST-wait_time)) -le 60 ]]; then
echo -n " ($((MAX_WAIT_TEST-wait_time)) seconds to timeout)" 1>&2
else
echo -n " ($wait_time seconds)" 1>&2
fi
fi
[[ $wait_time -ge $MAX_WAIT_TEST ]] && break
sleep 1
curr_time=$(date +%s)
done
done done
fi fi
done < "$FNAME" done < "$FNAME"
@ -12368,17 +12403,31 @@ run_mass_testing_parallel() {
while [[ $NEXT_PARALLEL_TEST_TO_FINISH -lt $NR_PARALLEL_TESTS ]]; do while [[ $NEXT_PARALLEL_TEST_TO_FINISH -lt $NR_PARALLEL_TESTS ]]; do
if [[ ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} -eq 0 ]] || \ if [[ ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} -eq 0 ]] || \
! ps ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >/dev/null ; then ! ps ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >/dev/null ; then
get_next_message_testing_parallel_result "$INTERACTIVE" && echo -en "\r \r" 1>&2
get_next_message_testing_parallel_result "completed"
NEXT_PARALLEL_TEST_TO_FINISH+=1 NEXT_PARALLEL_TEST_TO_FINISH+=1
elif [[ $curr_time-${start_time[NEXT_PARALLEL_TEST_TO_FINISH]} -ge $MAX_WAIT_TEST ]]; then elif [[ $curr_time-${start_time[NEXT_PARALLEL_TEST_TO_FINISH]} -ge $MAX_WAIT_TEST ]]; then
kill ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >&2 2>/dev/null kill ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} >&2 2>/dev/null
wait ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} 2>/dev/null # make sure pid terminated, see wait(1p) wait ${PARALLEL_TESTING_PID[NEXT_PARALLEL_TEST_TO_FINISH]} 2>/dev/null # make sure pid terminated, see wait(1p)
debugme echo "Test #$NEXT_PARALLEL_TEST_TO_FINISH stopped" "$INTERACTIVE" && echo -en "\r \r" 1>&2
get_next_message_testing_parallel_result "timeout"
NEXT_PARALLEL_TEST_TO_FINISH+=1 NEXT_PARALLEL_TEST_TO_FINISH+=1
else else
debugme echo "Waiting for test #$NEXT_PARALLEL_TEST_TO_FINISH" # Here it is okay to check process status every second, since the
# status of only one process is being checked.
if "$INTERACTIVE"; then
echo -en "\r \r" 1>&2
wait_time=$((curr_time-start_time[NEXT_PARALLEL_TEST_TO_FINISH]))
[[ $wait_time -gt $MAX_WAIT_TEST ]] && wait_time=$MAX_WAIT_TEST
echo -n "Waiting for test #$NEXT_PARALLEL_TEST_TO_FINISH to finish"
if [[ $((MAX_WAIT_TEST-wait_time)) -le 60 ]]; then
echo -n " ($((MAX_WAIT_TEST-wait_time)) seconds to timeout)" 1>&2
else
echo -n " ($wait_time seconds)" 1>&2
fi
fi
sleep 1 sleep 1
curr_time+=1 curr_time=$(date +%s)
fi fi
done done
return $? return $?
@ -13074,7 +13123,11 @@ lets_roll() {
if "$do_mass_testing"; then if "$do_mass_testing"; then
prepare_logging prepare_logging
run_mass_testing if "$EXPERIMENTAL"; then
run_mass_testing_parallel
else
run_mass_testing
fi
exit $? exit $?
fi fi
html_banner html_banner