pastebin - collaborative debugging tool
rovema.kpaste.net RSS


statistics rds test script for Phase4
Posted by Anonymous on Mon 20th Sep 2021 09:16
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. function test_cycle
  17. {
  18.         typeset s
  19.         integer x
  20.         nameref tc=$1
  21.  
  22.         cd '/opt/rovema/rds/' || return 1
  23.        
  24.         tc.rds_output_logfile="rds_statistics_myrdslog_${tc.i}.log"
  25.         rm -f "${tc.rds_output_logfile}"
  26.  
  27.         ./rds -dl 7 >"${tc.rds_output_logfile}" 2>&1 &
  28.         (( tc.rds_pid=$! ))
  29.         (( tc.rds_starttime=SECONDS, tc.rds_stoptime=0 ))
  30.        
  31.         for (( x=20 ; x > 0 ; x-- )) ; do
  32.                 sleep 3
  33.  
  34.                 s="$( <"${tc.rds_output_logfile}" )"
  35.  
  36.                 #
  37.                 # parse output:
  38.                 # rds success output: "transferDataOfPhase '4' with bReady = 1"
  39.                 # rds waiting for input "Input:"
  40.                 # rds failed to switch to phase 4: "Error during switching to CP4 in startup"
  41.                 #
  42.                
  43.                 if [[ "$s" == *"Input:"* ]] ; then
  44.                         printf $"Rds ready for input\n"
  45.                         (( x=0 ))
  46.                 fi
  47.                 if [[ "$s" == *"transferDataOfPhase '4' with bReady = 1"* ]] ; then
  48.                         printf $"Success: phase 4 reached\n"
  49.                         (( tc.runs_ok++ ))
  50.                         (( x=0 ))
  51.                 fi
  52.                 if [[ "$s" == ~(E)(Error\ during.+to\ CP4) ]] ; then
  53.                         printf $"Failure: phase 4 not reached\n"
  54.                         (( tc.runs_failed++ ))
  55.                         (( x=0 ))
  56.                        
  57.                         # log last twenty lines of output if we failed
  58.                         tc.output_of_failed_runs[tc.i]="$( tail -n 20 <<<"$s" )"
  59.                 fi
  60.         done
  61.  
  62.        
  63.         #
  64.         # wait 20 seconds for process to finish with SIGINT
  65.         # and send him a SIGKILL when it refuses to obey
  66.         #
  67.         kill -s INT ${tc.rds_pid}
  68.         for (( x=10 ; x > 0 ; x-- )) ; do
  69.                 sleep 2
  70.                 isvalidpid ${tc.rds_pid} || break
  71.         done
  72.         isvalidpid ${tc.rds_pid} && kill -s KILL ${tc.rds_pid}
  73.         wait
  74.         (( tc.rds_pid=-1 ))
  75.  
  76.         (( tc.rds_stoptime=SECONDS ))
  77.         (( tc.rds_runtime=tc.rds_stoptime-tc.rds_starttime ))
  78.        
  79.         return 0
  80. }
  81.  
  82.  
  83. function main
  84. {
  85.         # variables for the test runs
  86.         compound c=(
  87.                 typeset rds_output_logfile
  88.  
  89.                 integer rds_pid=-1
  90.                 float   rds_starttime
  91.                 float   rds_stoptime
  92.                 float   rds_runtime
  93.                 integer i
  94.                 integer runs_failed=0
  95.                 integer runs_ok=0
  96.        
  97.                 typeset -a output_of_failed_runs
  98.         )
  99.  
  100.         set -o errexit
  101.         set -o xtrace
  102.  
  103.         #
  104.         # prechecks
  105.         #
  106.         [[ -x '/opt/rovema/rds/start' ]] || return 1
  107.  
  108.         export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/rovema/lib
  109.         modprobe -f simatic_ipc_nvram
  110.         ulimit -c unlimited
  111.  
  112.  
  113.         #
  114.         # test loop
  115.         #
  116.         for (( c.i=0 ; c.i < 30 ; 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