# This is an ide startup file for mfg config testing
#report=3 # set verbose, but not debug
report=1 # set terse
$stoponerr=1
hinv -v

menu {
echo ""
echo "///////////////////////////////////////////////////////////////////////"
echo "                       SYSTEM TEST OPTIONS "
echo "                       -------------------"
echo "Command   	Description"
echo ""
echo "LED_check     	LED diagnostics"
echo "a2test     	A2 audio diagnostics"
echo ""
echo "///////////////////////////////////////////////////////////////////////"
}

a2test {
	$loopcount = 0;
	report =4;
	$a2tst0pass = 0;
	$a2tst0fail = 0;
	$a2tst1pass = 0;
	$a2tst1fail = 0;
	$a2tst2pass = 0;
	$a2tst2fail = 0;
	$a2tst3pass = 0;
	$a2tst3fail = 0;
	$a2tst4pass = 0;
	$a2tst4fail = 0;
	$a2tst5pass = 0;
	$a2tst5fail = 0;
	$a2tst6pass = 0;
	$a2tst6fail = 0;
	$a2tst7pass = 0;
	$a2tst7fail = 0;
	while ( $loopcount < 1 ) {
		echo ""
		echo "----------------------------------------------------"
		echo "Starting audio test loop" $loopcount
		echo "----------------------------------------------------\n"

		$a2tst = audio -t0
		if($a2tst) {
			$a2tst0fail = $a2tst1fail + 1;
			$failed = 1;
		}
		else {
			$a2tst0pass = $a2tst1pass + 1;
		}
		a2tst = audio -t1
		if($a2tst) {
			$a2tst1fail = $a2tst1fail + 1;
			$failed = 1;
		}
		else {
			$a2tst1pass = $a2tst1pass + 1;
		}
		a2tst = audio -t2
		if($a2tst) {
			$a2tst2fail = $a2tst2fail + 1;
			$failed = 1;
		}
		else {
			$a2tst2pass = $a2tst2pass + 1;
		}
		a2tst = audio -t3
		if($a2tst) 
			$a2tst3fail = $a2tst3fail + 1;
		else
			$a2tst3pass = $a2tst3pass + 1;
		a2tst = audio -t4
		if($a2tst)
			$a2tst4fail = $a2tst4fail + 1;
		else
			$a2tst4pass = $a2tst4pass + 1;
		a2tst = audio -t5
		if($a2tst) {
			$a2tst5fail = $a2tst5fail + 1;
			$failed = 1;
		}
		else {
			$a2tst5pass = $a2tst5pass + 1;
		}
		a2tst = audio -t6
		if($a2tst) {
			$a2tst6fail = $a2tst6fail + 1;
			$failed = 1;
		}
		else {
			$a2tst6pass = $a2tst6pass + 1;
		}
		a2tst = audio -t7
		if($a2tst) 
			$a2tst7fail = $a2tst7fail + 1;
		else
			$a2tst7pass = $a2tst7pass + 1;

		$loopcount = $loopcount + 1;
	}
	echo "audio test 0: 	Pass =" $a2tst0pass"	fail =" $a2tst0fail
	echo "audio test 1: 	Pass =" $a2tst1pass"	fail =" $a2tst1fail
	echo "audio test 2: 	Pass =" $a2tst2pass"	fail =" $a2tst2fail
	echo "audio test 3: 	Pass =" $a2tst3pass"	fail =" $a2tst3fail
	echo "audio test 4: 	Pass =" $a2tst4pass"	fail =" $a2tst4fail
	echo "audio test 5: 	Pass =" $a2tst5pass"	fail =" $a2tst5fail
	echo "audio test 6: 	Pass =" $a2tst6pass"	fail =" $a2tst6fail
	echo "audio test 7: 	Pass =" $a2tst7pass"	fail =" $a2tst7fail
	wait;

	if( $a2tst7pass == 0 ) {
		# Rerun audio -t7 ten more times to get it to pass
		echo "Audio test 7 failed three loops."
		echo "Press ENTER to run audio test 7 for 10 more loops"
		wait;
		$report=1
		$loopcount = 0;
		while ( $loopcount < 10 ) {
			a2tst = audio -t7
			if($a2tst) {
				$a2tst7fail = $a2tst7fail + 1;
			}
			else {
				$a2tst7pass = $a2tst7pass + 1;
				$loopcount = 10
			}
			$loopcount = $loopcount + 1;
		}
		if( $a2tst7pass == 0 ) {
			echo "Audio test 7 FAILED."
			echo "Reject this system with an Audio failure"
			$failed = 1;
		}
	}
}

boot_unix {
	echo "<<<< About to to boot UNIX......>>>>"
	boot dksc(0,1,0)unix;
}

LED_check {
    echo "----------------------------------------------------\n"
    $tmp = led 0;
	
    if($tmp){
	$failed=1;
	wait;
    }
    echo "The system LED should be "
    echo "        *******"
    echo "        * OFF *"
    echo "        *******"
    echo ""
    echo "REJECT the system if the system LED is not OFF."
    echo ""
    wait;
	
    $tmp = led 2;
	
    if($tmp){
	$failed=1;
	wait;
    }
    echo "The system LED should be "
    echo "        **********"
    echo "        * YELLOW *"
    echo "        **********"
    echo ""
    echo "REJECT the system if the system LED is not YELLOW."
    echo ""
    wait;
	
    $tmp = led 1;
	
    if($tmp){
	$failed=1;
	wait;
    }
	
    echo "The system LED should be "
    echo "        *********"
    echo "        * GREEN *"
    echo "        *********"
    echo ""
    echo "REJECT the system if the system LED is not GREEN."
    echo ""
    wait;

    echo "----------------------------------------------------\n"
}

menu
$failed=0;
echo ""
a2test
LED_check
if($failed) {
	echo "FAILURES DETECTED\n"
	$cpu_failed=1;
	led 1;
}
else
	{
	$cpu_failed=0;
	echo "ALL TESTS PASSED\n";
	led 2;
	boot_unix;
}
fi


