Use arithmetic expansion in scripts, avoid bashisms

This commit is contained in:
Manuel Pégourié-Gonnard 2014-08-31 10:22:11 +02:00
parent c0f6a692fb
commit 72e51ee7be
3 changed files with 29 additions and 30 deletions

View File

@ -3,7 +3,7 @@ compiler:
- clang
- gcc
before_install: sudo apt-get update
install: sudo apt-get install bc gnutls-bin valgrind perl
install: sudo apt-get install gnutls-bin valgrind perl
script:
- cmake -D CMAKE_BUILD_TYPE:String="Check" .
- make

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# Test interop with OpenSSL and GnuTLS (and self-op while at it).
#
@ -19,10 +19,10 @@ else
fi
# initialise counters
let "tests = 0"
let "failed = 0"
let "skipped = 0"
let "srvmem = 0"
TESTS=0
FAILED=0
SKIPPED=0
SRVMEM=0
# default commands, can be overriden by the environment
: ${P_SRV:=../programs/ssl/ssl_server2}
@ -791,7 +791,7 @@ stop_server() {
if [ "$MEMCHECK" -gt 0 ]; then
if is_polar "$SERVER_CMD" && has_mem_err $SRV_OUT; then
echo " ! Server had memory errors"
let "srvmem++"
SRVMEM=$(( $SRVMEM + 1 ))
return
fi
fi
@ -826,12 +826,12 @@ wait_client_done() {
# run_client <name> <cipher>
run_client() {
# announce what we're going to do
let "tests++"
TESTS=$(( $TESTS + 1 ))
VERIF=$(echo $VERIFY | tr '[:upper:]' '[:lower:]')
TITLE="${1:0:1}->${SERVER_NAME:0:1} $MODE,$VERIF $2"
TITLE="`echo $1 | head -c1`->`echo $SERVER_NAME | head -c1`"
TITLE="$TITLE $MODE,$VERIF $2"
echo -n "$TITLE "
LEN=`echo "$TITLE" | wc -c`
LEN=`echo 72 - $LEN | bc`
LEN=$(( 72 - `echo "$TITLE" | wc -c` ))
for i in `seq 1 $LEN`; do echo -n '.'; done; echo -n ' '
# run the command and interpret result
@ -843,7 +843,7 @@ run_client() {
( echo -e 'GET HTTP/1.0'; echo; ) | $CLIENT_CMD >> $CLI_OUT 2>&1 &
wait_client_done
if [ "$EXIT" == "0" ]; then
if [ $EXIT -eq 0 ]; then
RESULT=0
else
if grep 'Cipher is (NONE)' $CLI_OUT >/dev/null; then
@ -861,7 +861,7 @@ run_client() {
( echo -e 'GET HTTP/1.0'; echo; ) | $CLIENT_CMD >> $CLI_OUT 2>&1 &
wait_client_done
if [ "$EXIT" == "0" ]; then
if [ $EXIT -eq 0 ]; then
RESULT=0
else
RESULT=2
@ -915,14 +915,14 @@ run_client() {
;;
"1")
echo SKIP
let "skipped++"
SKIPPED=$(( $SKIPPED + 1 ))
;;
"2")
echo FAIL
cp $SRV_OUT c-srv-${tests}.log
cp $CLI_OUT c-cli-${tests}.log
echo " ! outputs saved to c-srv-${tests}.log, c-cli-${tests}.log"
let "failed++"
cp $SRV_OUT c-srv-${TESTS}.log
cp $CLI_OUT c-cli-${TESTS}.log
echo " ! outputs saved to c-srv-${TESTS}.log, c-cli-${TESTS}.log"
FAILED=$(( $FAILED + 1 ))
;;
esac
@ -1080,7 +1080,7 @@ done
echo "------------------------------------------------------------------------"
if (( failed != 0 || srvmem != 0 ));
if [ $FAILED -ne 0 -o $SRVMEM -ne 0 ];
then
echo -n "FAILED"
else
@ -1088,13 +1088,13 @@ else
fi
if [ "$MEMCHECK" -gt 0 ]; then
MEMREPORT=", $srvmem server memory errors"
MEMREPORT=", $SRVMEM server memory errors"
else
MEMREPORT=""
fi
let "passed = tests - failed"
echo " ($passed / $tests tests ($skipped skipped$MEMREPORT))"
PASSED=$(( $TESTS - $FAILED ))
echo " ($PASSED / $TESTS tests ($SKIPPED skipped$MEMREPORT))"
let "failed += srvmem"
exit $failed
FAILED=$(( $FAILED + $SRVMEM ))
exit $FAILED

View File

@ -97,12 +97,11 @@ requires_gnutls() {
# print_name <name>
print_name() {
echo -n "$1 "
LEN=`echo "$1" | wc -c`
LEN=`echo 72 - $LEN | bc`
LEN=$(( 72 - `echo "$1" | wc -c` ))
for i in `seq 1 $LEN`; do echo -n '.'; done
echo -n ' '
TESTS=`echo $TESTS + 1 | bc`
TESTS=$(( $TESTS + 1 ))
}
# fail <message>
@ -114,7 +113,7 @@ fail() {
cp $CLI_OUT o-cli-${TESTS}.log
echo " ! outputs saved to o-srv-${TESTS}.log and o-cli-${TESTS}.log"
FAILS=`echo $FAILS + 1 | bc`
FAILS=$(( $FAILS + 1 ))
}
# is_polar <cmd_line>
@ -190,7 +189,7 @@ run_test() {
if [ "X$SKIP_NEXT" = "XYES" ]; then
SKIP_NEXT="NO"
echo "SKIP"
SKIPS=`echo $SKIPS + 1 | bc`
SKIPS=$(( $SKIPS + 1 ))
return
fi
@ -1845,7 +1844,7 @@ if [ $FAILS = 0 ]; then
else
echo -n "FAILED"
fi
PASSES=`echo $TESTS - $FAILS | bc`
PASSES=$(( $TESTS - $FAILS ))
echo " ($PASSES / $TESTS tests ($SKIPS skipped))"
exit $FAILS