pastebin - collaborative debugging tool
rovema.kpaste.net RSS


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