• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {hiPerfThread,HiPerfThreadStruct,HiperfThreadRender} from "../../../../dist/trace/database/ui-worker/ProcedureWorkerHiPerfThread.js";
17
18describe('ProcedureWorkerHiPerfCPU Test', ()=>{
19
20    let res = [{
21        startNS: 0,
22        dur: 10,
23        frame: {
24            x:0,
25            y:9,
26            width:10,
27            height:10
28        }
29    }]
30    it('ProcedureWorkerHiPerfCPUTest01',()=>{
31        const data = {
32            frame:undefined,
33            cpu:1,
34            startNs:1,
35            value:1,
36        }
37        const canvas = document.createElement('canvas');
38        canvas.width = 1;
39        canvas.height = 1;
40        const ctx = canvas.getContext('2d');
41        expect(HiPerfThreadStruct.draw(ctx,'',data,true)).toBeUndefined();
42    });
43
44    it('ProcedureWorkerHiPerfCPUTest02', function () {
45        let dataList = new Array();
46        dataList.push({startNS: 0, dur: 10,length:1, frame: {x:0, y:9, width:10, height:10}})
47        dataList.push({startNS: 1, dur: 2,length:1})
48        let frame = {
49            x:0,
50            y:9,
51            width:10,
52            height:10
53        }
54        hiPerfThread(dataList, [{length:0}], 1, 8, 3, frame,false,1,false)
55    });
56
57    it('ProcedureWorkerHiPerfCPUTest03', function () {
58        let dataList = new Array();
59        dataList.push({startNS: 0, dur: 10,length:1, frame: {x:0, y:9, width:10, height:10}})
60        dataList.push({startNS: 1, dur: 2,length:1})
61        let frame = {
62            x:0,
63            y:9,
64            width:10,
65            height:10
66        }
67        hiPerfThread(dataList, [{length:1}], 1, 8, 3, frame,true,1,true)
68    });
69
70    it('ProcedureWorkerHiPerfCPUTest04', function () {
71        expect(HiPerfThreadStruct.groupBy10MS([{ps:1},{coX:"1"}],10,"")).toEqual([{"dur": 10000000,"height": 80, "startNS": NaN}])
72    });
73
74    it('ProcedureWorkerHiPerfCPUTest05', function () {
75        let hiperfThreadRender = new HiperfThreadRender()
76        let  req = {
77            lazyRefresh:true,
78            type:"",
79            startNS:1,
80            endNS:1,
81            totalNS:1,
82            frame: {
83                x: 20,
84                y: 20,
85                width: 100,
86                height: 100
87            },
88            useCache:false,
89            range:{
90                refresh:"",
91            },
92            canvas:'',
93            context:{
94                font:"11px sans-serif",
95                fillStyle:"#ec407a",
96                globalAlpha:0.6,
97            },
98            lineColor:'',
99            isHover:'',
100            hoverX:1,
101            params:'',
102            wakeupBean:undefined,
103            flagMoveInfo:'',
104            flagSelectedInfo:'',
105            slicesTime:3,
106            id:1,
107            x: 20,
108            y: 20,
109            width: 100,
110            height: 100,
111            scale:100_000_001
112        }
113        window.postMessage = jest.fn(()=>true)
114        expect(hiperfThreadRender.render(req,[],[])).toBeUndefined()
115    });
116})