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 16jest.mock('../../../../dist/trace/component/trace/base/TraceRow.js', () => { 17 return {}; 18}); 19 20//@ts-ignore 21import { 22 hiPerfCpu, 23 HiPerfCpuStruct, 24 HiperfCpuRender, 25} from '../../../../dist/trace/database/ui-worker/ProcedureWorkerHiPerfCPU.js'; 26// @ts-ignore 27import { TraceRow } from '../../../../dist/trace/component/trace/base/TraceRow.js'; 28// @ts-ignore 29import { hiPerf } from '../../../../dist/trace/database/ui-worker/ProcedureWorkerCommon.js'; 30jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => { 31 return {}; 32}); 33 34describe('ProcedureWorkerHiPerfCPU Test', () => { 35 let frame = { 36 x: 0, 37 y: 9, 38 width: 10, 39 height: 10, 40 }; 41 it('ProcedureWorkerHiPerfCPUTest01', () => { 42 const data = { 43 frame: undefined, 44 cpu: 3, 45 startNs: 56, 46 value: 45, 47 }; 48 const canvas = document.createElement('canvas'); 49 canvas.width = 1; 50 canvas.height = 4; 51 const ctx = canvas.getContext('2d'); 52 expect(HiPerfCpuStruct.draw(ctx, '', data, true)).toBeUndefined(); 53 }); 54 55 it('ProcedureWorkerHiPerfCPUTest04', () => { 56 const canvas = document.createElement('canvas'); 57 canvas.width = 1; 58 canvas.height = 1; 59 const ctx = canvas.getContext('2d'); 60 expect(HiPerfCpuStruct.drawRoundRectPath(ctx, 1, 1, 1, 1, 1)).toBeUndefined(); 61 }); 62 63 it('ProcedureWorkerHiPerfCPUTest05', function () { 64 expect(HiPerfCpuStruct.groupBy10MS([{ id: 1, NS: 3 }, { copy: '1' }], 10, '')).toEqual([ 65 { dur: 10000000, height: Infinity, startNS: NaN }, 66 ]); 67 }); 68 it('ProcedureWorkerHiPerfCPUTest06', function () { 69 let req = { 70 lazyRefresh: true, 71 type: 'a', 72 startNS: 1, 73 endNS: 1, 74 totalNS: 1, 75 frame: { 76 x: 20, 77 y: 20, 78 width: 100, 79 height: 300, 80 }, 81 useCache: false, 82 range: { 83 refresh: '', 84 }, 85 canvas: 'a', 86 context: { 87 font: '11px sans-serif', 88 fillStyle: '#ec407a', 89 globalAlpha: 0.7, 90 fill: jest.fn(() => true), 91 clearRect: jest.fn(() => true), 92 beginPath: jest.fn(() => true), 93 stroke: jest.fn(() => true), 94 closePath: jest.fn(() => true), 95 measureText: jest.fn(() => true), 96 fillRect: jest.fn(() => true), 97 }, 98 lineColor: '', 99 isHover: '', 100 hoverX: 1, 101 params: '', 102 wakeupBean: undefined, 103 flagMoveInfo: '', 104 flagSelectedInfo: '', 105 slicesTime: 3, 106 id: 1, 107 x: 20, 108 y: 20, 109 width: 100, 110 height: 100, 111 scale: 100_000_001, 112 }; 113 let hiperfCpuRender = new HiperfCpuRender(); 114 window.postMessage = jest.fn(() => true); 115 expect(hiperfCpuRender.render(req, [], [], [])).toBeUndefined(); 116 }); 117 it('ProcedureWorkerHiPerfCPUTest08', function () { 118 let dataList = new Array(); 119 dataList.push({ 120 startNS: 0, 121 dur: 10, 122 length: 1, 123 frame: { x: 0, y: 9, width: 10, height: 10 }, 124 }); 125 dataList.push({ startNS: 1, dur: 2, length: 1 }); 126 hiPerf(dataList, [{ length: 0 }], dataList, 8, 3, '', true, 1, true); 127 }); 128}); 129