• 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 { TraceRow } from '../../../../dist/trace/component/trace/base/TraceRow.js';
18
19jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => {
20  return {};
21});
22// @ts-ignore
23import {
24  CpuFreqLimitRender,
25  CpuFreqLimitsStruct,
26} from '../../../../dist/trace/database/ui-worker/ProcedureWorkerCpuFreqLimits.js';
27
28describe('ProcedureWorkerCpuFreqLimits Test', () => {
29  let cpuFreqLimits = {
30    frame: {
31      x: 20,
32      y: 20,
33      width: 100,
34      height: 100,
35    },
36    startNs: 255,
37    dur: 2545,
38    max: 14111,
39    min: 200,
40    cpu: 10,
41  };
42  it('Test01', () => {
43    const canvas = document.createElement('canvas');
44    canvas.width = 15;
45    canvas.height = 15;
46    const ctx = canvas.getContext('2d');
47
48    const data = {
49      frame: {
50        x: 205,
51        y: 205,
52        width: 100,
53        height: 100,
54      },
55      startNs: 54,
56      dur: 2453,
57      max: 3433,
58      min: 13,
59      cpu: 3,
60    };
61    expect(CpuFreqLimitsStruct.draw(ctx!, data, 2)).toBeUndefined();
62  });
63
64  it('Test02', () => {
65    const canvas = document.createElement('canvas');
66    canvas.width = 1;
67    canvas.height = 1;
68    const ctx = canvas.getContext('2d');
69    expect(CpuFreqLimitsStruct.drawArcLine(ctx, cpuFreqLimits, 100, 500)).toBeUndefined();
70  });
71
72  it('Test03', () => {
73    let node = {
74      frame: {
75        x: 24,
76        y: 20,
77        width: 100,
78        height: 150,
79      },
80      startNS: 200,
81      length: 1,
82      height: 40,
83      startTime: 2,
84      dur: 41,
85    };
86    expect(
87      CpuFreqLimitsStruct.setFreqLimitFrame(node, 1, 1, 1, 1, {
88        width: 10,
89      })
90    ).toBeUndefined();
91  });
92
93  it('Test04', function () {
94    let cpuFreqLimitRender = new CpuFreqLimitRender();
95    let req = {
96      type: '',
97      startNS: 10,
98      endNS: 101,
99      totalNS: 91,
100      frame: {
101        x: 43,
102        y: 230,
103        width: 340,
104        height: 342,
105      },
106      canvas: 'a',
107      context: {
108        measureText: jest.fn(() => true),
109        clearRect: jest.fn(() => true),
110        stroke: jest.fn(() => false),
111        closePath: jest.fn(() => true),
112        fillText: jest.fn(() => true),
113        beginPath: jest.fn(() => true),
114        fillRect: jest.fn(() => true),
115      },
116      lineColor: '#ffae8a',
117      isHover: '',
118      hoverX: 1,
119      params: '',
120      wakeupBean: undefined,
121      flagMoveInfo: '',
122      flagSelectedInfo: '',
123      slicesTime: 133,
124      id: 36,
125      x: 565,
126      y: 600,
127      width: 100,
128      height: 230,
129    };
130    window.postMessage = jest.fn(() => true);
131    expect(cpuFreqLimitRender.render(req, [], [])).toBeUndefined();
132  });
133  it('Test05', function () {
134    let cpuFreqLimitRender = new CpuFreqLimitRender();
135    let canvas = document.createElement('canvas') as HTMLCanvasElement;
136    let context = canvas.getContext('2d');
137    const data = {
138      context: context!,
139      useCache: true,
140      type: '',
141      traceRange: [],
142    };
143    window.postMessage = jest.fn(() => true);
144    expect(cpuFreqLimitRender.renderMainThread(data, new TraceRow())).toBeUndefined();
145  });
146});
147