1fb726d48Sopenharmony_ci 2fb726d48Sopenharmony_ci/* 3fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 4fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 5fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 6fb726d48Sopenharmony_ci * You may obtain a copy of the License at 7fb726d48Sopenharmony_ci * 8fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 9fb726d48Sopenharmony_ci * 10fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 11fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 12fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 14fb726d48Sopenharmony_ci * limitations under the License. 15fb726d48Sopenharmony_ci */ 16fb726d48Sopenharmony_ciimport '../../../../src/trace/component/trace/base/TraceRow'; 17fb726d48Sopenharmony_ciimport { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 18fb726d48Sopenharmony_ciimport { 19fb726d48Sopenharmony_ci cpuAbilityUserDataSender, 20fb726d48Sopenharmony_ci abilityMemoryUsedDataSender, 21fb726d48Sopenharmony_ci abilityBytesReadDataSender, 22fb726d48Sopenharmony_ci abilityBytesInTraceDataSender 23fb726d48Sopenharmony_ci} from '../../../../src/trace/database/data-trafic/AbilityMonitorSender'; 24fb726d48Sopenharmony_ciimport { threadPool } from '../../../../src/trace/database/SqlLite'; 25fb726d48Sopenharmony_ciimport { DiskAbilityMonitorStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerDiskIoAbility'; 26fb726d48Sopenharmony_ciimport { NetworkAbilityMonitorStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerNetworkAbility'; 27fb726d48Sopenharmony_ciimport { CpuAbilityMonitorStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerCpuAbility'; 28fb726d48Sopenharmony_ciimport { MemoryAbilityMonitorStruct } from '../../../../src/trace/database/ui-worker/ProcedureWorkerMemoryAbility'; 29fb726d48Sopenharmony_cijest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 30fb726d48Sopenharmony_ci return {}; 31fb726d48Sopenharmony_ci}); 32fb726d48Sopenharmony_cijest.mock('../../../../src/trace/database/ui-worker/ProcedureWorkerSnapshot', () => { 33fb726d48Sopenharmony_ci return {}; 34fb726d48Sopenharmony_ci}); 35fb726d48Sopenharmony_cijest.mock('../../../../src/js-heap/model/DatabaseStruct', () => {}); 36fb726d48Sopenharmony_cidescribe('AbilityMonitorSender Test', () => { 37fb726d48Sopenharmony_ci let traceRowData = { 38fb726d48Sopenharmony_ci dur: 9928, 39fb726d48Sopenharmony_ci frame: 40fb726d48Sopenharmony_ci {x: 16, y: 5, width: 17, height: 30}, 41fb726d48Sopenharmony_ci startNS: 9928, 42fb726d48Sopenharmony_ci value: 6 43fb726d48Sopenharmony_ci } 44fb726d48Sopenharmony_ci let useTraceRowData = { 45fb726d48Sopenharmony_ci dur: 9928, 46fb726d48Sopenharmony_ci frame: 47fb726d48Sopenharmony_ci {x: 16, y: 5, width: 17, height: 30}, 48fb726d48Sopenharmony_ci startNS: 9928, 49fb726d48Sopenharmony_ci value: 2.62424 50fb726d48Sopenharmony_ci } 51fb726d48Sopenharmony_ci let sysTraceRowData = { 52fb726d48Sopenharmony_ci dur: 92876, 53fb726d48Sopenharmony_ci frame: 54fb726d48Sopenharmony_ci {x: 16, y: 5, width: 17, height: 30}, 55fb726d48Sopenharmony_ci startNS: 6648, 56fb726d48Sopenharmony_ci value: 3.474 57fb726d48Sopenharmony_ci } 58fb726d48Sopenharmony_ci let memoryUsedData = { 59fb726d48Sopenharmony_ci dur: 877, 60fb726d48Sopenharmony_ci frame: 61fb726d48Sopenharmony_ci {x: 68, y: 5, width: 83, height: 30}, 62fb726d48Sopenharmony_ci startNS: 2089, 63fb726d48Sopenharmony_ci value: 2012 64fb726d48Sopenharmony_ci } 65fb726d48Sopenharmony_ci let bytesReadData = { 66fb726d48Sopenharmony_ci dur: 9961, 67fb726d48Sopenharmony_ci frame: 68fb726d48Sopenharmony_ci {x: 16, y: 5, width: 17, height: 30}, 69fb726d48Sopenharmony_ci startNS: 147, 70fb726d48Sopenharmony_ci value: 4 71fb726d48Sopenharmony_ci } 72fb726d48Sopenharmony_ci let bytesInTraceRowData = { 73fb726d48Sopenharmony_ci dur: 1768, 74fb726d48Sopenharmony_ci frame: 75fb726d48Sopenharmony_ci {x: 16, y: 5, width: 18, height: 30}, 76fb726d48Sopenharmony_ci startNS: 21817, 77fb726d48Sopenharmony_ci value: 24 78fb726d48Sopenharmony_ci } 79fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest01', () => { 80fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 81fb726d48Sopenharmony_ci callback(traceRowData, 1, true); 82fb726d48Sopenharmony_ci }); 83fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<CpuAbilityMonitorStruct>(); 84fb726d48Sopenharmony_ci cpuAbilityUserDataSender(traceRow,'CpuAbilityMonitorData').then(res => { 85fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 86fb726d48Sopenharmony_ci }); 87fb726d48Sopenharmony_ci }); 88fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest02', () => { 89fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 90fb726d48Sopenharmony_ci callback(useTraceRowData, 1, true); 91fb726d48Sopenharmony_ci }); 92fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<CpuAbilityMonitorStruct>(); 93fb726d48Sopenharmony_ci cpuAbilityUserDataSender(traceRow,'CpuAbilityUserData').then(res => { 94fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 95fb726d48Sopenharmony_ci }); 96fb726d48Sopenharmony_ci }); 97fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest03', () => { 98fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 99fb726d48Sopenharmony_ci callback(sysTraceRowData, 1, true); 100fb726d48Sopenharmony_ci }); 101fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<CpuAbilityMonitorStruct>(); 102fb726d48Sopenharmony_ci cpuAbilityUserDataSender(traceRow,'CpuAbilitySystemData').then(res => { 103fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 104fb726d48Sopenharmony_ci }); 105fb726d48Sopenharmony_ci }); 106fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest04', () => { 107fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 108fb726d48Sopenharmony_ci callback(memoryUsedData, 1, true); 109fb726d48Sopenharmony_ci }); 110fb726d48Sopenharmony_ci let memoryUsedTraceRow = TraceRow.skeleton<MemoryAbilityMonitorStruct>(); 111fb726d48Sopenharmony_ci abilityMemoryUsedDataSender('2241',memoryUsedTraceRow).then(res => { 112fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 113fb726d48Sopenharmony_ci }); 114fb726d48Sopenharmony_ci }); 115fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest05', () => { 116fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 117fb726d48Sopenharmony_ci callback(memoryUsedData, 1, true); 118fb726d48Sopenharmony_ci }); 119fb726d48Sopenharmony_ci let memoryUsedTraceRow = TraceRow.skeleton<MemoryAbilityMonitorStruct>(); 120fb726d48Sopenharmony_ci abilityMemoryUsedDataSender('2241',memoryUsedTraceRow).then(res => { 121fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 122fb726d48Sopenharmony_ci }); 123fb726d48Sopenharmony_ci }); 124fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest06', () => { 125fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 126fb726d48Sopenharmony_ci callback(bytesReadData, 1 , true); 127fb726d48Sopenharmony_ci }); 128fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<DiskAbilityMonitorStruct>(); 129fb726d48Sopenharmony_ci abilityBytesReadDataSender(traceRow,'AbilityBytesReadData').then(res => { 130fb726d48Sopenharmony_ci expect(Array.isArray(res)).toBe(true); 131fb726d48Sopenharmony_ci }); 132fb726d48Sopenharmony_ci }); 133fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest07', () => { 134fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 135fb726d48Sopenharmony_ci callback(bytesReadData, 1, true); 136fb726d48Sopenharmony_ci }); 137fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<DiskAbilityMonitorStruct>(); 138fb726d48Sopenharmony_ci abilityBytesReadDataSender(traceRow,'AbilityBytesWrittenData').then(res => { 139fb726d48Sopenharmony_ci expect(Array.isArray(res)).toBe(true); 140fb726d48Sopenharmony_ci }); 141fb726d48Sopenharmony_ci }); 142fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest08', () => { 143fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 144fb726d48Sopenharmony_ci callback(bytesReadData, 1, true); 145fb726d48Sopenharmony_ci }); 146fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<DiskAbilityMonitorStruct>(); 147fb726d48Sopenharmony_ci abilityBytesReadDataSender(traceRow,'AbilityReadOpsData').then(res => { 148fb726d48Sopenharmony_ci expect(Array.isArray(res)).toBe(true); 149fb726d48Sopenharmony_ci }); 150fb726d48Sopenharmony_ci }); 151fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest08', () => { 152fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 153fb726d48Sopenharmony_ci callback(bytesReadData, 1, true); 154fb726d48Sopenharmony_ci }); 155fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<DiskAbilityMonitorStruct>(); 156fb726d48Sopenharmony_ci abilityBytesReadDataSender(traceRow,'AbilityWrittenOpsData').then(res => { 157fb726d48Sopenharmony_ci expect(Array.isArray(res)).toBe(true); 158fb726d48Sopenharmony_ci }); 159fb726d48Sopenharmony_ci }); 160fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest09', () => { 161fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 162fb726d48Sopenharmony_ci callback(bytesInTraceRowData, 1, true); 163fb726d48Sopenharmony_ci }); 164fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<NetworkAbilityMonitorStruct>(); 165fb726d48Sopenharmony_ci abilityBytesInTraceDataSender(traceRow, 'AbilityBytesInTraceData').then(res => { 166fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 167fb726d48Sopenharmony_ci }); 168fb726d48Sopenharmony_ci }); 169fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest10', () => { 170fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 171fb726d48Sopenharmony_ci callback(bytesInTraceRowData, 1, true); 172fb726d48Sopenharmony_ci }); 173fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<NetworkAbilityMonitorStruct>(); 174fb726d48Sopenharmony_ci abilityBytesInTraceDataSender(traceRow, 'AbilityBytesOutTraceData').then(res => { 175fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 176fb726d48Sopenharmony_ci }); 177fb726d48Sopenharmony_ci }); 178fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest11', () => { 179fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 180fb726d48Sopenharmony_ci callback(bytesInTraceRowData, 1, true); 181fb726d48Sopenharmony_ci }); 182fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<NetworkAbilityMonitorStruct>(); 183fb726d48Sopenharmony_ci abilityBytesInTraceDataSender(traceRow, 'AbilityPacketInTraceData').then(res => { 184fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 185fb726d48Sopenharmony_ci }); 186fb726d48Sopenharmony_ci }); 187fb726d48Sopenharmony_ci it('AbilityMonitorSenderTest12', () => { 188fb726d48Sopenharmony_ci threadPool.submitProto = jest.fn((query: number, params: any, callback: Function) => { 189fb726d48Sopenharmony_ci callback(bytesInTraceRowData, 1, true); 190fb726d48Sopenharmony_ci }); 191fb726d48Sopenharmony_ci let traceRow = TraceRow.skeleton<NetworkAbilityMonitorStruct>(); 192fb726d48Sopenharmony_ci abilityBytesInTraceDataSender(traceRow, 'AbilityPacketsOutTraceData').then(res => { 193fb726d48Sopenharmony_ci expect(res).toHaveLength(1); 194fb726d48Sopenharmony_ci }); 195fb726d48Sopenharmony_ci }); 196fb726d48Sopenharmony_ci});