• 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';
17import {
18  VirtualMemoryStruct,
19  VirtualMemoryRender,
20} from '../../../../src/trace/database/ui-worker/ProcedureWorkerVirtualMemory';
21import { mem } from '../../../../src/trace/database/ui-worker/ProcedureWorkerCommon';
22jest.mock('../../../../src/trace/component/SpSystemTrace', () => {
23  return {};
24});
25describe('ProcedureWorkerVirtualMemory Test', () => {
26  it('ProcedureWorkerVirtualMemoryTest01', function () {
27    let frame = {
28      x: 34,
29      y: 44,
30      width: 144,
31      height: 430,
32    };
33    let dataList = new Array();
34    dataList.push({
35      startTime: 0,
36      dur: 130,
37      frame: { x: 30, y: 44, width: 10, height: 140 },
38    });
39    dataList.push({ startTime: 41, dur: 411 });
40    mem(dataList, [{ length: 1 }], 1, 1, 1, frame, true);
41  });
42
43  it('ProcedureWorkerVirtualMemoryTest02', function () {
44    let frame = {
45      x: 70,
46      y: 77,
47      width: 443,
48      height: 180,
49    };
50    let dataList = new Array();
51    dataList.push({
52      startTime: 80,
53      dur: 180,
54      frame: { x: 870, y: 97, width: 177, height: 107 },
55    });
56    dataList.push({ startTime: 71, dur: 178 });
57    mem(dataList, [{ length: 0 }], 1, 1, 1, frame, false);
58  });
59
60  it('ProcedureWorkerVirtualMemoryTest03', () => {
61    const data = {
62      cpu: 1,
63      startNs: 14,
64      value: 143,
65      frame: {
66        x: 44,
67        y: 43,
68        width: 120,
69        height: 233,
70      },
71      maxValue: undefined,
72      startTime: 1,
73      filterID: 5,
74    };
75    const canvas = document.createElement('canvas');
76    canvas.width = 1;
77    canvas.height = 1;
78    const ctx = canvas.getContext('2d');
79    expect(VirtualMemoryStruct.draw(ctx, data)).toBeUndefined();
80  });
81
82  it('ProcedureWorkerVirtualMemoryTest04', function () {
83    let virtualMemoryRender = new VirtualMemoryRender();
84    let virtualMemoryReq = {
85      lazyRefresh: true,
86      type: '',
87      startNS: 22,
88      endNS: 155,
89      totalNS: 133,
90      frame: {
91        x: 20,
92        y: 20,
93        width: 165,
94        height: 100,
95      },
96      useCache: false,
97      range: {
98        refresh: '',
99      },
100      canvas: 'a',
101      context: {
102        font: '11px sans-serif',
103        fillStyle: '#f3a97e',
104        globalAlpha: 0.6,
105        clearRect: jest.fn(() => true),
106        beginPath: jest.fn(() => true),
107        stroke: jest.fn(() => true),
108        closePath: jest.fn(() => true),
109        measureText: jest.fn(() => []),
110        fillRect: jest.fn(() => true),
111      },
112      lineColor: '#ff0000',
113      isHover: '',
114      hoverX: 71,
115      params: '',
116      wakeupBean: undefined,
117      flagMoveInfo: '',
118      flagSelectedInfo: '',
119      slicesTime: 557,
120      id: 1,
121      x: 20,
122      y: 20,
123      width: 121,
124      height: 121,
125    };
126    window.postMessage = jest.fn(() => true);
127    expect(virtualMemoryRender.renderMainThread(virtualMemoryReq, new TraceRow<VirtualMemoryStruct>())).toBeUndefined();
128  });
129  it('ProcedureWorkerVirtualMemoryTest05', function () {
130    let virtualMemoryRender = new VirtualMemoryRender();
131    let canvas = document.createElement('canvas') as HTMLCanvasElement;
132    let context = canvas.getContext('2d');
133    const data = {
134      context: context!,
135      useCache: true,
136      type: '',
137      traceRange: [],
138    };
139    window.postMessage = jest.fn(() => true);
140    expect(virtualMemoryRender.renderMainThread(data, new TraceRow())).toBeUndefined();
141  });
142});
143