Changeset 89f863f in mod_gnutls for test/runtests


Ignore:
Timestamp:
Oct 19, 2015, 9:07:40 PM (5 years ago)
Author:
Daniel Kahn Gillmor <dkg@…>
Branches:
debian/master, debian/stretch-backports, jessie-backports, upstream
Children:
02c8e54, 24c6c16
Parents:
4addf74 (diff), 71cac80 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Imported Upstream version 0.7.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/runtests

    r4addf74 r89f863f  
    77set -e
    88
    9 tests="${1##t-}"
    10 
    11 if [ -n "${TEST_LOCK}" ]; then
    12     TEST_LOCK="$(realpath ${TEST_LOCK})"
    13     flock_cmd="flock -w ${TEST_LOCK_WAIT} ${TEST_LOCK}"
     9testid="${1##t-}"
     10
     11if [ -z "$testid" ] ; then
     12    echo -e "No test case selected.\nUsage: ${0} t-N" >&2
     13    exit 1
     14else
     15    testid=${srcdir}/tests/"$(printf "%02d" "$testid")"_*
    1416fi
    1517
    1618BADVARS=0
    17 for v in APACHE2 TEST_HOST TEST_IP TEST_PORT TEST_QUERY_DELAY TEST_GAP MSVA_PORT; do
     19for v in APACHE2 TEST_HOST TEST_IP TEST_PORT TEST_QUERY_DELAY TEST_MSVA_WAIT \
     20                 MSVA_PORT TEST_LOCK; do
    1821    if [ ! -v "$v" ]; then
    1922        printf "You need to set the %s environment variable\n" "$v" >&2
     
    111114    fi
    112115}
    113 
    114 if [ -z "$tests" ] ; then
    115     tests=${srcdir}/tests/*
    116 else
    117     tests=${srcdir}/tests/"$(printf "%02d" "$tests")"_*
    118 fi
    119116
    120117if [ -n "${USE_MSVA}" ]; then
     
    137134            echo "MSVA not ready yet"
    138135        fi
    139         sleep "${TEST_GAP}"
    140         waited=$(echo "${waited} + ${TEST_GAP}" | bc)
     136        sleep "${TEST_MSVA_WAIT}"
     137        waited=$(echo "${waited} + ${TEST_MSVA_WAIT}" | bc)
    141138    done
    142139
     
    150147fi
    151148
    152 for t in $tests; do
    153     if [ -z "${flock_cmd}" ]; then
    154         echo "Warning: no lock file set"
    155         sleep "$TEST_GAP"
    156     fi
    157     t="$(realpath ${t})"
    158     export srcdir="$(realpath ${srcdir})"
    159     export TEST_NAME="$(basename "$t")"
    160     output="outputs/${TEST_NAME}.output"
    161     rm -f "$output"
    162 
    163     if [ -e ${t}/fail.* ]; then
    164         EXPECTED_FAILURE="$(printf " (expected: %s)" fail.*)"
    165     else
    166         unset EXPECTED_FAILURE
    167     fi
    168     printf "TESTING: %s%s\n" "$TEST_NAME" "$EXPECTED_FAILURE"
    169     trap apache_down_err EXIT
    170     if [ -n "${USE_MSVA}" ]; then
    171         MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT" \
    172             ${flock_cmd} \
    173             ${APACHE2} -f "${t}/apache.conf" -k start \
    174             || [ -e "${t}/fail.server" ]
    175     else
    176         ${flock_cmd} \
    177             ${APACHE2} -f "${t}/apache.conf" -k start \
    178             || [ -e "${t}/fail.server" ]
    179     fi
    180 
    181     # PID file for sleep command (explanation below)
    182     sleep_pidfile="$(mktemp mod_gnutls_test-XXXXXX.pid)"
    183 
    184     # The sleep call keeps the pipe from the subshell to gnutls-cli
    185     # open. Without it gnutls-cli would terminate as soon as sed is
    186     # done, and not wait for a response from the server, leading to
    187     # failing tests. Sending sleep to the background allows the test
    188     # case to proceed instead of waiting for it to return. The sleep
    189     # process is stopped after gnutls-cli terminates.
    190     if (sed "s/__HOSTNAME__/${TEST_HOST}/" <${t}/input && \
    191         run_with_pidfile "${sleep_pidfile}" sleep "${TEST_QUERY_DELAY}" &) | \
    192         gnutls-cli -p "${TEST_PORT}" $(cat ${t}/gnutls-cli.args) "${TEST_HOST}" \
    193         >"$output";
    194     then
    195         if [ -e ${t}/fail* ]; then
    196             printf "%s should have failed but succeeded\n" "$(basename "$t")" >&2
    197             exit 1
    198         fi
    199     else
    200         if [ ! -e ${t}/fail* ]; then
    201             printf "%s should have succeeded but failed\n" "$(basename "$t")" >&2
    202             exit 1
    203         fi
    204     fi
    205 
    206     kill_by_pidfile "${sleep_pidfile}"
    207     unset sleep_pidfile
    208 
    209     if [ -e ${t}/output ] ; then
    210         diff_output_filter_headers "${t}/output" "$output" "-q"
    211     fi
    212     if [ -n "${USE_MSVA}" ]; then
    213         trap stop_msva EXIT
    214     else
    215         trap - EXIT
    216     fi
    217     ${APACHE2} -f "${t}/apache.conf" -k stop || [ -e ${t}/fail.server ]
    218     printf "SUCCESS: %s\n" "$TEST_NAME"
    219 done
     149# configure locking for the Apache process
     150flock_cmd="flock -w ${TEST_LOCK_WAIT} $(realpath ${TEST_LOCK})"
     151
     152t="$(realpath ${testid})"
     153export srcdir="$(realpath ${srcdir})"
     154export TEST_NAME="$(basename "$t")"
     155output="outputs/${TEST_NAME}.output"
     156rm -f "$output"
     157
     158if [ -e ${t}/fail.* ]; then
     159    EXPECTED_FAILURE="$(printf " (expected: %s)" fail.*)"
     160else
     161    unset EXPECTED_FAILURE
     162fi
     163printf "TESTING: %s%s\n" "$TEST_NAME" "$EXPECTED_FAILURE"
     164trap apache_down_err EXIT
     165if [ -n "${USE_MSVA}" ]; then
     166    MONKEYSPHERE_VALIDATION_AGENT_SOCKET="http://127.0.0.1:$MSVA_PORT" \
     167                                        ${flock_cmd} \
     168                                        ${APACHE2} -f "${t}/apache.conf" -k start \
     169        || [ -e "${t}/fail.server" ]
     170else
     171    ${flock_cmd} \
     172        ${APACHE2} -f "${t}/apache.conf" -k start \
     173        || [ -e "${t}/fail.server" ]
     174fi
     175
     176# PID file for sleep command (explanation below)
     177sleep_pidfile="$(mktemp mod_gnutls_test-XXXXXX.pid)"
     178
     179# The sleep call keeps the pipe from the subshell to gnutls-cli
     180# open. Without it gnutls-cli would terminate as soon as sed is
     181# done, and not wait for a response from the server, leading to
     182# failing tests. Sending sleep to the background allows the test
     183# case to proceed instead of waiting for it to return. The sleep
     184# process is stopped after gnutls-cli terminates.
     185if (sed "s/__HOSTNAME__/${TEST_HOST}/" <${t}/input && \
     186           run_with_pidfile "${sleep_pidfile}" sleep "${TEST_QUERY_DELAY}" &) | \
     187       gnutls-cli -p "${TEST_PORT}" $(cat ${t}/gnutls-cli.args) "${TEST_HOST}" \
     188                  >"$output";
     189then
     190    if [ -e ${t}/fail* ]; then
     191        printf "%s should have failed but succeeded\n" "$(basename "$t")" >&2
     192        exit 1
     193    fi
     194else
     195    if [ ! -e ${t}/fail* ]; then
     196        printf "%s should have succeeded but failed\n" "$(basename "$t")" >&2
     197        exit 1
     198    fi
     199fi
     200
     201kill_by_pidfile "${sleep_pidfile}"
     202unset sleep_pidfile
     203
     204if [ -e ${t}/output ] ; then
     205    diff_output_filter_headers "${t}/output" "$output" "-q"
     206fi
     207if [ -n "${USE_MSVA}" ]; then
     208    trap stop_msva EXIT
     209else
     210    trap - EXIT
     211fi
     212${APACHE2} -f "${t}/apache.conf" -k stop || [ -e ${t}/fail.server ]
     213printf "SUCCESS: %s\n" "$TEST_NAME"
    220214
    221215if [ -n "${USE_MSVA}" ]; then
Note: See TracChangeset for help on using the changeset viewer.