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 filterNativeMemoryChartData, 18 nativeMemoryDataHandler 19} from '../../../../src/trace/database/data-trafic/NativeMemoryDataReceiver'; 20 21describe(' NativeMemoryDataReceiver Test', () => { 22 let data; 23 let proc; 24 const dataCache = { 25 normalCache: new Map(), 26 statisticsCache: new Map(), 27 }; 28 beforeEach(() => { 29 data = { 30 id: 'c07094fb-5340-4f1e-be9d-cd4071a77e24', 31 name: 206, 32 action: 'exec-proto', 33 params: { 34 totalNS: 108952700947, 35 recordStartNS: 8406282873525, 36 recordEndNS: 8515235574472, 37 model: 'native_hook', 38 processes: [ 39 1 40 ], 41 trafic: 1, 42 isCache: true 43 } 44 }; 45 proc = jest.fn((sql) => [ 46 {data: {id: 4, startTs: 4.4, pid: 40, tid: 400, dur: 40000, depth: 4}}, 47 {data: {id: 5, startTs: 5.5, pid: 50, tid: 500, dur: 50000, depth: 5}}, 48 ]); 49 }); 50 afterEach(() => { 51 dataCache.normalCache.clear(); 52 dataCache.statisticsCache.clear(); 53 }); 54 it(' NativeMemoryDataReceiver01', () => { 55 const mockPostMessage = jest.fn(); 56 global.postMessage = mockPostMessage; 57 nativeMemoryDataHandler(data, proc); 58 expect(mockPostMessage).toHaveBeenCalledTimes(1); 59 }); 60 it(' NativeMemoryDataReceiver02', () => { 61 const model = 'native_hook'; 62 const startNS = 0; 63 const endNS = 100; 64 const totalNS = 200; 65 const drawType = 0; 66 const frame = 1; 67 const key = 'testKey'; 68 const result = filterNativeMemoryChartData(model, startNS, endNS, totalNS, drawType, frame, key); 69 expect(result.startTime).toEqual([]); 70 expect(result.dur).toEqual([]); 71 expect(result.heapSize).toEqual([]); 72 expect(result.density).toEqual([]); 73 }); 74}); 75