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: undefined, height: NaN, startNS: NaN, sampleCount: undefined}, 95 { dur: 10000000, eventCount: NaN, height: NaN, startNS: NaN, sampleCount: 2}, 96 ]); 97 }); 98 99 it('ProcedureWorkerHiPerfThreadTest05', function () { 100 let hiperfThreadRender = new HiperfThreadRender2(); 101 let hiperfThreadReq = { 102 lazyRefresh: true, 103 type: '', 104 startNS: 21, 105 endNS: 31, 106 totalNS: 10, 107 frame: { 108 x: 134, 109 y: 120, 110 width: 102, 111 height: 100, 112 }, 113 useCache: false, 114 range: { 115 refresh: '', 116 }, 117 canvas: 'thread', 118 context: { 119 font: '15px sans-serif', 120 fillStyle: '#b4617b', 121 globalAlpha: 0.65, 122 closePath: jest.fn(() => true), 123 clearRect: jest.fn(() => true), 124 beginPath: jest.fn(() => true), 125 stroke: jest.fn(() => []), 126 measureText: jest.fn(() => true), 127 fillRect: jest.fn(() => true), 128 fillText: jest.fn(() => []), 129 fill: jest.fn(() => true), 130 }, 131 lineColor: '#210202', 132 isHover: '', 133 hoverX: 3, 134 params: '', 135 wakeupBean: undefined, 136 flagMoveInfo: '', 137 flagSelectedInfo: '', 138 slicesTime: 9, 139 id: 7, 140 x: 71, 141 y: 21, 142 width: 100, 143 height: 107, 144 scale: 100_000_006, 145 }; 146 window.postMessage = jest.fn(() => true); 147 let a = { 148 dataList: [ 149 { 150 callchain_id: 1329, 151 thread_name: 'uinput_inject', 152 tid: 247, 153 pid: 247, 154 startNS: 1179247952, 155 timestamp_group: 1170000000, 156 }, 157 { 158 callchain_id: 1330, 159 thread_name: 'uinput_inject', 160 tid: 247, 161 pid: 247, 162 startNS: 1179308910, 163 timestamp_group: 1170000000, 164 }, 165 ], 166 }; 167 168 expect(hiperfThreadRender.render(hiperfThreadReq, [], [], [])).toBeUndefined(); 169 }); 170 it('ProcedureWorkerHiPerfThreadTest06', function () { 171 let hiperfThreadRender = new HiperfThreadRender2(); 172 window.postMessage = jest.fn(() => true); 173 let canvas = document.createElement('canvas') as HTMLCanvasElement; 174 let context = canvas.getContext('2d'); 175 const data = { 176 context: context!, 177 useCache: true, 178 type: '', 179 traceRange: [], 180 }; 181 expect(hiperfThreadRender.renderMainThread(data, new TraceRow())).toBeUndefined(); 182 }); 183}); 184