Commits

Sebastian Bub committed d73d15f

added automated tests for external commands

Comments (0)

Files changed (6)

src/test/resources/README.md

 ## Here are all resources for automated tests
 
-The automated tests are only run in simulation mode. Do not change `src/test/resources/gpio.conf` because it's configuration has all different gpio port configurations and is checked from the `src/test/resources/testscript.sh`.
+The automated tests are only run in simulation mode. Do not change `src/test/resources/gpio.conf` and do not change `src/test/resources/cmd.conf` because it's configuration has all different gpio port configurations and external commands and is checked from the `src/test/resources/testscript.sh`.
 
-In `start.sh` there is a commented line to be used for configuration.
+In `start.sh` there are comments to be used for configuration.
 
 ### Testing
 
 In order to run the test:
 
-* uncomment the testline in `start.sh`
+* uncomment the testlines in `start.sh`
 * start the server
-* run the testscript (it expects a curl in it's $PATH)
+* run the testscript (it expects a curl in it's $PATH) `src/test/resources/testscript.sh`
 * stop the server
-* (runnint the testscript multiple times will show failures (because of tests of uninitialized values))
+* (running the testscript multiple times will show failures (because of tests of uninitialized values))
 

src/test/resources/cmd.conf

+# Copyright 2012 der-bub.de
+# http://www.der-bub.de
+# Author: Sebastian Bub (sebastian@der-bub.de)
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
+#
+# simple configuration file to define external commands to be called within normal processing
+# of GPIO ports
+#
+# In order to integrate anything you want to your GPIO server, you can define external
+# processes, e.g. you may send a notification on special conditions or you may integrate
+# a commands/scripts which handles other hardware like the SPI port.
+#
+# The external command is only called when it is given a value, e.g. CMDsample=1. It is not called,
+# when used in a condition, e.g. CMDsample==1 or when only read, e.g. CMDsample=IN (old values are
+# evaluated/read here, or 0 if it has not run since server startup).
+# The value for the GET-Parameter is send as first parameter, e.g. CMDsample=1 would call /xxx/sample.sh 1
+# The STDOUT and STDERR is only logged on debug level and can not be processed by the server. The return
+# value of the script can be used in coditions.
+# The script is only called when not used in a condition. You must call it before,
+# e.g. CMDsample=1&CMDsample==0&...
+#
+#
+
+# you may define multiple commands, just count up the suffix (starting with 1) and specify the maximum 
+# (0 means nothing is read)
+EXTCMD.NO=4
+
+# a name to address, e.g. the name 'date' must be addressed like CMDdate
+EXTCMD.NAME.1=sleeper1
+# define a full qualified path and name to call the command
+EXTCMD.COMMANDNAME.1=src/test/resources/extcmdtest1.sh
+# timeout in milliseconds
+EXTCMD.TIMEOUT.1=1500
+
+
+EXTCMD.NAME.2=sleeper2
+EXTCMD.COMMANDNAME.2=src/test/resources/extcmdtest2.sh
+EXTCMD.TIMEOUT.2=1500
+
+EXTCMD.NAME.3=fileMissing
+EXTCMD.COMMANDNAME.3=src/test/resources/doe
+EXTCMD.TIMEOUT.3=1500
+
+

src/test/resources/extcmdtest1.sh

+#!/bin/bash
+
+# set the parameter (just as an example)
+PARAM=$1
+
+echo test on stdout, param was $PARAM
+echo test on stderr >&2
+
+# sleep a little
+sleep $PARAM
+
+# return parameter+1
+exit  $[ PARAM + 1 ]
+

src/test/resources/extcmdtest2.sh

+#!/bin/bash
+
+# set the parameter (just as an example)
+PARAM=$1
+
+echo test on stdout, param was $PARAM
+echo test on stderr >&2
+
+# sleep a little
+sleep $PARAM
+
+# return parameter+1
+exit  $[ PARAM - 1 ]
+

src/test/resources/testscript.sh

 singletest 'OUTg0d0t250b1000=IN' '{"OUTg0d0t250b1000":1}'
 sleep 1
 singletest 'OUTg0d0t250b1000=IN' '{"OUTg0d0t250b1000":0}'
-# write input port
-singletest 'INg4=1' '{"INg4":-1}'
+# write input port (which does not work)
+singletest 'INg4=1' '{}'
 # read input port (simulation returns 2)
 singletest 'INg4=IN' '{"INg4":2}'
 # conditions on input, set virtual variable
 # conditions on input, set output port
 singletest 'INg4==2&OUTg8=1' '{"OUTg8":1}'
 singletest 'INg4!=2&OUTg8=1' '{}'
+# read uninitialized value of a command
+singletest 'CMDsleeper1=IN' '{"CMDsleeper1":0}'
+# check on an uninitialized value of a command
+singletest 'CMDsleeper2==0&VIRTUALt3=1' '{"VIRTUALt3":1}'
+# execute two commands
+singletest 'CMDsleeper1=1&CMDsleeper2=1' '{"CMDsleeper1":2,"CMDsleeper2":0}'
+singletest 'CMDsleeper2=1&CMDsleeper1=1' '{"CMDsleeper1":2,"CMDsleeper2":0}'
+# execute a command and check on it successful
+singletest 'CMDsleeper1=0&CMDsleeper1==1&VIRTUALt3=2' '{"CMDsleeper1":1,"VIRTUALt3":2}'
+# execute a command and check on it successful
+singletest 'CMDsleeper1=0&CMDsleeper1==7&VIRTUALt3=2' '{"CMDsleeper1":1}'
+# execute a command and check on it unsuccessful
+singletest 'CMDsleeper1=0&CMDsleeper1==7&VIRTUALt3=2' '{"CMDsleeper1":1}'
+# execute a command which runs into timeout and check on it unsuccessful
+singletest 'CMDsleeper2=2&CMDsleeper2==0&VIRTUALt3=2' '{"CMDsleeper2":143}'
 
 
 echo "SUCCESS: $SUCCESSCOUNTER - FAILURE: $FAILURECOUNTER"
 
 # remote debugging parameter java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 \
 
-# for automated testing, overwrite GPIO_CONFIG=src/test/resources/gpio.conf
+# for automated testing, overwrite gpio.conf and cmd.conf (just uncomment)
+# GPIO_CONFIG=src/test/resources/gpio.conf
+# CMD_CONFIG=src/test/resources/cmd.conf
 
 java \
           -Dlog4j.configuration=$RPI_GPIO_LOG \