state.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. 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: 32 * 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: 32 * 1024 * 1024,
  33. filesystem: {},
  34. bzimage: { url: __dirname + "/../../images/buildroot-bzimage.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. function run_test(name, config, done)
  41. {
  42. const emulator = new V86(config);
  43. setTimeout(async function()
  44. {
  45. console.log("Saving: %s", name);
  46. const state = await emulator.save_state();
  47. setTimeout(async function()
  48. {
  49. console.log("Restoring: %s", name);
  50. await emulator.restore_state(state);
  51. setTimeout(function()
  52. {
  53. console.log("Done: %s", name);
  54. emulator.stop();
  55. done && done();
  56. }, 1000);
  57. }, 1000);
  58. }, 5000);
  59. }
  60. run_test("async cdrom", config_async_cdrom, function()
  61. {
  62. run_test("sync cdrom", config_sync_cdrom, function()
  63. {
  64. run_test("filesystem", config_filesystem, function()
  65. {
  66. });
  67. });
  68. });