• 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
16import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow';
17jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
18  return {};
19});
20import {
21  HiPerfProcessStruct,
22  HiperfProcessRender2,
23} from '../../../../src/trace/database/ui-worker/hiperf/ProcedureWorkerHiPerfProcess2';
24import { hiPerf } from '../../../../src/trace/database/ui-worker/ProcedureWorkerCommon';
25jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
26  return {};
27});
28describe('ProcedureWorkerHiPerfProcess Test', () => {
29  it('ProcedureWorkerHiPerfProcessTest01', () => {
30    const data = {
31      frame: undefined,
32      cpu: 1,
33      startNs: 41,
34      value: 41,
35    };
36    const canvas = document.createElement('canvas');
37    canvas.width = 1;
38    canvas.height = 2;
39    const ctx = canvas.getContext('2d');
40    expect(HiPerfProcessStruct.draw(ctx, '', data, true)).toBeUndefined();
41  });
42
43  it('ProcedureWorkerHiPerfProcessTest02', function () {
44    let dataList = new Array();
45    dataList.push({
46      startNS: 0,
47      dur: 10,
48      length: 1,
49      frame: { x: 0, y: 9, width: 10, height: 10 },
50    });
51    dataList.push({ startNS: 1, dur: 2, length: 1 });
52    hiPerf(dataList, [{ length: 0 }], dataList, 8, 3, '', true, 1, true);
53  });
54
55  it('ProcedureWorkerHiPerfProcessTest03', function () {
56    let dataList = new Array();
57    dataList.push({
58      startNS: 0,
59      dur: 10,
60      length: 1,
61      frame: { x: 0, y: 9, width: 10, height: 10 },
62    });
63    dataList.push({ startNS: 1, dur: 2, length: 1 });
64    hiPerf(dataList, [{ length: 0 }], dataList, 8, 3, '', false, 1, false);
65  });
66
67  it('ProcedureWorkerHiPerfProcessTest04', function () {
68    expect(HiPerfProcessStruct.groupBy10MS([{ a: '1', b: 2, c: 3 }], 10)).toEqual([
69      { dur: 10000000, height: NaN, eventCount: undefined, startNS: NaN, sampleCount : 1},
70    ]);
71  });
72
73  it('ProcedureWorkerHiPerfProcessTest05', function () {
74    let hiperfProcessRender = new HiperfProcessRender2();
75    let hiperfProcessReq = {
76      lazyRefresh: true,
77      type: '',
78      startNS: 1,
79      endNS: 12,
80      totalNS: 11,
81      frame: {
82        x: 145,
83        y: 202,
84        width: 110,
85        height: 101,
86      },
87      useCache: false,
88      range: {
89        refresh: '',
90      },
91      canvas: 's',
92      context: {
93        font: '11px sans-serif',
94        fillStyle: '#ec407a',
95        globalAlpha: 0.3,
96        clearRect: jest.fn(() => true),
97        beginPath: jest.fn(() => true),
98        fillText: jest.fn(() => true),
99        fill: jest.fn(() => false),
100        stroke: jest.fn(() => true),
101        closePath: jest.fn(() => true),
102        measureText: jest.fn(() => ''),
103        fillRect: jest.fn(() => true),
104      },
105      lineColor: '',
106      isHover: '',
107      hoverX: 1,
108      params: 'q',
109      wakeupBean: undefined,
110      flagMoveInfo: '',
111      flagSelectedInfo: '',
112      slicesTime: 7,
113      id: 1,
114      x: 27,
115      y: 27,
116      width: 100,
117      height: 100,
118      scale: 100_070_001,
119    };
120    window.postMessage = jest.fn(() => true);
121    expect(hiperfProcessRender.render(hiperfProcessReq, [], [], [])).toBeUndefined();
122  });
123  it('ProcedureWorkerHiPerfProcessTest06', function () {
124    let hiperfProcessRender = new HiperfProcessRender2();
125    let canvas = document.createElement('canvas') as HTMLCanvasElement;
126    let context = canvas.getContext('2d');
127    const data = {
128      context: context!,
129      useCache: true,
130      type: '',
131      traceRange: [],
132    };
133    window.postMessage = jest.fn(() => true);
134    expect(hiperfProcessRender.renderMainThread(data, new TraceRow())).toBeUndefined();
135  });
136});
137