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 16// @ts-ignore 17import { VmTrackerChart } from '../../../../dist/trace/component/chart/SpVmTrackerChart.js'; 18// @ts-ignore 19import { SpChartManager } from '../../../../dist/trace/component/chart/SpChartManager.js'; 20const sqlite = require('../../../../dist/trace/database/SqlLite.js'); 21jest.mock('../../../../dist/trace/database/SqlLite.js'); 22jest.mock('../../../../dist/trace/database/ui-worker/ProcedureWorker.js', () => { 23 return {}; 24}); 25 26// @ts-ignore 27window.ResizeObserver = 28 window.ResizeObserver || 29 jest.fn().mockImplementation(() => ({ 30 disconnect: jest.fn(), 31 observe: jest.fn(), 32 unobserve: jest.fn(), 33 })); 34 35describe('SpVmTrackerChart Test', () => { 36 let smapsData = sqlite.querySmapsData; 37 let smapsSixData = [ 38 { 39 startNs: 0, 40 value: 1024, 41 name: 'dirty', 42 }, 43 ]; 44 smapsData.mockResolvedValue(smapsSixData); 45 let dmaSmapsData = sqlite.queryDmaSampsData; 46 let smapsDmaData = [ 47 { 48 startNs: 0, 49 value: 1024, 50 flag: 1, 51 ipid: 1, 52 expTaskComm: 'delay', 53 }, 54 ]; 55 dmaSmapsData.mockResolvedValue(smapsDmaData); 56 let gpuMemoryData = sqlite.queryGpuMemoryData; 57 let gpuData = [ 58 { 59 startNs: 0, 60 value: 1024, 61 ipid: 1, 62 }, 63 ]; 64 gpuMemoryData.mockResolvedValue(gpuData); 65 let smapsExits = sqlite.querySmapsExits; 66 let exits = [ 67 { 68 event_name: 'trace_smaps', 69 }, 70 ]; 71 smapsExits.mockResolvedValue(exits); 72 let vmTrackerShmData = sqlite.queryVmTrackerShmData; 73 let shmData = [ 74 { 75 startNs: 0, 76 value: 1024, 77 }, 78 ]; 79 vmTrackerShmData.mockResolvedValue(shmData); 80 let purgeableProcessData = sqlite.queryPurgeableProcessData; 81 let processData = [ 82 { 83 startNs: 0, 84 value: 1024, 85 }, 86 ]; 87 purgeableProcessData.mockResolvedValue(processData); 88 let gpuGlData = sqlite.queryGpuGLData; 89 let glData = [ 90 { 91 startNs: 0, 92 value: 1024, 93 }, 94 ]; 95 gpuGlData.mockResolvedValue(glData); 96 let gpuTotalData = sqlite.queryGpuTotalData; 97 let totalData = [ 98 { 99 startNs: 0, 100 value: 1024, 101 }, 102 ]; 103 gpuTotalData.mockResolvedValue(totalData); 104 let gpuTotalType = sqlite.queryGpuTotalType; 105 let totalType = [ 106 { 107 id: 1, 108 data: 'delay', 109 }, 110 ]; 111 gpuTotalType.mockResolvedValue(totalType); 112 let gpuWindowData = sqlite.queryGpuWindowData; 113 let windowsData = [ 114 { 115 startNs: 0, 116 value: 1024, 117 }, 118 ]; 119 gpuWindowData.mockResolvedValue(windowsData); 120 let gpuWindowType = sqlite.queryGpuWindowType; 121 let windowsType = [ 122 { 123 id: 1, 124 data: 'delay', 125 pid: 1, 126 }, 127 ]; 128 gpuWindowType.mockResolvedValue(windowsType); 129 let manager = new SpChartManager(); 130 let spVmTrackerChart = new VmTrackerChart(manager); 131 let memoryData = [ 132 { 133 startNs: 0, 134 endNs: 0, 135 dur: 0, 136 name: '', 137 textWidth: 0, 138 value: 0, 139 type: '', 140 }, 141 ]; 142 it('SpVmTrackerChart01', function () { 143 spVmTrackerChart.initVmTrackerFolder(); 144 expect(spVmTrackerChart).toBeDefined(); 145 }); 146 it('SpVmTrackerChart02', function () { 147 expect(spVmTrackerChart.getSmapsKeyName('USS')).toBeDefined(); 148 }); 149 it('SpVmTrackerChart07', function () { 150 expect(spVmTrackerChart.getSmapsKeyName('RSS')).toBeDefined(); 151 }); 152 it('SpVmTrackerChart08', function () { 153 expect(spVmTrackerChart.getSmapsKeyName('')).toBeDefined(); 154 }); 155 it('SpVmTrackerChart03', function () { 156 expect(spVmTrackerChart.initTraceRow('dirty', 'smaps', 'VmTracker')).toBeDefined(); 157 }); 158 it('SpVmTrackerChart04', function () { 159 expect(spVmTrackerChart.initPurgeablePin()).toBeDefined(); 160 }); 161 it('SpVmTrackerChart05', function () { 162 expect(spVmTrackerChart.initPurgeableTotal()).toBeDefined(); 163 }); 164 it('SpVmTrackerChart06', function () { 165 expect(spVmTrackerChart.showTip).toBeDefined(); 166 }); 167 it('SpVmTrackerChart09', function () { 168 expect(spVmTrackerChart.initGpuFolder()).toBeDefined(); 169 }); 170 it('SpVmTrackerChart09', function () { 171 expect(spVmTrackerChart.initSMapsFolder()).toBeDefined(); 172 }); 173 it('SpVmTrackerChart10', function () { 174 expect(spVmTrackerChart.initVmTrackerFolder()).toBeDefined(); 175 }); 176 it('SpVmTrackerChart11', function () { 177 expect(spVmTrackerChart.initDmaRow()).toBeDefined(); 178 }); 179 it('SpVmTrackerChart12', function () { 180 expect(spVmTrackerChart.initSmapsRows('Swapped')).toBeDefined(); 181 }); 182 it('SpVmTrackerChart13', function () { 183 expect(spVmTrackerChart.initShmRows()).toBeDefined(); 184 }); 185 it('SpVmTrackerChart14', function () { 186 expect(spVmTrackerChart.initGpuMemoryRow(memoryData)).toBeDefined(); 187 }); 188 it('SpVmTrackerChart15', function () { 189 expect(spVmTrackerChart.addGpuGLRow(memoryData)).toBeDefined(); 190 }); 191 it('SpVmTrackerChart16', function () { 192 expect(spVmTrackerChart.addGpuTotalRow()).toBeDefined(); 193 }); 194}); 195