mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-06-24 20:21:48 +00:00
Add evanw's buddy allocator for testing
This commit is contained in:
30
tests/allocators/buddy/index.js
Normal file
30
tests/allocators/buddy/index.js
Normal file
@ -0,0 +1,30 @@
|
||||
const fs = require("fs");
|
||||
|
||||
function test(file) {
|
||||
console.log("Testing '" + file + "' ...\n");
|
||||
|
||||
const exports = new WebAssembly.Instance(WebAssembly.Module(fs.readFileSync(__dirname + "/" + file)), {
|
||||
env: {
|
||||
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); }
|
||||
}
|
||||
}).exports;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
var ptr = exports.allocate_memory(16);
|
||||
exports.free_memory(ptr);
|
||||
// runner(exports, 20, 20000); // picked so I/O isn't the bottleneck
|
||||
console.log("mem final: " + exports.memory.buffer.byteLength);
|
||||
console.log();
|
||||
}
|
||||
|
||||
test("buddy.untouched.wasm");
|
||||
test("buddy.optimized.wasm");
|
Reference in New Issue
Block a user