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