test_tree-model-01.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests if a call tree model can be correctly computed from a samples array.
  6. */
  7. function run_test() {
  8. run_next_test();
  9. }
  10. add_task(function test() {
  11. const { ThreadNode } = require("devtools/client/performance/modules/logic/tree-model");
  12. // Create a root node from a given samples array.
  13. let threadNode = new ThreadNode(gThread, { startTime: 0, endTime: 20 });
  14. let root = getFrameNodePath(threadNode, "(root)");
  15. // Test the root node.
  16. equal(threadNode.getInfo().nodeType, "Thread",
  17. "The correct node type was retrieved for the root node.");
  18. equal(threadNode.duration, 20,
  19. "The correct duration was calculated for the ThreadNode.");
  20. equal(root.getInfo().functionName, "(root)",
  21. "The correct function name was retrieved for the root node.");
  22. equal(root.getInfo().categoryData.abbrev, "other",
  23. "The correct empty category data was retrieved for the root node.");
  24. equal(root.calls.length, 1,
  25. "The correct number of child calls were calculated for the root node.");
  26. ok(getFrameNodePath(root, "A"),
  27. "The root node's only child call is correct.");
  28. // Test all the descendant nodes.
  29. equal(getFrameNodePath(root, "A").calls.length, 2,
  30. "The correct number of child calls were calculated for the 'A' node.");
  31. ok(getFrameNodePath(root, "A > B"),
  32. "The 'A' node has a 'B' child call.");
  33. ok(getFrameNodePath(root, "A > E"),
  34. "The 'A' node has a 'E' child call.");
  35. equal(getFrameNodePath(root, "A > B").calls.length, 2,
  36. "The correct number of child calls were calculated for the 'A > B' node.");
  37. ok(getFrameNodePath(root, "A > B > C"),
  38. "The 'A > B' node has a 'C' child call.");
  39. ok(getFrameNodePath(root, "A > B > D"),
  40. "The 'A > B' node has a 'D' child call.");
  41. equal(getFrameNodePath(root, "A > E").calls.length, 1,
  42. "The correct number of child calls were calculated for the 'A > E' node.");
  43. ok(getFrameNodePath(root, "A > E > F"),
  44. "The 'A > E' node has a 'F' child call.");
  45. equal(getFrameNodePath(root, "A > B > C").calls.length, 1,
  46. "The correct number of child calls were calculated for the 'A > B > C' node.");
  47. ok(getFrameNodePath(root, "A > B > C > D"),
  48. "The 'A > B > C' node has a 'D' child call.");
  49. equal(getFrameNodePath(root, "A > B > C > D").calls.length, 1,
  50. "The correct number of child calls were calculated for the 'A > B > C > D' node.");
  51. ok(getFrameNodePath(root, "A > B > C > D > E"),
  52. "The 'A > B > C > D' node has a 'E' child call.");
  53. equal(getFrameNodePath(root, "A > B > C > D > E").calls.length, 1,
  54. "The correct number of child calls were calculated for the 'A > B > C > D > E' " +
  55. "node.");
  56. ok(getFrameNodePath(root, "A > B > C > D > E > F"),
  57. "The 'A > B > C > D > E' node has a 'F' child call.");
  58. equal(getFrameNodePath(root, "A > B > C > D > E > F").calls.length, 1,
  59. "The correct number of child calls were calculated for the 'A > B > C > D > E > F' " +
  60. "node.");
  61. ok(getFrameNodePath(root, "A > B > C > D > E > F > G"),
  62. "The 'A > B > C > D > E > F' node has a 'G' child call.");
  63. equal(getFrameNodePath(root, "A > B > C > D > E > F > G").calls.length, 0,
  64. "The correct number of child calls were calculated for the " +
  65. "'A > B > C > D > E > F > G' node.");
  66. equal(getFrameNodePath(root, "A > B > D").calls.length, 0,
  67. "The correct number of child calls were calculated for the 'A > B > D' node.");
  68. equal(getFrameNodePath(root, "A > E > F").calls.length, 0,
  69. "The correct number of child calls were calculated for the 'A > E > F' node.");
  70. // Check the location, sample times, and samples of the root.
  71. equal(getFrameNodePath(root, "A").location, "A",
  72. "The 'A' node has the correct location.");
  73. equal(getFrameNodePath(root, "A").youngestFrameSamples, 0,
  74. "The 'A' has correct `youngestFrameSamples`");
  75. equal(getFrameNodePath(root, "A").samples, 4,
  76. "The 'A' has correct `samples`");
  77. // A frame that is both a leaf and caught in another stack
  78. equal(getFrameNodePath(root, "A > B > C").youngestFrameSamples, 1,
  79. "The 'A > B > C' has correct `youngestFrameSamples`");
  80. equal(getFrameNodePath(root, "A > B > C").samples, 2,
  81. "The 'A > B > C' has correct `samples`");
  82. // ...and the rightmost leaf.
  83. equal(getFrameNodePath(root, "A > E > F").location, "F",
  84. "The 'A > E > F' node has the correct location.");
  85. equal(getFrameNodePath(root, "A > E > F").samples, 1,
  86. "The 'A > E > F' node has the correct number of samples.");
  87. equal(getFrameNodePath(root, "A > E > F").youngestFrameSamples, 1,
  88. "The 'A > E > F' node has the correct number of youngestFrameSamples.");
  89. // ...and the leftmost leaf.
  90. equal(getFrameNodePath(root, "A > B > C > D > E > F > G").location, "G",
  91. "The 'A > B > C > D > E > F > G' node has the correct location.");
  92. equal(getFrameNodePath(root, "A > B > C > D > E > F > G").samples, 1,
  93. "The 'A > B > C > D > E > F > G' node has the correct number of samples.");
  94. equal(getFrameNodePath(root, "A > B > C > D > E > F > G").youngestFrameSamples, 1,
  95. "The 'A > B > C > D > E > F > G' node has the correct number of " +
  96. "youngestFrameSamples.");
  97. });
  98. var gThread = synthesizeProfileForTest([{
  99. time: 5,
  100. frames: [
  101. { location: "(root)" },
  102. { location: "A" },
  103. { location: "B" },
  104. { location: "C" }
  105. ]
  106. }, {
  107. time: 5 + 6,
  108. frames: [
  109. { location: "(root)" },
  110. { location: "A" },
  111. { location: "B" },
  112. { location: "D" }
  113. ]
  114. }, {
  115. time: 5 + 6 + 7,
  116. frames: [
  117. { location: "(root)" },
  118. { location: "A" },
  119. { location: "E" },
  120. { location: "F" }
  121. ]
  122. }, {
  123. time: 20,
  124. frames: [
  125. { location: "(root)" },
  126. { location: "A" },
  127. { location: "B" },
  128. { location: "C" },
  129. { location: "D" },
  130. { location: "E" },
  131. { location: "F" },
  132. { location: "G" }
  133. ]
  134. }]);