#!/bin/sh # # Build a coverage-enabled darkhttpd, run unit tests and calculate coverage. # cd $(dirname $0) DIR=tmp.httpd.tests PORT=12346 CC=gcc if [ ! -e test.py ]; then echo "can't find test.py, aborting" >&2 exit 1 fi if [ \( ! -x a.out \) -o \( ../darkhttpd.c -nt a.out \) ]; then echo "===> building a.out, darkhttpd.gcno" $CC -g -O2 -fprofile-arcs -ftest-coverage ../darkhttpd.c || exit 1 fi if [ -e $DIR ]; then rm -rf $DIR || exit 1 fi mkdir $DIR || exit 1 rm -f darkhttpd.gcda darkhttpd.log echo "===> test_make_safe_uri" $CC -g -O2 test_make_safe_uri.c -o test_make_safe_uri || exit 1 if ./test_make_safe_uri | egrep '^FAIL:'; then echo test_make_safe_uri failed >&2 exit 1 fi echo "===> run usage statement" ./a.out >/dev/null echo "===> run tests against a basic instance (generates darkhttpd.gcda)" ./a.out $DIR --port $PORT --log darkhttpd.log >/dev/null & PID=$! kill -0 $PID || exit 1 python test.py kill $PID wait $PID echo "===> run --forward tests" ./a.out $DIR --port $PORT \ --forward example.com http://www.example.com \ --forward secure.example.com https://www.example.com/secure >/dev/null & PID=$! kill -0 $PID || exit 1 python test_forward.py kill $PID wait $PID echo "===> run --forward-all tests" ./a.out $DIR --port $PORT \ --forward example.com http://www.example.com \ --forward-all http://catchall.example.com >/dev/null & PID=$! kill -0 $PID || exit 1 python test_forward_all.py kill $PID wait $PID echo "===> run --no-server-id tests" ./a.out $DIR --port $PORT --no-server-id >/dev/null & PID=$! kill -0 $PID || exit 1 python test_server_id.py kill $PID wait $PID echo "===> run mimemap tests" echo "test/type1 a1" > $DIR/mimemap echo "test/this-gets-replaced ap2" >> $DIR/mimemap echo "# this is a comment" >> $DIR/mimemap printf "test/type3\\tapp3\n" >> $DIR/mimemap echo "test/type2 ap2" >> $DIR/mimemap ./a.out $DIR --port $PORT --mimetypes $DIR/mimemap >/dev/null & PID=$! kill -0 $PID || exit 1 python test_mimemap.py kill $PID wait $PID echo "===> generating darkhttpd.c.gcov report" gcov darkhttpd rm -rf $DIR rm -f darkhttpd.gcda darkhttpd.gcno darkhttpd.log a.out echo done