From 528451eac05ea0b48e2ea72fd4cde57b34fcddfe Mon Sep 17 00:00:00 2001 From: Fabian Date: Sat, 15 Mar 2025 17:18:33 +0700 Subject: [PATCH] qemutests: port to es6, write to file to avoid clobbering with log output --- Makefile | 4 ++-- tests/qemu/run.js | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 0058e191..e6a77546 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/tests/qemu/run.js b/tests/qemu/run.js index b4b0d7d2..ef195453 100755 --- a/tests/qemu/run.js +++ b/tests/qemu/run.js @@ -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(); } });