run.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. log_level: 0,
  16. });
  17. emulator.bus.register("emulator-started", function()
  18. {
  19. console.error("Booting now, please stand by");
  20. emulator.create_file("test-i386", test_executable);
  21. });
  22. var ran_command = false;
  23. var line = "";
  24. emulator.add_listener("serial0-output-char", function(chr)
  25. {
  26. if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
  27. {
  28. return;
  29. }
  30. if(chr === "\n")
  31. {
  32. var new_line = line;
  33. console.error("Serial: %s", line);
  34. line = "";
  35. }
  36. else if(chr >= " " && chr <= "~")
  37. {
  38. line += chr;
  39. }
  40. if(!ran_command && line.endsWith("~% "))
  41. {
  42. ran_command = true;
  43. emulator.serial0_send("chmod +x /mnt/test-i386\n");
  44. emulator.serial0_send("/mnt/test-i386 > /mnt/result\n");
  45. emulator.serial0_send("echo test fini''shed\n");
  46. }
  47. if(new_line && new_line.includes("test finished"))
  48. {
  49. console.error("Done. Reading result ...");
  50. emulator.read_file("/result", function(err, data)
  51. {
  52. if(err)
  53. {
  54. console.error("Reading test result failed: " + err);
  55. process.exit(1);
  56. }
  57. console.error("Got result, writing to stdout");
  58. process.stdout.write(Buffer.from(data));
  59. emulator.stop();
  60. });
  61. }
  62. });