source: mod_gnutls/t/runtests @ cf2b905

debian/masterdebian/stretch-backportsjessie-backportsupstream
Last change on this file since cf2b905 was 4b53371, checked in by Daniel Kahn Gillmor <dkg@…>, 7 years ago

initial testing framework, with one simple test.

  • Property mode set to 100755
File size: 2.1 KB
Line 
1#!/bin/bash
2
3# Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
4
5set -e
6
7tests="${1##t-}"
8
9BADVARS=0
10for v in TEST_HOST TEST_IP TEST_PORT TEST_QUERY_DELAY TEST_GAP; do
11    if [ ! -v "$v" ]; then
12        printf "You need to set the %s environment variable\n" "$v" >&2
13        BADVARS=1
14    fi
15done
16
17if [ 0 != "$BADVARS" ]; then
18    exit 1
19fi
20
21if [ . != "$(dirname "$0")" ]; then
22    printf "You should only run this mod-gnutls test suite from the t/ directory of the mod_gnutls source.\n" >&2
23    exit 1
24fi
25
26function apache_down_err() {
27    printf "FAILURE: %s\n" "$TEST_NAME"
28    /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || true
29    if [ -e output ]; then
30        printf "\ngnutls-cli outputs:\n"
31        diff -u output <( tail -n "$(wc -l < output)" "$output" ) || true
32    fi
33    printf "\nApache error logs:\n"
34    tail "../../logs/${TEST_NAME}.error.log"
35}
36
37if [ -z "$tests" ] ; then
38    tests=./tests/*
39else
40    tests=./tests/"$(printf "%02d" "$tests")"_*
41fi
42
43for t in $tests; do 
44    export TEST_NAME="$(basename "$t")"
45    output="../../outputs/${TEST_NAME}.output"
46    rm -f "$output"
47    cd "$t"
48    if [ -e fail.* ]; then
49        EXPECTED_FAILURE="$(printf " (expected: %s)" fail.*)"
50    else
51        unset EXPECTED_FAILURE
52    fi
53    printf "TESTING: %s%s\n" "$TEST_NAME" "$EXPECTED_FAILURE"
54    trap apache_down_err EXIT
55    /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k start || [ -e fail.server ]
56
57    if (sed "s/__HOSTNAME__/${TEST_HOST}/" < ./input && sleep "$TEST_QUERY_DELAY") | \
58        gnutls-cli -p "${TEST_PORT}" $(cat ./gnutls-cli.args) "${TEST_HOST}" > \
59        "$output" ; then
60        if [ -e fail* ]; then
61            printf "%s should have failed but succeeded\n" "$(basename "$t")" >&2
62            exit 1
63        fi
64    else
65        if [ ! -e fail* ]; then
66            printf "%s should have succeeded but failed\n" "$(basename "$t")" >&2
67            exit 1
68        fi
69    fi
70    if [ -e output ] ; then
71        diff -q -u output <( tail -n "$(wc -l < output)" "$output" )
72    fi
73    /usr/sbin/apache2 -f "$(pwd)/apache.conf" -k stop || [ -e fail.server ]
74    trap - EXIT
75    printf "SUCCESS: %s\n" "$TEST_NAME"
76    cd ../..
77    sleep "$TEST_GAP"
78done
Note: See TracBrowser for help on using the repository browser.