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

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