#!/bin/sh
#
#
#    Copyright (c) 1996-2001 Brocade Communications Systems, Inc.
#    All rights reserved.
#
#    File name:   burninStatus
#    Module name: diag/scripts
#
#    This file reports the state of the burnin activity.
#
# NAME
#      burninstatus - display the diagnostics burnin status
# 
# SYNOPSIS
#      burninstatus
# 
# AVAILABILITY
#      admin
# 
# DESCRIPTION
#      This command displays the burnin status of each blade in the
#      system.  The output contains the slot,  state,  current  run
#      number, current command in the run, total commands in a run,
#      and the burnin script name.
# 
# EXAMPLES for blade based systems
#      > burninstatus
#      Slot    State    Status  Run     Cmd   TotCmds Script
#      1       ABORT    PASS    3       18    41      switchess.sh
#      2       ABORT    PASS    3       18    41      switchess.sh
#      3       ABORT    PASS    3       18    41      switchess.sh
#      4       ABORT    FAIL    3       11    34      switchess.sh
#
# EXAMPLES for switch based systems
#      > burninstatus
#      State    Status  Run     Cmd   TotCmds Script
#      ABORT    PASS    3       18    41      switchess.sh
# 
# SEE ALSO
#      diagsetburnin(1d)
# 
do_a_switch()
{
slots=`/fabos/sbin/exec_diag diagshow | \
		/bin/grep Slot | \
		/usr/bin/cut -d " " -f2 | \
		/usr/bin/xargs /bin/echo`
if [ ! -z "$slots" ] ;
then
	for slot in $slots
	do
		_cmd=`commandPath getBladeParameters`
		export BladeParameters=`$_cmd -slot $slot`
		ParamState=KNOWN
		script=`getBladeParam $slot SCRIPT_NAME`
		state=`getBladeParam $slot STATE`
		cum_status=`getBladeParam $slot CUM_STATUS`
		run_num=`getBladeParam $slot RUN_NUMBER`
		tot_cmd=`getBladeParam $slot TOTAL_CMD_NUMBER`
		cmd_num=`getBladeParam $slot CMD_NUMBER`
		if [ $cum_status -eq 0 ]
		then
			cum_status=PASS
		else
			cum_status=FAIL
		fi
		if [ $state = ABORT ]
		then
			state="ABORT   "
		else
		    if [ $state = ACTIVE ]
		    then
			state="ACTIVE   "
		    fi
		fi
		# cover the case where the run_number and command number are post incremented
		if [ $state = COMPLETED ]
		then
			run_num=`expr $run_num - 1`
			cmd_num=`expr $cmd_num - 1`
		fi
		if [ `isMultiBlade` = TRUE ]
		then
		    /bin/echo "$slot	$state	$cum_status	$run_num	$cmd_num	$tot_cmd	$script"
		else
		    /bin/echo "$state	$cum_status	$run_num	$cmd_num	$tot_cmd	$script"
		fi
	done
fi
}

home="/fabos/share"
util="diagcommon.sh"
export syntax="$0"
ok=0
for f in "./$util" "$FABOSHOME/share/$util" "$home/$util" ; do
	if [ -r $f ] ; then
		. $f
		ok=1
		break;
	fi
done
if [ $ok -ne 1 ] ; then
	err "Could not locate $util"
	exit 3
fi
export FABOS_SWITCHNO=0
slots=`/fabos/sbin/exec_diag diagshow | \
		/bin/grep Slot | \
		/usr/bin/cut -d " " -f2 | \
		/usr/bin/xargs /bin/echo`
if [ `isMultiBlade` = TRUE ]
then
    /bin/echo "Slot	State   	Status	Run	Cmd	TotCmds	Script"
    do_a_switch
    export FABOS_SWITCHNO=1
    do_a_switch
else
    /bin/echo "State   	Status	Run	Cmd	TotCmds	Script"
    do_a_switch
fi
