Add a real test harness.

This commit is contained in:
Will Scullin 2019-03-26 21:02:27 -07:00
parent 82815e5b85
commit 6a5fd9cf0c
No known key found for this signature in database
GPG Key ID: 9092A5C0A673416B
9 changed files with 3177 additions and 64 deletions

View File

@ -29,7 +29,7 @@
"extends": "eslint:recommended",
"overrides": [
{
"files": [ "bin/*", "webpack.config.js" ],
"files": [ "bin/*", "babel.config.js", "webpack.config.js" ],
"rules": {
"no-console": 0
},
@ -38,6 +38,11 @@
"jquery": false,
"browser": false
}
}, {
"files": [ "test/*"],
"env": {
"jest": true
}
}
]
}

13
babel.config.js Normal file
View File

@ -0,0 +1,13 @@
// babel.config.js
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
};

View File

@ -1,51 +0,0 @@
import CPU6502 from './cpu6502';
import Test6502 from './6502test';
import Test65C02 from './65C02test';
import { toHex } from './util';
var SYMBOLS = {};
var cpu;
var trace = [];
var lastPC = 0;
var done = false;
function traceCB() {
var pc = cpu.getPC();
done = lastPC == pc;
lastPC = pc;
var line = cpu.dumpRegisters() + ' ' + cpu.dumpPC(undefined, SYMBOLS);
trace.push(line);
if (trace.length > 1000) {
trace.shift();
}
}
window.test6502 = function test6502() {
cpu = new CPU6502();
var test = new Test6502();
cpu.addPageHandler(test);
cpu.setPC(0x400);
do {
cpu.stepCyclesDebug(1000, traceCB);
} while (!done);
if (lastPC == 0x3469) {
window.alert('6502 Success!');
} else {
window.alert('Failed! ' + toHex(lastPC));
}
};
window.test65C02 = function test65C02() {
cpu = new CPU6502({'65C02': true});
var test = new Test65C02();
cpu.addPageHandler(test);
cpu.setPC(0x400);
do {
cpu.stepCyclesDebug(1000, traceCB);
} while (!done);
if (lastPC == 0x24f1) {
window.alert('65C02 Success!');
} else {
window.alert('Failed! ' + toHex(lastPC));
}
};

3106
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,8 @@
"dev": "webpack-dev-server",
"index": "scripts/index.pl > json/disks/index.js",
"lint": "eslint js",
"start": "webpack-dev-server"
"start": "webpack-dev-server",
"test": "jest"
},
"repository": {
"type": "git",
@ -20,8 +21,12 @@
},
"homepage": "https://github.com/whscullin/apple2js#readme",
"devDependencies": {
"@babel/core": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"ajv": "^6.9.2",
"babel-jest": "^24.5.0",
"eslint": "^5.12.0",
"jest": "^24.5.0",
"webpack": "^4.29.6",
"webpack-cli": "^3.2.3",
"webpack-dev-server": "^3.2.1"

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
<script src="dist/test.js"></script>
<button onclick="test6502()">Test 6502</button>
<button onclick="test65C02()">Test 65C02</button>
</body>
</html>

46
test/cpu.spec.js Normal file
View File

@ -0,0 +1,46 @@
import CPU6502 from '../js/cpu6502';
import Test6502 from '../js/roms/6502test';
import Test65C02 from '../js/roms/65C02test';
var cpu;
var lastPC = 0;
var done = false;
function traceCB() {
var pc = cpu.getPC();
done = lastPC == pc;
lastPC = pc;
}
describe('CPU', function () {
describe('6502', function () {
it('completes the test ROM', function () {
cpu = new CPU6502();
var test = new Test6502();
cpu.addPageHandler(test);
cpu.setPC(0x400);
do {
cpu.stepCyclesDebug(1000, traceCB);
} while (!done);
expect(lastPC).toEqual(0x3469);
});
});
describe('65C02', function () {
it('completes the test ROM', function () {
cpu = new CPU6502({'65C02': true});
var test = new Test65C02();
cpu.addPageHandler(test);
cpu.setPC(0x400);
do {
cpu.stepCyclesDebug(1000, traceCB);
} while (!done);
expect(lastPC).toEqual(0x24f1);
});
});
});