• 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 { func, SampleRender, SampleStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerBpftrace';
21import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect';
22jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
23  return {};
24});
25jest
26  .spyOn(require('../../../../src/trace/database/ui-worker/ProcedureWorkerCommon'), 'isFrameContainPoint')
27  .mockReturnValue(true);
28describe('Test', () => {
29  let row: TraceRow<SampleStruct>;
30  let context: CanvasRenderingContext2D;
31
32  row = TraceRow.skeleton<SampleStruct>();
33  row.isHover = true;
34  TraceRow.range = {
35    startNS: 0,
36    endNS: 1000000,
37    totalNS: 1000000,
38  };
39
40  row.dataList = [
41    {
42      detail: '100',
43      translateY: 50,
44      frame: new Rect(0, 0, 100, 100),
45      name: 'all-state',
46      property: [],
47      begin: 55,
48      end: 80,
49      depth: 80,
50      startTs: 80,
51      instructions: 80,
52      cycles: 80,
53    },
54  ];
55
56  row.dataListCache = [
57    {
58      detail: '100',
59      translateY: 50,
60      frame: new Rect(0, 0, 100, 100),
61      name: 'all-state',
62      property: [],
63      begin: 55,
64      end: 80,
65      depth: 80,
66      startTs: 80,
67      instructions: 80,
68      cycles: 80,
69    },
70  ];
71
72  context = {
73    save: jest.fn(),
74    translate: jest.fn(),
75    rect: jest.fn(),
76    clip: jest.fn(),
77    strokeStyle: '#000000',
78    strokeRect: jest.fn(),
79    fillRect: jest.fn(),
80    fillText: jest.fn(),
81    measureText: jest.fn().mockReturnValue({ width: 10 }),
82    beginPath: jest.fn(),
83    closePath: jest.fn(),
84    stroke: jest.fn(),
85    clearRect: jest.fn(),
86    fill: jest.fn(),
87    fillStyle: '#000000',
88    globalAlpha: 0.5,
89    font: '10px sans-serif',
90    canvas: {
91      clientWidth: 800,
92    },
93  } as unknown as CanvasRenderingContext2D;
94
95  it('SamplerTest01', () => {
96    const sampleRender = new SampleRender();
97    jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerBpftrace', () => ({
98      ...jest.requireActual('./ProcedureWorkerBpftrace'),
99      func: jest.fn(),
100    }));
101    sampleRender.renderMainThread(
102      { context, useCache: false, type: 'cpu', start_ts: 5, uniqueProperty: [], flattenTreeArray: [] },
103      row
104    );
105    expect(context.beginPath).toHaveBeenCalled();
106    expect(context.closePath).toHaveBeenCalled();
107  });
108
109  it('SamplerTest02', () => {
110    SampleStruct.selectSampleStruct = row.dataList[0];
111    expect(SampleStruct.draw(context, row.dataList[0])).toBeUndefined();
112  });
113});
114