run.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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-jit"));
  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-jit", 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
  39. {
  40. line += chr;
  41. }
  42. if(!ran_command && line.endsWith("~% "))
  43. {
  44. ran_command = true;
  45. emulator.serial0_send("chmod +x /mnt/test-jit\n");
  46. emulator.serial0_send("/mnt/test-jit 2>&1 | tee /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. emulator.stop();
  54. let result = Buffer.from(data).toString();
  55. if(result !== "test_shared passed\ntest_consecutive_written passed\n")
  56. {
  57. console.error("[!] Error. Result was:\n" + result);
  58. process.exit(1);
  59. }
  60. else
  61. {
  62. console.log("[+] Test passed");
  63. }
  64. }
  65. });