test_census-tree-node-04.js (3621B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 /** 6 * Tests CensusTreeNode with `allocationStack` breakdown. 7 */ 8 9 function run_test() { 10 const countBreakdown = { by: "count", count: true, bytes: true }; 11 12 const BREAKDOWN = { 13 by: "allocationStack", 14 then: countBreakdown, 15 noStack: countBreakdown, 16 }; 17 18 let stack1, stack2, stack3, stack4; 19 20 (function a() { 21 (function b() { 22 (function c() { 23 stack1 = saveStack(3); 24 })(); 25 (function d() { 26 stack2 = saveStack(3); 27 stack3 = saveStack(3); 28 })(); 29 stack4 = saveStack(2); 30 })(); 31 })(); 32 33 const stack5 = saveStack(1); 34 35 const REPORT = new Map([ 36 [stack1, { bytes: 10, count: 1 }], 37 [stack2, { bytes: 20, count: 2 }], 38 [stack3, { bytes: 30, count: 3 }], 39 [stack4, { bytes: 40, count: 4 }], 40 [stack5, { bytes: 50, count: 5 }], 41 ["noStack", { bytes: 60, count: 6 }], 42 ]); 43 44 const EXPECTED = { 45 name: null, 46 bytes: 0, 47 totalBytes: 210, 48 count: 0, 49 totalCount: 21, 50 children: [ 51 { 52 name: stack4.parent, 53 bytes: 0, 54 totalBytes: 100, 55 count: 0, 56 totalCount: 10, 57 children: [ 58 { 59 name: stack3.parent, 60 bytes: 0, 61 totalBytes: 50, 62 count: 0, 63 totalCount: 5, 64 children: [ 65 { 66 name: stack3, 67 bytes: 30, 68 totalBytes: 30, 69 count: 3, 70 totalCount: 3, 71 children: undefined, 72 id: 7, 73 parent: 5, 74 reportLeafIndex: 3, 75 }, 76 { 77 name: stack2, 78 bytes: 20, 79 totalBytes: 20, 80 count: 2, 81 totalCount: 2, 82 children: undefined, 83 id: 6, 84 parent: 5, 85 reportLeafIndex: 2, 86 }, 87 ], 88 id: 5, 89 parent: 2, 90 reportLeafIndex: undefined, 91 }, 92 { 93 name: stack4, 94 bytes: 40, 95 totalBytes: 40, 96 count: 4, 97 totalCount: 4, 98 children: undefined, 99 id: 8, 100 parent: 2, 101 reportLeafIndex: 4, 102 }, 103 { 104 name: stack1.parent, 105 bytes: 0, 106 totalBytes: 10, 107 count: 0, 108 totalCount: 1, 109 children: [ 110 { 111 name: stack1, 112 bytes: 10, 113 totalBytes: 10, 114 count: 1, 115 totalCount: 1, 116 children: undefined, 117 id: 4, 118 parent: 3, 119 reportLeafIndex: 1, 120 }, 121 ], 122 id: 3, 123 parent: 2, 124 reportLeafIndex: undefined, 125 }, 126 ], 127 id: 2, 128 parent: 1, 129 reportLeafIndex: undefined, 130 }, 131 { 132 name: "noStack", 133 bytes: 60, 134 totalBytes: 60, 135 count: 6, 136 totalCount: 6, 137 children: undefined, 138 id: 10, 139 parent: 1, 140 reportLeafIndex: 6, 141 }, 142 { 143 name: stack5, 144 bytes: 50, 145 totalBytes: 50, 146 count: 5, 147 totalCount: 5, 148 children: undefined, 149 id: 9, 150 parent: 1, 151 reportLeafIndex: 5, 152 }, 153 ], 154 id: 1, 155 parent: undefined, 156 reportLeafIndex: undefined, 157 }; 158 159 compareCensusViewData(BREAKDOWN, REPORT, EXPECTED); 160 }