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 chartIrqDataSql, 18 chartIrqDataSqlMem, 19 irqDataReceiver, 20} from '../../../../src/trace/database/data-trafic/IrqDataReceiver'; 21import { TraficEnum } from "../../../../src/trace/database/data-trafic/utils/QueryEnum"; 22 23describe('IrqReceiver Test', () => { 24 let data1; 25 let data2; 26 let proc; 27 28 beforeEach(() => { 29 data1 = { 30 params: { 31 trafic: TraficEnum.ProtoBuffer, 32 cpu: 0, 33 endNS: 19473539059, 34 name: 'irq', 35 recordEndNS: 30167849973030, 36 recordStartNS: 30148376433971, 37 startNS: 0, 38 t: 1703665514720, 39 width: 708, 40 sharedArrayBuffers: {}, 41 }, 42 }; 43 data2 = { 44 params: { 45 trafic: TraficEnum.Memory, 46 cpu: 0, 47 endNS: 19473539059, 48 name: 'irq', 49 recordEndNS: 30167849973030, 50 recordStartNS: 30148376433971, 51 startNS: 0, 52 t: 1703665514720, 53 width: 708, 54 sharedArrayBuffers: {}, 55 }, 56 }; 57 proc = jest.fn((sql) => [ 58 { irqData: { argSetId: 74, dur: 3646, id: 74, startNs: 4255208 } }, 59 { irqData: { argSetId: 400, dur: 3125, id: 397, startNs: 38229687 } }, 60 ]); 61 }); 62 test('IrqReceiverTest01', () => { 63 const args = { 64 trafic: TraficEnum.ProtoBuffer, 65 cpu: 0, 66 endNS: 19473539059, 67 name: 'irq', 68 recordEndNS: 30167849973030, 69 recordStartNS: 30148376433971, 70 startNS: 0, 71 t: 1703665514720, 72 width: 708, 73 sharedArrayBuffers: {}, 74 }; 75 expect(chartIrqDataSql(args)).toBeTruthy(); 76 }); 77 test('IrqReceiverTest02', () => { 78 const args = { 79 trafic: TraficEnum.Memory, 80 cpu: 0, 81 endNS: 19473539059, 82 name: 'irq', 83 recordEndNS: 30167849973030, 84 recordStartNS: 30148376433971, 85 startNS: 0, 86 t: 1703665514720, 87 width: 708, 88 sharedArrayBuffers: {}, 89 }; 90 expect(chartIrqDataSqlMem(args)).toBeTruthy(); 91 }); 92 test('IrqReceiverTest03', () => { 93 let mockPostMessage = jest.fn(); 94 global.postMessage = mockPostMessage; 95 irqDataReceiver(data1, proc); 96 expect(mockPostMessage).toHaveBeenCalledTimes(1); 97 }); 98 test('IrqReceiverTest04', () => { 99 let mockPostMessage = jest.fn(); 100 global.postMessage = mockPostMessage; 101 irqDataReceiver(data2, proc); 102 expect(mockPostMessage).toHaveBeenCalledTimes(1); 103 }); 104}); 105