#!/bin/ksh
#
#ident	"@(#)mcpu.sh	1.6	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

prgdir=../../../prgs
NCPUS=`/usr/sbin/psrinfo | wc -l`
NTESTS=`echo "$NCPUS * 2" | bc `

sleep $RUNTIME &
sleepid=$!

clean_up()
{
 	echo "CPU Test Ending!"
}

trap 'clean_up;exit' 17
i=0
while [ -d /proc/$sleepid ]
do
        i=`expr $i + 1`
        starttime=`$prgdir/time_sec`
        echo "Starting iteration $i"

        #Kick of four X number of cpu instances of matrix multiply to
        #make the CPU(s) v. busy
        COUNT=0
        while (( "$COUNT" != "$NTESTS" ))
        do
                /usr/bin/nice -n +20 ./mcpu &
                COUNT=`expr $COUNT + 1`
                sleep 20
        done

        endtime=`$prgdir/time_sec`
        ltime=`expr $endtime - $starttime`
        if [ $ltime -gt 300 ]
        then
                echo LOOPTIME: $ltime
        fi

        sleep 1800 &

        interval_id=$!
        while [[ -d "/proc/$sleepid" ]] && [[ -d "/proc/$interval_id" ]]
        do
                sleep 60
        done
done

echo "!PASS: No errors found in MCPU test: Did $i iteration(s)"

clean_up


