1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// @ts-ignore 17import {TabPaneSPT} from "../../../../../dist/trace/component/trace/sheet/TabPaneSPT.js" 18// @ts-ignore 19import {SpSystemTrace} from "../../../../../dist/trace/component/SpSystemTrace.js"; 20 21window.ResizeObserver = window.ResizeObserver || 22 jest.fn().mockImplementation(() => ({ 23 disconnect: jest.fn(), 24 observe: jest.fn(), 25 unobserve: jest.fn(), 26 })); 27 28describe('TabPaneSPT Test', () => { 29 let tabPaneSPT = new TabPaneSPT(); 30 31 SpSystemTrace.SPT_DATA = [{ 32 process: "", 33 processId: 0, 34 thread: "", 35 threadId: 0, 36 state: '', 37 dur: 0, 38 start_ts: 0, 39 end_ts: 0, 40 cpu: 0, 41 priority: "-", 42 note: "-", 43 },{ 44 process: "", 45 processId: 1, 46 thread: "", 47 threadId: 1, 48 state: '', 49 dur: 0, 50 start_ts: 0, 51 end_ts: 0, 52 cpu: 0, 53 priority: "-", 54 note: "-", 55 },{ 56 process: "", 57 processId: 2, 58 thread: "", 59 threadId: 2, 60 state: '', 61 dur: 0, 62 start_ts: 0, 63 end_ts: 0, 64 cpu: 0, 65 priority: "-", 66 note: "-", 67 }] 68 69 let dataList = [{ 70 id: "", 71 pid: "", 72 title: "", 73 children: [], 74 process: "", 75 processId: 0, 76 thread: "", 77 threadId: 0, 78 state: "", 79 wallDuration: 0, 80 avgDuration: "", 81 count: 0, 82 minDuration: 0, 83 maxDuration: 0, 84 stdDuration: "", 85 }] 86 87 let dataArray = [{ 88 id: "", 89 pid: "", 90 title: "", 91 children: [], 92 process: "", 93 processId: 0, 94 thread: "", 95 threadId: 0, 96 state: "", 97 wallDuration: 0, 98 avgDuration: "", 99 count: 0, 100 minDuration: 0, 101 maxDuration: 0, 102 stdDuration: "", 103 }] 104 105 it('TabPaneSPTTest01', function () { 106 let result = tabPaneSPT.groupByStateToMap(dataArray); 107 expect(result.get('').length).toBe(1); 108 }); 109 110 it('TabPaneSPTTest02', function () { 111 let result = tabPaneSPT.groupByProcessToMap(dataArray) 112 expect(result.get(0).length).toBe(1); 113 }); 114 115 it('TabPaneSPTTest03', function () { 116 let result = tabPaneSPT.groupByStateProcessToMap(dataArray) 117 expect(result.get('').get(0).length).toBe(1); 118 }); 119 120 it('TabPaneSPTTest05', function () { 121 let data = { 122 cpus: [], 123 threadIds: [], 124 trackIds: [], 125 funTids: [], 126 heapIds: [], 127 nativeMemory: [], 128 cpuAbilityIds: [], 129 memoryAbilityIds: [], 130 diskAbilityIds: [], 131 networkAbilityIds: [], 132 leftNs: 0, 133 rightNs: 0, 134 hasFps: false, 135 statisticsSelectData: undefined, 136 perfSampleIds: [], 137 perfCpus: [], 138 perfProcess: [], 139 perfThread: [], 140 perfAll: false, 141 } 142 let queryDataInCacheData = tabPaneSPT.queryDataByCacheData(data); 143 expect(queryDataInCacheData.length).toBeUndefined() 144 }); 145 146 it('TabPaneSPTTest04', function () { 147 expect(tabPaneSPT.initHtml()).toMatchInlineSnapshot(` 148" 149 <style> 150 :host{ 151 display: flex; 152 flex-direction: column; 153 padding: 10px 10px; 154 } 155 </style> 156 <label id=\\"time-range\\" style=\\"width: 100%;height: 20px;text-align: end;font-size: 10pt;margin-bottom: 5px\\">Selected range:0.0 ms</label> 157 <lit-table id=\\"tb-states\\" style=\\"height: auto\\" tree> 158 <lit-table-column width=\\"27%\\" title=\\"State/Process/Thread\\" data-index=\\"title\\" key=\\"title\\" align=\\"flex-start\\"> 159 </lit-table-column> 160 <lit-table-column width=\\"1fr\\" title=\\"Count\\" data-index=\\"count\\" key=\\"count\\" align=\\"flex-start\\" > 161 </lit-table-column> 162 <lit-table-column width=\\"1fr\\" title=\\"Duration(ns)\\" data-index=\\"wallDuration\\" key=\\"wallDuration\\" align=\\"flex-start\\" > 163 </lit-table-column> 164 <lit-table-column width=\\"1fr\\" title=\\"Min Duration(ns)\\" data-index=\\"minDuration\\" key=\\"minDuration\\" align=\\"flex-start\\" > 165 </lit-table-column> 166 <lit-table-column width=\\"1fr\\" title=\\"Avg Duration(ns)\\" data-index=\\"avgDuration\\" key=\\"avgDuration\\" align=\\"flex-start\\" > 167 </lit-table-column> 168 <lit-table-column width=\\"1fr\\" title=\\"Max Duration(ns)\\" data-index=\\"maxDuration\\" key=\\"maxDuration\\" align=\\"flex-start\\" > 169 </lit-table-column> 170 </lit-table> 171 " 172`); 173 }); 174}) 175