• 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 { TabPaneFilesystemStatisticsAnalysis } from '../../../../../../src/trace/component/trace/sheet/file-system/TabPaneFilesystemStatisticsAnalysis';
17import '../../../../../../src/trace/component/trace/sheet/file-system/TabPaneFilesystemStatisticsAnalysis';
18import { LitTable } from '../../../../../../src/base-ui/table/lit-table';
19import crypto from 'crypto';
20import { TabPaneFilter } from '../../../../../../src/trace/component/trace/sheet/TabPaneFilter';
21jest.mock('../../../../../../src/trace/component/trace/sheet/SheetUtils', () => {
22  return {
23    initSort: ()=>{}
24  };
25});
26// @ts-ignore
27window.ResizeObserver =
28  window.ResizeObserver ||
29  jest.fn().mockImplementation(() => ({
30    disconnect: jest.fn(),
31    unobserve: jest.fn(),
32    observe: jest.fn(),
33  }));
34Object.defineProperty(global.self, 'crypto', {
35  value: {
36    getRandomValues: (arr: string | any[]) => crypto.randomBytes(arr.length),
37  },
38});
39
40describe('TabPaneFilesystemStatisticsAnalysis Test', () => {
41  document.body.innerHTML = `<tabpane-file-statistics-analysis id="statistics-analysis"></tabpane-file-statistics-analysis>`;
42  let tabPane = document.querySelector<TabPaneFilesystemStatisticsAnalysis>('#statistics-analysis');
43
44  let param = {
45    anomalyEnergy: [],
46    clockMapData: { size: 193 },
47    cpuAbilityIds: [10, 8],
48    cpuFreqFilterIds: [56],
49    cpuFreqLimitDatas: [],
50    cpuStateFilterIds: [12, 98],
51    cpus: [],
52    diskAbilityIds: [],
53    diskIOLatency: false,
54    diskIOReadIds: [2, 33],
55    diskIOWriteIds: [54, 4, 54, 6],
56    diskIOipids: [2, 17, 45, 5, 16],
57    fileSysVirtualMemory: false,
58    fileSystemType: [],
59    fsCount: 3,
60    funAsync: [],
61    funTids: [],
62    hasFps: false,
63    irqMapData: { size: 996 },
64    jsMemory: [],
65    leftNs: 964699125,
66    memoryAbilityIds: [12, 34],
67    nativeMemory: [],
68    nativeMemoryStatistic: [],
69    networkAbilityIds: [34, 87],
70    perfAll: false,
71    perfCpus: [],
72    perfProcess: [],
73    perfSampleIds: [67, 33],
74    perfThread: [],
75    powerEnergy: [],
76    processTrackIds: [122, 34],
77    promiseList: [],
78    recordStartNs: 780423788588,
79    rightNs: 69267555654,
80    sdkCounterIds: [34, 22, 12],
81    sdkSliceIds: [221],
82    smapsType: [],
83    systemEnergy: [],
84    threadIds: [12, 45],
85    virtualTrackIds: [],
86    vmCount: 850,
87  };
88
89  let item = {
90    durFormat: '194.23ms ',
91    duration: 194230478,
92    isHover: true,
93    percent: '99.00',
94    pid: 3744,
95    tableName: 'test(3744)',
96  };
97
98  let res = [
99    {
100      durFormat: '1334.23ms ',
101      duration: 13230478,
102      isHover: true,
103      percent: '232.00',
104      pid: 34,
105      tableName: 'test(3554)',
106    },
107  ];
108
109  let processData = [
110    {
111      callChainId: 113,
112      dur: 24010,
113      libId: 539,
114      libName: 'libName.z.so',
115      pid: 911,
116      processName: 'ksoftirqd/1',
117      symbolId: 799,
118      symbolName: 'ksoftirqd/1 17',
119      threadName: 'ksoftirqd/1',
120      tid: 404,
121      type: 0,
122    },
123  ];
124
125  let threadStatisticsData = { durFormat: '194.23ms ', duration: 0, isHover: false, percent: '100.00', tableName: '' };
126
127  it('systemStatisticsAnalysis01', function () {
128    let litTable = new LitTable();
129    tabPane.appendChild(litTable);
130    let filter = new TabPaneFilter();
131    tabPane.filter = filter;
132    tabPane.loadingList = [];
133    tabPane.data = param;
134    expect(tabPane.fileStatisticsAnalysisCurrentSelection).toBeUndefined();
135  });
136
137  it('systemStatisticsAnalysis02', function () {
138    expect(tabPane.clearData()).toBeUndefined();
139  });
140
141  it('systemStatisticsAnalysis03', function () {
142    tabPane.fileStatisticsAnalysisProcessData = processData;
143    tabPane.getFilesystemType(item, param);
144    expect(tabPane.fileStatisticsAnalysisProgressEL.loading).toBeFalsy();
145  });
146
147  it('systemStatisticsAnalysis04', function () {
148    tabPane.fileStatisticsAnalysisProcessData = processData;
149    tabPane.getFilesystemThread(item, param);
150    expect(tabPane.currentLevel).toEqual(2);
151  });
152
153  it('systemStatisticsAnalysis05', function () {
154    tabPane.fileStatisticsAnalysisProcessData = processData;
155    tabPane.getFilesystemSo(item, param);
156    expect(tabPane.currentLevel).toEqual(3);
157  });
158
159  it('systemStatisticsAnalysis06', function () {
160    tabPane.fileStatisticsAnalysisFunctionData = processData;
161    tabPane.getFilesystemFunction(item, param);
162    expect(tabPane.currentLevel).toEqual(4);
163  });
164
165  it('systemStatisticsAnalysis07', function () {
166    expect(tabPane.typeIdToString(0)).toEqual('OPEN');
167  });
168
169  it('systemStatisticsAnalysis08', function () {
170    expect(tabPane.typeIdToString(2)).toEqual('READ');
171  });
172
173  it('systemStatisticsAnalysis09', function () {
174    expect(tabPane.typeIdToString(1)).toEqual('CLOSE');
175  });
176
177  it('systemStatisticsAnalysis10', function () {
178    expect(tabPane.getFsPieChartData(res).length).toEqual(1);
179  });
180
181  it('systemStatisticsAnalysis11', function () {
182    tabPane.fileStatisticsAnalysisProcessData = jest.fn(() => true);
183    tabPane.fileStatisticsAnalysisProcessData.reMeauseHeight = jest.fn(() => true);
184    let parames = [
185      {
186        type: 0,
187        callChainId: 13,
188        dur: 240916,
189        pid: 911,
190        tid: 404,
191        threadName: null,
192        processName: 'power_host(911)',
193        libId: 542,
194        symbolId: 802,
195        libName: 'libbattery_interface_service_1.0.z.so',
196        symbolName:
197          'OHOS::HDI::Battery::V1_0::PowerSupplyProvider::ReadBatterySysfsToBuff(char const*, char*, unsigned long) const',
198      },
199      {
200        type: 0,
201        callChainId: 17,
202        dur: 42000,
203        pid: 911,
204        tid: 404,
205        threadName: null,
206        processName: 'power_host(911)',
207        libId: 542,
208        symbolId: 802,
209        libName: 'libbattery_interface_service_1.0.z.so',
210        symbolName:
211          'OHOS::HDI::Battery::V1_0::PowerSupplyProvider::ReadBatterySysfsToBuff(char const*, char*, unsigned long) const',
212      },
213    ];
214    tabPane.getFilesystemProcess(parames, processData);
215    expect(tabPane.fileStatisticsAnalysisProcessData).not.toBeUndefined();
216  });
217  it('systemStatisticsAnalysis12', function () {
218    tabPane.currentLevel = 0;
219    let paras = [
220      {
221        type: 3,
222        callChainId: 1,
223        dur: 4757959,
224        pid: 237,
225        tid: 237,
226        threadName: 'jbd2/mmcblk0p11',
227        processName: 'jbd2/mmcblk0p11(237)',
228        libId: 263,
229        symbolId: 12560,
230        libName: 'kallsyms',
231        symbolName: 'submit_bh',
232      },
233      {
234        type: 3,
235        callChainId: 1,
236        dur: 4673084,
237        pid: 237,
238        tid: 237,
239        threadName: 'jbd2/mmcblk0p11',
240        processName: 'jbd2/mmcblk0p11(237)',
241        libId: 263,
242        symbolId: 12560,
243        libName: 'kallsyms',
244        symbolName: 'submit_bh',
245      },
246    ];
247    tabPane.currentLevelData = paras;
248    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
249    tabPane.currentLevel = 1;
250    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
251    tabPane.currentLevel = 2;
252    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
253    tabPane.currentLevel = 3;
254    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
255    tabPane.currentLevel = 4;
256    expect(tabPane.sortByColumn('tableName', 0)).toBeUndefined();
257    tabPane.currentLevel = 0;
258    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
259    tabPane.currentLevel = 1;
260    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
261    tabPane.currentLevel = 2;
262    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
263    tabPane.currentLevel = 3;
264    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
265    tabPane.currentLevel = 4;
266    expect(tabPane.sortByColumn('tableName', 1)).toBeUndefined();
267    tabPane.currentLevel = 0;
268    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
269    tabPane.currentLevel = 1;
270    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
271    tabPane.currentLevel = 2;
272    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
273    tabPane.currentLevel = 3;
274    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
275    tabPane.currentLevel = 4;
276    expect(tabPane.sortByColumn('durFormat', 1)).toBeUndefined();
277  });
278  it('systemStatisticsAnalysis13', function () {
279    let it = {
280      tableName: '',
281    };
282    expect(tabPane.fileProcessLevelClickEvent(it)).toBeUndefined();
283  });
284  it('systemStatisticsAnalysis14', function () {
285    let it = {
286      tableName: '',
287    };
288    expect(tabPane.fileTypeLevelClickEvent(it)).toBeUndefined();
289  });
290  it('systemStatisticsAnalysis15', function () {
291    let it = {
292        tableName: '',
293      };
294    expect(tabPane.fileThreadLevelClickEvent(it)).toBeUndefined();
295  });
296  it('systemStatisticsAnalysis16', function () {
297    let it = {
298      tableName: '',
299    };
300    expect(tabPane.fileSoLevelClickEvent(it)).toBeUndefined();
301  });
302  it('TabPanePerfAnalysisTest17 ', function () {
303    let itemClick = new CustomEvent('click', <CustomEventInit>{
304      detail: {
305        ...{},
306        data: {},
307      },
308      composed: true,
309    });
310    tabPane.tabName!.textContent = 'Statistic By type AllDuration';
311    tabPane.processStatisticsData = jest.fn(() => true);
312    tabPane.processStatisticsData.allDuration = jest.fn(() => true);
313    tabPane.fileStatisticsAnalysisPidData = [{}, {}];
314    tabPane.fsBack!.dispatchEvent(itemClick);
315    expect(tabPane.goBack()).toBeUndefined();
316  });
317  it('TabPanePerfAnalysisTest18 ', function () {
318    let itemClick = new CustomEvent('click', <CustomEventInit>{
319      detail: {
320        ...{},
321        data: {},
322      },
323      composed: true,
324    });
325    tabPane.tabName!.textContent = 'Statistic By Library AllDuration';
326    tabPane.threadStatisticsData = jest.fn(() => true);
327    tabPane.threadStatisticsData.allDuration = jest.fn(() => true);
328    tabPane.fileStatisticsAnalysisThreadData = [{}, {}];
329    tabPane.fsBack!.dispatchEvent(itemClick);
330    expect(tabPane.goBack()).toBeUndefined();
331  });
332  it('TabPanePerfAnalysisTest19 ', function () {
333    let itemClick = new CustomEvent('click', <CustomEventInit>{
334      detail: {
335        ...{},
336        data: {},
337      },
338      composed: true,
339    });
340    tabPane.tabName!.textContent = 'Statistic By Function AllDuration';
341    tabPane.libStatisticsData = jest.fn(() => true);
342    tabPane.libStatisticsData.allDuration = jest.fn(() => true);
343    tabPane.fileStatisticsAnalysisSoData = [{}, {}];
344    tabPane.fsBack!.dispatchEvent(itemClick);
345    expect(tabPane.goBack()).toBeUndefined();
346  });
347  it('TabPanePerfAnalysisTest20 ', function () {
348    let itemClick = new CustomEvent('click', <CustomEventInit>{
349      detail: {
350        ...{},
351        data: {},
352      },
353      composed: true,
354    });
355    tabPane.tabName!.textContent = 'Statistic By Thread AllDuration';
356    tabPane.typeStatisticsData = jest.fn(() => true);
357    tabPane.typeStatisticsData.allDuration = jest.fn(() => true);
358    tabPane.fileStatisticsAnalysisTypeData = [{}, {}];
359    tabPane.fsBack!.dispatchEvent(itemClick);
360    expect(tabPane.goBack()).toBeUndefined();
361  });
362});
363