test_DominatorTreeNode_attachShortestPaths_01.js (3595B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 "use strict"; 4 5 // Test that the DominatorTreeNode.attachShortestPaths function can correctly 6 // attach the deduplicated shortest retaining paths for each node it is given. 7 8 const startNodeId = 9999; 9 const maxNumPaths = 2; 10 11 // Mock data mapping node id to shortest paths to that node id. 12 const shortestPaths = new Map([ 13 [ 14 1000, 15 [ 16 [pathEntry(1100, "a"), pathEntry(1200, "b")], 17 [pathEntry(1100, "c"), pathEntry(1300, "d")], 18 ], 19 ], 20 [2000, [[pathEntry(2100, "e"), pathEntry(2200, "f"), pathEntry(2300, "g")]]], 21 [ 22 3000, 23 [ 24 [pathEntry(3100, "h")], 25 [pathEntry(3100, "i")], 26 [pathEntry(3100, "j")], 27 [pathEntry(3200, "k")], 28 [pathEntry(3300, "l")], 29 [pathEntry(3400, "m")], 30 ], 31 ], 32 ]); 33 34 const actual = [ 35 makeTestDominatorTreeNode({ nodeId: 1000 }), 36 makeTestDominatorTreeNode({ nodeId: 2000 }), 37 makeTestDominatorTreeNode({ nodeId: 3000 }), 38 ]; 39 40 const expected = [ 41 makeTestDominatorTreeNode({ 42 nodeId: 1000, 43 shortestPaths: { 44 nodes: [ 45 { id: 1000, label: ["SomeType-1000"] }, 46 { id: 1100, label: ["SomeType-1100"] }, 47 { id: 1200, label: ["SomeType-1200"] }, 48 { id: 1300, label: ["SomeType-1300"] }, 49 ], 50 edges: [ 51 { from: 1100, to: 1200, name: "a" }, 52 { from: 1100, to: 1300, name: "c" }, 53 { from: 1200, to: 1000, name: "b" }, 54 { from: 1300, to: 1000, name: "d" }, 55 ], 56 }, 57 }), 58 59 makeTestDominatorTreeNode({ 60 nodeId: 2000, 61 shortestPaths: { 62 nodes: [ 63 { id: 2000, label: ["SomeType-2000"] }, 64 { id: 2100, label: ["SomeType-2100"] }, 65 { id: 2200, label: ["SomeType-2200"] }, 66 { id: 2300, label: ["SomeType-2300"] }, 67 ], 68 edges: [ 69 { from: 2100, to: 2200, name: "e" }, 70 { from: 2200, to: 2300, name: "f" }, 71 { from: 2300, to: 2000, name: "g" }, 72 ], 73 }, 74 }), 75 76 makeTestDominatorTreeNode({ 77 nodeId: 3000, 78 shortestPaths: { 79 nodes: [ 80 { id: 3000, label: ["SomeType-3000"] }, 81 { id: 3100, label: ["SomeType-3100"] }, 82 { id: 3200, label: ["SomeType-3200"] }, 83 { id: 3300, label: ["SomeType-3300"] }, 84 { id: 3400, label: ["SomeType-3400"] }, 85 ], 86 edges: [ 87 { from: 3100, to: 3000, name: "h" }, 88 { from: 3100, to: 3000, name: "i" }, 89 { from: 3100, to: 3000, name: "j" }, 90 { from: 3200, to: 3000, name: "k" }, 91 { from: 3300, to: 3000, name: "l" }, 92 { from: 3400, to: 3000, name: "m" }, 93 ], 94 }, 95 }), 96 ]; 97 98 const breakdown = { 99 by: "internalType", 100 then: { by: "count", count: true, bytes: true }, 101 }; 102 103 const mockSnapshot = { 104 computeShortestPaths: (start, nodeIds, max) => { 105 equal(start, startNodeId); 106 equal(max, maxNumPaths); 107 108 return new Map( 109 nodeIds.map(nodeId => { 110 const paths = shortestPaths.get(nodeId); 111 ok(paths, "Expected computeShortestPaths call for node id = " + nodeId); 112 return [nodeId, paths]; 113 }) 114 ); 115 }, 116 117 describeNode: (bd, nodeId) => { 118 equal(bd, breakdown); 119 return { 120 ["SomeType-" + nodeId]: { 121 count: 1, 122 bytes: 10, 123 }, 124 }; 125 }, 126 }; 127 128 function run_test() { 129 DominatorTreeNode.attachShortestPaths( 130 mockSnapshot, 131 breakdown, 132 startNodeId, 133 actual, 134 maxNumPaths 135 ); 136 137 dumpn("Expected = " + JSON.stringify(expected, null, 2)); 138 dumpn("Actual = " + JSON.stringify(actual, null, 2)); 139 140 assertStructurallyEquivalent(expected, actual); 141 }