run.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/usr/bin/env node
  2. "use strict";
  3. process.on("unhandledRejection", exn => { throw exn; });
  4. var V86 = require("../../build/libv86-debug.js").V86;
  5. var fs = require("fs");
  6. var test_executable = new Uint8Array(fs.readFileSync(__dirname + "/test-jit"));
  7. var emulator = new V86({
  8. bios: { url: __dirname + "/../../bios/seabios.bin" },
  9. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  10. cdrom: { url: __dirname + "/../../images/linux4.iso" },
  11. autostart: true,
  12. memory_size: 32 * 1024 * 1024,
  13. filesystem: {},
  14. log_level: 0,
  15. });
  16. emulator.bus.register("emulator-started", function()
  17. {
  18. console.error("Booting now, please stand by");
  19. emulator.create_file("test-jit", test_executable);
  20. });
  21. var ran_command = false;
  22. var line = "";
  23. emulator.add_listener("serial0-output-char", function(chr)
  24. {
  25. if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
  26. {
  27. return;
  28. }
  29. if(chr === "\n")
  30. {
  31. var new_line = line;
  32. console.error("Serial: %s", line);
  33. line = "";
  34. }
  35. else
  36. {
  37. line += chr;
  38. }
  39. if(!ran_command && line.endsWith("~% "))
  40. {
  41. ran_command = true;
  42. emulator.serial0_send("chmod +x /mnt/test-jit\n");
  43. emulator.serial0_send("/mnt/test-jit 2>&1 | tee /mnt/result\n");
  44. emulator.serial0_send("echo test fini''shed\n");
  45. }
  46. if(new_line && new_line.includes("test finished"))
  47. {
  48. console.error("Done. Reading result ...");
  49. emulator.read_file("/result", function(err, data)
  50. {
  51. emulator.stop();
  52. if(err) throw err;
  53. let result = Buffer.from(data).toString();
  54. if(result !== "test_shared passed\ntest_consecutive_written passed\n")
  55. {
  56. console.error("[!] Error. Result was:\n" + result);
  57. process.exit(1);
  58. }
  59. else
  60. {
  61. console.log("[+] Test passed");
  62. }
  63. });
  64. }
  65. });