1
0

reboot.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env node
  2. "use strict";
  3. const TEST_RELEASE_BUILD = +process.env.TEST_RELEASE_BUILD;
  4. const fs = require("fs");
  5. var V86 = require(`../../build/${TEST_RELEASE_BUILD ? "libv86" : "libv86-debug"}.js`).V86;
  6. process.on("unhandledRejection", exn => { throw exn; });
  7. const config = {
  8. bios: { url: __dirname + "/../../bios/seabios.bin" },
  9. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  10. cdrom: { url: __dirname + "/../../images/linux4.iso", async: true },
  11. net_device: {
  12. relay_url: "fetch",
  13. type: "virtio",
  14. },
  15. autostart: true,
  16. memory_size: 32 * 1024 * 1024,
  17. filesystem: {},
  18. virtio_console: true,
  19. log_level: 0,
  20. disable_jit: +process.env.DISABLE_JIT,
  21. };
  22. const emulator = new V86(config);
  23. let did_reboot = false;
  24. let serial_text = "";
  25. const timeout = setTimeout(() => {
  26. console.log(serial_data);
  27. throw new Error("Timeout");
  28. }, 120 * 1000);
  29. emulator.add_listener("serial0-output-byte", function(byte)
  30. {
  31. var chr = String.fromCharCode(byte);
  32. serial_text += chr;
  33. if(did_reboot)
  34. {
  35. if(serial_text.endsWith("Files send via emulator appear in /mnt/"))
  36. {
  37. console.log("Ok");
  38. emulator.stop();
  39. clearTimeout(timeout);
  40. }
  41. }
  42. else
  43. {
  44. if(serial_text.endsWith("~% "))
  45. {
  46. console.log("rebooting");
  47. emulator.serial0_send("reboot\n");
  48. serial_text = "";
  49. did_reboot = true;
  50. }
  51. }
  52. });