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 */ 15import { 16 HiPerfEventStruct, 17 HiperfEventRender, 18} from '../../../../src/trace/database/ui-worker/hiperf/ProcedureWorkerHiPerfEvent'; 19import { hiPerf } from '../../../../src/trace/database/ui-worker/ProcedureWorkerCommon'; 20import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 21jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 22 return {}; 23}); 24jest.mock('../../../../src/trace/component/trace/base/TraceRow', () => { 25 return { 26 TraceRow: () => {}, 27 }; 28}); 29 30describe('ProcedureWorkerHiPerfEvent Test', () => { 31 it('ProcedureWorkerHiPerfEventTest03', () => { 32 const data = { 33 frame: { 34 x: 50, 35 y: 21, 36 width: 60, 37 height: 16, 38 }, 39 cpu: 3, 40 startNs: 41, 41 value: 14, 42 }; 43 const canvas = document.createElement('canvas'); 44 canvas.width = 1; 45 canvas.height = 1; 46 const ctx = canvas.getContext('2d'); 47 expect(HiPerfEventStruct.drawRoundRectPath(ctx, 1, 0, 10, 10, 12)).toBeUndefined(); 48 }); 49 50 it('ProcedureWorkerHiPerfEventTest04', function () { 51 let node = { 52 frame: { 53 x: 22, 54 y: 30, 55 width: 90, 56 height: 80, 57 }, 58 startNS: 3, 59 value: 33, 60 startTs: 35, 61 dur: 35, 62 height: 55, 63 }; 64 let frame = { 65 x: 37, 66 y: 77, 67 width: 460, 68 height: 600, 69 }; 70 expect(HiPerfEventStruct.setFrame(node, 2, 1, 2, frame)).toBeUndefined(); 71 }); 72 73 it('ProcedureWorkerHiPerfEventTest05', function () { 74 let node = { 75 frame: { 76 x: 30, 77 y: 30, 78 width: 660, 79 height: 660, 80 }, 81 startNS: 20, 82 value: 60, 83 startTs: 3, 84 dur: 61, 85 height: 63, 86 }; 87 let frame = { 88 x: 10, 89 y: 20, 90 width: 166, 91 height: 330, 92 }; 93 expect(HiPerfEventStruct.setFrame(node, 2, 1, 2, frame)).toBeUndefined(); 94 }); 95 96 it('ProcedureWorkerHiPerfEventTest06', function () { 97 expect(HiPerfEventStruct.eventGroupBy10MS([{ ps: 1 }, { coX: '1' }], 10, '')).toEqual([ 98 { dur: 10000000, height: NaN, startNS: NaN, max: 0, sum: NaN }, 99 ]); 100 }); 101 it('ProcedureWorkerHiPerfProcessTest08', function () { 102 let hiperfEventRender = new HiperfEventRender(); 103 let req = { 104 lazyRefresh: true, 105 type: '', 106 startNS: 1, 107 endNS: 1, 108 totalNS: 1, 109 frame: { 110 x: 234, 111 y: 120, 112 width: 100, 113 height: 100, 114 }, 115 useCache: false, 116 range: { 117 refresh: '', 118 }, 119 canvas: 'event', 120 context: { 121 font: '11px sans-serif', 122 fillStyle: '#ec407a', 123 globalAlpha: 0.6, 124 clearRect: jest.fn(() => true), 125 measureText: jest.fn(() => true), 126 fillRect: jest.fn(() => true), 127 fillText: jest.fn(() => true), 128 fill: jest.fn(() => true), 129 beginPath: jest.fn(() => true), 130 stroke: jest.fn(() => true), 131 closePath: jest.fn(() => true), 132 }, 133 isHover: '', 134 hoverX: 1, 135 id: 1, 136 params: '', 137 wakeupBean: undefined, 138 flagMoveInfo: '', 139 flagSelectedInfo: '', 140 slicesTime: 3, 141 lineColor: '', 142 x: 20, 143 y: 20, 144 width: 100, 145 height: 100, 146 scale: 100_000_001, 147 }; 148 window.postMessage = jest.fn(() => true); 149 expect(hiperfEventRender.render(req, [], [], [])).toBeUndefined(); 150 }); 151 it('ProcedureWorkerHiPerfEventTest09', function () { 152 let dataList = new Array(); 153 dataList.push({ 154 length: 1, 155 dur: 10, 156 frame: { x: 0, y: 9, width: 10, height: 10 }, 157 startNS: 0, 158 }); 159 dataList.push({ startNS: 1, dur: 2, length: 1 }); 160 hiPerf(dataList, [{ length: 0 }], dataList, 8, 3, '', false, 1, false); 161 }); 162}); 163