• 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 {
17  NativeHookStatistics,
18  NativeHookMalloc,
19  NativeEventHeap,
20  NativeHookProcess,
21  NativeHookStatisticsTableData,
22  NativeMemory,
23  NativeHookSamplerInfo,
24  NativeHookSampleQueryInfo,
25  NativeHookCallInfo,
26  NativeEvent,
27} from '../../../src/trace/bean/NativeHook';
28jest.mock('../../../src/trace/component/trace/base/TraceRow', () => {
29  return {};
30});
31
32describe('NativeHook Test', () => {
33  it('NativeHookStatisticsTest01', function () {
34    let nativeHookStatistics = new NativeHookStatistics();
35    nativeHookStatistics = {
36      eventId: 0,
37      eventType: 'eventType',
38      subType: 'subType',
39      heapSize: 0,
40      addr: 'addr',
41      startTs: 0,
42      endTs: 0,
43      sumHeapSize: 0,
44      max: 0,
45      count: 0,
46      tid: 0,
47      isSelected: false,
48    };
49    expect(nativeHookStatistics).not.toBeUndefined();
50    expect(nativeHookStatistics).toMatchInlineSnapshot(
51{
52  eventId: expect.any(Number),
53  eventType: expect.any(String),
54  subType: expect.any(String),
55  heapSize: expect.any(Number),
56  addr: expect.any(String),
57  startTs: expect.any(Number),
58  endTs: expect.any(Number),
59  sumHeapSize: expect.any(Number),
60  max: expect.any(Number),
61  count: expect.any(Number),
62  tid: expect.any(Number),
63  isSelected: expect.any(Boolean) }, `
64{
65  "addr": Any<String>,
66  "count": Any<Number>,
67  "endTs": Any<Number>,
68  "eventId": Any<Number>,
69  "eventType": Any<String>,
70  "heapSize": Any<Number>,
71  "isSelected": Any<Boolean>,
72  "max": Any<Number>,
73  "startTs": Any<Number>,
74  "subType": Any<String>,
75  "sumHeapSize": Any<Number>,
76  "tid": Any<Number>,
77}
78`);
79  });
80
81  it('NativeEventHeapTest02', function () {
82    let nativeHookMalloc = new NativeHookMalloc();
83    nativeHookMalloc = {
84      eventType: 'eventType',
85      subType: 'subType',
86      heapSize: 0,
87      allocByte: 0,
88      allocCount: 0,
89      freeByte: 0,
90      freeCount: 0,
91    };
92    expect(nativeHookMalloc).not.toBeUndefined();
93    expect(nativeHookMalloc).toMatchInlineSnapshot(
94{
95  eventType: expect.any(String),
96  subType: expect.any(String),
97  heapSize: expect.any(Number),
98  allocByte: expect.any(Number),
99  allocCount: expect.any(Number),
100  freeByte: expect.any(Number),
101  freeCount: expect.any(Number) }, `
102{
103  "allocByte": Any<Number>,
104  "allocCount": Any<Number>,
105  "eventType": Any<String>,
106  "freeByte": Any<Number>,
107  "freeCount": Any<Number>,
108  "heapSize": Any<Number>,
109  "subType": Any<String>,
110}
111`);
112  });
113
114  it('NativeEventHeapTest03', function () {
115    let nativeEventHeap = new NativeEventHeap();
116    nativeEventHeap = {
117      eventType: 'eventType',
118      sumHeapSize: 0,
119    };
120    expect(nativeEventHeap).not.toBeUndefined();
121    expect(nativeEventHeap).toMatchInlineSnapshot(
122{
123  eventType: expect.any(String),
124  sumHeapSize: expect.any(Number) }, `
125{
126  "eventType": Any<String>,
127  "sumHeapSize": Any<Number>,
128}
129`);
130  });
131
132  it('NativeHookProcessTest04', function () {
133    let nativeHookProcess = new NativeHookProcess();
134    nativeHookProcess = {
135      ipid: 0,
136      pid: 0,
137      name: 'name',
138    };
139    expect(nativeHookProcess).not.toBeUndefined();
140    expect(nativeHookProcess).toMatchInlineSnapshot(
141{
142  ipid: expect.any(Number),
143  pid: expect.any(Number),
144  name: expect.any(String) }, `
145{
146  "ipid": Any<Number>,
147  "name": Any<String>,
148  "pid": Any<Number>,
149}
150`);
151  });
152
153  it('NativeHookStatisticsTableDataTest05', function () {
154    let nativeHookStatisticsTableData = new NativeHookStatisticsTableData();
155    nativeHookStatisticsTableData = {
156      memoryTap: '',
157      existing: 0,
158      existingString: '',
159      allocCount: 0,
160      freeCount: 0,
161      totalBytes: 0,
162      totalBytesString: '',
163      maxStr: '',
164      max: 0,
165      totalCount: 0,
166    };
167    expect(nativeHookStatisticsTableData).not.toBeUndefined();
168    expect(nativeHookStatisticsTableData).toMatchInlineSnapshot(
169{
170  memoryTap: expect.any(String),
171  existing: expect.any(Number),
172  existingString: expect.any(String),
173  allocCount: expect.any(Number),
174  freeCount: expect.any(Number),
175  totalBytes: expect.any(Number),
176  totalBytesString: expect.any(String),
177  maxStr: expect.any(String),
178  max: expect.any(Number),
179  totalCount: expect.any(Number) }, `
180{
181  "allocCount": Any<Number>,
182  "existing": Any<Number>,
183  "existingString": Any<String>,
184  "freeCount": Any<Number>,
185  "max": Any<Number>,
186  "maxStr": Any<String>,
187  "memoryTap": Any<String>,
188  "totalBytes": Any<Number>,
189  "totalBytesString": Any<String>,
190  "totalCount": Any<Number>,
191}
192`);
193  });
194
195  it('NativeMemoryTest06', function () {
196    let nativeMemory = new NativeMemory();
197    nativeMemory = {
198      index: 0,
199      eventId: 0,
200      eventType: 'eventType',
201      subType: 'subType',
202      addr: 'addr',
203      startTs: 0,
204      timestamp: 'timestamp',
205      heapSize: 0,
206      heapSizeUnit: 'heapSizeUnit',
207      symbol: 'symbol',
208      library: 'library',
209      isSelected: false,
210    };
211    expect(nativeMemory).not.toBeUndefined();
212    expect(nativeMemory).toMatchInlineSnapshot(
213{
214  index: expect.any(Number),
215  eventId: expect.any(Number),
216  eventType: expect.any(String),
217  subType: expect.any(String),
218  addr: expect.any(String),
219  startTs: expect.any(Number),
220  timestamp: expect.any(String),
221  heapSize: expect.any(Number),
222  heapSizeUnit: expect.any(String),
223  symbol: expect.any(String),
224  library: expect.any(String),
225  isSelected: expect.any(Boolean) }, `
226{
227  "addr": Any<String>,
228  "eventId": Any<Number>,
229  "eventType": Any<String>,
230  "heapSize": Any<Number>,
231  "heapSizeUnit": Any<String>,
232  "index": Any<Number>,
233  "isSelected": Any<Boolean>,
234  "library": Any<String>,
235  "startTs": Any<Number>,
236  "subType": Any<String>,
237  "symbol": Any<String>,
238  "timestamp": Any<String>,
239}
240`);
241  });
242
243  it('NativeHookCallInfoTest07', function () {
244    let nativeHookSamplerInfo = new NativeHookSamplerInfo();
245    nativeHookSamplerInfo = {
246      current: 'current',
247      currentSize: 0,
248      startTs: 0,
249      heapSize: 0,
250      snapshot: 'snapshot',
251      growth: 'growth',
252      total: 0,
253      totalGrowth: 'totalGrowth',
254      existing: 0,
255      timestamp: 'timestamp',
256      eventId: -1,
257    };
258    expect(nativeHookSamplerInfo).not.toBeUndefined();
259    expect(nativeHookSamplerInfo).toMatchInlineSnapshot(
260{
261  current: expect.any(String),
262  currentSize: expect.any(Number),
263  startTs: expect.any(Number),
264  heapSize: expect.any(Number),
265  snapshot: expect.any(String),
266  growth: expect.any(String),
267  total: expect.any(Number),
268  totalGrowth: expect.any(String),
269  existing: expect.any(Number),
270  timestamp: expect.any(String),
271  eventId: expect.any(Number) }, `
272{
273  "current": Any<String>,
274  "currentSize": Any<Number>,
275  "eventId": Any<Number>,
276  "existing": Any<Number>,
277  "growth": Any<String>,
278  "heapSize": Any<Number>,
279  "snapshot": Any<String>,
280  "startTs": Any<Number>,
281  "timestamp": Any<String>,
282  "total": Any<Number>,
283  "totalGrowth": Any<String>,
284}
285`);
286  });
287
288  it('NativeHookCallInfoTest08', function () {
289    let nativeHookSampleQueryInfo = new NativeHookSampleQueryInfo();
290    nativeHookSampleQueryInfo = {
291      eventId: -1,
292      current: 0,
293      eventType: 'eventType',
294      subType: 'subType',
295      growth: 0,
296      existing: 0,
297      addr: 'addr',
298      startTs: 0,
299      endTs: 0,
300      total: 0,
301    };
302
303    expect(nativeHookSampleQueryInfo).not.toBeUndefined();
304    expect(nativeHookSampleQueryInfo).toMatchInlineSnapshot(
305{
306  eventId: expect.any(Number),
307  current: expect.any(Number),
308  eventType: expect.any(String),
309  subType: expect.any(String),
310  growth: expect.any(Number),
311  existing: expect.any(Number),
312  addr: expect.any(String),
313  startTs: expect.any(Number),
314  endTs: expect.any(Number),
315  total: expect.any(Number) }, `
316{
317  "addr": Any<String>,
318  "current": Any<Number>,
319  "endTs": Any<Number>,
320  "eventId": Any<Number>,
321  "eventType": Any<String>,
322  "existing": Any<Number>,
323  "growth": Any<Number>,
324  "startTs": Any<Number>,
325  "subType": Any<String>,
326  "total": Any<Number>,
327}
328`);
329  });
330
331  it('NativeHookCallInfoTest09', function () {
332    let nativeHookCallInfo = new NativeHookCallInfo();
333    nativeHookCallInfo = {
334      id: 'id',
335      pid: 'pid',
336      library: 'library',
337      title: 'title',
338      count: 0,
339      type: 0,
340      heapSize: 0,
341      heapSizeStr: 'heapSizeStr',
342      eventId: 0,
343      threadId: 0,
344      isSelected: false,
345    };
346    expect(nativeHookCallInfo).not.toBeUndefined();
347    expect(nativeHookCallInfo).toMatchInlineSnapshot(
348{
349  id: expect.any(String),
350  pid: expect.any(String),
351  library: expect.any(String),
352  title: expect.any(String),
353  count: expect.any(Number),
354  type: expect.any(Number),
355  heapSize: expect.any(Number),
356  heapSizeStr: expect.any(String),
357  eventId: expect.any(Number),
358  threadId: expect.any(Number),
359  isSelected: expect.any(Boolean) }, `
360{
361  "count": Any<Number>,
362  "eventId": Any<Number>,
363  "heapSize": Any<Number>,
364  "heapSizeStr": Any<String>,
365  "id": Any<String>,
366  "isSelected": Any<Boolean>,
367  "library": Any<String>,
368  "pid": Any<String>,
369  "threadId": Any<Number>,
370  "title": Any<String>,
371  "type": Any<Number>,
372}
373`);
374  });
375
376  it('NativeHookCallInfoTest10', function () {
377    let nativeHookSamplerInfo = new NativeHookSamplerInfo();
378    expect(nativeHookSamplerInfo.merageObj(NativeHookSamplerInfo)).toBeUndefined();
379  });
380
381  it('NativeEventHeapTest11', function () {
382    let nativeEvent = new NativeEvent();
383    nativeEvent = {
384      startTime: 0,
385      heapSize: 0,
386      eventType: '',
387    };
388    expect(nativeEvent).not.toBeUndefined();
389    expect(nativeEvent).toMatchInlineSnapshot(
390{
391  startTime: expect.any(Number),
392  heapSize: expect.any(Number),
393  eventType: expect.any(String) }, `
394{
395  "eventType": Any<String>,
396  "heapSize": Any<Number>,
397  "startTime": Any<Number>,
398}
399`);
400  });
401});
402