run.js 2.1 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. 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-jit", 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
  37. {
  38. line += chr;
  39. }
  40. if(!ran_command && line.endsWith("~% "))
  41. {
  42. ran_command = true;
  43. emulator.serial0_send("chmod +x /mnt/test-jit\n");
  44. emulator.serial0_send("/mnt/test-jit 2>&1 | tee /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. emulator.stop();
  53. if(err) throw err;
  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. }
  66. });