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 { threadPool } from '../../../../src/trace/database/SqlLite'; 17import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 18import { CpuStruct } from '../../../../src/trace/database/ui-worker/cpu/ProcedureWorkerCPU'; 19import { cpuDataSender } from '../../../../src/trace/database/data-trafic/CpuDataSender'; 20import { QueryEnum } from '../../../../src/trace/database/data-trafic/utils/QueryEnum'; 21jest.mock('../../../../src/js-heap/model/DatabaseStruct', () => {}); 22jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 23 return {}; 24}); 25jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 26 return {}; 27}); 28describe('CpuDataSender Test', () => { 29 let CpuData = { 30 processId: 182, 31 cpu: 0, 32 tid: 182, 33 id: 76, 34 dur: 198041, 35 startTime: 6670, 36 end_state: 'S', 37 priority: 4294, 38 processName: 'sugov:0', 39 processCmdLine: 'sugov:0', 40 name: 'sugov:0', 41 type: 'thread', 42 frame: { 43 y: 5, 44 height: 30, 45 x: 4, 46 width: 1 47 }, 48 translateY: 0 49 } 50 it('CpuDataSenderTest01 ', function () { 51 threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 52 callback(CpuData, 1, true); 53 }); 54 let CpuDataTraceRow = TraceRow.skeleton<CpuStruct>(); 55 cpuDataSender(QueryEnum.CpuData, CpuDataTraceRow).then(res => { 56 expect(res).toHaveLength(1); 57 }); 58 }); 59}); 60