qemutests: port to es6, write to file to avoid clobbering with log output

This commit is contained in:
Fabian 2025-03-15 17:18:33 +07:00
parent 1e17944535
commit 528451eac0
2 changed files with 16 additions and 6 deletions

View file

@ -315,13 +315,13 @@ jitpagingtests: all-debug
qemutests: all-debug
$(MAKE) -C tests/qemu test-i386
./tests/qemu/run.js > build/qemu-test-result
./tests/qemu/run.js build/qemu-test-result
./tests/qemu/run-qemu.js > build/qemu-test-reference
diff build/qemu-test-result build/qemu-test-reference
qemutests-release: build/libv86.js build/v86.wasm
$(MAKE) -C tests/qemu test-i386
TEST_RELEASE_BUILD=1 time ./tests/qemu/run.js > build/qemu-test-result
TEST_RELEASE_BUILD=1 time ./tests/qemu/run.js build/qemu-test-result
./tests/qemu/run-qemu.js > build/qemu-test-reference
diff build/qemu-test-result build/qemu-test-reference

View file

@ -5,8 +5,12 @@ process.on("unhandledRejection", exn => { throw exn; });
const TEST_RELEASE_BUILD = +process.env.TEST_RELEASE_BUILD;
var V86 = require(`../../build/${TEST_RELEASE_BUILD ? "libv86" : "libv86-debug"}.js`).V86;
var fs = require("fs");
import { fileURLToPath } from "url";
import path from "path";
import fs from "fs";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const { default: { V86 } } = await import(`../../build/${TEST_RELEASE_BUILD ? "libv86" : "libv86-debug"}.js`);
var test_executable = new Uint8Array(fs.readFileSync(__dirname + "/test-i386"));
@ -18,7 +22,7 @@ var emulator = new V86({
memory_size: 32 * 1024 * 1024,
filesystem: {},
disable_jit: +process.env.DISABLE_JIT,
log_level: 0,
log_level: 3,
});
emulator.bus.register("emulator-started", function()
@ -29,6 +33,12 @@ emulator.bus.register("emulator-started", function()
var ran_command = false;
var line = "";
let outfile = process.stdout;
if(process.argv[2])
{
outfile = await fs.promises.open(process.argv[2], "w");
}
emulator.add_listener("serial0-output-byte", async function(byte)
{
var chr = String.fromCharCode(byte);
@ -63,7 +73,7 @@ emulator.add_listener("serial0-output-byte", async function(byte)
const data = await emulator.read_file("/result");
console.error("Got result, writing to stdout");
process.stdout.write(Buffer.from(data));
outfile.write(Buffer.from(data));
emulator.destroy();
}
});