# HG changeset patch # User Edouard Tisserant # Date 1717446295 -7200 # Node ID 792ae5ff01ca9fa924d1b7fb6cb7b9bf6255b644 # Parent fe7c5e8b20bbeac4f7a80a9c28284ca12e029b84 Tests: Add minimal C runtime test diff -r fe7c5e8b20bb -r 792ae5ff01ca tests/Makefile --- a/tests/Makefile Sat May 25 16:45:38 2024 +0200 +++ b/tests/Makefile Mon Jun 03 22:24:55 2024 +0200 @@ -71,7 +71,7 @@ # SOURCE and BUILD # -BUILT_PROJECTS=beremiz matiec open62541 Modbus +BUILT_PROJECTS=beremiz matiec open62541 Modbus erpc tar_opts=--absolute-names --exclude=.hg --exclude=.git --exclude=.*.pyc --exclude=.*.swp @@ -109,8 +109,11 @@ cd $(build_dir)/Modbus && \ make - -built_apps: $(build_dir)/matiec/iec2c $(build_dir)/beremiz/$(beremiz_checksum).sha1 $(build_dir)/open62541/build/bin/libopen62541.a $(build_dir)/Modbus/libmb.a +$(build_dir)/beremiz/C_runtime/beremiz_runtime: | $(build_dir)/erpc/$(erpc_checksum).sha1 + cd $(build_dir)/beremiz/C_runtime && \ + make + +built_apps: $(build_dir)/matiec/iec2c $(build_dir)/beremiz/$(beremiz_checksum).sha1 $(build_dir)/open62541/build/bin/libopen62541.a $(build_dir)/Modbus/libmb.a $(build_dir)/beremiz/C_runtime/beremiz_runtime touch $@ define log_command diff -r fe7c5e8b20bb -r 792ae5ff01ca tests/cli_tests/C_runtime.bash --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/cli_tests/C_runtime.bash Mon Jun 03 22:24:55 2024 +0200 @@ -0,0 +1,55 @@ +#!/bin/bash + +rm -f ./PLC_OK ./CLI_OK + +# Run C runtime +$BEREMIZPATH/C_runtime/beremiz_runtime -v -t tcp -p 61131 -h localhost > >( + echo "Start PLC stdout reader loop" + while read line; do + # Wait for server to print modified value + echo "PLC>> $line" + if [[ "$line" == "C runtime OK #3" ]]; then + echo "$line" + touch ./PLC_OK + fi + done + echo "End PLC stdout reader loop" +) & +PLC_PID=$! + +# Start PLC with C runtime test +setsid $BEREMIZPYTHONPATH $BEREMIZPATH/Beremiz_cli.py -k \ + --project-home $BEREMIZPATH/tests/projects/c_runtime build transfer run > >( +echo "Start CLI loop" +while read line; do + # Wait for CLI to output expected PLC log message on stdout + echo "CLI>> $line" + if [[ $line =~ .*C\ runtime\ log\ OK\ #3$ ]]; then + echo "$line" + touch ./CLI_OK + fi +done +echo "End CLI loop" +) & +CLI_PID=$! + +echo all subprocess started, start polling results +res=110 # default to ETIMEDOUT +c=45 +while ((c--)); do + if [[ -a ./PLC_OK && -a ./CLI_OK ]]; then + echo got results. + res=0 # OK success + break + else + echo waiting.... $c + sleep 1 + fi +done + +# Kill PLC and subprocess +echo will kill CLI:$CLI_PID and PLC:$PLC_PID +pkill -s $CLI_PID +kill $PLC_PID + +exit $res diff -r fe7c5e8b20bb -r 792ae5ff01ca tests/projects/c_runtime/beremiz.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/c_runtime/beremiz.xml Mon Jun 03 22:24:55 2024 +0200 @@ -0,0 +1,5 @@ + + + + + diff -r fe7c5e8b20bb -r 792ae5ff01ca tests/projects/c_runtime/plc.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/projects/c_runtime/plc.xml Mon Jun 03 22:24:55 2024 +0200 @@ -0,0 +1,399 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 'C runtime log OK #' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + beat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + count + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + lvl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + T#1s + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +