serial.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/usr/bin/env node
  2. "use strict";
  3. const TEST_RELEASE_BUILD = +process.env.TEST_RELEASE_BUILD;
  4. const assert = require("assert").strict;
  5. const fs = require("fs");
  6. const crypto = require("crypto");
  7. var V86 = require(`../../build/${TEST_RELEASE_BUILD ? "libv86" : "libv86-debug"}.js`).V86;
  8. process.on("unhandledRejection", exn => { throw exn; });
  9. const config = {
  10. bios: { url: __dirname + "/../../bios/seabios.bin" },
  11. vga_bios: { url: __dirname + "/../../bios/vgabios.bin" },
  12. cdrom: { url: __dirname + "/../../images/linux.iso" },
  13. network_relay_url: "<UNUSED>",
  14. autostart: true,
  15. memory_size: 32 * 1024 * 1024,
  16. filesystem: {},
  17. log_level: 0,
  18. disable_jit: +process.env.DISABLE_JIT,
  19. };
  20. const emulator = new V86(config);
  21. let serial_data = [];
  22. setTimeout(async () =>
  23. {
  24. await emulator.wait_until_vga_screen_contains("/root% ");
  25. console.log("Booted, sending file to ttyS0");
  26. emulator.keyboard_send_text("cat /bin/busybox > /dev/ttyS0\n");
  27. }, 1000);
  28. const timeout = setTimeout(() => {
  29. throw new Error("Timeout");
  30. }, 60 * 1000);
  31. emulator.add_listener("serial0-output-byte", function(byte)
  32. {
  33. serial_data.push(byte);
  34. if(serial_data.length === 510277)
  35. {
  36. const hash = crypto.createHash("sha256");
  37. hash.update(new Uint8Array(serial_data));
  38. assert("da1fb5b421123c58080a59832675632505b8c139a8d7ecd1c31591ca5c65cea6" === hash.digest("hex"));
  39. console.log("ok");
  40. clearTimeout(timeout);
  41. emulator.stop();
  42. }
  43. });