test_asm.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Check that asm.js code shows up on the stack.
  2. function run_test() {
  3. let p = Cc["@mozilla.org/tools/profiler;1"];
  4. // Just skip the test if the profiler component isn't present.
  5. if (!p)
  6. return;
  7. p = p.getService(Ci.nsIProfiler);
  8. if (!p)
  9. return;
  10. // This test assumes that it's starting on an empty SPS stack.
  11. // (Note that the other profiler tests also assume the profiler
  12. // isn't already started.)
  13. do_check_true(!p.IsActive());
  14. let jsFuns = Cu.getJSTestingFunctions();
  15. if (!jsFuns.isAsmJSCompilationAvailable())
  16. return;
  17. const ms = 10;
  18. p.StartProfiler(10000, ms, ["js"], 1);
  19. let stack = null;
  20. function ffi_function(){
  21. var delayMS = 5;
  22. while (1) {
  23. let then = Date.now();
  24. do {} while (Date.now() - then < delayMS);
  25. var thread0 = p.getProfileData().threads[0];
  26. if (delayMS > 30000)
  27. return;
  28. delayMS *= 2;
  29. if (thread0.samples.data.length == 0)
  30. continue;
  31. var lastSample = thread0.samples.data[thread0.samples.data.length - 1];
  32. stack = String(getInflatedStackLocations(thread0, lastSample));
  33. if (stack.indexOf("trampoline") !== -1)
  34. return;
  35. }
  36. }
  37. function asmjs_module(global, ffis) {
  38. "use asm";
  39. var ffi = ffis.ffi;
  40. function asmjs_function() {
  41. ffi();
  42. }
  43. return asmjs_function;
  44. }
  45. do_check_true(jsFuns.isAsmJSModule(asmjs_module));
  46. var asmjs_function = asmjs_module(null, {ffi:ffi_function});
  47. do_check_true(jsFuns.isAsmJSFunction(asmjs_function));
  48. asmjs_function();
  49. do_check_neq(stack, null);
  50. var i1 = stack.indexOf("entry trampoline");
  51. do_check_true(i1 !== -1);
  52. var i2 = stack.indexOf("asmjs_function");
  53. do_check_true(i2 !== -1);
  54. var i3 = stack.indexOf("FFI trampoline");
  55. do_check_true(i3 !== -1);
  56. var i4 = stack.indexOf("ffi_function");
  57. do_check_true(i4 !== -1);
  58. do_check_true(i1 < i2);
  59. do_check_true(i2 < i3);
  60. do_check_true(i3 < i4);
  61. p.StopProfiler();
  62. }