1
0

state.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/usr/bin/env node
  2. "use strict";
  3. process.on("unhandledRejection", exn => { throw exn; });
  4. const TEST_RELEASE_BUILD = +process.env.TEST_RELEASE_BUILD;
  5. var V86 = require(`../../build/${TEST_RELEASE_BUILD ? "libv86" : "libv86-debug"}.js`).V86;
  6. const assert = require("assert").strict;
  7. var fs = require("fs");
  8. const config_async_cdrom = {
  9. bios: { url: __dirname + "/../../bios/seabios.bin" },
  10. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  11. cdrom: { url: __dirname + "/../../images/linux4.iso", async: true },
  12. autostart: true,
  13. memory_size: 64 * 1024 * 1024,
  14. filesystem: {},
  15. disable_jit: +process.env.DISABLE_JIT,
  16. log_level: 0,
  17. };
  18. const config_sync_cdrom = {
  19. bios: { url: __dirname + "/../../bios/seabios.bin" },
  20. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  21. cdrom: { url: __dirname + "/../../images/linux4.iso", async: false },
  22. autostart: true,
  23. memory_size: 64 * 1024 * 1024,
  24. filesystem: {},
  25. disable_jit: +process.env.DISABLE_JIT,
  26. log_level: 0,
  27. };
  28. const config_filesystem = {
  29. bios: { url: __dirname + "/../../bios/seabios.bin" },
  30. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  31. autostart: true,
  32. memory_size: 64 * 1024 * 1024,
  33. filesystem: {},
  34. bzimage: { url: __dirname + "/../../images/buildroot-bzimage68.bin" },
  35. cmdline: "tsc=reliable mitigations=off random.trust_cpu=on",
  36. network_relay_url: "<UNUSED>",
  37. disable_jit: +process.env.DISABLE_JIT,
  38. log_level: 0,
  39. };
  40. const config_large_memory = {
  41. bios: { url: __dirname + "/../../bios/seabios.bin" },
  42. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  43. cdrom: { url: __dirname + "/../../images/linux4.iso", async: true },
  44. autostart: true,
  45. memory_size: 2048 * 1024 * 1024,
  46. vga_memory_size: 512 * 1024 * 1024,
  47. network_relay_url: "<UNUSED>",
  48. disable_jit: +process.env.DISABLE_JIT,
  49. log_level: 0,
  50. };
  51. async function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
  52. async function run_test(name, config, done)
  53. {
  54. const emulator = new V86(config);
  55. await sleep(2000);
  56. console.log("Saving: %s", name);
  57. const state = await emulator.save_state();
  58. await sleep(1000);
  59. console.log("Restoring: %s", name);
  60. await emulator.restore_state(state);
  61. await emulator.wait_until_vga_screen_contains("~% ");
  62. await sleep(1000);
  63. emulator.keyboard_send_text("echo -n test; echo passed\n");
  64. await sleep(1000);
  65. const lines = emulator.screen_adapter.get_text_screen();
  66. if(!lines.some(line => line.startsWith("testpassed")))
  67. {
  68. console.warn("Failed: " + name);
  69. console.warn(lines.map(line => line.replace(/\x00/g, " ")));
  70. process.exit(1);
  71. }
  72. console.log("Done: %s", name);
  73. emulator.stop();
  74. }
  75. (async function() {
  76. await run_test("async cdrom", config_async_cdrom);
  77. await run_test("sync cdrom", config_sync_cdrom);
  78. await run_test("filesystem", config_filesystem);
  79. await run_test("large memory size", config_large_memory);
  80. })();