state.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env node
  2. "use strict";
  3. process.on("unhandledRejection", exn => { throw exn; });
  4. var V86 = require("../../build/libv86-debug.js").V86;
  5. var fs = require("fs");
  6. const config_async_cdrom = {
  7. bios: { url: __dirname + "/../../bios/seabios.bin" },
  8. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  9. cdrom: { url: __dirname + "/../../images/linux3.iso", async: true },
  10. autostart: true,
  11. memory_size: 32 * 1024 * 1024,
  12. filesystem: {},
  13. log_level: 0,
  14. };
  15. const config_sync_cdrom = {
  16. bios: { url: __dirname + "/../../bios/seabios.bin" },
  17. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  18. cdrom: { url: __dirname + "/../../images/linux3.iso", async: false },
  19. autostart: true,
  20. memory_size: 32 * 1024 * 1024,
  21. filesystem: {},
  22. log_level: 0,
  23. };
  24. function run_test(name, config, done)
  25. {
  26. const emulator = new V86(config);
  27. setTimeout(function()
  28. {
  29. console.log("Saving: %s", name);
  30. emulator.save_state(function(error, state)
  31. {
  32. console.assert(!error);
  33. setTimeout(function()
  34. {
  35. console.log("Restoring: %s", name);
  36. emulator.restore_state(state);
  37. setTimeout(function()
  38. {
  39. console.log("Done: %s", name);
  40. emulator.stop();
  41. done();
  42. }, 1000);
  43. }, 1000);
  44. });
  45. }, 1000);
  46. }
  47. run_test("async cdrom", config_async_cdrom, function()
  48. {
  49. run_test("sync cdrom", config_sync_cdrom, function() {});
  50. });