• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17import { TabPaneBinderDataCut } from '../../../../../../src/trace/component/trace/sheet/binder/TabPaneBinderDataCut';
18import '../../../../../../src/trace/component/trace/sheet/binder/TabPaneBinderDataCut';
19import { LitTable } from '../../../../../../src/base-ui/table/lit-table';
20import { SpSegmentationChart } from '../../../../../../src/trace/component/chart/SpSegmentationChart';
21import { TraceRow } from '../../../../../../src/trace/component/trace/base/TraceRow';
22import { BinderStruct } from '../../../../../../src/trace/database/ui-worker/procedureWorkerBinder';
23import { SpSystemTrace } from '../../../../../../src/trace/component/SpSystemTrace';
24
25const processSqlite = require('../../../../../../src/trace/database/sql/ProcessThread.sql');
26jest.mock('../../../../../../src/trace/database/sql/ProcessThread.sql');
27const sqlite = require('../../../../../../src/trace/database/sql/Func.sql');
28jest.mock('../../../../../../src/trace/database/sql/Func.sql');
29jest.mock('../../../../../../src/trace/component/trace/base/TraceSheet', () => {
30});
31jest.mock('../../../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
32  return {};
33});
34jest.mock('../../../../../../src/trace/database/ui-worker/cpu/ProcedureWorkerCPU', () => {
35  return {};
36});
37jest.mock('../../../../../../src/trace/component/trace/timer-shaft/RangeRuler', () => {
38  return {};
39});
40window.ResizeObserver =
41  window.ResizeObserver ||
42  jest.fn().mockImplementation(() => ({
43    disconnect: jest.fn(),
44    observe: jest.fn(),
45    unobserve: jest.fn(),
46  }));
47describe('TabPaneBinderDataCut Test', () => {
48  global.scrollTo = jest.fn();
49  document.body.innerHTML = `<div><tabpane-binder-datacut id="binder-datacut"></tabpane-binder-datacut></div>`;
50  let tabPaneBinderDataCut = document.querySelector<TabPaneBinderDataCut>('#binder-datacut');
51  SpSegmentationChart.binderRow = new TraceRow<BinderStruct>;
52  SpSegmentationChart.trace = new SpSystemTrace();
53  let threadIdInput = document.createElement('input');
54  threadIdInput.value = 'threadIdInput';
55  let threadFuncInput = document.createElement('input');
56  threadFuncInput.value = 'threadFuncInput';
57  let threadStatesParam = {
58    cpus: [],
59    threadIds: [1, 2, 3],
60    trackIds: [23, 56, 77],
61    funTids: [675, 75],
62    heapIds: [11, 223],
63    processIds: [114, 23],
64    nativeMemory: [],
65    leftNs: 12222,
66    rightNs: 654233,
67    hasFps: false,
68    statisticsSelectData: undefined,
69    range: {
70        refresh: true,
71    }
72  };
73  let binderItem = [{
74    title: 'test title',
75    name: 'name',
76    count: 2,
77    ts: 2536,
78    dur: 3666,
79    startTime: 3655,
80    endTime: 83663,
81    tid: 363,
82    pid: 523,
83    cycleDur: 366,
84    cycleStartTime: 3652,
85    funcName: 'funcName',
86    id: 12,
87    thread: 'thread',
88    process: 'process',
89    totalCount: 12,
90    idx: 366
91  }];
92
93  let bindGroup = [{
94    title: 'title',
95    count: 3,
96    totalCount: 3,
97    binderAsyncRcvCount: 2,
98    binderReplyCount: 6,
99    binderTransactionAsyncCount: 2,
100    binderTransactionCount: 1,
101    tid: 5,
102    pid: 36,
103    thread: 'thread',
104    process: 'process',
105    name: 'name',
106    cycleStartTime: 1222,
107    cycleDur: 366,
108    id: 65,
109    children: [],
110    type: 'loop',
111    status: false,
112    idx: 2,
113    isSelected: true
114  }]
115  SpSegmentationChart.setBinderChartData =  jest.fn();
116  tabPaneBinderDataCut.data = threadStatesParam;
117  let loopFuncNameCycle = sqlite.queryLoopFuncNameCycle;
118  let loopFuncNameCycleData = [{
119    funcName: 'funcName',
120    cycleStartTime: 1233,
121    cycleDur: 0,
122    id: 123,
123    tid: 254,
124    pid: 258
125  }];
126  loopFuncNameCycle.mockResolvedValue(loopFuncNameCycleData);
127
128  let queryBinder = processSqlite.queryBinderByThreadId;
129  let binderData = [{
130    name: 'test',
131    count: 1,
132    ts: 2533,
133    dur: 563,
134    startTime: 22554,
135    endTime: 2633333,
136    tid: 122,
137    pid: 36
138  }];
139  queryBinder.mockResolvedValue(binderData);
140
141  let queryFuncName = sqlite.queryFuncNameCycle;
142  let funcNameData = [{
143    name: 'test',
144    count: 1,
145    ts: 2533,
146    dur: 563,
147    startTime: 22554,
148    endTime: 2633333,
149    tid: 122,
150    pid: 36
151  }];
152  queryFuncName.mockResolvedValue(funcNameData);
153
154  let singleFuncName = sqlite.querySingleFuncNameCycle;
155  let singleFuncNameData = [{
156    funcName: 'funcName',
157    cycleStartTime: 2553,
158    cycleDur: 36633,
159    id: 253,
160    tid: 366,
161    pid: 369,
162    endTime: 366922
163  }];
164  singleFuncName.mockResolvedValue(singleFuncNameData);
165  let data = [
166    {
167      cycleStartTime: 2677246000,
168      dur: 154698000,
169      id: 5567,
170      tid: 2532,
171      pid: 2519
172    },
173    {
174      cycleStartTime: 3093830000,
175      dur: 133540000,
176      id: 6417,
177      tid: 2532,
178      pid: 2519
179    },
180    {
181      cycleStartTime: 3873240000,
182      dur: 149769000,
183      id: 8045,
184      tid: 2532,
185      pid: 2519
186    },
187    {
188      cycleStartTime: 5546299000,
189      dur: 148508000,
190      id: 18380,
191      tid: 2532,
192      pid: 2519
193    },
194    {
195      cycleStartTime: 5935477000,
196      dur: 178657000,
197      id: 20853,
198      tid: 2532,
199      pid: 2519
200    },
201    {
202      cycleStartTime: 8979430000,
203      dur: 151986000,
204      id: 61239,
205      tid: 2532,
206      pid: 2519
207    },
208    {
209      cycleStartTime: 10574029000,
210      dur: 154463000,
211      id: 70140,
212      tid: 2532,
213      pid: 2519
214    }
215  ];
216  it('TabPaneBinderDataCutTest01 ',  () => {
217    tabPaneBinderDataCut.dataCutFunc(threadIdInput, threadFuncInput, 'loop');
218    expect(tabPaneBinderDataCut.threadBindersTbl.loading).toBeUndefined();
219  });
220
221  it('TabPaneBinderDataCutTest02 ',  () => {
222    tabPaneBinderDataCut.verifyInputIsEmpty('', '', threadIdInput, threadFuncInput);
223    expect(tabPaneBinderDataCut.threadBindersTbl.loading).toBeFalsy();
224  });
225
226  it('TabPaneBinderDataCutTest03 ',  () => {
227    tabPaneBinderDataCut.clearCycleRange();
228    expect(tabPaneBinderDataCut.cycleAStartRangeDIV.value).toEqual('');
229  });
230
231  it('TabPaneBinderDataCutTest04 ',  () => {
232    tabPaneBinderDataCut.singleDataCutCycleMap(data);
233    tabPaneBinderDataCut.loopDataCutCycleMap(data);
234    let cycData = [
235      {
236        title: "cycle 1_ACCS0",
237        tid: 2716,
238        pid: 2519,
239        durNs: 416584000,
240        tsNs: 2677246000,
241        cycleDur: 416.584,
242        cycleStartTime: 2677.246,
243        totalCount: 214,
244        binderTransactionCount: 214,
245        binderAsyncRcvCount: 0,
246        binderReplyCount: 0,
247        binderTransactionAsyncCount: 0,
248        idx: 1,
249        type: "Cycle",
250        isHover: false
251      },
252      {
253        title: "cycle 2_ACCS0",
254        tid: 2716,
255        pid: 2519,
256        durNs: 368880000,
257        tsNs: 3093830000,
258        cycleDur: 368.88,
259        cycleStartTime: 3093.83,
260        totalCount: 198,
261        binderTransactionCount: 198,
262        binderAsyncRcvCount: 0,
263        binderReplyCount: 0,
264        binderTransactionAsyncCount: 0,
265        idx: 2,
266        type: "Cycle",
267        isHover: false
268      },
269      {
270        title: "cycle 6_ACCS0",
271        tid: 2716,
272        pid: 2519,
273        durNs: 458350000,
274        tsNs: 4706839000,
275        cycleDur: 458.35,
276        cycleStartTime: 4706.839,
277        totalCount: 200,
278        binderTransactionCount: 200,
279        binderAsyncRcvCount: 0,
280        binderReplyCount: 0,
281        binderTransactionAsyncCount: 0,
282        idx: 6,
283        type: "Cycle",
284        isHover: false
285      },
286      {
287        title: "cycle 10_ACCS0",
288        tid: 2716,
289        pid: 2519,
290        durNs: 465838000,
291        tsNs: 6408752000,
292        cycleDur: 465.838,
293        cycleStartTime: 6408.752,
294        totalCount: 217,
295        binderTransactionCount: 217,
296        binderAsyncRcvCount: 0,
297        binderReplyCount: 0,
298        binderTransactionAsyncCount: 0,
299        idx: 10,
300        type: "Cycle",
301        isHover: false
302      },
303      {
304        title: "cycle 12_ACCS0",
305        tid: 2716,
306        pid: 2519,
307        durNs: 631522000,
308        tsNs: 7411421000,
309        cycleDur: 631.522,
310        cycleStartTime: 7411.421,
311        totalCount: 248,
312        binderTransactionCount: 248,
313        binderAsyncRcvCount: 0,
314        binderReplyCount: 0,
315        binderTransactionAsyncCount: 0,
316        idx: 12,
317        type: "Cycle",
318        isHover: false
319      },
320      {
321        title: "cycle 14_ACCS0",
322        tid: 2716,
323        pid: 2519,
324        durNs: 470715000,
325        tsNs: 8508715000,
326        cycleDur: 470.715,
327        cycleStartTime: 8508.715,
328        totalCount: 252,
329        binderTransactionCount: 252,
330        binderAsyncRcvCount: 0,
331        binderReplyCount: 0,
332        binderTransactionAsyncCount: 0,
333        idx: 14,
334        type: "Cycle",
335        isHover: false
336      },
337      {
338        title: "cycle 18_ACCS0",
339        tid: 2716,
340        pid: 2519,
341        durNs: 394807000,
342        tsNs: 10179222000,
343        cycleDur: 394.807,
344        cycleStartTime: 10179.222,
345        totalCount: 225,
346        binderTransactionCount: 225,
347        binderAsyncRcvCount: 0,
348        binderReplyCount: 0,
349        binderTransactionAsyncCount: 0,
350        idx: 18,
351        type: "Cycle",
352        isHover: false
353      }
354    ]
355    expect(tabPaneBinderDataCut.structuredLaneChartData(cycData)).toEqual([[{
356      "cycle": 1,
357      "dur": 416584000,
358      "name": "binder transaction",
359      "startNS": 2677246000,
360      "value": 214,
361    }], [{
362      "cycle": 2,
363      "dur": 368880000,
364      "name": "binder transaction",
365      "startNS": 3093830000,
366      "value": 198,
367    }], [{
368      "cycle": 6,
369      "dur": 458350000,
370      "name": "binder transaction",
371      "startNS": 4706839000,
372      "value": 200,
373    }], [{
374      "cycle": 10,
375      "dur": 465838000,
376      "name": "binder transaction",
377      "startNS": 6408752000,
378      "value": 217,
379    }], [{
380      "cycle": 12,
381      "dur": 631522000,
382      "name": "binder transaction",
383      "startNS": 7411421000,
384      "value": 248,
385    }], [{
386      "cycle": 14,
387      "dur": 470715000,
388      "name": "binder transaction",
389      "startNS": 8508715000,
390      "value": 252,
391    }], [{
392      "cycle": 18,
393      "dur": 394807000,
394      "name": "binder transaction",
395      "startNS": 10179222000,
396      "value": 225,
397    }]]);
398  });
399
400  it('TabPaneBinderDataCutTest05 ',  () => {
401    let clickData = {
402      pid: 2519,
403      title: "tutu.ABenchMark [2519]",
404      totalCount: 4097,
405      type: "Process",
406      children: [
407        {
408          title: "ACCS0 [2716]",
409          totalCount: 4097,
410          tid: 2716,
411          pid: 2519,
412          children: [
413            {
414              title: "cycle 1_ACCS0",
415              tid: 2716,
416              pid: 2519,
417              durNs: 416584000,
418              tsNs: 2677246000,
419              cycleDur: 416.584,
420              cycleStartTime: 2677.246,
421              totalCount: 214,
422              binderTransactionCount: 214,
423              binderAsyncRcvCount: 0,
424              binderReplyCount: 0,
425              binderTransactionAsyncCount: 0,
426              idx: 1,
427              type: "Cycle"
428            },
429            {
430              title: "cycle 3_ACCS0",
431              tid: 2716,
432              pid: 2519,
433              durNs: 410530000,
434              tsNs: 3462710000,
435              cycleDur: 410.53,
436              cycleStartTime: 3462.71,
437              totalCount: 216,
438              binderTransactionCount: 216,
439              binderAsyncRcvCount: 0,
440              binderReplyCount: 0,
441              binderTransactionAsyncCount: 0,
442              idx: 3,
443              type: "Cycle"
444            },
445            {
446              title: "cycle 17_ACCS0",
447              tid: 2716,
448              pid: 2519,
449              durNs: 295990000,
450              tsNs: 9883232000,
451              cycleDur: 295.99,
452              cycleStartTime: 9883.232,
453              totalCount: 171,
454              binderTransactionCount: 171,
455              binderAsyncRcvCount: 0,
456              binderReplyCount: 0,
457              binderTransactionAsyncCount: 0,
458              idx: 17,
459              type: "Cycle"
460            },
461            {
462              title: "cycle 18_ACCS0",
463              tid: 2716,
464              pid: 2519,
465              durNs: 394807000,
466              tsNs: 10179222000,
467              cycleDur: 394.807,
468              cycleStartTime: 10179.222,
469              totalCount: 225,
470              binderTransactionCount: 225,
471              binderAsyncRcvCount: 0,
472              binderReplyCount: 0,
473              binderTransactionAsyncCount: 0,
474              idx: 18,
475              type: "Cycle"
476            }
477          ],
478          type: "Thread",
479          isHover: false,
480          status: true,
481          isSelected: true
482        }
483      ],
484      isHover: false
485    }
486    tabPaneBinderDataCut.tHeadClick(clickData);
487    tabPaneBinderDataCut.drawColumn();
488    expect(tabPaneBinderDataCut.chartTotal.config.appendPadding).toEqual(10);
489  });
490
491  it('TabPaneBinderDataCutTest06 ',  () => {
492    let itemRowClick = new CustomEvent('row-click', <CustomEventInit>{
493      detail: {
494        ...{},
495        data: {
496          tid: 1,
497          pid: 2,
498          type: 'Process',
499          isSelected: false
500        },
501      }
502    });
503    tabPaneBinderDataCut.tableRowClickFunc();
504    tabPaneBinderDataCut.threadBindersTbl.dispatchEvent(itemRowClick);
505    expect(tabPaneBinderDataCut.hasAttribute('hideQueryArea')).toBeTruthy();
506  });
507
508  it('TabPaneBinderDataCutTest7 ',  () => {
509    let itemRowClick = new CustomEvent('row-click', <CustomEventInit>{
510      detail: {
511        ...{},
512        data: {
513          tid: 1,
514          pid: 2,
515          type: 'Thread',
516          isSelected: false
517        },
518      }
519    });
520    tabPaneBinderDataCut.structuredLaneChartData = jest.fn();
521    SpSegmentationChart.setBinderChartData = jest.fn();
522    tabPaneBinderDataCut.tableRowClickFunc();
523    tabPaneBinderDataCut.threadBindersTbl.dispatchEvent(itemRowClick);
524    expect(tabPaneBinderDataCut.hasAttribute('hideQueryArea')).toBeFalsy();
525  });
526
527  it('TabPaneBinderDataCutTest8 ',  () => {
528    let itemRowClick = new CustomEvent('row-click', <CustomEventInit>{
529      detail: {
530        ...{},
531        data: {
532          tid: 1,
533          pid: 2,
534          type: 'Cycle',
535          isSelected: false
536        },
537      }
538    });
539    tabPaneBinderDataCut.tableRowClickFunc();
540    tabPaneBinderDataCut.threadBindersTbl.dispatchEvent(itemRowClick);
541    expect(tabPaneBinderDataCut.hasAttribute('hideQueryArea')).toBeFalsy();
542  });
543
544  it('TabPaneBinderDataCutTest9 ',  () => {
545    let itemRowClick = new CustomEvent('click', <CustomEventInit>{
546      detail: {
547        ...{},
548        data: {
549          tid: 1,
550          pid: 2,
551          type: 'Cycle',
552          isSelected: false
553        },
554      }
555    });
556    tabPaneBinderDataCut.queryBtnClick();
557    tabPaneBinderDataCut.shadowRoot?.querySelector('#query-btn').dispatchEvent(itemRowClick);
558    expect(tabPaneBinderDataCut.hasAttribute('hideQueryArea')).toBeFalsy();
559  });
560});
561