var assert = require('assert'); var fs = require('fs'); var wtu = require('./workertestutils.js'); global.onmessage({data:{preload:'cc65', platform:'nes'}}); global.onmessage({data:{preload:'ca65', platform:'nes'}}); global.onmessage({data:{preload:'sdcc'}}); // TODO: check msg against spec function compile(tool, code, platform, callback, outlen, nlines, nerrors) { var msgs = [{code:code, platform:platform, tool:tool, path:'src.'+tool}]; doBuild(msgs, callback, outlen, nlines, nerrors); } function doBuild(msgs, callback, outlen, nlines, nerrors) { var msgcount = msgs.length; global.postMessage = function(msg) { if (!msg.unchanged) { if (msg.errors && msg.errors.length) { console.log(msg.errors); assert.equal(nerrors, msg.errors.length, "errors"); } else { assert.equal(nerrors||0, 0, "errors"); assert.equal(msg.output.code?msg.output.code.length:msg.output.length, outlen, "output binary"); if (nlines) { if (typeof nlines === 'number') nlines = [nlines]; //console.log(msg.listings, nlines); var i = 0; for (var key in msg.listings) { var listing = msg.listings[key]; assert.equal(listing.lines.length, nlines[i++], "listing lines"); } } } } if (--msgcount == 0) callback(null, msg); else console.log(msgcount + ' msgs left'); }; global.onmessage({data:{reset:true}}); for (var i=0; i\nvoid main() {\nstrlen(0);\n}\n', 'mw8080bw', done, 8192, 2, 0); }); it('should compile vicdual skeleton', function(done) { var csource = ab2str(fs.readFileSync('presets/vicdual/skeleton.sdcc')); compile('sdcc', csource, 'vicdual', done, 16416, 45, 0); }); it('should compile mw8080 skeleton', function(done) { var csource = ab2str(fs.readFileSync('presets/mw8080bw/skeleton.sdcc')); compile('sdcc', csource, 'mw8080bw', done, 8192, 84, 0); }); it('should compile galaxian skeleton', function(done) { var csource = ab2str(fs.readFileSync('presets/galaxian-scramble/skeleton.sdcc')); compile('sdcc', csource, 'galaxian-scramble', done, 20512, 29, 0); }); it('should compile vector skeleton', function(done) { var csource = ab2str(fs.readFileSync('presets/vector-z80color/skeleton.sdcc')); compile('sdcc', csource, 'vector-z80color', done, 32768, 23, 0); }); it('should compile williams skeleton', function(done) { var csource = ab2str(fs.readFileSync('presets/williams-z80/skeleton.sdcc')); compile('sdcc', csource, 'williams-z80', done, 38912, 38, 0); }); it('should compile williams_sound skeleton', function(done) { var csource = ab2str(fs.readFileSync('presets/sound_williams-z80/skeleton.sdcc')); compile('sdcc', csource, 'sound_williams-z80', done, 16384, 6, 0); }); it('should compile coleco skeleton', function(done) { var csource = ab2str(fs.readFileSync('presets/coleco/skeleton.sdcc')); compile('sdcc', csource, 'coleco', done, 32768, 31, 0); }); it('should compile verilog example', function(done) { var csource = ab2str(fs.readFileSync('presets/verilog/lfsr.v')); compile('verilator', csource, 'verilog', done, 2782, 0, 0); }); it('should compile verilog inline assembler (JSASM)', function(done) { var csource = ab2str(fs.readFileSync('presets/verilog/test2.asm')); var dependfiles = ["hvsync_generator.v", "font_cp437_8x8.v", "ram.v", "tile_renderer.v", "sprite_scanline_renderer.v", "lfsr.v", "sound_generator.v", "cpu16.v", "cpu_platform.v"]; var depends = []; for (var dfile of dependfiles) { depends.push({filename:dfile, prefix:"verilog"}); } var msgs = [{code:csource, platform:"verilog", tool:"jsasm", dependencies:depends}]; doBuild(msgs, done, 2782, 0, 0); }); it('should NOT preprocess SDCC', function(done) { compile('sdcc', 'int x=0\n#bah\n', 'mw8080bw', done, 0, 0, 1); }); /* it('should compile XASM6809', function(done) { compile('xasm6809', '\tasld\n\tasld\n', 'mw8080bw', done, 4, 2, 0); }); */ it('should link two files with SDCC', function(done) { var msgs = [ { "updates":[ {"path":"main.c", "data":"extern int mul2(int x);\nint main() { return mul2(2); }\n"}, {"path":"fn.c", "data":"int mul2(int x) { return x*x; }\n"} ], "buildsteps":[ {"path":"main.c", "platform":"mw8080bw", "tool":"sdcc"}, {"path":"fn.c", "platform":"mw8080bw", "tool":"sdcc"} ] } ]; doBuild(msgs, done, 8192, [1,1], 0); }); // TODO: doesn't fail it('should not build unchanged files with CC65', function(done) { var m = { "updates":[ {"path":"main.c", "data":"extern int mul2(int x);\n int main() { return mul2(2); }\n"}, {"path":"fn.c", "data":"int mul2(int x) { return x*x; }\n"} ], "buildsteps":[ {"path":"main.c", "platform":"nes-conio", "tool":"cc65"}, {"path":"fn.c", "platform":"nes-conio", "tool":"cc65"} ] }; var m2 = { "updates":[ {"path":"main.c", "data":"extern int mul2(int x); \nint main() { return mul2(2); }\n"} ], "buildsteps":[ {"path":"main.c", "platform":"nes-conio", "tool":"cc65"}, {"path":"fn.c", "platform":"nes-conio", "tool":"cc65"} ] }; var msgs = [m, m, m2]; doBuild(msgs, done, 40976, [1,1], 0); }); it('should not build unchanged files with SDCC', function(done) { var m = { "updates":[ {"path":"main.c", "data":"extern int mul2(int x);\n int main() { return mul2(2); }\n"}, {"path":"fn.c", "data":"int mul2(int x) { return x*x; }\n"} ], "buildsteps":[ {"path":"main.c", "platform":"mw8080bw", "tool":"sdcc"}, {"path":"fn.c", "platform":"mw8080bw", "tool":"sdcc"} ] }; var m2 = { "updates":[ {"path":"main.c", "data":"extern int mul2(int x); \nint main() { return mul2(2); }\n"} ], "buildsteps":[ {"path":"main.c", "platform":"mw8080bw", "tool":"sdcc"}, {"path":"fn.c", "platform":"mw8080bw", "tool":"sdcc"} ] }; var msgs = [m, m, m2]; doBuild(msgs, done, 8192, [1,1], 0); }); });