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//@ts-ignore 16import {hiPerfProcess,HiPerfProcessStruct,HiperfProcessRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerHiPerfProcess.js"; 17 18describe('ProcedureWorkerHiPerfCPU Test', ()=>{ 19 20 it('ProcedureWorkerHiPerfCPUTest01',()=>{ 21 const data = { 22 frame:undefined, 23 cpu:1, 24 startNs:1, 25 value:1, 26 } 27 const canvas = document.createElement('canvas'); 28 canvas.width = 1; 29 canvas.height = 1; 30 const ctx = canvas.getContext('2d'); 31 expect(HiPerfProcessStruct.draw(ctx,'',data,true)).toBeUndefined(); 32 }); 33 34 it('ProcedureWorkerHiPerfCPUTest02', function () { 35 let dataList = new Array(); 36 dataList.push({startNS: 0, dur: 10,length:1, frame: {x:0, y:9, width:10, height:10}}) 37 dataList.push({startNS: 1, dur: 2,length:1}) 38 hiPerfProcess(dataList, [{length:0}], 1, 8, 3, "",true,1,true) 39 }); 40 41 it('ProcedureWorkerHiPerfCPUTest03', function () { 42 let dataList = new Array(); 43 dataList.push({startNS: 0, dur: 10,length:1, frame: {x:0, y:9, width:10, height:10}}) 44 dataList.push({startNS: 1, dur: 2,length:1}) 45 hiPerfProcess(dataList, [{length:0}], 1, 8, 3, "",false,1,false) 46 }); 47 48 it('ProcedureWorkerHiPerfCPUTest04', function () { 49 expect(HiPerfProcessStruct.groupBy10MS([{a:'1',b:2,c:3}],10,)).toEqual([{"dur": 10000000, "height": 40, "startNS": NaN,}]) 50 }); 51 52 it('ProcedureWorkerHiPerfCPUTest05', function () { 53 let hiperfProcessRender = new HiperfProcessRender() 54 let req = { 55 lazyRefresh:true, 56 type:"", 57 startNS:1, 58 endNS:1, 59 totalNS:1, 60 frame: { 61 x: 20, 62 y: 20, 63 width: 100, 64 height: 100 65 }, 66 useCache:false, 67 range:{ 68 refresh:"", 69 }, 70 canvas:'', 71 context:{ 72 font:"11px sans-serif", 73 fillStyle:"#ec407a", 74 globalAlpha:0.6, 75 }, 76 lineColor:'', 77 isHover:'', 78 hoverX:1, 79 params:'', 80 wakeupBean:undefined, 81 flagMoveInfo:'', 82 flagSelectedInfo:'', 83 slicesTime:3, 84 id:1, 85 x: 20, 86 y: 20, 87 width: 100, 88 height: 100, 89 scale:100_000_001 90 } 91 window.postMessage = jest.fn(()=>true) 92 expect(hiperfProcessRender.render(req,[],[])).toBeUndefined() 93 }); 94})