[dev]add trace checksum for self-checking tests

This commit is contained in:
BigEd 2010-10-05 19:14:08 +00:00
parent f439d8fc8d
commit ee196947e3
2 changed files with 37 additions and 7 deletions

View File

@ -139,9 +139,16 @@ function signalSet(n){
return signals;
}
var traceChecksum='';
var goldenChecksum;
// simulate a single clock phase, updating trace and highlighting layout
function step(){
trace[cycle]= {chip: stateString(), mem: getMem()};
var s=stateString();
var m=getMem();
trace[cycle]= {chip: s, mem: m};
if(goldenChecksum != undefined)
traceChecksum=adler32(traceChecksum+s+m.slice(0,511).toString(16));
halfStep();
if(animateChipLayout)
refresh();
@ -340,7 +347,10 @@ function chipStatus(){
' Y:' + hexByte(readY()) +
' SP:' + hexByte(readSP()) +
' ' + readPstring();
setStatus(machine1, machine2, "Hz: " + estimatedHz().toFixed(1));
var chk='';
if(goldenChecksum != undefined)
chk=" Chk:" + traceChecksum + ((traceChecksum==goldenChecksum)?" OK":" no match");
setStatus(machine1, machine2, "Hz: " + estimatedHz().toFixed(1) + chk);
if (loglevel>0) {
updateLogbox(signalSet(loglevel));
}
@ -400,3 +410,13 @@ function setMem(arr){
function hexWord(n){return (0x10000+n).toString(16).substring(1)}
function hexByte(n){return (0x100+n).toString(16).substring(1)}
function adler32(x){
var a=1;
var b=0;
for(var i=0;i<x.length;i++){
a=(a+x.charCodeAt(i))%65521;
b=(b+a)%65521;
}
return (0x100000000+(b<<16)+a).toString(16).slice(-8);
}

View File

@ -125,22 +125,25 @@ function setupParams(){
var name=params[0];
var value=params[1].replace(/\/$/,""); // chrome sometimes adds trailing slash
// be (relatively) forgiving in what we accept
//
// user interface mode control
if(name=="loglevel" && parseInt(value)>0){
updateLoglevel(value);
} else if(name=="expert" && value.indexOf("t")==0){
updateExpertMode(true);
} else if(name=="graphics" && value.indexOf("f")==0){
updateChipLayoutVisibility(false);
} else if(name=="panx" && parseInt(value)!=NaN){
} else
// place the graphics window at a point of interest
if(name=="panx" && parseInt(value)!=NaN){
panx=parseInt(value);
} else if(name=="pany" && parseInt(value)!=NaN){
pany=parseInt(value);
} else if(name=="zoom" && parseInt(value)!=NaN){
zoom=parseInt(value);
} else if(name=="steps" && parseInt(value)!=NaN){
userSteps=parseInt(value);
running=true;
} else if(name=="a" && parseInt(value,16)!=NaN){
} else
// load a test program: Address, Data and Reset
if(name=="a" && parseInt(value,16)!=NaN){
userAddress=parseInt(value,16);
} else if(name=="d" && value.match(/[0-9a-fA-F]*/)[0].length==value.length){
for(var j=0;j<value.length;j+=2)
@ -148,6 +151,13 @@ function setupParams(){
} else if(name=="r" && parseInt(value,16)!=NaN){
userResetLow=parseInt(value,16)%256;
userResetHigh=(parseInt(value,16)>>8)%256;
} else
// run a test program, and optionally check against a golden checksum
if(name=="steps" && parseInt(value)!=NaN){
userSteps=parseInt(value);
running=true;
} else if(name=="checksum" && parseInt(value,16)!=NaN){
goldenChecksum=(0x100000000+parseInt(value,16)).toString(16).slice(-8);
} else {
if(loglevel>0)
console.log('unrecognised parameters:',params);