• 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 { SpHiPerf } from '../../../../src/trace/component/chart/SpHiPerf';
17import {
18  queryHiPerfCpuMergeData2,
19  queryHiPerfEventList,
20  queryPerfThread,
21} from '../../../../src/trace/database/SqlLite';
22import { SpChartManager } from '../../../../src/trace/component/chart/SpChartManager';
23import { queryPerfEventType } from '../../../../src/trace/database/SqlLite';
24const sqlit = require('../../../../src/trace/database/SqlLite');
25jest.mock('../../../../src/trace/database/SqlLite');
26jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => {
27  return {};
28});
29
30window.ResizeObserver =
31  window.ResizeObserver ||
32  jest.fn().mockImplementation(() => ({
33    disconnect: jest.fn(),
34    observe: jest.fn(),
35    unobserve: jest.fn(),
36  }));
37
38describe('SpHiPerf Test', () => {
39  let queryPerfCmdline = sqlit.queryPerfCmdline;
40  queryPerfCmdline.mockResolvedValue([
41    {
42      report_value:
43        'hiperf record --control prepare -o /data/local/tmp…e sched:sched_waking -a -s dwarf -f 1000 --offcpu',
44    },
45  ]);
46
47  let queryPerfThread = sqlit.queryPerfThread;
48  queryPerfThread.mockResolvedValue([
49    {
50      tid: 2,
51      threadName: 'threadName',
52      pid: 2,
53      processName: 'processName',
54    },
55    {
56      tid: 1,
57      threadName: 'threadName111',
58      pid: 1,
59      processName: 'processNam111e',
60    },
61  ]);
62
63  let queryHiPerfEventList = sqlit.queryHiPerfEventList;
64  queryHiPerfEventList.mockResolvedValue([
65    {
66      id: 0,
67      report_value: 'sched:sched_waking',
68    },
69    {
70      id: 1,
71      report_value: 'sched:sched_switch',
72    },
73  ]);
74
75  let queryHiPerfCpuMergeData2 = sqlit.queryHiPerfCpuMergeData2;
76  queryHiPerfCpuMergeData2.mockResolvedValue([
77    {
78      id: 0,
79      callchain_id: 1,
80      timestamp: 3468360924674,
81      thread_id: 2469,
82      event_count: 1,
83      event_type_id: 0,
84      timestamp_trace: 3468360965799,
85      cpu_id: 2,
86      thread_state: 'Running',
87      startNS: 0,
88    },
89    {
90      id: 4,
91      callchain_id: 1,
92      timestamp: 3468361000799,
93      thread_id: 2469,
94      event_count: 1,
95      event_type_id: 0,
96      timestamp_trace: 3468361041924,
97      cpu_id: 2,
98      thread_state: 'Running',
99      startNS: 76125,
100    },
101    {
102      id: 8,
103      callchain_id: 1,
104      timestamp: 3468361045716,
105      thread_id: 2469,
106      event_count: 1,
107      event_type_id: 0,
108      timestamp_trace: 3468361086841,
109      cpu_id: 2,
110      thread_state: 'Running',
111      startNS: 121042,
112    },
113    {
114      id: 9,
115      callchain_id: 4,
116      timestamp: 3468361054466,
117      thread_id: 1336,
118      event_count: 1,
119      event_type_id: 1,
120      timestamp_trace: 3468361095591,
121      cpu_id: 3,
122      thread_state: 'Suspend',
123      startNS: 129792,
124    },
125  ]);
126  let getPerfEventType = sqlit.queryPerfEventType;
127  getPerfEventType.mockResolvedValue([{
128    id:1,
129    report_value:'sched:sched_waking',
130  }])
131  let ss = new SpChartManager();
132  let spHiPerf = new SpHiPerf(ss);
133  it('SpHiPerf01', function () {
134    spHiPerf.init();
135    expect(spHiPerf).toBeDefined();
136  });
137  it('SpHiPerf02', function () {
138    ss.displayTip = jest.fn(()=>true);
139    expect(spHiPerf.hoverTip()).toBeUndefined();
140  });
141});
142