• 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 {
18  getTimeString,
19  TabPaneCurrentSelection,
20} from '../../../../../dist/trace/component/trace/sheet/TabPaneCurrentSelection.js';
21const sqlite = require('../../../../../dist/trace/database/SqlLite.js');
22jest.mock('../../../../../dist/trace/database/SqlLite.js');
23
24describe('TabPaneCurrentSelection Test', () => {
25  let tabPaneCurrentSelection = new TabPaneCurrentSelection();
26
27  const canvas = document.createElement('canvas');
28  canvas.width = 1;
29  canvas.height = 1;
30  let context = canvas.getContext('2d');
31
32  let cpuData = [
33    {
34      cpu: 1,
35      dur: 1,
36      end_state: 'string',
37      id: 12,
38      name: 'name',
39      priority: 11,
40      processCmdLine: 'processCmdLine',
41      processId: 1111,
42      processName: 'processName',
43      schedId: 221,
44      startTime: 0,
45      tid: 1001,
46      type: 'type',
47    },
48  ];
49  let functionData = [
50    {
51      argsetid: 53161,
52      depth: 0,
53      dur: 570000,
54      funName: 'binder transaction',
55      id: 92749,
56      is_main_thread: 0,
57      parent_id: null,
58      startTs: 9729867000,
59      threadName: 'Thread-15',
60      tid: 2785,
61    },
62  ];
63  let memData = [
64    {
65      trackId: 100,
66      processName: 'processName',
67      pid: 11,
68      upid: 1,
69      trackName: 'trackName',
70      type: 'type',
71      track_id: 'track_id',
72      value: 111,
73      startTime: 0,
74      duration: 1000,
75      maxValue: 4000,
76      delta: 2,
77    },
78  ];
79  let threadData = [
80    {
81      hasSched: 14724852000,
82      pid: 2519,
83      processName: null,
84      threadName: 'ACCS0',
85      tid: 2716,
86      upid: 1,
87      utid: 1,
88      cpu: null,
89      dur: 405001,
90      end_ts: null,
91      id: 11,
92      is_main_thread: 0,
93      name: 'ACCS0',
94      startTime: 58001,
95      start_ts: null,
96      state: 'S',
97      type: 'thread',
98    },
99  ];
100  let wakeupBean = [
101    {
102      wakeupTime: 0,
103      cpu: 1,
104      process: 'process',
105      pid: 11,
106      thread: 'thread',
107      tid: 22,
108      schedulingLatency: 33,
109      schedulingDesc: 'schedulingDesc',
110    },
111  ];
112
113  let queryData = [
114    {
115      id: 1,
116      startTime: 0,
117      hasSched: 14724852000,
118      pid: 2519,
119      processName: null,
120      threadName: 'ACCS0',
121      tid: 2716,
122      upid: 1,
123      utid: 1,
124      cpu: null,
125      dur: 405002,
126      end_ts: null,
127      is_main_thread: 2,
128      name: 'ACCS0',
129      start_ts: null,
130      state: 'S',
131      type: 'thread',
132    },
133  ];
134  let scrollWakeUp = [
135    {
136      startTime: 0,
137      pid: 11,
138      tid: 22,
139    },
140  ];
141  let data = [
142    {
143      cpu: 1,
144      dur: 1,
145      end_state: 'string',
146      id: 12,
147      name: 'name',
148      priority: 11,
149      processCmdLine: 'processCmdLine',
150      processId: 1112,
151      processName: 'processName',
152      schedId: 222,
153      startTime: 0,
154      tid: 1002,
155      type: 'type',
156    },
157  ];
158
159  let jankData = {
160    id: 10,
161    ts: 25415,
162    dur: 1200,
163    name: '1523',
164    depth: 1,
165    jank_tag: true,
166    cmdline: 'com.test',
167    type: '0',
168    pid: 20,
169    frame_type: 'app',
170    app_dur: 110,
171    dst_slice: 488,
172  };
173
174  let jankDataRender = {
175    id: 22,
176    ts: 254152,
177    dur: 1202,
178    name: '1583',
179    depth: 1,
180    jank_tag: true,
181    cmdline: 'render.test',
182    type: '0',
183    pid: 22,
184    frame_type: 'render_service',
185    src_slice: '525',
186    rs_ts: 2562,
187    rs_vsync: '2562',
188    rs_dur: 1528,
189    rs_pid: 1252,
190    rs_name: 'name',
191    gpu_dur: 2568,
192  };
193
194  let irqData = [
195    {
196      id: 25,
197      startNS: 1526,
198      name: 'test',
199      dur: 125,
200      argSetId: 526,
201    },
202  ];
203
204  let clockData = [
205    {
206      filterId: 96,
207      value: 253,
208      startNS: 25852,
209      dur: 125,
210      delta: 2586,
211    },
212  ];
213
214  let functionDataTest = {
215    argsetid: 53161,
216    depth: 0,
217    dur: 570000,
218    funName: 'binder async',
219    id: 92749,
220    is_main_thread: 0,
221    parent_id: null,
222    startTs: 9729867000,
223    threadName: 'Thread-15',
224    tid: 2785,
225  };
226
227  tabPaneCurrentSelection.queryWakeUpData = jest.fn(() => 'WakeUpData');
228  tabPaneCurrentSelection.queryWakeUpData.wb = jest.fn(() => null);
229  tabPaneCurrentSelection.setCpuData(cpuData, undefined, 1);
230  let argsetTest = sqlite.queryBinderArgsByArgset;
231  let argsetIdTest = sqlite.queryBinderByArgsId;
232  let argsetData = [
233    {
234      argset: 12,
235      keyName: 'test',
236      id: 123,
237      desc: 'desc',
238      strValue: 'value',
239    },
240    {
241      argset: 11,
242      keyName: 'test',
243      id: 113,
244      desc: 'desc',
245      strValue: 'value',
246    },
247  ];
248
249  let argsetIdData = [
250    {
251      type: 'func',
252      startTs: 1258,
253      dur: 25,
254      depth: 1,
255      argsetid: 258,
256    },
257  ];
258  argsetTest.mockResolvedValue(argsetData);
259  argsetIdTest.mockResolvedValue(argsetIdData);
260
261  let gpuDur = sqlite.queryGpuDur;
262  let gpuDurData = [
263    {
264      gpu_dur: 1528,
265    },
266  ];
267  gpuDur.mockResolvedValue(gpuDurData);
268
269  let queryFlows = sqlite.queryFlowsData;
270  let queryFlowsData = [
271    {
272      name: '25962',
273      pid: 1885,
274      cmdline: 'render Test',
275      type: 1,
276    },
277  ];
278  queryFlows.mockResolvedValue(queryFlowsData);
279
280  let queryPreceding = sqlite.queryPrecedingData;
281  let queryPrecedingData = [
282    {
283      name: '2596562',
284      pid: 18854,
285      cmdline: 'app Test',
286      type: 0,
287    },
288  ];
289  queryPreceding.mockResolvedValue(queryPrecedingData);
290
291  tabPaneCurrentSelection.queryWakeUpData = jest.fn(() => 'WakeUpData');
292  tabPaneCurrentSelection.queryWakeUpData.wb = jest.fn(() => null);
293  tabPaneCurrentSelection.setCpuData(cpuData, undefined, 1);
294
295  it('TabPaneCurrentSelectionTest01', function () {
296    let result = tabPaneCurrentSelection.setFunctionData(functionData);
297    expect(result).toBeUndefined();
298  });
299
300  it('TabPaneCurrentSelectionTest02', function () {
301    let result = tabPaneCurrentSelection.setMemData(memData);
302    expect(result).toBeUndefined();
303  });
304
305  it('TabPaneCurrentSelectionTest03', function () {
306    let result = getTimeString(3600_000_000_002);
307    expect(result).toBe('1h 2ns ');
308  });
309
310  it('TabPaneCurrentSelectionTest04', function () {
311    let result = getTimeString(60000000001);
312    expect(result).toBe('1m 1ns ');
313  });
314
315  it('TabPaneCurrentSelectionTest05', function () {
316    let result = getTimeString(1000000001);
317    expect(result).toBe('1s 1ns ');
318  });
319
320  it('TabPaneCurrentSelectionTest06', function () {
321    let result = getTimeString(1000001);
322    expect(result).toBe('1ms 1ns ');
323  });
324
325  it('TabPaneCurrentSelectionTest07', function () {
326    let result = getTimeString(1001);
327    expect(result).toBe('1μs 1ns ');
328  });
329
330  it('TabPaneCurrentSelectionTest08', function () {
331    let result = getTimeString(101);
332    expect(result).toBe('101ns ');
333  });
334
335  it('TabPaneCurrentSelectionTest09', function () {
336    tabPaneCurrentSelection.setCpuData = jest.fn(() => true);
337    tabPaneCurrentSelection.data = jest.fn(() => true);
338    expect(tabPaneCurrentSelection.data).toBeUndefined();
339  });
340
341  it('TabPaneCurrentSelectionTest10', function () {
342    expect(tabPaneCurrentSelection.setCpuData(cpuData, undefined, 1)).toBeTruthy();
343  });
344
345  it('TabPaneCurrentSelectionTest13', function () {
346    expect(tabPaneCurrentSelection.initCanvas()).not.toBeUndefined();
347  });
348
349  it('TabPaneCurrentSelectionTest14', function () {
350    let str = {
351      length: 0,
352    };
353    expect(tabPaneCurrentSelection.transferString(str)).toBe('');
354  });
355
356  it('TabPaneCurrentSelectionTest16', function () {
357    expect(tabPaneCurrentSelection.drawRight(null)).toBeUndefined();
358  });
359
360  it('TabPaneCurrentSelectionTest01', function () {
361    let result = tabPaneCurrentSelection.setFunctionData(functionData);
362    expect(result).toBeUndefined();
363  });
364
365  it('TabPaneCurrentSelectionTest02', function () {
366    let result = tabPaneCurrentSelection.setMemData(memData);
367    expect(result).toBeUndefined();
368  });
369
370  it('TabPaneCurrentSelectionTest12', function () {
371    let result = tabPaneCurrentSelection.setJankData(jankData, undefined, 1);
372    expect(result).toBeUndefined();
373  });
374
375  it('TabPaneCurrentSelectionTest13', function () {
376    let result = tabPaneCurrentSelection.setJankData(jankDataRender, undefined, 1);
377    expect(result).toBeUndefined();
378  });
379
380  it('TabPaneCurrentSelectionTest14', function () {
381    let result = tabPaneCurrentSelection.setIrqData(irqData);
382    expect(result).toBeUndefined();
383  });
384
385  it('TabPaneCurrentSelectionTest16', function () {
386    let result = tabPaneCurrentSelection.setClockData(clockData);
387    expect(result).toBeUndefined();
388  });
389
390  it('TabPaneCurrentSelectionTest17', function () {
391    let result = tabPaneCurrentSelection.setFunctionData(functionDataTest);
392    expect(result).toBeUndefined();
393  });
394  it('TabPaneCurrentSelectionTest18', function () {
395    let result = tabPaneCurrentSelection.setStartupData(irqData, 1);
396    expect(result).toBeUndefined();
397  });
398  it('TabPaneCurrentSelectionTest19', function () {
399    let result = tabPaneCurrentSelection.setStaticInitData(irqData, 1);
400    expect(result).toBeUndefined();
401  });
402  it('TabPaneCurrentSelectionTest20', function () {
403    let list: never[] = [];
404    let data = [
405      {
406        jank_tag: 1,
407        frame_type: 'render_service',
408      },
409    ];
410    let result = tabPaneCurrentSelection.setJankType(data, list);
411    expect(result).toBeUndefined();
412  });
413});
414