pastebin - collaborative debugging tool
rovema.kpaste.net RSS


statistics rds test script for Phase4
Posted by Anonymous on Tue 14th Sep 2021 15:27
raw | new post
view followups (newest first): statistics rds test script for Phase4 by Anonymous
modification of post by Anonymous (view diff)

  1. #!/usr/bin/ksh93
  2. # needs ksh93 for floating-point math in $((...))
  3.  
  4. function isvalidpid
  5. {
  6.         integer pid=$1
  7.         # POSIX uses $ kill -0 ... # to check whether the pid is valid
  8.         if kill -0 $pid 2>'/dev/null' ; then
  9.                 return 0
  10.         else
  11.                 return 1
  12.         fi
  13. }
  14.  
  15.  
  16. trap 'print -v c' INT
  17.  
  18.  
  19. function test_cycle
  20. {
  21.         typeset s
  22.         integer x
  23.         nameref tc=$1
  24.  
  25.         ./rds -dl 7 >"${tc.rds_output_logfile}" 2>&1    &
  26.         (( tc.rds_pid=$! ))
  27.         (( tc.rds_starttime=SECONDS, tc.rds_stoptime=0 ))
  28.        
  29.         for (( x=20 ; x > 0 ; x-- )) ; do
  30.                 sleep 3
  31.  
  32.                 s="$( <"${tc.rds_output_logfile}" )"
  33.  
  34.                 #
  35.                 # parse output:
  36.                 # rds success output: "transferDataOfPhase '4' with bReady = 1"
  37.                 # rds waiting for input "Input:"
  38.                 # rds failed to switch to phase 4: "Error during switching to CP4 in startup"
  39.                 #
  40.                
  41.                 if [[ "$s" == *"Input:"* ]] ; then
  42.                         printf $"Rds ready for input\n"
  43.                         (( x=0 ))
  44.                 fi
  45.                 if [[ "$s" == *"transferDataOfPhase '4' with bReady = 1"* ]] ; then
  46.                         printf $"Success: phase 4 reached\n"
  47.                         (( tc.runs_ok++ ))
  48.                         (( x=0 ))
  49.                 fi
  50.                 if [[ "$s" == ~(E)(Error\ during.+to\ CP4) ]] ; then
  51.                         printf $"Failure: phase 4 not reached\n"
  52.                         (( tc.runs_failed++ ))
  53.                         (( x=0 ))
  54.                        
  55.                         # log last twenty lines of output if we failed
  56.                         tc.output_of_failed_runs[tc.i]="$( tail -n 20 <<<"$s" )"
  57.                 fi
  58.         done
  59.  
  60.        
  61.         #
  62.         # wait 20 seconds for process to finish with SIGINT
  63.         # and send him a SIGKILL when it refuses to obey
  64.         #
  65.         kill -s INT ${tc.rds_pid}
  66.         for (( x=10 ; x > 0 ; x-- )) ; do
  67.                 sleep 2
  68.                 isvalidpid ${tc.rds_pid} || break
  69.         done
  70.         isvalidpid ${tc.rds_pid} && kill -s KILL ${tc.rds_pid}
  71.         wait
  72.         (( tc.rds_pid=-1 ))
  73.  
  74.         (( tc.rds_stoptime=SECONDS ))
  75.         (( tc.rds_runtime=tc.rds_stoptime-tc.rds_starttime ))
  76.        
  77.         return 0
  78. }
  79.  
  80.  
  81. function main
  82. {
  83.         # variables for the test runs
  84.         compound c=(
  85.                 typeset -r rds_output_logfile='mylog.log'
  86.  
  87.                 integer rds_pid=-1
  88.                 float   rds_starttime
  89.                 float   rds_stoptime
  90.                 float   rds_runtime
  91.                 integer i
  92.                 integer runs_failed=0
  93.                 integer runs_ok=0
  94.        
  95.                 typeset -a output_of_failed_runs
  96.         )
  97.  
  98.         set -o errexit
  99.         set -o xtrace
  100.  
  101.         #
  102.         # prechecks
  103.         #
  104.         [[ -x '/opt/rovema/rds/start' ]] || exit 1
  105.  
  106.         export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rovema/lib
  107.         modprobe -f simatic_ipc_nvram
  108.         ulimit -c unlimited
  109.  
  110.  
  111.         cd '/opt/rovema/rds/' || exit 1
  112.  
  113.         #
  114.         # test loop
  115.         #
  116.         for (( c.i=0 ; c.i < 8 ; c.i++ )) ; do
  117.                 test_cycle c
  118.  
  119.                 # print statistics
  120.                 printf $"#### Statistics:\n"
  121.                 print -v c
  122.  
  123.                 sleep 2
  124.         done
  125.  
  126.         #
  127.         # done
  128.         #
  129.         printf $"#\n#Done:\n#\n"
  130.         print -v c
  131.  
  132.         return 0
  133. }
  134.  
  135. main "$@"
  136. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at