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