pastebin - collaborative debugging tool
rovema.kpaste.net RSS


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