-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.js
executable file
·98 lines (80 loc) · 2.98 KB
/
state.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env node
"use strict";
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;
const assert = require("assert").strict;
var fs = require("fs");
const config_async_cdrom = {
bios: { url: __dirname + "/../../bios/seabios.bin" },
vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
cdrom: { url: __dirname + "/../../images/linux4.iso", async: true },
autostart: true,
memory_size: 64 * 1024 * 1024,
filesystem: {},
disable_jit: +process.env.DISABLE_JIT,
log_level: 0,
};
const config_sync_cdrom = {
bios: { url: __dirname + "/../../bios/seabios.bin" },
vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
cdrom: { url: __dirname + "/../../images/linux4.iso", async: false },
autostart: true,
memory_size: 64 * 1024 * 1024,
filesystem: {},
disable_jit: +process.env.DISABLE_JIT,
log_level: 0,
};
const config_filesystem = {
bios: { url: __dirname + "/../../bios/seabios.bin" },
vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
autostart: true,
memory_size: 64 * 1024 * 1024,
filesystem: {},
bzimage: { url: __dirname + "/../../images/buildroot-bzimage68.bin" },
cmdline: "tsc=reliable mitigations=off random.trust_cpu=on",
network_relay_url: "<UNUSED>",
disable_jit: +process.env.DISABLE_JIT,
log_level: 0,
};
const config_large_memory = {
bios: { url: __dirname + "/../../bios/seabios.bin" },
vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
cdrom: { url: __dirname + "/../../images/linux4.iso", async: true },
autostart: true,
memory_size: 2048 * 1024 * 1024,
vga_memory_size: 512 * 1024 * 1024,
network_relay_url: "<UNUSED>",
disable_jit: +process.env.DISABLE_JIT,
log_level: 0,
};
async function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
async function run_test(name, config, done)
{
const emulator = new V86(config);
await sleep(2000);
console.log("Saving: %s", name);
const state = await emulator.save_state();
await sleep(1000);
console.log("Restoring: %s", name);
await emulator.restore_state(state);
await emulator.wait_until_vga_screen_contains("~% ");
await sleep(1000);
emulator.keyboard_send_text("echo -n test; echo passed\n");
await sleep(1000);
const lines = emulator.screen_adapter.get_text_screen();
if(!lines.some(line => line.startsWith("testpassed")))
{
console.warn("Failed: " + name);
console.warn(lines.map(line => line.replace(/\x00/g, " ")));
process.exit(1);
}
console.log("Done: %s", name);
emulator.stop();
}
(async function() {
await run_test("async cdrom", config_async_cdrom);
await run_test("sync cdrom", config_sync_cdrom);
await run_test("filesystem", config_filesystem);
await run_test("large memory size", config_large_memory);
})();