:: vax-diag.ini
:: This script will run the available CPU instruction and core
:: functional diagnostics for the different VAX simulators.
::
:: Default output summarizes success or failure.
:: if the script is invoked with -v as a parameter, verbose 
:: diagnostic output will be produced.
::
:: The related diagnostic files must be located in the same directory 
:: as this procedure.
::
#set clock async
#set debug -ntp todr.dbg
#set todr debug
#set tmr debug
#set int-clock debug=calib
#set int-clock nodebug=queue;gettime;check
#set cpu hist=20000
#break A3B4 SHOW HIST=40
cd %~p0
set runlimit 2 minutes
set on
on error ignore
on runtime echof "\r\n*** Test Runtime Limit %SIM_RUNLIMIT% %SIM_RUNLIMIT_UNITS% Exceeded ***\n"; exit 1

set env DIAG_QUIET_MODE=0
if ("%1" == "-v") set console notelnet
else set -qu console telnet=localhost:65432,telnet=buffered; set env -a DIAG_QUIET_MODE=1
goto DIAG_%SIM_BIN_NAME%

:DIAG_MICROVAX2
:DIAG_MICROVAX2000
:DIAG_MICROVAX3100M80
:DIAG_RTVAX1000
:DIAG_VAXSTATION3100M76
:DIAG_VAXSTATION4000M60
:DIAG_VAXSTATION4000VLC
echof "No diagnostics are available for the %SIM_NAME% Simulator\n"
exit 0

:DIAG_MICROVAX1
echo Running Hardware Core Test (EHKAA)
if not exist ehkaa-uv1.exe echof "\r\nMISSING - Diagnostic '%~p0ehkaa-uv1.exe' is missing\n"; exit 1
load ehkaa-uv1.exe
go -q 200
if (PC != 0x1150DA51) echof "\r\n*** FAILED - %SIM_NAME% Hardware Core Instruction test EHKAA\n"; exit 1
else                  echof "\r\n*** PASSED - %SIM_NAME% Hardware Core Instruction test EHKAA\n"; exit 0

:DIAG_INFOSERVER100
:DIAG_INFOSERVER1000
:DIAG_INFOSERVER150VXT
:DIAG_MICROVAX3100
:DIAG_MICROVAX3100E
:DIAG_VAX
:DIAG_MICROVAX3900
:DIAG_VAXSTATION3100M30
:DIAG_VAXSTATION3100M38
echo Running Hardware Core Test (EHKAA)
if not exist ehkaa.exe echof "\r\nMISSING - Diagnostic '%~p0ehkaa.exe' is missing\n"; exit 1
load ehkaa.exe
go -q 200
if (PC != 0x80018AD1) echof "\r\n*** FAILED - %SIM_NAME% Hardware Core Instruction test EHKAA\n"; exit 1
else                  echof "\r\n*** PASSED - %SIM_NAME% Hardware Core Instruction test EHKAA\n"; exit 0

:DIAG_VAX730
:DIAG_VAX750
:DIAG_VAX780
:DIAG_VAX8200
:DIAG_VAX8600
echo Running Hardware Core Test (EVKAA)
if not exist evkaa.exe echof "\r\nMISSING - Diagnostic '%~p0evkaa.exe' is missing\n"; exit 1
load evkaa.exe
expect "Hit any key to continue" send "\r"; go -q
expect [2] "done!" echof "\r\n*** PASSED - %SIM_NAME% Hardware Core Instruction test EVKAA\n"; goto extended_tests
go -q 200
echof "\r\n*** FAILED - %SIM_NAME% Hardware Core Instruction test EVKAA\n"
exit 1

:extended_tests
reset -p
if (DIAG_QUIET_MODE) echof "\nStarting VAX Diagnostic Supervisor\n"
if not exist VAX_MINIMUM_DIAGS.dsk echof "\r\nMISSING - Diagnostic disk image '%~p0VAX_MINIMUM_DIAGS.dsk' is missing\n"; exit 1
attach -rq rq0 VAX_MINIMUM_DIAGS.dsk
goto %SIM_BIN_NAME%

:VAX730
# VAX 11/730 Diagnostic Supervisor Setup for EVKAB/C/D/E
expect "DS> " send "ATTACH KA730 HUB KA0 no 0 0 2048 no no\r"; go -q
expect "DS> " send "ATTACH DW730 HUB DW0\r"; go -q
call Common
call do_test EVKAB "VAX Basic Instructions Exerciser"
call do_test EVKAC "VAX Floating Point Instructions Exerciser"
call do_test EVKAD "VAX Compatibility Mode Instructions Exerciser"
#call do_test EVKAE "VAX Privileged Architecture Exerciser"
echof "\n*** All Diagnostic Supervisor tests PASSED ***\n"
exit 0

