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 */ 15import '../../../../../../src/trace/component/trace/sheet/native-memory/TabPaneNMSampleList'; 16import { TabPaneNMSampleList } from '../../../../../../src/trace/component/trace/sheet/native-memory/TabPaneNMSampleList'; 17import { NativeHookSamplerInfo, NativeMemory } from '../../../../../../src/trace/bean/NativeHook'; 18import { NativeHookSampleQueryInfo } from '../../../../../../src/trace/bean/NativeHook'; 19import { LitTable } from '../../../../../../src/base-ui/table/lit-table'; 20jest.mock('../../../../../../src/trace/component/trace/base/TraceRow', () => { 21 return {}; 22}); 23jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 24 return {}; 25}); 26jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 27 return {}; 28}); 29jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => {}); 30const sqlit = require('../../../../../../src/trace/database/sql/NativeHook.sql'); 31jest.mock('../../../../../../src/trace/database/sql/NativeHook.sql'); 32// @ts-ignore 33window.ResizeObserver = window.ResizeObserver || 34 jest.fn().mockImplementation(() => ({ 35 unobserve: jest.fn(), 36 disconnect: jest.fn(), 37 observe: jest.fn(), 38 })); 39describe('TabPaneNMSampleList Test', () => { 40 let tabPaneNMSampleList = new TabPaneNMSampleList(); 41 tabPaneNMSampleList.sampleTbl = new LitTable(); 42 TabPaneNMSampleList.samplerInfoSource = [ 43 { 44 current: '', 45 currentSize: 101, 46 startTs: 110, 47 heapSize: 10, 48 snapshot: 'snapshot01', 49 growth: '', 50 total: 980, 51 totalGrowth: '', 52 existing: 7810, 53 children: [], 54 tempList: [], 55 timestamp: '', 56 eventId: 320, 57 }, 58 ]; 59 TabPaneNMSampleList.filterSelect = '0'; 60 tabPaneNMSampleList.currentSelection = jest.fn(() => true); 61 let dat = { 62 cpus: [], 63 threadIds: [1,2,3], 64 trackIds: [23,56,77], 65 funTids: [675,75], 66 heapIds: [11,223], 67 nativeMemory: [], 68 leftNs: 12222, 69 rightNs: 654233, 70 hasFps: false, 71 statisticsSelectData: undefined, 72 }; 73 74 let NativeHookSnapshotTypes = [ 75 { 76 eventId: -1, 77 current: 0, 78 eventType: '', 79 subType: '', 80 growth: 0, 81 existing: 0, 82 addr: '', 83 startTs: 0, 84 endTs: 0, 85 total: 0, 86 children: [], 87 }, 88 ]; 89 90 let MockNativeHookSnapshotTypes = sqlit.queryNativeHookSnapshotTypes; 91 92 MockNativeHookSnapshotTypes.mockResolvedValue([new NativeHookSampleQueryInfo()]); 93 94 let samplerInfo = [ 95 { 96 current: '', 97 currentSize: 102, 98 startTs: 540, 99 heapSize: 23, 100 snapshot: 'snapshot02', 101 growth: '', 102 total: 332, 103 totalGrowth: '', 104 existing: 60, 105 children: [], 106 tempList: [], 107 timestamp: '', 108 eventId: 55, 109 threadId: 33, 110 threadName: '', 111 }, 112 { 113 current: '', 114 currentSize: 103, 115 startTs: 369, 116 heapSize: 98, 117 snapshot: 'snapshot03', 118 growth: '', 119 total: 9855, 120 totalGrowth: '', 121 existing: 10, 122 children: [], 123 tempList: [], 124 timestamp: '', 125 eventId: 132, 126 threadId: 130, 127 threadName: '', 128 }, 129 ]; 130 131 tabPaneNMSampleList.data = dat; 132 it('TabPaneNMSampleListTest01', function () { 133 expect(TabPaneNMSampleList.serSelection(dat)).toBeUndefined(); 134 }); 135 136 it('TabPaneNMSampleListTest02', function () { 137 let sampleData = new NativeMemory(); 138 139 let MockqueryAllHookData = sqlit.queryAllHookData; 140 MockqueryAllHookData.mockResolvedValue([new NativeHookSampleQueryInfo()]); 141 142 expect(TabPaneNMSampleList.addSampleData(sampleData)).toBeUndefined(); 143 }); 144 145 it('TabPaneNMSampleListTest04', function () { 146 let snapshot = { 147 current: '', 148 currentSize: 104, 149 startTs: 960, 150 heapSize: 99, 151 snapshot: 'snapshot04', 152 growth: '', 153 total: 990, 154 totalGrowth: '', 155 existing: 634, 156 children: [], 157 tempList: [], 158 timestamp: '', 159 eventId: 22, 160 }; 161 162 let snapshotLeft = { 163 current: 'left', 164 currentSize: 0, 165 startTs: 4, 166 heapSize: 40, 167 snapshot: '', 168 growth: '', 169 total: 400, 170 totalGrowth: '', 171 existing: 0, 172 children: [snapshot], 173 tempList: [], 174 timestamp: '', 175 eventId: -1, 176 }; 177 178 let snapshotRight = { 179 current: 'right', 180 currentSize: 0, 181 startTs: 5, 182 heapSize: 50, 183 snapshot: '', 184 growth: '', 185 total: 500, 186 totalGrowth: '', 187 existing: 0, 188 children: [snapshot], 189 tempList: [], 190 timestamp: '', 191 eventId: -1, 192 }; 193 expect(TabPaneNMSampleList.prepChild(snapshotLeft, snapshotRight)).toBeUndefined(); 194 }); 195 196 it('TabPaneNMSampleListTest10', function () { 197 expect(TabPaneNMSampleList.data).toBeUndefined(); 198 }); 199 200 it('TabPaneNMSampleListTest11', function () { 201 expect(TabPaneNMSampleList.initTypes()).toBeUndefined(); 202 }); 203 204 205 it('TabPaneNMSampleListTest09', function () { 206 let rootSample = new NativeHookSamplerInfo(); 207 208 let merageSample = { 209 growth: 1, 210 endTs: 2, 211 startTs: 2, 212 addr: '1', 213 eventId: 0, 214 }; 215 expect(TabPaneNMSampleList.merageSampleData(1, 1, rootSample, merageSample)).toBeUndefined(); 216 }); 217 218 it('TabPaneNMSampleListTest12', function () { 219 let rootSample = new NativeHookSamplerInfo(); 220 221 let MockqueryAllHookData = sqlit.queryAllHookData; 222 223 MockqueryAllHookData.mockResolvedValue([ 224 { 225 eventId: 1, 226 eventType: 'aa', 227 subType: 1, 228 addr: 'aaaa', 229 growth: 2, 230 startTs: 11111, 231 endTs: 211111, 232 }, 233 ]); 234 expect(TabPaneNMSampleList.queryAllHookInfo(dat, rootSample)).toBeUndefined(); 235 }); 236 237 it('TabPaneNMSampleListTest13', function () { 238 TabPaneNMSampleList.samplerInfoSource = [ 239 { 240 current: '', 241 currentSize: 0, 242 startTs: 1, 243 heapSize: 10, 244 snapshot: '', 245 growth: '', 246 total: 100, 247 totalGrowth: '', 248 existing: 0, 249 children: samplerInfo, 250 tempList: samplerInfo, 251 timestamp: '', 252 eventId: -1, 253 threadId: 1, 254 threadName: '', 255 }, 256 ]; 257 TabPaneNMSampleList.filterSelect = '0'; 258 TabPaneNMSampleList.sampleTbl!.meauseTreeRowElement = jest.fn(() => { 259 return []; 260 }); 261 TabPaneNMSampleList.sampleTbl!.recycleDataSource = jest.fn(() => []); 262 expect(tabPaneNMSampleList.filterAllList()).toBeUndefined(); 263 }); 264 265 it('TabPaneNMSampleListTest14', function () { 266 TabPaneNMSampleList.samplerInfoSource = [ 267 { 268 current: '', 269 currentSize: 0, 270 startTs: 2, 271 heapSize: 20, 272 snapshot: '', 273 growth: '', 274 total: 200, 275 totalGrowth: '', 276 existing: 0, 277 children: samplerInfo, 278 tempList: samplerInfo, 279 timestamp: '', 280 eventId: -1, 281 threadId: 2, 282 threadName: '', 283 }, 284 ]; 285 TabPaneNMSampleList.filterSelect = '1'; 286 TabPaneNMSampleList.sampleTbl!.meauseTreeRowElement = jest.fn(() => { 287 return []; 288 }); 289 TabPaneNMSampleList.sampleTbl!.recycleDataSource = jest.fn(() => []); 290 expect(tabPaneNMSampleList.filterAllList()).toBeUndefined(); 291 }); 292 293 it('TabPaneNMSampleListTest15', function () { 294 TabPaneNMSampleList.samplerInfoSource = [ 295 { 296 current: '', 297 currentSize: 108, 298 startTs: 9951, 299 heapSize: 123, 300 snapshot: 'snapshot06', 301 growth: '', 302 total: 70, 303 totalGrowth: '', 304 existing: 50, 305 children: [], 306 tempList: [], 307 timestamp: '', 308 eventId: 5, 309 threadId: 57, 310 threadName: '', 311 }, 312 ]; 313 TabPaneNMSampleList.filterSelect = '1'; 314 TabPaneNMSampleList.sampleTbl!.meauseTreeRowElement = jest.fn(() => { 315 return []; 316 }); 317 TabPaneNMSampleList.sampleTbl!.recycleDataSource = jest.fn(() => []); 318 expect(tabPaneNMSampleList.filterAllList()).toBeUndefined(); 319 }); 320 321 it('TabPaneNMSampleListTest16', function () { 322 TabPaneNMSampleList.samplerInfoSource = [ 323 { 324 current: '', 325 currentSize: 0, 326 startTs: 3, 327 heapSize: 30, 328 snapshot: '', 329 growth: '', 330 total: 300, 331 totalGrowth: '', 332 existing: 0, 333 children: samplerInfo, 334 tempList: samplerInfo, 335 timestamp: '', 336 eventId: -1, 337 threadId: 3, 338 threadName: '', 339 }, 340 ]; 341 TabPaneNMSampleList.filterSelect = '2'; 342 TabPaneNMSampleList.sampleTbl!.meauseTreeRowElement = jest.fn(() => { 343 return []; 344 }); 345 TabPaneNMSampleList.sampleTbl!.recycleDataSource = jest.fn(() => []); 346 expect(tabPaneNMSampleList.filterAllList()).toBeUndefined(); 347 }); 348 349 it('TabPaneNMSampleListTest17', function () { 350 TabPaneNMSampleList.samplerInfoSource = [ 351 { 352 current: '', 353 currentSize: 109, 354 startTs: 95, 355 heapSize: 987, 356 snapshot: 'snapshot08', 357 growth: '', 358 total: 52, 359 totalGrowth: '', 360 existing: 1002, 361 children: [], 362 tempList: [], 363 timestamp: '', 364 eventId: 106, 365 threadId: 980, 366 threadName: '', 367 }, 368 ]; 369 TabPaneNMSampleList.filterSelect = '2'; 370 TabPaneNMSampleList.sampleTbl!.meauseTreeRowElement = jest.fn(() => { 371 return []; 372 }); 373 TabPaneNMSampleList.sampleTbl!.recycleDataSource = jest.fn(() => []); 374 expect(tabPaneNMSampleList.filterAllList()).toBeUndefined(); 375 }); 376}); 377