Blame tests/p_sysstat/15-mpstat-basic.sh

root 2bfd68
#!/bin/bash
root 2bfd68
# Author: Steve Barnes (steve@echo.id.au)
root 2bfd68
root 2bfd68
# A simple mpstat test to verify cpu load is being measured
root 2bfd68
root 2bfd68
t_Log "Running $0 - a simple mpstat test to verify cpu load is being measured"
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
output_file=$(mktemp)
Carlos Rodriguez-Fernandez 4baccd
trap "rm -f ${output_file}" EXIT
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
n_cpu=$(nproc)
Carlos Rodriguez-Fernandez 4baccd
load=$((${n_cpu}/2))
Carlos Rodriguez-Fernandez 4baccd
if [ "${load}" -eq 0 ]; then
Carlos Rodriguez-Fernandez 4baccd
 load=1
Carlos Rodriguez-Fernandez 4baccd
fi
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
/usr/bin/mpstat 1 5 >${output_file} 2>&1 &
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
# Time for iostat booting
Carlos Rodriguez-Fernandez 4baccd
sleep 1
root 2bfd68
root 2bfd68
# Give the CPU something to chew on
Carlos Rodriguez-Fernandez 4baccd
for i in $(seq 1 ${load}); do 
Carlos Rodriguez-Fernandez 4baccd
  sha1sum /dev/zero &
Carlos Rodriguez-Fernandez 4baccd
done
root 2bfd68
root 2bfd68
# Give mpstat a chance to log our task
Athmane Madjoudj b5d067
sleep 6
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
killall sha1sum
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
cpu_user_percent=$(awk '$4 ~ /[0-9]\./ {$4>a ? a=$4 : $4} END {print int(a)}' ${output_file})
root 2bfd68
Carlos Rodriguez-Fernandez 4baccd
if [ "$cpu_user_percent" -eq 0 ]; then
Carlos Rodriguez-Fernandez 4baccd
  t_Log "FAIL: ${0}: no cpu activity registered"
Carlos Rodriguez-Fernandez 4baccd
  cat ${output_file}
Carlos Rodriguez-Fernandez 4baccd
  t_CheckExitStatus 1
Carlos Rodriguez-Fernandez 4baccd
fi
Carlos Rodriguez-Fernandez 4baccd
Carlos Rodriguez-Fernandez 4baccd
t_CheckExitStatus 0