arch-bytemark.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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-nongz/") },
  16. screen_dummy: true,
  17. disable_jit: +process.env.DISABLE_JIT,
  18. log_level: 0,
  19. });
  20. emulator.bus.register("emulator-started", function()
  21. {
  22. let exclude_tests = [];
  23. if(process.argv.length > 2)
  24. {
  25. exclude_tests = [
  26. "DONUMSORT",
  27. "DOSTRINGSORT",
  28. "DOBITFIELD",
  29. "DOEMF",
  30. "DOFOUR",
  31. "DOASSIGN",
  32. "DOIDEA",
  33. "DOHUFF",
  34. "DONNET",
  35. "DOLU",
  36. ].filter(name => !process.argv.includes(name));
  37. }
  38. setTimeout(() => {
  39. const set = exclude_tests.map(name => `echo ${name}=0 >> CMD`).join(" && ");
  40. emulator.serial0_send(`echo 0 > /sys/class/graphics/fbcon/cursor_blink && cd nbench && touch CMD && ${set || "echo"} && ./nbench -cCMD\n`);
  41. }, 1000);
  42. });
  43. var line = "";
  44. emulator.add_listener("serial0-output-byte", function(byte)
  45. {
  46. var chr = String.fromCharCode(byte);
  47. if(chr < " " && chr !== "\n" && chr !== "\t" || chr > "~")
  48. {
  49. return;
  50. }
  51. if(chr === "\n")
  52. {
  53. console.log("%s", line);
  54. line = "";
  55. }
  56. else
  57. {
  58. line += chr;
  59. }
  60. if(line === "* Trademarks are property of their respective holder.")
  61. {
  62. emulator.stop();
  63. if(BENCH_COLLECT_STATS)
  64. {
  65. const cpu = emulator.v86.cpu;
  66. console.log(print_stats.stats_to_string(cpu));
  67. }
  68. }
  69. });