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