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. screen_dummy: true,
  20. };
  21. const emulator = new V86(config);
  22. let serial_data = [];
  23. emulator.automatically([
  24. { sleep: 1 },
  25. { vga_text: "/root% " },
  26. { call: () => { console.log("Booted, sending file to ttyS0"); } },
  27. { keyboard_send: "cat /bin/busybox > /dev/ttyS0\n" },
  28. ]);
  29. const timeout = setTimeout(() => {
  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. });