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 { TabPaneGpufreq } from '../../../../../../src/trace/component/trace/sheet/gpufreq/tabPaneGpufreqUsage'; 17import { LitTable } from '../../../../../../src/base-ui/table/lit-table'; 18 19jest.mock('../../../../../../src/trace/component/trace/base/TraceRow', () => { 20 return {}; 21}); 22 23window.ResizeObserver = 24 window.ResizeObserver || 25 jest.fn().mockImplementation(() => ({ 26 disconnect: jest.fn(), 27 observe: jest.fn(), 28 unobserve: jest.fn(), 29 })); 30 31const sqlite = require('../../../../../../src/trace/database/SqlLite'); 32jest.mock('../../../../../../src/trace/database/SqlLite'); 33 34describe('tabPaneGpufreqUsage Test', () => { 35 let tabGpuFreq = new TabPaneGpufreq(); 36 tabGpuFreq.threadStatesTbl = jest.fn(() => { 37 return new LitTable(); 38 }); 39 let gpuCountBean = { 40 filterId: '12', 41 freq: 'freq', 42 count: '4', 43 value: '45', 44 ts: '2255', 45 startNS: '4455', 46 dur: '58547', 47 endTime: '1255858', 48 thread: 'thread', 49 parentIndex: 0, 50 leve: 0, 51 name: 'name', 52 leftNs: 48555, 53 rightNs: 58555 54 } 55 let threadStatesParam = { 56 cpus: [], 57 threadIds: [1, 2, 3], 58 trackIds: [23, 56, 77], 59 funTids: [675, 75], 60 heapIds: [11, 223], 61 processIds: [114, 23], 62 nativeMemory: [], 63 leftNs: 12222, 64 rightNs: 654233, 65 hasFps: false, 66 statisticsSelectData: undefined, 67 } 68 69 let gpufreq = sqlite.getGpufreqData; 70 let gpufreqData = [{ 71 filterId: '12', 72 freq: 'freq', 73 count: '4', 74 value: '45', 75 ts: '2255', 76 startNS: '4455', 77 dur: '58547', 78 endTime: '1255858', 79 thread: 'thread', 80 parentIndex: 0, 81 leve: 0, 82 name: 'name' 83 }]; 84 gpufreq.mockResolvedValue(gpufreqData); 85 86 it('tabPaneGpufreqUsageTest01', function () { 87 tabGpuFreq.data = threadStatesParam; 88 expect(tabGpuFreq.threadStatesTbl.loading).toBeTruthy(); 89 }); 90 91 it('tabPaneGpufreqUsageTest02', function () { 92 expect(tabGpuFreq.createTree([gpuCountBean])).not.toBeUndefined(); 93 }); 94 95 it('tabPaneGpufreqUsageTest03', function () { 96 expect(tabGpuFreq.updateValueMap(gpuCountBean, '', {})).toBeUndefined(); 97 }); 98}); 99