Source

Raspberry Pi GPIO Web Control / src / test / resources / testscript.sh

Full commit
#!/bin/bash

# simple curl test script which must conform to src/test/resources/gpio.conf

# GPIO.0.DIRECTION=OUT
# GPIO.0.NAME=OUTg0d0t250b1000
# GPIO.0.OUT.DEFAULT.STATE=0
# GPIO.0.OUT.AUTO.TOGGLE.TIME=250
# GPIO.0.OUT.BLOCK.TIME=1000
#
# GPIO.1.DIRECTION=OUT
# GPIO.1.NAME=OUTg1
#
# GPIO.4.DIRECTION=IN
# GPIO.4.NAME=INg4
#
# GPIO.7.DIRECTION=TI
# GPIO.7.NAME=TIg7
# GPIO.7.OUT.DEFAULT.STATE=0
# GPIO.7.OUT.AUTO.TOGGLE.TIME=250
# GPIO.7.OUT.BLOCK.TIME=1000

CURL=curl
HOST=localhost
PORT=8080

SUCCESSCOUNTER=0
FAILURECOUNTER=0


singletest() {
	CMD=$1
	EXPECTED=$2
	RESPONSE="`$CURL -s http://$HOST:$PORT/handle?$CMD`"
	if [ "$RESPONSE" == "$EXPECTED" ]; then
		echo "SUCCESS for $CMD - was $RESPONSE"
		SUCCESSCOUNTER=$(( $SUCCESSCOUNTER + 1 ))
	else
		echo "FAILED for $CMD - was $RESPONSE --- expected $EXPECTED"
		FAILURECOUNTER=$(( $FAILURECOUNTER + 1 ))
	fi
}

# read unset output port
singletest 'OUTg1=IN' '{"OUTg1":-1}'
# set output port
singletest 'OUTg1=1' '{"OUTg1":1}'
# read output port
singletest 'OUTg1=IN' '{"OUTg1":1}'
# set output port
singletest 'OUTg1=1' '{"OUTg1":1}'
# set output port with other value
singletest 'OUTg1=0' '{"OUTg1":0}'
# read output port
singletest 'OUTg1=IN' '{"OUTg1":0}'
# set output port with other value
singletest 'OUTg1=1' '{"OUTg1":1}'
# read unset virtual variable
singletest 'VIRTUALt1=IN' '{"VIRTUALt1":0}'
# set virtual variable
singletest 'VIRTUALt1=1' '{"VIRTUALt1":1}'
# read virtual variable
singletest 'VIRTUALt1=IN' '{"VIRTUALt1":1}'
# set virtual variable other value
singletest 'VIRTUALt1=0' '{"VIRTUALt1":0}'
# read virtual variable
singletest 'VIRTUALt1=IN' '{"VIRTUALt1":0}'
# conditions on output, set virtual variable
singletest 'OUTg1==1&VIRTUALt1=1' '{"VIRTUALt1":1}'
singletest 'OUTg1!=1&VIRTUALt1=1' '{}'
singletest 'OUTg1!=0&VIRTUALt1=1' '{"VIRTUALt1":1}'
singletest 'OUTg1>=1&VIRTUALt1=1' '{"VIRTUALt1":1}'
singletest 'OUTg1>1&VIRTUALt1=1' '{}'
singletest 'OUTg1<=1&VIRTUALt1=1' '{"VIRTUALt1":1}'
singletest 'OUTg1<1&VIRTUALt1=1' '{}'
# conditions on output, set output port
singletest 'OUTg1==1&OUTg8=1' '{"OUTg8":1}'
singletest 'OUTg1!=1&OUTg8=1' '{}'
# conditions on virtual variable, set virtual variable
singletest 'VIRTUALt1==1&VIRTUALt2=1' '{"VIRTUALt2":1}'
singletest 'VIRTUALt1!=1&VIRTUALt2=1' '{}'
# conditions on virtual variable, set output port
singletest 'VIRTUALt1==1&OUTg8=1' '{"OUTg8":1}'
singletest 'VIRTUALt1!=1&OUTg8=1' '{}'
# check blocking time
singletest 'OUTg0d0t250b1000=1' '{"OUTg0d0t250b1000":1}'
singletest 'OUTg0d0t250b1000=0' '{"OUTg0d0t250b1000":-2}'
sleep 1
singletest 'OUTg0d0t250b1000=0' '{"OUTg0d0t250b1000":0}'
sleep 1
# check toggle time
singletest 'OUTg0d0t250b1000=1' '{"OUTg0d0t250b1000":1}'
singletest 'OUTg0d0t250b1000=IN' '{"OUTg0d0t250b1000":1}'
sleep 1
singletest 'OUTg0d0t250b1000=IN' '{"OUTg0d0t250b1000":0}'
# write input port
singletest 'INg4=1' '{"INg4":-1}'
# read input port (simulation returns 2)
singletest 'INg4=IN' '{"INg4":2}'
# conditions on input, set virtual variable
singletest 'INg4==2&VIRTUALt2=1' '{"VIRTUALt2":1}'
singletest 'INg4!=2&VIRTUALt2=1' '{}'
# conditions on input, set output port
singletest 'INg4==2&OUTg8=1' '{"OUTg8":1}'
singletest 'INg4!=2&OUTg8=1' '{}'


echo "SUCCESS: $SUCCESSCOUNTER - FAILURE: $FAILURECOUNTER"