• 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 { TabPaneFilesystemStatisticsAnalysis } from '../../../../../../dist/trace/component/trace/sheet/file-system/TabPaneFilesystemStatisticsAnalysis.js';
18import '../../../../../../dist/trace/component/trace/sheet/file-system/TabPaneFilesystemStatisticsAnalysis.js';
19// @ts-ignore
20import { LitTable } from '../../../../../../dist/base-ui/table/lit-table.js';
21import crypto from 'crypto';
22// @ts-ignore
23import { TabPaneFilter } from '../../../../../../dist/trace/component/trace/sheet/TabPaneFilter.js';
24// @ts-ignore
25window.ResizeObserver = window.ResizeObserver ||
26  jest.fn().mockImplementation(() => ({
27    disconnect: jest.fn(),
28    unobserve: jest.fn(),
29    observe: jest.fn(),
30  }));
31Object.defineProperty(global.self, 'crypto', {
32  value: {
33    getRandomValues: (arr: string | any[]) => crypto.randomBytes(arr.length),
34  },
35});
36
37describe('TabPaneFilesystemStatisticsAnalysis Test', () => {
38  document.body.innerHTML = `<tabpane-file-statistics-analysis id="statistics-analysis"></tabpane-file-statistics-analysis>`;
39  let tabPane = document.querySelector<TabPaneFilesystemStatisticsAnalysis>('#statistics-analysis');
40
41  let param = {
42    anomalyEnergy: [],
43    clockMapData: { size: 193 },
44    cpuAbilityIds: [10,8],
45    cpuFreqFilterIds: [56],
46    cpuFreqLimitDatas: [],
47    cpuStateFilterIds: [12,98],
48    cpus: [],
49    diskAbilityIds: [],
50    diskIOLatency: false,
51    diskIOReadIds: [2,33],
52    diskIOWriteIds: [54, 4, 54, 6],
53    diskIOipids: [2, 17, 45, 5, 16],
54    fileSysVirtualMemory: false,
55    fileSystemType: [],
56    fsCount: 3,
57    funAsync: [],
58    funTids: [],
59    hasFps: false,
60    irqMapData: { size: 996 },
61    jsMemory: [],
62    leftNs: 964699125,
63    memoryAbilityIds: [12,34],
64    nativeMemory: [],
65    nativeMemoryStatistic: [],
66    networkAbilityIds: [34,87],
67    perfAll: false,
68    perfCpus: [],
69    perfProcess: [],
70    perfSampleIds: [67,33],
71    perfThread: [],
72    powerEnergy: [],
73    processTrackIds: [122,34],
74    promiseList: [],
75    recordStartNs: 780423788588,
76    rightNs: 69267555654,
77    sdkCounterIds: [34,22,12],
78    sdkSliceIds: [221],
79    smapsType: [],
80    systemEnergy: [],
81    threadIds: [12,45],
82    virtualTrackIds: [],
83    vmCount: 850,
84  };
85
86  let item = {
87    durFormat: '194.23ms ',
88    duration: 194230478,
89    isHover: true,
90    percent: '99.00',
91    pid: 3744,
92    tableName: 'test(3744)',
93  };
94
95  let res = [
96    {
97      durFormat: '1334.23ms ',
98      duration: 13230478,
99      isHover: true,
100      percent: '232.00',
101      pid: 34,
102      tableName: 'test(3554)',
103    },
104  ];
105
106  let processData = [
107    {
108      callChainId: 113,
109      dur: 24010,
110      libId: 539,
111      libName: 'libName.z.so',
112      pid: 911,
113      processName: 'ksoftirqd/1',
114      symbolId: 799,
115      symbolName: 'ksoftirqd/1 17',
116      threadName: 'ksoftirqd/1',
117      tid: 404,
118      type: 0,
119    },
120  ];
121
122  let threadStatisticsData = { durFormat: '194.23ms ', duration: 0, isHover: false, percent: '100.00', tableName: '' };
123
124  it('systemStatisticsAnalysis01', function () {
125    let litTable = new LitTable();
126    tabPane.appendChild(litTable);
127    let filter = new TabPaneFilter();
128    tabPane.filter = filter;
129    tabPane.loadingList = [];
130    tabPane.data = param;
131    expect(tabPane.fileStatisticsAnalysisCurrentSelection).not.toBeUndefined();
132  });
133
134  it('systemStatisticsAnalysis02', function () {
135    expect(tabPane.clearData()).toBeUndefined();
136  });
137
138  it('systemStatisticsAnalysis03', function () {
139    tabPane.fileStatisticsAnalysisProcessData = processData;
140    tabPane.getFilesystemType(item, param);
141    expect(tabPane.fileStatisticsAnalysisProgressEL.loading).toBeFalsy();
142  });
143
144  it('systemStatisticsAnalysis04', function () {
145    tabPane.fileStatisticsAnalysisProcessData = processData;
146    tabPane.getFilesystemThread(item, param);
147    expect(tabPane.currentLevel).toEqual(2);
148  });
149
150  it('systemStatisticsAnalysis05', function () {
151    tabPane.fileStatisticsAnalysisProcessData = processData;
152    tabPane.getFilesystemSo(item, param);
153    expect(tabPane.currentLevel).toEqual(3);
154  });
155
156  it('systemStatisticsAnalysis06', function () {
157    tabPane.fileStatisticsAnalysisProcessData = processData;
158    tabPane.getFilesystemFunction(item, param);
159    expect(tabPane.currentLevel).toEqual(4);
160  });
161
162  it('systemStatisticsAnalysis07', function () {
163    expect(tabPane.typeIdToString(0)).toEqual('OPEN');
164  });
165
166  it('systemStatisticsAnalysis08', function () {
167    expect(tabPane.typeIdToString(2)).toEqual('READ');
168  });
169
170  it('systemStatisticsAnalysis09', function () {
171    expect(tabPane.typeIdToString(1)).toEqual('CLOSE');
172  });
173
174  it('systemStatisticsAnalysis10', function () {
175    expect(tabPane.getFsPieChartData(res).length).toEqual(1);
176  });
177
178  it('systemStatisticsAnalysis11', function () {
179    tabPane.fileStatisticsAnalysisProcessData = jest.fn(() => true);
180    tabPane.fileStatisticsAnalysisProcessData.reMeauseHeight = jest.fn(() => true);
181    let parames = [
182      {
183        type: 0,
184        callChainId: 13,
185        dur: 240916,
186        pid: 911,
187        tid: 404,
188        threadName: null,
189        processName: 'power_host(911)',
190        libId: 542,
191        symbolId: 802,
192        libName: 'libbattery_interface_service_1.0.z.so',
193        symbolName:
194          'OHOS::HDI::Battery::V1_0::PowerSupplyProvider::ReadBatterySysfsToBuff(char const*, char*, unsigned long) const',
195      },
196      {
197        type: 0,
198        callChainId: 17,
199        dur: 42000,
200        pid: 911,
201        tid: 404,
202        threadName: null,
203        processName: 'power_host(911)',
204        libId: 542,
205        symbolId: 802,
206        libName: 'libbattery_interface_service_1.0.z.so',
207        symbolName:
208          'OHOS::HDI::Battery::V1_0::PowerSupplyProvider::ReadBatterySysfsToBuff(char const*, char*, unsigned long) const',
209      },
210    ];
211    tabPane.getFilesystemProcess(parames, processData);
212    expect(tabPane.fileStatisticsAnalysisProcessData).not.toBeUndefined();
213  });
214  it('systemStatisticsAnalysis12', function () {
215    tabPane.currentLevel = 0;
216    let paras = [
217      {
218        type: 3,
219        callChainId: 1,
220        dur: 4757959,
221        pid: 237,
222        tid: 237,
223        threadName: 'jbd2/mmcblk0p11',
224        processName: 'jbd2/mmcblk0p11(237)',
225        libId: 263,
226        symbolId: 12560,
227        libName: 'kallsyms',
228        symbolName: 'submit_bh',
229      },
230      {
231        type: 3,
232        callChainId: 1,
233        dur: 4673084,
234        pid: 237,
235        tid: 237,
236        threadName: 'jbd2/mmcblk0p11',
237        processName: 'jbd2/mmcblk0p11(237)',
238        libId: 263,
239        symbolId: 12560,
240        libName: 'kallsyms',
241        symbolName: 'submit_bh',
242      },
243    ];
244    tabPane.currentLevelData = paras;
245    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
246    tabPane.currentLevel = 1;
247    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
248    tabPane.currentLevel = 2;
249    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
250    tabPane.currentLevel = 3;
251    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
252    tabPane.currentLevel = 4;
253    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
254    tabPane.currentLevel = 0;
255    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
256    tabPane.currentLevel = 1;
257    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
258    tabPane.currentLevel = 2;
259    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
260    tabPane.currentLevel = 3;
261    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
262    tabPane.currentLevel = 4;
263    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
264    tabPane.currentLevel = 0;
265    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
266    tabPane.currentLevel = 1;
267    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
268    tabPane.currentLevel = 2;
269    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
270    tabPane.currentLevel = 3;
271    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
272    tabPane.currentLevel = 4;
273    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
274  });
275});
276