:VAX750
# VAX 11/750 Diagnostic Supervisor Setup for EVKAB/C/D/E
expect "DS> " send "ATTACH KA750 CMI KA0 yes yes yes 0 0\r"; go -q
expect "DS> " send "ATTACH DW750 CMI DW0 8\r"; go -q
call Common
call do_test EVKAB "VAX Basic Instructions Exerciser"
call do_test EVKAC "VAX Floating Point Instructions Exerciser"
call do_test EVKAD "VAX Compatibility Mode Instructions Exerciser"
#call do_test EVKAE "VAX Privileged Architecture Exerciser"
echof "\n*** All Diagnostic Supervisor tests PASSED ***\n"
exit 0

:VAX780
# VAX 11/780 Diagnostic Supervisor Setup for EVKAB/C/D/E
expect "DS> " send "ATTACH KA780 SBI KA0 yes yes 0 0\r"; go -q
expect "DS> " send "ATTACH DW780 SBI DW0 3 5\r"; go -q
call Common
call do_test EVKAB "VAX Basic Instructions Exerciser"
call do_test EVKAC "VAX Floating Point Instructions Exerciser"
call do_test EVKAD "VAX Compatibility Mode Instructions Exerciser"
#call do_test EVKAE "VAX Privileged Architecture Exerciser"
echof "\n*** All Diagnostic Supervisor tests PASSED ***\n"
exit 0

:VAX8200
# VAX 8200 Diagnostic Supervisor Setup for EVKAB/C/D/E
expect "DS> " send "ATTACH KA820 HUB KA0 4096 0\r"; go -q
expect "DS> " send "ATTACH DWBUA HUB DW0 4 5\r"; go -q
# VAX 8200 simulates the floating point accelerator which then 
# inspires tests to use it.  This takes more time.
set runlimit 3 minutes
call Common
call do_test EVKAB "VAX Basic Instructions Exerciser"
call do_test EVKAC "VAX Floating Point Instructions Exerciser"
#call do_test EVKAE "VAX Privileged Architecture Exerciser"
echof "\n*** All Diagnostic Supervisor tests PASSED ***\n"
exit 0

:VAX8600
# VAX 8600 Diagnostic Supervisor Setup for EVKAB/C/D/E
expect "DS> " send "ATTACH KA780 ABUS KA0 yes yes 0 0\r"; go -q
expect "DS> " send "ATTACH DW780 ABUS DW0 3 5\r"; go -q
call Common
call do_test EVKAB "VAX Basic Instructions Exerciser"
call do_test EVKAC "VAX Floating Point Instructions Exerciser"
call do_test EVKAD "VAX Compatibility Mode Instructions Exerciser"
#call do_test EVKAE "VAX Privileged Architecture Exerciser"
echof "\n*** All Diagnostic Supervisor tests PASSED ***\n"
exit 0

:Common
expect "DS> " send "ATTACH UDA50 DW0 DUA 772150 154 5 10\r"; go -q
expect "DS> " send "ATTACH RA81 DUA DUA0\r"; go -q
expect "DS> " send "SET LOAD DUA0:[SYSMAINT]\r"; go -q
expect "DS> " send "SELECT KA0\r"; go -q
expect "DS> "
boot -q RQ0 /R5:10
#set todr debug
#set tmr debug
#set int-clock debug=calib
#set int-clock nodebug=queue;gettime;check
#set nodebug
return

:do_test
set env DIAG_TEST=%1
set env DIAG_DESC=%2
set env -a DIAG_ERRORS=1
noexpect
if (SIM_REGEX_TYPE == "") echof "Missing Regular Expression support - skipping %DIAG_TEST% test\n"; exit 0
expect -r "Hard error" go -q
expect -r "Pass 1, test ([0-9][0-9]*), subtest ([0-9][0-9]*), error ([0-9][0-9]*)," set env -a DIAG_ERRORS=_EXPECT_MATCH_GROUP_3; return
expect -r "System fatal error while testing" go -q
expect -r "\.\. End of run, ([0-9][0-9]*) (error|errors) detected, pass count is [0-9][0-9]*," set env -a DIAG_ERRORS=_EXPECT_MATCH_GROUP_1; go -q
expect "DS> "
if (DIAG_QUIET_MODE) echof "\nRunning - %DIAG_DESC% %DIAG_TEST%\n"
send "RUN %DIAG_TEST%\r"
go -q
if (DIAG_ERRORS > 0) echof "\n*** FAILED - %DIAG_DESC% %DIAG_TEST%\n"; exit 1
if (DIAG_QUIET_MODE) echof "\n*** PASSED - %DIAG_DESC% %DIAG_TEST%\n"
return
