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 HiPerfCallChartRender, 17 HiPerfCallChartStruct 18} from '../../../../src/trace/database/ui-worker/hiperf/ProcedureWorkerHiPerfCallChart'; 19import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 20 21jest.mock('../../../../src/trace/database/ui-worker/cpu/ProcedureWorkerCPU', () => { 22 return {}; 23}); 24jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 25 return {}; 26}); 27describe('ProcedureWorkerHiPerfCallChart Test',()=>{ 28 it('ProcedureWorkerHiPerfCallChartTest01 ', function () { 29 const canvas = document.createElement('canvas'); 30 canvas.width = 2; 31 canvas.height = 2; 32 const ctx = canvas.getContext('2d'); 33 const data = { 34 frame: { 35 x: 120, 36 y: 120, 37 width: 100, 38 height: 100, 39 }, 40 id: 21, 41 ts: 254151, 42 dur: 1201, 43 name: '1583', 44 depth: 6, 45 jank_tag: true, 46 cmdline: 'render.test', 47 type: '0', 48 pid: 21, 49 frame_type: 'render_service', 50 src_slice: '5', 51 rs_ts: 3, 52 rs_vsync: '2561', 53 rs_dur: 965, 54 rs_pid: 320, 55 rs_name: 'name', 56 gpu_dur: 102, 57 }; 58 expect(HiPerfCallChartStruct.draw(ctx,data)).toBeUndefined() 59 }); 60 it('ProcedureWorkerHiPerfCallChartTest02 ', function () { 61 let node = { 62 frame: { 63 x: 65, 64 y: 20, 65 width: 99, 66 height: 330, 67 }, 68 startNS: 200, 69 length: 1, 70 height: 90, 71 startTime: 0, 72 dur: 31, 73 }; 74 let frame= { 75 x: 65, 76 y: 20, 77 width: 99, 78 height: 330, 79 } 80 expect(HiPerfCallChartStruct.setPerfFrame(node,1,2,3,frame)).toBeUndefined() 81 }); 82 it('ProcedureWorkerHiPerfCallChartTest03', function () { 83 let hiPerfCallChartRender = new HiPerfCallChartRender(); 84 const hiPerfCallReq = { 85 lazyRefresh: true, 86 type: '', 87 startNS: 2, 88 endNS: 45, 89 totalNS: 43, 90 frame: { 91 x: 130, 92 y: 210, 93 width: 200, 94 height: 120, 95 }, 96 useCache: false, 97 range: { 98 refresh: '', 99 }, 100 canvas: 'a', 101 context: { 102 font: '11px sans-serif', 103 fillStyle: '#408dec', 104 globalAlpha: 0.29, 105 clearRect: jest.fn(() => true), 106 fillRect: jest.fn(() => true), 107 beginPath: jest.fn(() => true), 108 stroke: jest.fn(() => true), 109 closePath: jest.fn(() => true), 110 measureText: jest.fn(() => []), 111 fillText: jest.fn(() => true), 112 }, 113 lineColor: '#d90606', 114 isHover: '', 115 hoverX: 2, 116 params: '', 117 wakeupBean: undefined, 118 flagMoveInfo: '', 119 flagSelectedInfo: '', 120 slicesTime: 3, 121 id: 1, 122 x: 66, 123 y: 66, 124 width: 100, 125 height: 101, 126 }; 127 TraceRow.range = jest.fn(() => true); 128 TraceRow.range!.startNS = jest.fn(() => 0); 129 TraceRow.range!.endNS = jest.fn(() => 27763331331); 130 TraceRow.range!.totalNS = jest.fn(() => 27763331331); 131 expect(hiPerfCallChartRender.renderMainThread(hiPerfCallReq,new TraceRow())).toBeUndefined() 132 }); 133}) 134