edouard@3955: #!/bin/bash edouard@3955: edouard@3955: rm -f ./PLC_OK ./CLI_OK edouard@3955: edouard@3955: # Run C runtime edouard@3955: $BEREMIZPATH/C_runtime/beremiz_runtime -v -t tcp -p 61131 -h localhost > >( edouard@3955: echo "Start PLC stdout reader loop" edouard@3955: while read line; do edouard@3955: # Wait for server to print modified value edouard@3955: echo "PLC>> $line" edouard@3955: if [[ "$line" == "C runtime OK #3" ]]; then edouard@3955: echo "$line" edouard@3955: touch ./PLC_OK edouard@3955: fi edouard@3955: done edouard@3955: echo "End PLC stdout reader loop" edouard@3955: ) & edouard@3955: PLC_PID=$! edouard@3955: edouard@3955: # Start PLC with C runtime test edouard@3955: setsid $BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \ edouard@3955: --project-home $BEREMIZPATH/tests/projects/c_runtime build transfer run > >( edouard@3955: echo "Start CLI loop" edouard@3955: while read line; do edouard@3955: # Wait for CLI to output expected PLC log message on stdout edouard@3955: echo "CLI>> $line" edouard@3955: if [[ $line =~ .*C\ runtime\ log\ OK\ #3$ ]]; then edouard@3955: echo "$line" edouard@3955: touch ./CLI_OK edouard@3955: fi edouard@3955: done edouard@3955: echo "End CLI loop" edouard@3955: ) & edouard@3955: CLI_PID=$! edouard@3955: edouard@3955: echo all subprocess started, start polling results edouard@3955: res=110 # default to ETIMEDOUT edouard@3955: c=45 edouard@3955: while ((c--)); do edouard@3955: if [[ -a ./PLC_OK && -a ./CLI_OK ]]; then edouard@3955: echo got results. edouard@3955: res=0 # OK success edouard@3955: break edouard@3955: else edouard@3955: echo waiting.... $c edouard@3955: sleep 1 edouard@3955: fi edouard@3955: done edouard@3955: edouard@3955: # Kill PLC and subprocess edouard@3955: echo will kill CLI:$CLI_PID and PLC:$PLC_PID edouard@3955: pkill -s $CLI_PID edouard@3955: kill $PLC_PID edouard@3955: edouard@3955: exit $res