• 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 { SpSystemTrace } from '../../../../dist/trace/component/SpSystemTrace.js';
18// @ts-ignore
19import { SpNativeMemoryChart } from '../../../../dist/trace/component/chart/SpNativeMemoryChart.js';
20// @ts-ignore
21import { SpChartManager } from '../../../../dist/trace/component/chart/SpChartManager.js';
22const sqlit = require('../../../../dist/trace/database/SqlLite.js');
23jest.mock('../../../../dist/trace/database/SqlLite.js');
24window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
25const intersectionObserverMock = () => ({
26  observe: () => null,
27});
28// @ts-ignore
29window.ResizeObserver = window.ResizeObserver ||
30  jest.fn().mockImplementation(() => ({
31    disconnect: jest.fn(),
32    unobserve: jest.fn(),
33    observe: jest.fn(),
34  }));
35describe('SpNativeMemoryChart Test', () => {
36  let chartManager = new SpChartManager();
37  let spNativeMemoryChart = new SpNativeMemoryChart(chartManager);
38
39  let queryNativeHookStatisticsCount = sqlit.queryNativeHookStatisticsCount;
40  queryNativeHookStatisticsCount.mockResolvedValue([
41    {
42      num: 2,
43    },
44  ]);
45
46  let queryNativeMemoryRealTime = sqlit.queryNativeMemoryRealTime;
47  queryNativeMemoryRealTime.mockResolvedValue([
48    {
49      ts: 1502013097360370200,
50      clock_name: 'realtime',
51    },
52  ]);
53
54  let queryBootTime = sqlit.queryBootTime;
55  queryBootTime.mockResolvedValue([
56    {
57      ts: -557295431,
58      clock_name: 'boottime',
59    },
60  ]);
61
62  let nativeHookProcess = sqlit.queryNativeHookProcess;
63  nativeHookProcess.mockResolvedValue([
64    {
65      ipid: 0,
66      pid: 0,
67      name: 'name',
68    },
69  ]);
70
71  let heapGroupByEvent = sqlit.queryHeapGroupByEvent;
72  heapGroupByEvent.mockResolvedValue([
73    {
74      eventType: 'AllocEvent',
75      sumHeapSize: 10,
76    },
77  ]);
78
79  it('SpNativeMemoryChart01', function () {
80    expect(spNativeMemoryChart.initChart()).toBeDefined();
81  });
82});
83