tests - Tweak tests in preparation for attempted CI
[tpg/opendispense2.git] / tests / _common.sh
1 #
2 # NOTE: Not a script, to be included by scripts
3 #
4 BASEDIR=rundir/${TESTNAME}/
5 PORT=22222
6
7 mkdir -p ${BASEDIR}
8 rm -f ${BASEDIR}cokebank.db
9
10 # Template configuration (disables door and the coke machine)
11 cat << EOF > ${BASEDIR}cfg_server.conf
12 # AUTOGENERATED Test ${TESTNAME}
13 server_port ${PORT}
14 cokebank_database ${BASEDIR}cokebank.db
15 items_file ${BASEDIR}cfg_items.conf
16 door_serial_port /dev/null
17
18 coke_modbus_address 0.0.0.0
19 coke_modbus_port 502
20 test_mode no
21
22 disable_syslog yes
23 coke_dummy_mode yes
24 EOF
25
26 echo "# AUTOGENERATED Test ${TESTNAME}" > ${BASEDIR}cfg_items.conf
27
28 LOG() {
29         echo "TEST ${TESTNAME}: "$*
30 }
31 FAIL() {
32         echo "TEST ${TESTNAME} FAIL: "$*
33         exit 1
34 }
35 TRY_COMMAND() {
36         cmd="$*"
37         if ! $cmd ; then
38                 FAIL "Command \`$cmd\` failed"
39         fi
40 }
41
42 DISPENSE="../dispense -H localhost -P ${PORT}"
43
44 LD_LIBRARY_PATH=.. ../dispsrv -f ${BASEDIR}cfg_server.conf --dont-daemonise > ${BASEDIR}server.log 2>&1 &
45 server_pid=$!
46
47 cleanup() {
48         LOG "Killing ${server_pid}"
49         kill ${server_pid}
50 }
51 trap cleanup EXIT
52
53 LOG "Server running on PID ${server_pid}"
54 sleep 1
55 echo "" | nc localhost ${PORT}

UCC git Repository :: git.ucc.asn.au