1
0

run.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. emulator.create_file("test-i386", test_executable);
  21. });
  22. var ran_command = false;
  23. var line = "";
  24. emulator.add_listener("serial0-output-byte", async function(byte)
  25. {
  26. var chr = String.fromCharCode(byte);
  27. if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
  28. {
  29. return;
  30. }
  31. if(chr === "\n")
  32. {
  33. var new_line = line;
  34. console.error("Serial: %s", line);
  35. line = "";
  36. }
  37. else if(chr >= " " && chr <= "~")
  38. {
  39. line += chr;
  40. }
  41. if(!ran_command && line.endsWith("~% "))
  42. {
  43. ran_command = true;
  44. emulator.serial0_send("chmod +x /mnt/test-i386\n");
  45. emulator.serial0_send("/mnt/test-i386 > /mnt/result\n");
  46. emulator.serial0_send("echo test fini''shed\n");
  47. }
  48. if(new_line && new_line.includes("test finished"))
  49. {
  50. console.error("Done. Reading result ...");
  51. const data = await emulator.read_file("/result");
  52. console.error("Got result, writing to stdout");
  53. process.stdout.write(Buffer.from(data));
  54. emulator.destroy();
  55. }
  56. });