• 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
16import { TabPanePTS } from '../../../../../../src/trace/component/trace/sheet/cpu/TabPanePTS';
17import { SpSystemTrace } from '../../../../../../src/trace/component/SpSystemTrace';
18jest.mock('../../../../../../src/js-heap/model/DatabaseStruct', () => {});
19
20window.ResizeObserver =
21  window.ResizeObserver ||
22  jest.fn().mockImplementation(() => ({
23    unobserve: jest.fn(),
24    disconnect: jest.fn(),
25    observe: jest.fn(),
26  }));
27describe('TabPanePTS Test', () => {
28  document.body.innerHTML = `<div><tabpane-pts class="pts"></tabpane-pts></div>`;
29  let tabPane = document.querySelector('.pts') as TabPanePTS;
30
31  SpSystemTrace.SPT_DATA = [
32    {
33      process: 'hiperf 2471',
34      processId: 2471,
35      thread: 'hiperf',
36      threadId: 2471,
37      state: '',
38      dur: 98,
39      start_ts: 8,
40      end_ts: 90,
41      cpu: 0,
42      priority: '-',
43      note: 'note',
44    },
45    {
46      process: '',
47      processId: 372,
48      thread: 'download_server',
49      threadId: 708,
50      state: '',
51      dur: 963,
52      start_ts: 6,
53      end_ts: 969,
54      cpu: 1,
55      priority: 'a',
56      note: 'a',
57    },
58    {
59      process: '',
60      processId: 487,
61      thread: 'CellularDataSer',
62      threadId: 1244,
63      state: '',
64      dur: 888,
65      start_ts: 0,
66      end_ts: 888,
67      cpu: 2,
68      priority: '120',
69      note: '2',
70    },
71  ];
72
73  let dataArray = [
74    {
75      id: 4,
76      pid: 3,
77      title: '',
78      children: [],
79      process: '',
80      processId: 2452,
81      thread: 'hiprofiler_cmd 2452',
82      threadId: 2452,
83      state: '',
84      wallDuration: 5655,
85      avgDuration: '',
86      count: 43,
87      minDuration: 12,
88      maxDuration: 6333,
89      stdDuration: '',
90    },
91  ];
92
93  it('TabPanePTSTest01', function () {
94    expect(tabPane.getDataByPTS(0, 0, [])).toBeUndefined();
95  });
96
97  it('TabPanePTSTest02', function () {
98    let source = [
99      {
100        process: '',
101        processId: 487,
102        thread: 'CellularDataSer',
103        threadId: 1244,
104        state: '0',
105        dur: 1100,
106        start_ts: 100_0000_0,
107        end_ts: 100_0000_1100,
108        cpu: 1,
109        priority: '118',
110        note: '-',
111      },
112    ];
113    expect(tabPane.getDataByPTS(10, 100_000, source)).toBeUndefined();
114  });
115});
116