• 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// @ts-ignore
17import { SpProcessChart } from '../../../../dist/trace/component/chart/SpProcessChart.js';
18const sqlit = require('../../../../dist/trace/database/SqlLite.js');
19jest.mock('../../../../dist/trace/database/SqlLite.js');
20
21jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => {
22  return {};
23});
24
25const intersectionObserverMock = () => ({
26  observe: () => null,
27});
28window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
29import { SpChartManager } from '../../../../dist/trace/component/chart/SpChartManager.js';
30// @ts-ignore
31window.ResizeObserver = window.ResizeObserver || jest.fn().mockImplementation(() => ({
32    observe: jest.fn(),
33    unobserve: jest.fn(),
34    disconnect: jest.fn(),
35  }));
36
37describe('SpProcessChart Test', () => {
38  let manager = new SpChartManager();
39  let spProcessChart = new SpProcessChart(manager);
40  let MockqueryProcessAsyncFunc = sqlit.queryProcessAsyncFunc;
41
42  MockqueryProcessAsyncFunc.mockResolvedValue([
43    {
44      tid: 1,
45      pid: 1,
46      threadName: '1',
47      track_id: 3,
48      startTs: 1111,
49      dur: 2000000,
50      funName: 'deliverInputEvent',
51      parent_id: 4,
52      id: 5,
53      cookie: 'ff',
54      depth: 5,
55      argsetid: 6,
56    },
57  ]);
58  let processContentCount = sqlit.queryProcessContentCount;
59  processContentCount.mockResolvedValue([
60    {
61      pid: 1,
62      switch_count: 2,
63      thread_count: 3,
64      slice_count: 4,
65      mem_count: 5,
66    },
67  ]);
68  let queryProcessThreads = sqlit.queryProcessThreads;
69  queryProcessThreads.mockResolvedValue([
70    {
71      utid: 1,
72      hasSched: 0,
73      pid: 1,
74      tid: 4,
75      processName: 'process',
76      threadName: 'thread',
77    },
78  ]);
79  let queryProcessThreadsByTable = sqlit.queryProcessThreadsByTable;
80  queryProcessThreadsByTable.mockResolvedValue([
81    {
82      pid: 1,
83      tid: 0,
84      processName: 'process',
85      threadName: 'thread',
86    },
87  ]);
88  let getAsyncEvents = sqlit.getAsyncEvents;
89  getAsyncEvents.mockResolvedValue([
90    {
91      pid: 1,
92      startTime: 100000,
93    },
94  ]);
95  let queryProcessMem = sqlit.queryProcessMem;
96  queryProcessMem.mockResolvedValue([
97    {
98      trackId: 1,
99      trackName: 'trackName',
100      upid: 2,
101      pid: 1,
102      processName: 'processName',
103    },
104  ]);
105  let queryEventCountMap = sqlit.queryEventCountMap;
106  queryEventCountMap.mockResolvedValue([
107    {
108      eventName: 'eventName',
109      count: 1,
110    },
111  ]);
112  let queryProcess = sqlit.queryProcess;
113  queryProcess.mockResolvedValue([
114    {
115      pid: 1,
116      processName: 'processName',
117    },
118  ]);
119
120  let queryProcessByTable = sqlit.queryProcessByTable;
121  queryProcessByTable.mockResolvedValue([
122    {
123      pid: 2,
124      processName: 'processName',
125    },
126  ]);
127
128  let getMaxDepthByTid = sqlit.getMaxDepthByTid;
129  getMaxDepthByTid.mockResolvedValue([
130    {
131      tid: 1,
132      maxDepth: 1,
133    },
134    {
135      tid: 2,
136      maxDepth: 2,
137    },
138  ]);
139  let queryAllJankProcess = sqlit.queryAllJankProcess;
140  queryAllJankProcess.mockResolvedValue([
141    {
142      pid: 1,
143    },
144  ]);
145
146  let queryAllExpectedData = sqlit.queryAllExpectedData;
147  queryAllExpectedData.mockResolvedValue([
148    {
149      id: 41,
150      ts: 749660047,
151      name: 1159,
152      type: 1,
153      dur: 16657682,
154      pid: 1242,
155      cmdline: 'render_service',
156    },
157    {
158      id: 45,
159      ts: 766321174,
160      name: 1160,
161      type: 1,
162      dur: 16657682,
163      pid: 1,
164      cmdline: 'render_service',
165    },
166  ]);
167
168  let queryAllActualData = sqlit.queryAllActualData;
169  queryAllActualData.mockResolvedValue([
170    {
171      id: 40,
172      ts: 750328000,
173      name: 1159,
174      type: 0,
175      dur: 22925000,
176      src_slice: '36',
177      jank_tag: 1,
178      dst_slice: null,
179      pid: 1242,
180      cmdline: 'render_service',
181      frame_type: 'render_service',
182    },
183    {
184      id: 44,
185      ts: 773315000,
186      name: 1160,
187      type: 0,
188      dur: 17740000,
189      src_slice: '38,42',
190      jank_tag: 1,
191      dst_slice: null,
192      pid: 1,
193      cmdline: 'render_service',
194      frame_type: 'render_service',
195    },
196  ]);
197
198  let queryAllTaskPoolPid = sqlit.queryAllTaskPoolPid;
199  queryAllTaskPoolPid.mockResolvedValue([
200    {
201      pid: 1,
202    },
203    {
204      id: 2,
205    },
206  ]);
207
208  let queryProcessStartup = sqlit.queryProcessStartup;
209  queryProcessStartup.mockResolvedValue([
210    {
211      'pid': 3913,
212      'tid': 3913,
213      'itid': 366,
214      'startTs': 5651745832,
215      'dur': 38654167,
216      'startName': 0,
217      'endItid': 341,
218      'frame': {
219        'y': 5,
220        'height': 20,
221        'x': 1154,
222        'width': 9
223      },
224      'v': true,
225      'stepName': 'Process Creating (38.65ms)',
226      'textMetricsWidth': 129.072265625
227    },
228    {
229      'pid': 3913,
230      'tid': 3913,
231      'itid': 341,
232      'startTs': 5690399999,
233      'dur': 43619792,
234      'startName': 1,
235      'endItid': 486,
236      'frame': {
237        'y': 5,
238        'height': 20,
239        'x': 1162,
240        'width': 10
241      },
242      'v': true,
243      'stepName': 'Application Launching (43.62ms)',
244      'textMetricsWidth': 156.416015625
245    },
246    {
247      'pid': 3913,
248      'tid': 3913,
249      'itid': 486,
250      'startTs': 5734019791,
251      'dur': 23194270,
252      'startName': 2,
253      'endItid': 486,
254      'frame': {
255        'y': 5,
256        'height': 20,
257        'x': 1171,
258        'width': 6
259      },
260      'v': true
261    },
262    {
263      'pid': 3913,
264      'tid': 3913,
265      'itid': 486,
266      'startTs': 5757214061,
267      'dur': 115679167,
268      'startName': 3,
269      'endItid': 486,
270      'frame': {
271        'y': 5,
272        'height': 20,
273        'x': 1176,
274        'width': 24
275      },
276      'v': true,
277      'stepName': 'UI Ability OnForeground (115.68ms)',
278      'textMetricsWidth': 172.59765625
279    },
280    {
281      'pid': 3913,
282      'tid': 3913,
283      'itid': 486,
284      'startTs': 5872893228,
285      'dur': 62756250,
286      'startName': 4,
287      'frame': {
288        'y': 5,
289        'height': 20,
290        'x': 1199,
291        'width': 14
292      },
293      'v': true,
294      'stepName': 'First Frame - APP Phase (62.76ms)',
295      'textMetricsWidth': 162.9638671875
296    },
297    {
298      'pid': 3913,
299      'tid': 3913,
300      'itid': 17,
301      'startTs': 5968040103,
302      'dur': 29438021,
303      'startName': 5,
304      'frame': {
305        'y': 5,
306        'height': 20,
307        'x': 1219,
308        'width': 7
309      },
310      'v': true
311    }
312  ]);
313
314  let queryProcessSoInitData = sqlit.queryProcessSoInitData;
315  queryProcessSoInitData.mockResolvedValue([
316    {
317      'pid': 3913,
318      'tid': 3913,
319      'itid': 486,
320      'startTs': 5678439061,
321      'dur': 1137500,
322      'soName': ' /system/lib64/seccomp/libapp_filter.z.so',
323      'depth': 0,
324      'frame': {
325        'x': 1160,
326        'y': 0,
327        'width': 1,
328        'height': 20
329      }
330    },
331    {
332      'pid': 3913,
333      'tid': 3913,
334      'itid': 486,
335      'startTs': 5682777082,
336      'dur': 1130729,
337      'soName': ' /system/lib64/libhidebug.so',
338      'depth': 0,
339      'frame': {
340        'x': 1160,
341        'y': 0,
342        'width': 1,
343        'height': 20
344      }
345    },
346    {
347      'pid': 3913,
348      'tid': 3913,
349      'itid': 486,
350      'startTs': 5696226041,
351      'dur': 4319791,
352      'soName': ' system/lib64/extensionability/libinputmethod_extension_module.z.so',
353      'depth': 0,
354      'frame': {
355        'x': 1163,
356        'y': 0,
357        'width': 1,
358        'height': 20
359      }
360    },
361    {
362      'pid': 3913,
363      'tid': 3913,
364      'itid': 486,
365      'startTs': 5700671874,
366      'dur': 4128125,
367      'soName': ' system/lib64/extensionability/libbackup_extension_ability_native.z.so',
368      'depth': 0,
369      'frame': {
370        'x': 1164,
371        'y': 0,
372        'width': 1,
373        'height': 20
374      }
375    },
376    {
377      'pid': 3913,
378      'tid': 3913,
379      'itid': 486,
380      'startTs': 5704894270,
381      'dur': 2187500,
382      'soName': ' system/lib64/extensionability/libwindow_extension_module.z.so',
383      'depth': 0,
384      'frame': {
385        'x': 1165,
386        'y': 0,
387        'width': 1,
388        'height': 20
389      }
390    },
391    {
392      'pid': 3913,
393      'tid': 3913,
394      'itid': 486,
395      'startTs': 5707165624,
396      'dur': 1503125,
397      'soName': ' system/lib64/extensionability/libdatashare_ext_ability_module.z.so',
398      'depth': 0,
399      'frame': {
400        'x': 1165,
401        'y': 0,
402        'width': 1,
403        'height': 20
404      }
405    },
406    {
407      'pid': 3913,
408      'tid': 3913,
409      'itid': 486,
410      'startTs': 5708719791,
411      'dur': 2018229,
412      'soName': ' system/lib64/extensionability/libpush_extension.z.so',
413      'depth': 0,
414      'frame': {
415        'x': 1166,
416        'y': 0,
417        'width': 1,
418        'height': 20
419      }
420    },
421    {
422      'pid': 3913,
423      'tid': 3913,
424      'itid': 486,
425      'startTs': 5710788020,
426      'dur': 846875,
427      'soName': ' system/lib64/extensionability/libenterprise_admin_extension_module.z.so',
428      'depth': 0,
429      'frame': {
430        'x': 1166,
431        'y': 0,
432        'width': 1,
433        'height': 20
434      }
435    },
436    {
437      'pid': 3913,
438      'tid': 3913,
439      'itid': 486,
440      'startTs': 5711693749,
441      'dur': 1522917,
442      'soName': ' system/lib64/extensionability/libstatic_subscriber_extension_module.z.so',
443      'depth': 0,
444      'frame': {
445        'x': 1166,
446        'y': 0,
447        'width': 1,
448        'height': 20
449      }
450    },
451    {
452      'pid': 3913,
453      'tid': 3913,
454      'itid': 486,
455      'startTs': 5713377603,
456      'dur': 1327604,
457      'soName': ' system/lib64/extensionability/libui_extension_module.z.so',
458      'depth': 0,
459      'frame': {
460        'x': 1167,
461        'y': 0,
462        'width': 1,
463        'height': 20
464      }
465    },
466    {
467      'pid': 3913,
468      'tid': 3913,
469      'itid': 486,
470      'startTs': 5714757291,
471      'dur': 2567187,
472      'soName': ' system/lib64/extensionability/libauthorization_extension_module.z.so',
473      'depth': 0,
474      'frame': {
475        'x': 1167,
476        'y': 0,
477        'width': 1,
478        'height': 20
479      }
480    },
481    {
482      'pid': 3913,
483      'tid': 3913,
484      'itid': 486,
485      'startTs': 5717385936,
486      'dur': 2341146,
487      'soName': ' system/lib64/extensionability/libaccessibility_extension_module.z.so',
488      'depth': 0,
489      'frame': {
490        'x': 1167,
491        'y': 0,
492        'width': 1,
493        'height': 20
494      }
495    },
496    {
497      'pid': 3913,
498      'tid': 3913,
499      'itid': 486,
500      'startTs': 5719780728,
501      'dur': 1603646,
502      'soName': ' system/lib64/extensionability/libservice_extension_module.z.so',
503      'depth': 0,
504      'frame': {
505        'x': 1168,
506        'y': 0,
507        'width': 1,
508        'height': 20
509      }
510    },
511    {
512      'pid': 3913,
513      'tid': 3913,
514      'itid': 486,
515      'startTs': 5721437499,
516      'dur': 1314583,
517      'soName': ' system/lib64/extensionability/libworkschedextension.z.so',
518      'depth': 0,
519      'frame': {
520        'x': 1168,
521        'y': 0,
522        'width': 1,
523        'height': 20
524      }
525    }
526  ]);
527
528  spProcessChart.setAttribute = jest.fn();
529  spProcessChart.addChildTraceRow = jest.fn();
530  it('SpProcessChart01', function () {
531    spProcessChart.initAsyncFuncData();
532    spProcessChart.init();
533    expect(spProcessChart).toBeDefined();
534  });
535
536  it('SpProcessChart02', function () {
537    expect(spProcessChart.initAsyncFuncData()).not.toBeUndefined();
538  });
539
540  it('SpProcessChart03', function () {
541    spProcessChart.initAsyncFuncData();
542    spProcessChart.initDeliverInputEvent();
543    expect(spProcessChart.processAsyncFuncArray.length).toEqual(1);
544  });
545
546  it('SpProcessChart04', function () {
547    let startUpRow = spProcessChart.addStartUpRow(spProcessChart);
548    expect(startUpRow).not.toBeUndefined();
549  });
550
551  it('SpProcessChart05', function () {
552    let soInitRow = spProcessChart.addSoInitRow(spProcessChart, 1);
553    expect(soInitRow).not.toBeUndefined();
554  });
555});
556