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'; 17jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 18 return {}; 19}); 20import { 21 MaleoonCounterObj, 22 GpuCounterStruct, 23 gpuCounterChart, 24 GpuCounterRender, 25 GpuCounterType, 26} from '../../../../src/trace/database/ui-worker/ProcedureWorkerGpuCounter'; 27import { Rect } from '../../../../src/trace/component/trace/timer-shaft/Rect'; 28jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 29 return {}; 30}); 31describe('Test', () => { 32 let row: TraceRow<GpuCounterStruct>; 33 let context: CanvasRenderingContext2D; 34 35 row = TraceRow.skeleton<GpuCounterStruct>(); 36 TraceRow.range = { 37 startNS: 0, 38 endNS: 1000000, 39 totalNS: 1000000, 40 }; 41 42 row.dataListCache = [ 43 { 44 startNS: 100, 45 type: '5587', 46 dur: 100, 47 }, 48 { 49 startNS: 100, 50 type: '557', 51 dur: 100, 52 }, 53 ]; 54 55 context = { 56 save: jest.fn(), 57 translate: jest.fn(), 58 rect: jest.fn(), 59 clip: jest.fn(), 60 strokeStyle: '#000000', 61 strokeRect: jest.fn(), 62 fillRect: jest.fn(), 63 fillText: jest.fn(), 64 measureText: jest.fn().mockReturnValue({ width: 10 }), 65 beginPath: jest.fn(), 66 closePath: jest.fn(), 67 stroke: jest.fn(), 68 clearRect: jest.fn(), 69 fill: jest.fn(), 70 fillStyle: '#000000', 71 globalAlpha: 1, 72 font: '10px sans-serif', 73 canvas: { 74 clientWidth: 800, 75 }, 76 } as unknown as CanvasRenderingContext2D; 77 78 it('GpuCounterTest01', () => { 79 const xpowerStatisticRender = new GpuCounterRender(); 80 xpowerStatisticRender.renderMainThread({ context, useCache: false, type: 'cpu', startTime: 0, maxValue: 5 }, row); 81 expect(context.beginPath).toHaveBeenCalled(); 82 expect(context.closePath).toHaveBeenCalled(); 83 }); 84 85 it('GpuCounterTest02', () => { 86 GpuCounterStruct.selectGpuCounterStruct = row.dataListCache[0]; 87 expect(GpuCounterStruct.draw(context, row.dataListCache[0])).toBeUndefined(); 88 }); 89 90 it('GpuCounterTest03', () => { 91 let data = new MaleoonCounterObj(); 92 data.gpu_clocks = []; 93 expect(data.gpu_clocks).toEqual([]); 94 }); 95 96 it('GpuCounterTest04', () => { 97 let data = new GpuCounterType(); 98 data.local_count = []; 99 expect(data.local_count).toEqual([]); 100 }); 101}); 102