1
0

serial.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. console.log(serial_data);
  30. throw new Error("Timeout");
  31. }, 60 * 1000);
  32. emulator.add_listener("serial0-output-byte", function(byte)
  33. {
  34. serial_data.push(byte);
  35. if(serial_data.length === 510277)
  36. {
  37. const hash = crypto.createHash("sha256");
  38. hash.update(new Uint8Array(serial_data));
  39. assert("da1fb5b421123c58080a59832675632505b8c139a8d7ecd1c31591ca5c65cea6" === hash.digest("hex"));
  40. console.log("ok");
  41. clearTimeout(timeout);
  42. emulator.stop();
  43. }
  44. });