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'; 17 18jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 19 return {}; 20}); 21import { 22 HiperfThreadRender2, 23 HiPerfThreadStruct, 24} from '../../../../src/trace/database/ui-worker/hiperf/ProcedureWorkerHiPerfThread2'; 25import { hiPerf } from '../../../../src/trace/database/ui-worker/ProcedureWorkerCommon'; 26jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 27 return {}; 28}); 29describe('ProcedureWorkerHiPerfThread Test', () => { 30 let res = [ 31 { 32 startNS: 13, 33 dur: 50, 34 frame: { 35 x: 60, 36 y: 69, 37 width: 16, 38 height: 69, 39 }, 40 }, 41 ]; 42 it('ProcedureWorkerHiPerfThreadTest01', () => { 43 const data = { 44 frame: undefined, 45 cpu: 0, 46 startNs: 58, 47 value: 5, 48 }; 49 const canvas = document.createElement('canvas'); 50 canvas.width = 4; 51 canvas.height = 1; 52 const ctx = canvas.getContext('2d'); 53 expect(HiPerfThreadStruct.draw(ctx, '', data, true)).toBeUndefined(); 54 }); 55 56 it('ProcedureWorkerHiPerfThreadTest02', function () { 57 let dataList = new Array(); 58 dataList.push({ 59 startNS: 80, 60 dur: 17, 61 length: 17, 62 frame: { x: 7, y: 9, width: 17, height: 170 }, 63 }); 64 dataList.push({ startNS: 1, dur: 2, length: 71 }); 65 let frame = { 66 x: 70, 67 y: 9, 68 width: 70, 69 height: 107, 70 }; 71 hiPerf(dataList, [{ length: 0 }], dataList, 8, 3, frame, false, 1, false); 72 }); 73 74 it('ProcedureWorkerHiPerfThreadTest03', function () { 75 let dataList = new Array(); 76 dataList.push({ 77 startNS: 30, 78 dur: 350, 79 length: 551, 80 frame: { x: 7, y: 76, width: 610, height: 106 }, 81 }); 82 dataList.push({ startNS: 1, dur: 62, length: 1 }); 83 let frame = { 84 x: 60, 85 y: 96, 86 width: 160, 87 height: 160, 88 }; 89 hiPerf(dataList, [{ length: 1 }], dataList, 8, 3, frame, true, 1, true); 90 }); 91 92 it('ProcedureWorkerHiPerfThreadTest04', function () { 93 expect(HiPerfThreadStruct.groupBy10MS([{ ps: 1 }, { coX: '1' }], 10, '')).toEqual([ 94 { dur: 10000000, eventCount: NaN, height: NaN, startNS: NaN, sampleCount: 2}, 95 ]); 96 }); 97 98 it('ProcedureWorkerHiPerfThreadTest05', function () { 99 let hiperfThreadRender = new HiperfThreadRender2(); 100 let hiperfThreadReq = { 101 lazyRefresh: true, 102 type: '', 103 startNS: 21, 104 endNS: 31, 105 totalNS: 10, 106 frame: { 107 x: 134, 108 y: 120, 109 width: 102, 110 height: 100, 111 }, 112 useCache: false, 113 range: { 114 refresh: '', 115 }, 116 canvas: 'thread', 117 context: { 118 font: '15px sans-serif', 119 fillStyle: '#b4617b', 120 globalAlpha: 0.65, 121 closePath: jest.fn(() => true), 122 clearRect: jest.fn(() => true), 123 beginPath: jest.fn(() => true), 124 stroke: jest.fn(() => []), 125 measureText: jest.fn(() => true), 126 fillRect: jest.fn(() => true), 127 fillText: jest.fn(() => []), 128 fill: jest.fn(() => true), 129 }, 130 lineColor: '#210202', 131 isHover: '', 132 hoverX: 3, 133 params: '', 134 wakeupBean: undefined, 135 flagMoveInfo: '', 136 flagSelectedInfo: '', 137 slicesTime: 9, 138 id: 7, 139 x: 71, 140 y: 21, 141 width: 100, 142 height: 107, 143 scale: 100_000_006, 144 }; 145 window.postMessage = jest.fn(() => true); 146 let a = { 147 dataList: [ 148 { 149 callchain_id: 1329, 150 thread_name: 'uinput_inject', 151 tid: 247, 152 pid: 247, 153 startNS: 1179247952, 154 timestamp_group: 1170000000, 155 }, 156 { 157 callchain_id: 1330, 158 thread_name: 'uinput_inject', 159 tid: 247, 160 pid: 247, 161 startNS: 1179308910, 162 timestamp_group: 1170000000, 163 }, 164 ], 165 }; 166 167 expect(hiperfThreadRender.render(hiperfThreadReq, [], [], [])).toBeUndefined(); 168 }); 169 it('ProcedureWorkerHiPerfThreadTest06', function () { 170 let hiperfThreadRender = new HiperfThreadRender2(); 171 window.postMessage = jest.fn(() => true); 172 let canvas = document.createElement('canvas') as HTMLCanvasElement; 173 let context = canvas.getContext('2d'); 174 const data = { 175 context: context!, 176 useCache: true, 177 type: '', 178 traceRange: [], 179 }; 180 expect(hiperfThreadRender.renderMainThread(data, new TraceRow())).toBeUndefined(); 181 }); 182}); 183