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 16import { TabPaneFilesystemStatisticsAnalysis } from '../../../../../../src/trace/component/trace/sheet/file-system/TabPaneFilesystemStatisticsAnalysis'; 17import '../../../../../../src/trace/component/trace/sheet/file-system/TabPaneFilesystemStatisticsAnalysis'; 18import { LitTable } from '../../../../../../src/base-ui/table/lit-table'; 19import crypto from 'crypto'; 20import { TabPaneFilter } from '../../../../../../src/trace/component/trace/sheet/TabPaneFilter'; 21jest.mock('../../../../../../src/trace/component/trace/sheet/SheetUtils', () => { 22 return { 23 initSort: ()=>{} 24 }; 25}); 26jest.mock('../../../../../../src/trace/bean/AbilityMonitor', () => { 27 return {}; 28}); 29jest.mock('../../../../../../src/trace/component/SpSystemTrace', () => { 30 return {}; 31}); 32// @ts-ignore 33window.ResizeObserver = 34 window.ResizeObserver || 35 jest.fn().mockImplementation(() => ({ 36 disconnect: jest.fn(), 37 unobserve: jest.fn(), 38 observe: jest.fn(), 39 })); 40Object.defineProperty(global.self, 'crypto', { 41 value: { 42 getRandomValues: (arr: string | any[]) => crypto.randomBytes(arr.length), 43 }, 44}); 45 46describe('TabPaneFilesystemStatisticsAnalysis Test', () => { 47 document.body.innerHTML = `<tabpane-file-statistics-analysis id="statistics-analysis"></tabpane-file-statistics-analysis>`; 48 let tabPane = document.querySelector<TabPaneFilesystemStatisticsAnalysis>('#statistics-analysis'); 49 50 let param = { 51 anomalyEnergy: [], 52 clockMapData: { size: 193 }, 53 cpuAbilityIds: [10, 8], 54 cpuFreqFilterIds: [56], 55 cpuFreqLimitDatas: [], 56 cpuStateFilterIds: [12, 98], 57 cpus: [], 58 diskAbilityIds: [], 59 diskIOLatency: false, 60 diskIOReadIds: [2, 33], 61 diskIOWriteIds: [54, 4, 54, 6], 62 diskIOipids: [2, 17, 45, 5, 16], 63 fileSysVirtualMemory: false, 64 fileSystemType: [], 65 fsCount: 3, 66 funAsync: [], 67 funTids: [], 68 hasFps: false, 69 irqMapData: { size: 996 }, 70 jsMemory: [], 71 leftNs: 964699125, 72 memoryAbilityIds: [12, 34], 73 nativeMemory: [], 74 nativeMemoryStatistic: [], 75 networkAbilityIds: [34, 87], 76 perfAll: false, 77 perfCpus: [], 78 perfProcess: [], 79 perfSampleIds: [67, 33], 80 perfThread: [], 81 powerEnergy: [], 82 processTrackIds: [122, 34], 83 promiseList: [], 84 recordStartNs: 780423788588, 85 rightNs: 69267555654, 86 sdkCounterIds: [34, 22, 12], 87 sdkSliceIds: [221], 88 smapsType: [], 89 systemEnergy: [], 90 threadIds: [12, 45], 91 virtualTrackIds: [], 92 vmCount: 850, 93 }; 94 95 let item = { 96 durFormat: '194.23ms ', 97 duration: 194230478, 98 isHover: true, 99 percent: '99.00', 100 pid: 3744, 101 tableName: 'test(3744)', 102 }; 103 104 let res = [ 105 { 106 durFormat: '1334.23ms ', 107 duration: 13230478, 108 isHover: true, 109 percent: '232.00', 110 pid: 34, 111 tableName: 'test(3554)', 112 }, 113 ]; 114 115 let processData = [ 116 { 117 callChainId: 113, 118 dur: 24010, 119 libId: 539, 120 libName: 'libName.z.so', 121 pid: 911, 122 processName: 'ksoftirqd/1', 123 symbolId: 799, 124 symbolName: 'ksoftirqd/1 17', 125 threadName: 'ksoftirqd/1', 126 tid: 404, 127 type: 0, 128 }, 129 ]; 130 131 let threadStatisticsData = { durFormat: '194.23ms ', duration: 0, isHover: false, percent: '100.00', tableName: '' }; 132 133 it('systemStatisticsAnalysis01', function () { 134 let litTable = new LitTable(); 135 tabPane.appendChild(litTable); 136 let filter = new TabPaneFilter(); 137 tabPane.filter = filter; 138 tabPane.loadingList = []; 139 tabPane.data = param; 140 expect(tabPane.fileStatisticsAnalysisCurrentSelection).toBeUndefined(); 141 }); 142 143 it('systemStatisticsAnalysis02', function () { 144 expect(tabPane.clearData()).toBeUndefined(); 145 }); 146 147 it('systemStatisticsAnalysis03', function () { 148 tabPane.fileStatisticsAnalysisProcessData = processData; 149 tabPane.getFilesystemType(item, param); 150 expect(tabPane.fileStatisticsAnalysisProgressEL.loading).toBeFalsy(); 151 }); 152 153 it('systemStatisticsAnalysis04', function () { 154 tabPane.fileStatisticsAnalysisProcessData = processData; 155 tabPane.getFilesystemThread(item, param); 156 expect(tabPane.currentLevel).toEqual(2); 157 }); 158 159 it('systemStatisticsAnalysis05', function () { 160 tabPane.fileStatisticsAnalysisProcessData = processData; 161 tabPane.getFilesystemSo(item, param); 162 expect(tabPane.currentLevel).toEqual(3); 163 }); 164 165 it('systemStatisticsAnalysis06', function () { 166 tabPane.fileStatisticsAnalysisFunctionData = processData; 167 tabPane.getFilesystemFunction(item, param); 168 expect(tabPane.currentLevel).toEqual(4); 169 }); 170 171 it('systemStatisticsAnalysis07', function () { 172 expect(tabPane.typeIdToString(0)).toEqual('OPEN'); 173 }); 174 175 it('systemStatisticsAnalysis08', function () { 176 expect(tabPane.typeIdToString(2)).toEqual('READ'); 177 }); 178 179 it('systemStatisticsAnalysis09', function () { 180 expect(tabPane.typeIdToString(1)).toEqual('CLOSE'); 181 }); 182 183 it('systemStatisticsAnalysis10', function () { 184 expect(tabPane.getFsPieChartData(res).length).toEqual(1); 185 }); 186 187 it('systemStatisticsAnalysis11', function () { 188 tabPane.fileStatisticsAnalysisProcessData = jest.fn(() => true); 189 tabPane.fileStatisticsAnalysisProcessData.reMeauseHeight = jest.fn(() => true); 190 let parames = [ 191 { 192 type: 0, 193 callChainId: 13, 194 dur: 240916, 195 pid: 911, 196 tid: 404, 197 threadName: null, 198 processName: 'power_host(911)', 199 libId: 542, 200 symbolId: 802, 201 libName: 'libbattery_interface_service_1.0.z.so', 202 symbolName: 203 'OHOS::HDI::Battery::V1_0::PowerSupplyProvider::ReadBatterySysfsToBuff(char const*, char*, unsigned long) const', 204 }, 205 { 206 type: 0, 207 callChainId: 17, 208 dur: 42000, 209 pid: 911, 210 tid: 404, 211 threadName: null, 212 processName: 'power_host(911)', 213 libId: 542, 214 symbolId: 802, 215 libName: 'libbattery_interface_service_1.0.z.so', 216 symbolName: 217 'OHOS::HDI::Battery::V1_0::PowerSupplyProvider::ReadBatterySysfsToBuff(char const*, char*, unsigned long) const', 218 }, 219 ]; 220 tabPane.getFilesystemProcess(parames, processData); 221 expect(tabPane.fileStatisticsAnalysisProcessData).not.toBeUndefined(); 222 }); 223 it('systemStatisticsAnalysis12', function () { 224 tabPane.currentLevel = 0; 225 let paras = [ 226 { 227 type: 3, 228 callChainId: 1, 229 dur: 4757959, 230 pid: 237, 231 tid: 237, 232 threadName: 'jbd2/mmcblk0p11', 233 processName: 'jbd2/mmcblk0p11(237)', 234 libId: 263, 235 symbolId: 12560, 236 libName: 'kallsyms', 237 symbolName: 'submit_bh', 238 }, 239 { 240 type: 3, 241 callChainId: 1, 242 dur: 4673084, 243 pid: 237, 244 tid: 237, 245 threadName: 'jbd2/mmcblk0p11', 246 processName: 'jbd2/mmcblk0p11(237)', 247 libId: 263, 248 symbolId: 12560, 249 libName: 'kallsyms', 250 symbolName: 'submit_bh', 251 }, 252 ]; 253 tabPane.currentLevelData = paras; 254 expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined(); 255 tabPane.currentLevel = 1; 256 expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined(); 257 tabPane.currentLevel = 2; 258 expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined(); 259 tabPane.currentLevel = 3; 260 expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined(); 261 tabPane.currentLevel = 4; 262 expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined(); 263 tabPane.currentLevel = 0; 264 expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined(); 265 tabPane.currentLevel = 1; 266 expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined(); 267 tabPane.currentLevel = 2; 268 expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined(); 269 tabPane.currentLevel = 3; 270 expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined(); 271 tabPane.currentLevel = 4; 272 expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined(); 273 tabPane.currentLevel = 0; 274 expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined(); 275 tabPane.currentLevel = 1; 276 expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined(); 277 tabPane.currentLevel = 2; 278 expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined(); 279 tabPane.currentLevel = 3; 280 expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined(); 281 tabPane.currentLevel = 4; 282 expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined(); 283 }); 284 it('systemStatisticsAnalysis13', function () { 285 let it = { 286 tableName: '', 287 }; 288 expect(tabPane.fileProcessLevelClickEvent(it)).toBeUndefined(); 289 }); 290 it('systemStatisticsAnalysis14', function () { 291 let it = { 292 tableName: '', 293 }; 294 expect(tabPane.fileTypeLevelClickEvent(it)).toBeUndefined(); 295 }); 296 it('systemStatisticsAnalysis15', function () { 297 let it = { 298 tableName: '', 299 }; 300 expect(tabPane.fileThreadLevelClickEvent(it)).toBeUndefined(); 301 }); 302 it('systemStatisticsAnalysis16', function () { 303 let it = { 304 tableName: '', 305 }; 306 expect(tabPane.fileSoLevelClickEvent(it)).toBeUndefined(); 307 }); 308 it('TabPanePerfAnalysisTest17 ', function () { 309 let itemClick = new CustomEvent('click', <CustomEventInit>{ 310 detail: { 311 ...{}, 312 data: {}, 313 }, 314 composed: true, 315 }); 316 tabPane.tabName!.textContent = 'Statistic By type AllDuration'; 317 tabPane.processStatisticsData = jest.fn(() => true); 318 tabPane.processStatisticsData.allDuration = jest.fn(() => true); 319 tabPane.fileStatisticsAnalysisPidData = [{}, {}]; 320 tabPane.fsBack!.dispatchEvent(itemClick); 321 expect(tabPane.goBack()).toBeUndefined(); 322 }); 323 it('TabPanePerfAnalysisTest18 ', function () { 324 let itemClick = new CustomEvent('click', <CustomEventInit>{ 325 detail: { 326 ...{}, 327 data: {}, 328 }, 329 composed: true, 330 }); 331 tabPane.tabName!.textContent = 'Statistic By Library AllDuration'; 332 tabPane.threadStatisticsData = jest.fn(() => true); 333 tabPane.threadStatisticsData.allDuration = jest.fn(() => true); 334 tabPane.fileStatisticsAnalysisThreadData = [{}, {}]; 335 tabPane.fsBack!.dispatchEvent(itemClick); 336 expect(tabPane.goBack()).toBeUndefined(); 337 }); 338 it('TabPanePerfAnalysisTest19 ', function () { 339 let itemClick = new CustomEvent('click', <CustomEventInit>{ 340 detail: { 341 ...{}, 342 data: {}, 343 }, 344 composed: true, 345 }); 346 tabPane.tabName!.textContent = 'Statistic By Function AllDuration'; 347 tabPane.libStatisticsData = jest.fn(() => true); 348 tabPane.libStatisticsData.allDuration = jest.fn(() => true); 349 tabPane.fileStatisticsAnalysisSoData = [{}, {}]; 350 tabPane.fsBack!.dispatchEvent(itemClick); 351 expect(tabPane.goBack()).toBeUndefined(); 352 }); 353 it('TabPanePerfAnalysisTest20 ', function () { 354 let itemClick = new CustomEvent('click', <CustomEventInit>{ 355 detail: { 356 ...{}, 357 data: {}, 358 }, 359 composed: true, 360 }); 361 tabPane.tabName!.textContent = 'Statistic By Thread AllDuration'; 362 tabPane.typeStatisticsData = jest.fn(() => true); 363 tabPane.typeStatisticsData.allDuration = jest.fn(() => true); 364 tabPane.fileStatisticsAnalysisTypeData = [{}, {}]; 365 tabPane.fsBack!.dispatchEvent(itemClick); 366 expect(tabPane.goBack()).toBeUndefined(); 367 }); 368}); 369