arch-bytemark.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env node
  2. "use strict";
  3. const BENCH_COLLECT_STATS = +process.env.BENCH_COLLECT_STATS;
  4. const { V86, print_stats } = require(`../../build/${BENCH_COLLECT_STATS ? "libv86-debug" : "libv86"}.js`);
  5. const path = require("path");
  6. const V86_ROOT = path.join(__dirname, "../..");
  7. const emulator = new V86({
  8. bios: { url: path.join(V86_ROOT, "/bios/seabios.bin") },
  9. vga_bios: { url: path.join(V86_ROOT, "/bios/vgabios.bin") },
  10. autostart: true,
  11. memory_size: 512 * 1024 * 1024,
  12. vga_memory_size: 8 * 1024 * 1024,
  13. network_relay_url: "<UNUSED>",
  14. initial_state: { url: path.join(V86_ROOT, "/images/arch_state.bin") },
  15. filesystem: { baseurl: path.join(V86_ROOT, "/images/arch/") },
  16. disable_jit: +process.env.DISABLE_JIT,
  17. log_level: 0,
  18. });
  19. emulator.bus.register("emulator-started", function()
  20. {
  21. let exclude_tests = [];
  22. if(process.argv.length > 2)
  23. {
  24. exclude_tests = [
  25. "DONUMSORT",
  26. "DOSTRINGSORT",
  27. "DOBITFIELD",
  28. "DOEMF",
  29. "DOFOUR",
  30. "DOASSIGN",
  31. "DOIDEA",
  32. "DOHUFF",
  33. "DONNET",
  34. "DOLU",
  35. ].filter(name => !process.argv.includes(name));
  36. }
  37. setTimeout(() => {
  38. const set = exclude_tests.map(name => `echo ${name}=0 >> CMD`).join(" && ");
  39. emulator.serial0_send(`echo 0 > /sys/class/graphics/fbcon/cursor_blink && cd nbench && touch CMD && ${set || "echo"} && ./nbench -cCMD\n`);
  40. }, 1000);
  41. });
  42. var line = "";
  43. emulator.add_listener("serial0-output-byte", function(byte)
  44. {
  45. var chr = String.fromCharCode(byte);
  46. if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
  47. {
  48. return;
  49. }
  50. if(chr === "\n")
  51. {
  52. console.log("%s", line);
  53. line = "";
  54. }
  55. else
  56. {
  57. line += chr;
  58. }
  59. if(line === "* Trademarks are property of their respective holder.")
  60. {
  61. emulator.stop();
  62. if(BENCH_COLLECT_STATS)
  63. {
  64. const cpu = emulator.v86.cpu;
  65. console.log(print_stats.stats_to_string(cpu));
  66. }
  67. }
  68. });