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 chartHiperfCpuData10MSProtoSql, chartHiperfCpuDataProtoSql, hiperfCpuDataReceiver 18} from '../../../../../src/trace/database/data-trafic/hiperf/HiperfCpuDataReceiver'; 19 20describe(' HiperfCpuDataReceiver Test', () => { 21 let data; 22 let proc; 23 24 beforeEach(() => { 25 data = { 26 id: '87cc16a3-5dc7-4202-9ac9-4f038b2979ee', 27 name: 200, 28 action: 'exec-proto', 29 params: { 30 cpu: -1, 31 scale: 2000000000, 32 maxCpuCount: 4, 33 drawType: -2, 34 intervalPerf: 1, 35 startNS: 0, 36 endNS: 30230251246, 37 recordStartNS: 1596201782236, 38 recordEndNS: 1626432033482, 39 width: 549, 40 trafic: 3 41 } 42 }; 43 proc = jest.fn((sql: any) => [ 44 {hiperfData: {startNs: 5600000000, eventCount: 58513886, sampleCount: 42, callchainId: 2279}}, 45 {hiperfData: {startNs: 5630000000, eventCount: 60359281, sampleCount: 36, callchainId: 5147}} 46 ]); 47 }); 48 it('HiperfCpuDataReceiverTest01 ', function () { 49 const args = { 50 recordStartNS: 1000, 51 endNS: 3000, 52 startNS: 2000, 53 width: 10 54 }; 55 expect(chartHiperfCpuData10MSProtoSql(args)).toBeTruthy(); 56 expect(chartHiperfCpuDataProtoSql(args)).toBeTruthy(); 57 }); 58 it('HiperfCpuDataReceiverTest02 ', function () { 59 const mockPostMessage = jest.fn(); 60 global.postMessage = mockPostMessage; 61 hiperfCpuDataReceiver(data, proc); 62 expect(mockPostMessage).toHaveBeenCalledTimes(1); 63 }); 64});