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}); 21 22import { thread, ThreadStruct, ThreadRender } from '../../../../src/trace/database/ui-worker/ProcedureWorkerThread'; 23import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 24 25describe('ProcedureWorkerThread Test', () => { 26 let frame = { 27 x: 0, 28 y: 9, 29 width: 10, 30 height: 10, 31 }; 32 33 it('ProcedureWorkerThreadTest01', () => { 34 const canvas = document.createElement('canvas'); 35 canvas.width = 3; 36 canvas.height = 3; 37 const ctx = canvas.getContext('2d'); 38 39 const data = { 40 frame: { 41 x: 201, 42 y: 201, 43 width: 100, 44 height: 100, 45 }, 46 startNS: 200, 47 value: 50, 48 }; 49 expect(ThreadStruct.draw(ctx, data)).toBeUndefined(); 50 }); 51 52 it('ProcedureWorkerThreadTest02', () => { 53 const canvas = document.createElement('canvas'); 54 canvas.width = 4; 55 canvas.height = 4; 56 const ctx = canvas.getContext('2d'); 57 58 const data = { 59 frame: { 60 x: 202, 61 y: 202, 62 width: 100, 63 height: 100, 64 }, 65 startNS: 200, 66 value: 50, 67 state: 'S', 68 }; 69 expect(ThreadStruct.draw(ctx, data)).toBeUndefined(); 70 }); 71 72 it('ProcedureWorkerThreadTest03', () => { 73 const canvas = document.createElement('canvas'); 74 canvas.width = 5; 75 canvas.height = 5; 76 const ctx = canvas.getContext('2d'); 77 78 const data = { 79 frame: { 80 x: 203, 81 y: 203, 82 width: 100, 83 height: 100, 84 }, 85 startNS: 200, 86 value: 50, 87 state: 'R', 88 }; 89 expect(ThreadStruct.drawThread(ctx, data)).toBeUndefined(); 90 }); 91 92 it('ProcedureWorkerThreadTest04', () => { 93 const canvas = document.createElement('canvas'); 94 canvas.width = 6; 95 canvas.height = 1; 96 const ctx = canvas.getContext('2d'); 97 98 const data = { 99 frame: { 100 x: 204, 101 y: 240, 102 width: 100, 103 height: 100, 104 }, 105 startNS: 200, 106 value: 50, 107 state: 'D', 108 }; 109 expect(ThreadStruct.drawThread(ctx, data)).toBeUndefined(); 110 }); 111 112 it('ProcedureWorkerThreadTest05', () => { 113 const canvas = document.createElement('canvas'); 114 canvas.width = 7; 115 canvas.height = 7; 116 const ctx = canvas.getContext('2d'); 117 118 const data = { 119 frame: { 120 x: 207, 121 y: 201, 122 width: 100, 123 height: 100, 124 }, 125 startNS: 200, 126 value: 50, 127 state: 'Running', 128 }; 129 expect(ThreadStruct.drawThread(ctx, data)).toBeUndefined(); 130 }); 131 132 it('ProcedureWorkerThreadTest06', () => { 133 const canvas = document.createElement('canvas'); 134 canvas.width = 1; 135 canvas.height = 2; 136 const ctx = canvas.getContext('2d'); 137 138 const data = { 139 frame: { 140 x: 202, 141 y: 203, 142 width: 100, 143 height: 100, 144 }, 145 startNS: 200, 146 value: 50, 147 state: 'T', 148 }; 149 expect(ThreadStruct.draw(ctx, data)).toBeUndefined(); 150 }); 151 152 it('ProcedureWorkerThreadTest07', () => { 153 const d1 = { 154 cpu: 1, 155 tid: 1, 156 state: '', 157 startTime: 1, 158 dur: 1, 159 }; 160 const d2 = { 161 cpu: 1, 162 tid: 1, 163 state: '', 164 startTime: 1, 165 dur: 1, 166 }; 167 expect(ThreadStruct.equals(d1, d2)).toBeTruthy(); 168 }); 169 170 it('ProcedureWorkerThreadTest08', function () { 171 let threadRender = new ThreadRender(); 172 let threadReq = { 173 lazyRefresh: true, 174 type: '', 175 startNS: 1, 176 endNS: 19, 177 totalNS: 18, 178 frame: { 179 x: 20, 180 y: 20, 181 width: 106, 182 height: 100, 183 }, 184 useCache: false, 185 range: { 186 refresh: '', 187 }, 188 canvas: '', 189 context: { 190 font: '11px sans-serif', 191 fillStyle: '#780229', 192 globalAlpha: 0.62, 193 }, 194 lineColor: '#519043', 195 isHover: '', 196 hoverX: 37, 197 params: '', 198 wakeupBean: undefined, 199 flagMoveInfo: '', 200 flagSelectedInfo: '', 201 slicesTime: 332, 202 id: 8, 203 x: 20, 204 y: 20, 205 width: 170, 206 height: 170, 207 }; 208 window.postMessage = jest.fn(() => true); 209 expect(threadRender.render(threadReq, [], [])).toBeUndefined(); 210 }); 211 it('ProcedureWorkerThreadTest08', function () { 212 let threadRender = new ThreadRender(); 213 let canvas = document.createElement('canvas') as HTMLCanvasElement; 214 let context = canvas.getContext('2d'); 215 const data = { 216 context: context!, 217 useCache: true, 218 type: '', 219 traceRange: [], 220 }; 221 window.postMessage = jest.fn(() => true); 222 expect(threadRender.renderMainThread(data, new TraceRow())).toBeUndefined(); 223 }); 224}); 225