• 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
16// @ts-ignore
17import {TabPaneCurrentSelection, getTimeString} from "../../../../../dist/trace/component/trace/sheet/TabPaneCurrentSelection.js"
18import {SpApplication} from "../../../../../src/trace/SpApplication";
19window.ResizeObserver = window.ResizeObserver ||
20    jest.fn().mockImplementation(() => ({
21        disconnect: jest.fn(),
22        observe: jest.fn(),
23        unobserve: jest.fn(),
24
25    }));
26describe('TabPaneCurrentSelection Test', () => {
27    let tabPaneCurrentSelection = new TabPaneCurrentSelection();
28
29    const canvas = document.createElement('canvas');
30    canvas.width = 1;
31    canvas.height = 1;
32    let context = canvas.getContext("2d");
33
34    let cpuData = [{
35        cpu: 1,
36        dur: 1,
37        end_state: 'string',
38        id: 12,
39        name: 'name',
40        priority: 11,
41        processCmdLine: 'processCmdLine',
42        processId: 111,
43        processName: 'processName',
44        schedId: 22,
45        startTime: 0,
46        tid: 100,
47        type: 'type',
48    }]
49    let functionData = [{
50        argsetid:  53161,
51        depth:  0,
52        dur:  570000,
53        funName: "binder transaction",
54        id: 92749,
55        is_main_thread:  0,
56        parent_id:  null,
57        startTs:  9729867000,
58        threadName: "Thread-15",
59        tid: 2785,
60    }]
61    let memData = [{
62        trackId: 100,
63        processName:'processName',
64        pid: 11,
65        upid:1,
66        trackName:'trackName',
67        type:'type',
68        track_id: 'track_id',
69        value: 111,
70        startTime:0,
71        duration:1000,
72        maxValue:4000,
73        delta: 2,
74    }]
75    let threadData = [{
76        hasSched: 14724852000,
77        pid: 2519,
78        processName: null,
79        threadName: "ACCS0",
80        tid: 2716,
81        upid:  1,
82        utid:  1,
83        cpu: null,
84        dur: 405000,
85        end_ts: null,
86        id: 1,
87        is_main_thread: 0,
88        name: "ACCS0",
89        startTime: 58000,
90        start_ts: null,
91        state: "S",
92        type: "thread",
93    }]
94    let wakeupBean = [{
95        wakeupTime:0,
96        cpu:1,
97        process:'process',
98        pid:11,
99        thread:'thread',
100        tid:22,
101        schedulingLatency:33,
102        schedulingDesc:'schedulingDesc',
103
104    }]
105
106    let queryData = [{
107        id:1,
108        startTime:0,
109        hasSched: 14724852000,
110        pid: 2519,
111        processName: null,
112        threadName: "ACCS0",
113        tid: 2716,
114        upid:  1,
115        utid:  1,
116        cpu: null,
117        dur: 405000,
118        end_ts: null,
119        is_main_thread: 0,
120        name: "ACCS0",
121        start_ts: null,
122        state: "S",
123        type: "thread",
124
125    }]
126    let scrollWakeUp = [{
127        startTime:0,
128        pid:11,
129        tid:22,
130
131    }]
132    let data = [{
133        cpu: 1,
134        dur: 1,
135        end_state: 'string',
136        id: 12,
137        name: 'name',
138        priority: 11,
139        processCmdLine: 'processCmdLine',
140        processId: 111,
141        processName: 'processName',
142        schedId: 22,
143        startTime: 0,
144        tid: 100,
145        type: 'type',
146
147    }]
148
149    tabPaneCurrentSelection.queryWakeUpData = jest.fn(()=> 'WakeUpData')
150    tabPaneCurrentSelection.queryWakeUpData.wb = jest.fn(()=>null)
151
152
153
154    it('TabPaneCurrentSelectionTest01', function () {
155        let result = tabPaneCurrentSelection.setFunctionData(functionData)
156        expect(result).toBeUndefined();
157    });
158
159    it('TabPaneCurrentSelectionTest02', function () {
160        let result = tabPaneCurrentSelection.setMemData(memData)
161        expect(result).toBeUndefined();
162    });
163
164    it('TabPaneCurrentSelectionTest03', function () {
165        let result = getTimeString(3600_000_000_002)
166        expect(result).toBe('1h 2ns ');
167    });
168
169    it('TabPaneCurrentSelectionTest04', function () {
170        let result = getTimeString(60000000001)
171        expect(result).toBe('1m 1ns ');
172    });
173
174    it('TabPaneCurrentSelectionTest05', function () {
175        let result = getTimeString(1000000001)
176        expect(result).toBe('1s 1ns ');
177    });
178
179    it('TabPaneCurrentSelectionTest06', function () {
180        let result = getTimeString(1000001)
181        expect(result).toBe('1ms 1ns ');
182    });
183
184    it('TabPaneCurrentSelectionTest07', function () {
185        let result = getTimeString(1001)
186        expect(result).toBe('1μs 1ns ');
187    });
188
189    it('TabPaneCurrentSelectionTest08', function () {
190        let result = getTimeString(101)
191        expect(result).toBe('101ns ');
192    });
193
194    it('TabPaneCurrentSelectionTest09',function(){
195        tabPaneCurrentSelection.setCpuData = jest.fn(()=>true);
196        tabPaneCurrentSelection.data = jest.fn(()=>true);
197        expect(tabPaneCurrentSelection.data).toBeUndefined();
198    });
199
200    it('TabPaneCurrentSelectionTest10',function(){
201        expect(tabPaneCurrentSelection.setCpuData(cpuData,undefined,1)).toBeTruthy();
202    });
203
204    it('TabPaneCurrentSelectionTest13', function () {
205        expect(tabPaneCurrentSelection.initCanvas()).not.toBeUndefined();
206    });
207
208    it('TabPaneCurrentSelectionTest14', function () {
209        let str = {
210            length:0
211        }
212        expect(tabPaneCurrentSelection.transferString(str)).toBe("");
213    });
214
215    it('TabPaneCurrentSelectionTest15', function () {
216        expect(tabPaneCurrentSelection.transferString("&")).not.toBeUndefined();
217    });
218
219    it('TabPaneCurrentSelectionTest16', function () {
220        expect(tabPaneCurrentSelection.drawRight(null)).toBeUndefined();
221    });
222
223    it('TabPaneCurrentSelectionTest11',function(){
224        expect(tabPaneCurrentSelection.initHtml()).toMatchInlineSnapshot(`
225"
226        <style>
227            .current-title{
228                width: 100%;
229                display: flex;
230                top: 0;
231                background: var(--dark-background,#ffffff);
232                position: sticky;
233            }
234            .current-title h2{
235                width: 50%;
236                padding: 0 10px;
237                font-size: 16px;
238                font-weight: 400;
239                visibility: visible;
240            }
241            .bottom-scroll-area{
242                display: flex;
243                height: auto;
244                overflow-y: auto;
245            }
246            .left-table{
247                width: 50%;
248                padding: 0 10px;
249            }
250            .right-table{
251                width: 50%;
252            }
253        </style>
254        <div style=\\"width: 100%;height: auto;position: relative\\">
255            <div class=\\"current-title\\">
256                <h2 id=\\"leftTitle\\"></h2>
257                <h2 id=\\"rightTitle\\">Scheduling Latency</h2>
258            </div>
259            <div class=\\"bottom-scroll-area\\">
260                <div class=\\"left-table\\">
261                    <lit-table id=\\"selectionTbl\\" no-head style=\\"height: auto\\">
262                        <lit-table-column title=\\"name\\" data-index=\\"name\\" key=\\"name\\" align=\\"flex-start\\"  width=\\"180px\\">
263                            <template><div>{{name}}</div></template>
264                        </lit-table-column>
265                        <lit-table-column title=\\"value\\" data-index=\\"value\\" key=\\"value\\" align=\\"flex-start\\" >
266                            <template><div style=\\"display: flex;\\">{{value}}</div></template>
267                        </lit-table-column>
268                    </lit-table>
269                </div>
270                <div class=\\"right-table\\">
271                    <canvas id=\\"rightDraw\\" style=\\"width: 100%;height: 100%;\\"></canvas>
272                </div>
273            </div>
274        </div>
275        "
276`);
277    });
278})
279