1
0

run.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. var fs = require("fs");
  7. var test_executable = new Uint8Array(fs.readFileSync(__dirname + "/test-i386"));
  8. var emulator = new V86({
  9. bios: { url: __dirname + "/../../bios/seabios.bin" },
  10. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  11. cdrom: { url: __dirname + "/../../images/linux4.iso" },
  12. autostart: true,
  13. memory_size: 32 * 1024 * 1024,
  14. filesystem: {},
  15. disable_jit: +process.env.DISABLE_JIT,
  16. log_level: 0,
  17. });
  18. emulator.bus.register("emulator-started", function()
  19. {
  20. console.error("Booting now, please stand by");
  21. emulator.create_file("test-i386", test_executable);
  22. });
  23. var ran_command = false;
  24. var line = "";
  25. emulator.add_listener("serial0-output-byte", async function(byte)
  26. {
  27. var chr = String.fromCharCode(byte);
  28. if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
  29. {
  30. return;
  31. }
  32. if(chr === "\n")
  33. {
  34. var new_line = line;
  35. console.error("Serial: %s", line);
  36. line = "";
  37. }
  38. else if(chr >= " " && chr <= "~")
  39. {
  40. line += chr;
  41. }
  42. if(!ran_command && line.endsWith("~% "))
  43. {
  44. ran_command = true;
  45. emulator.serial0_send("chmod +x /mnt/test-i386\n");
  46. emulator.serial0_send("/mnt/test-i386 > /mnt/result\n");
  47. emulator.serial0_send("echo test fini''shed\n");
  48. }
  49. if(new_line && new_line.includes("test finished"))
  50. {
  51. console.error("Done. Reading result ...");
  52. const data = await emulator.read_file("/result");
  53. console.error("Got result, writing to stdout");
  54. process.stdout.write(Buffer.from(data));
  55. emulator.stop();
  56. }
  57. });