2018-02-02 19:05:49 +01:00
|
|
|
const fs = require("fs");
|
2018-04-03 23:56:48 +02:00
|
|
|
const COMMON_MAX = 1 << 30;
|
2018-02-01 17:35:51 +01:00
|
|
|
|
2018-01-16 17:52:48 +01:00
|
|
|
function test(file) {
|
2018-02-01 17:35:51 +01:00
|
|
|
console.log("Testing '" + file + "' ...\n");
|
2018-01-16 05:25:03 +01:00
|
|
|
|
2018-02-12 19:17:50 +01:00
|
|
|
const exports = new WebAssembly.Instance(WebAssembly.Module(fs.readFileSync(__dirname + "/" + file)), {
|
2018-01-16 17:52:48 +01:00
|
|
|
env: {
|
2018-02-01 17:35:51 +01:00
|
|
|
abort: function(msg, file, line, column) {
|
|
|
|
throw Error("Assertion failed: " + (msg ? "'" + getString(msg) + "' " : "") + "at " + getString(file) + ":" + line + ":" + column);
|
|
|
|
},
|
|
|
|
log: function(ptr) { console.log(getString(ptr)); },
|
|
|
|
logi: function(i) { console.log(i); }
|
2018-01-16 05:25:03 +01:00
|
|
|
}
|
2018-01-16 17:52:48 +01:00
|
|
|
}).exports;
|
|
|
|
|
2018-02-01 17:35:51 +01:00
|
|
|
function getString(ptr) {
|
|
|
|
var len = new Uint32Array(exports.memory.buffer, ptr)[0];
|
|
|
|
var str = new Uint16Array(exports.memory.buffer, ptr + 4).subarray(0, len);
|
|
|
|
return String.fromCharCode.apply(String, str);
|
2018-01-16 05:25:03 +01:00
|
|
|
}
|
2018-02-01 17:35:51 +01:00
|
|
|
|
2018-04-11 23:35:19 +02:00
|
|
|
require("./runner")(exports, 20, 20000);
|
2018-02-19 22:45:31 +01:00
|
|
|
|
2018-02-01 17:35:51 +01:00
|
|
|
console.log("mem final: " + exports.memory.buffer.byteLength);
|
2018-01-16 17:52:48 +01:00
|
|
|
console.log();
|
2018-04-03 23:56:48 +02:00
|
|
|
|
2018-04-08 00:43:38 +02:00
|
|
|
try {
|
|
|
|
exports.allocate_memory(COMMON_MAX + 1); // unreachable
|
2018-04-03 23:56:48 +02:00
|
|
|
throw Error("allocation is allowed to overflow MAX_SIZE");
|
2018-04-08 00:43:38 +02:00
|
|
|
} catch (e) {}
|
|
|
|
try {
|
|
|
|
exports.allocate_memory(0xffffffff); // unreachable
|
2018-04-03 23:56:48 +02:00
|
|
|
throw Error("allocation is allowed to overflow INT_MAX");
|
2018-04-08 00:43:38 +02:00
|
|
|
} catch (e) {}
|
2018-01-16 05:25:03 +01:00
|
|
|
}
|
|
|
|
|
2018-03-04 17:25:32 +01:00
|
|
|
if (process.argv.length > 2) {
|
|
|
|
test(process.argv[2] + "/untouched.wasm");
|
|
|
|
test(process.argv[2] + "/optimized.wasm");
|
|
|
|
} else {
|
|
|
|
console.error("Usage: npm test <allocator>");
|
|
|
|
process.exit(1);
|
|
|
|
}
|