<commit_before>#!/usr/bin/env node
"use strict";

const fs = require("fs");
const { spawn } = require("child_process");
const path = require("path");

const share_dir_9p = fs.mkdtempSync("/tmp/v86-test-qemu-9p");

fs.copyFileSync(path.join(__dirname, "/test-i386"), path.join(share_dir_9p, "/test-i386"));

const qemu = spawn("qemu-system-x86_64",
    [
        "-serial", "stdio",
        "-cdrom", path.join(__dirname, "/../../images/linux3.iso"),
        "-device", "virtio-9p-pci,fsdev=fs9p,mount_tag=host9p",
        "-fsdev", `local,id=fs9p,path=${share_dir_9p},security_model=none`,
        "-display", "none",
        "-cpu", "Westmere", // default doesn't support popcnt

        //"-monitor", "telnet:127.0.0.1:1235,server,nowait",
    ]
);

let qemu_output = "";
let ran_command = false;
let finished = false;

qemu.stdout.on("data", data => {
    process.stderr.write(data);
    qemu_output += data.toString().replace(/\r/, "");

    if(!ran_command && qemu_output.endsWith("~% "))
    {
        ran_command = true;
        qemu.stdin.write("chmod +x /mnt/test-i386\n");
        qemu.stdin.write("/mnt/test-i386 > /mnt/result\n");
        qemu.stdin.write("echo test fini''shed\n");
    }

    if(ran_command && !finished && qemu_output.endsWith("test finished\n"))
    {
        const result_file = path.join(share_dir_9p, "result");

        finished = true;
        console.error("Finished");
        process.stdout.write(fs.readFileSync(result_file));

        fs.unlinkSync(result_file);
        fs.unlinkSync(path.join(share_dir_9p, "test-i386"));
        fs.rmdirSync(share_dir_9p);

        qemu.kill();
    }
});


qemu.stderr.on("data", data => {
    process.stderr.write(data);
});<commit_msg>qemutests: Fix bug where test would hang forever sometimes<commit_after>#!/usr/bin/env node
"use strict";

const fs = require("fs");
const { spawn } = require("child_process");
const path = require("path");

const share_dir_9p = fs.mkdtempSync("/tmp/v86-test-qemu-9p");

fs.copyFileSync(path.join(__dirname, "/test-i386"), path.join(share_dir_9p, "/test-i386"));

const qemu = spawn("qemu-system-x86_64",
    [
        "-serial", "stdio",
        "-cdrom", path.join(__dirname, "/../../images/linux3.iso"),
        "-device", "virtio-9p-pci,fsdev=fs9p,mount_tag=host9p",
        "-fsdev", `local,id=fs9p,path=${share_dir_9p},security_model=none`,
        "-display", "none",
        "-cpu", "Westmere", // default doesn't support popcnt

        //"-monitor", "telnet:127.0.0.1:1235,server,nowait",
    ]
);

let qemu_output = "";
let ran_command = false;
let finished = false;

qemu.stdout.on("data", data => {
    process.stderr.write(data);
    qemu_output += data.toString().replace(/\r/, "");

    if(!ran_command && qemu_output.endsWith("~% "))
    {
        ran_command = true;
        qemu.stdin.write("chmod +x /mnt/test-i386\n");
        qemu.stdin.write("/mnt/test-i386 > /mnt/result\n");
        qemu.stdin.write("echo test fini''shed\n");
    }

    if(ran_command && !finished && qemu_output.includes("test finished\n"))
    {
        const result_file = path.join(share_dir_9p, "result");

        finished = true;
        console.error("Finished");
        process.stdout.write(fs.readFileSync(result_file));

        fs.unlinkSync(result_file);
        fs.unlinkSync(path.join(share_dir_9p, "test-i386"));
        fs.rmdirSync(share_dir_9p);

        qemu.kill();
    }
});


qemu.stderr.on("data", data => {
    process.stderr.write(data);
});
{'fraction_non_alphanumeric': 0.19298245614035087, 'fraction_numerical': 0.02473396606269773, 'mean_word_length': 3.106257378984652, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6502789', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1255, 'n_words': 182}