state.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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: 32 * 1024 * 1024,
  14. filesystem: {},
  15. screen_dummy: true,
  16. disable_jit: +process.env.DISABLE_JIT,
  17. log_level: 0,
  18. };
  19. const config_sync_cdrom = {
  20. bios: { url: __dirname + "/../../bios/seabios.bin" },
  21. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  22. cdrom: { url: __dirname + "/../../images/linux4.iso", async: false },
  23. autostart: true,
  24. memory_size: 32 * 1024 * 1024,
  25. filesystem: {},
  26. screen_dummy: true,
  27. disable_jit: +process.env.DISABLE_JIT,
  28. log_level: 0,
  29. };
  30. const config_filesystem = {
  31. bios: { url: __dirname + "/../../bios/seabios.bin" },
  32. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  33. autostart: true,
  34. memory_size: 32 * 1024 * 1024,
  35. filesystem: {},
  36. bzimage: { url: __dirname + "/../../images/buildroot-bzimage.bin" },
  37. cmdline: "tsc=reliable mitigations=off random.trust_cpu=on",
  38. network_relay_url: "<UNUSED>",
  39. screen_dummy: true,
  40. disable_jit: +process.env.DISABLE_JIT,
  41. log_level: 0,
  42. };
  43. const config_large_memory = {
  44. bios: { url: __dirname + "/../../bios/seabios.bin" },
  45. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  46. cdrom: { url: __dirname + "/../../images/linux4.iso", async: true },
  47. autostart: true,
  48. memory_size: 2048 * 1024 * 1024,
  49. vga_memory_size: 512 * 1024 * 1024,
  50. network_relay_url: "<UNUSED>",
  51. screen_dummy: true,
  52. disable_jit: +process.env.DISABLE_JIT,
  53. log_level: 0,
  54. };
  55. async function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
  56. function screen_contains(emulator, text)
  57. {
  58. const lines = emulator.screen_adapter.get_text_screen();
  59. return lines.some(line => line.startsWith(text));
  60. }
  61. async function run_test(name, config, done)
  62. {
  63. const emulator = new V86(config);
  64. await sleep(2000);
  65. console.log("Saving: %s", name);
  66. const state = await emulator.save_state();
  67. await sleep(1000);
  68. console.log("Restoring: %s", name);
  69. await emulator.restore_state(state);
  70. do
  71. {
  72. await sleep(1000);
  73. }
  74. while(!screen_contains(emulator, "~% "));
  75. emulator.keyboard_send_text("echo -n test; echo passed\n");
  76. await sleep(1000);
  77. const lines = emulator.screen_adapter.get_text_screen();
  78. if(!screen_contains(emulator, "testpassed"))
  79. {
  80. console.warn("Failed: " + name);
  81. console.warn(lines.map(line => line.replace(/\x00/g, " ")));
  82. process.exit(1);
  83. }
  84. console.log("Done: %s", name);
  85. emulator.stop();
  86. }
  87. (async function() {
  88. await run_test("async cdrom", config_async_cdrom);
  89. await run_test("sync cdrom", config_sync_cdrom);
  90. await run_test("filesystem", config_filesystem);
  91. await run_test("large memory size", config_large_memory);
  92. })();