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 { CpuAndIrqBean } from '../../../../../../src/trace/component/trace/sheet/cpu/CpuAndIrqBean'; 17import { TabPaneCpuByThread } from '../../../../../../src/trace/component/trace/sheet/cpu/TabPaneCpuByThread'; 18 19window.ResizeObserver = 20 window.ResizeObserver || 21 jest.fn().mockImplementation(() => ({ 22 disconnect: jest.fn(), 23 observe: jest.fn(), 24 unobserve: jest.fn(), 25 })); 26 27const sqlit = require('../../../../../../src/trace/database/sql/Cpu.sql'); 28jest.mock('../../../../../../src/trace/database/sql/Cpu.sql'); 29jest.mock('../../../../../../src/trace/bean/NativeHook', () => { 30 return {}; 31}); 32 33describe('TabPaneCpuByThread Test', () => { 34 let tabPaneCpuByThread = new TabPaneCpuByThread(); 35 tabPaneCpuByThread.cpuByThreadTbl!.injectColumns = jest.fn(() => true); 36 let val = [ 37 { 38 leftNs: 11, 39 rightNs: 34, 40 state: true, 41 processId: 3, 42 threadId: 1, 43 traceId: 0, 44 cpus: '0, 1, 2', 45 isJumpPage: 0, 46 currentId: 0, 47 }, 48 ]; 49 let cpuAndIrqBean = new CpuAndIrqBean(); 50 it('TabPaneCpuByThreadTest01', function () { 51 expect( 52 tabPaneCpuByThread.sortByColumn({ 53 key: 'number', 54 sort: () => {}, 55 }) 56 ).toBeUndefined(); 57 }); 58 59 it('TabPaneCpuByThreadTest02', function () { 60 expect( 61 tabPaneCpuByThread.sortByColumn({ 62 key: 'pid' || 'wallDuration' || 'avgDuration' || 'occurrences', 63 }) 64 ).toBeUndefined(); 65 }); 66 67 it('TabPaneCpuByThreadTest03', function () { 68 let mockgetTabCpuByThread = sqlit.getTabCpuByThread; 69 mockgetTabCpuByThread.mockResolvedValue([ 70 { process: 'test', wallDuration: 10, occurrences: 10, thread: '' }, 71 { process: 'test2', wallDuration: 11, occurrences: 11, thread: '' }, 72 ]); 73 let a = { rightNs: 1, cpus: [11, 12, 13] }; 74 expect((tabPaneCpuByThread.data = a)).toBeTruthy(); 75 }); 76 77 it('TabPaneCpuByThreadTest04', function () { 78 let mockgetTabCpuByThread = sqlit.getTabCpuByThread; 79 mockgetTabCpuByThread.mockResolvedValue([]); 80 let a = { rightNs: 1, cpus: [11, 12, 13] }; 81 expect((tabPaneCpuByThread.data = a)).toBeTruthy(); 82 }); 83 it('TabPaneCpuByThreadTest06', function () { 84 let finalResultBean = [ 85 { 86 dur: 0, 87 cat: '', 88 cpu: 0, 89 occurrences: 1, 90 pid: '[NULL]', 91 tid: '[NULL]', 92 }, 93 ]; 94 expect(tabPaneCpuByThread.groupByCpu([cpuAndIrqBean])).toStrictEqual(finalResultBean); 95 expect(tabPaneCpuByThread.cpuByIrq([cpuAndIrqBean])).toStrictEqual(finalResultBean); 96 }); 97 it('TabPaneCpuByThreadTest07', function () { 98 expect(tabPaneCpuByThread.findMaxPriority([cpuAndIrqBean])).toStrictEqual(cpuAndIrqBean); 99 expect(tabPaneCpuByThread.findMaxPriority([cpuAndIrqBean])).toStrictEqual(cpuAndIrqBean); 100 }); 101 it('TabPaneCpuByThreadTest08', function () { 102 expect(tabPaneCpuByThread.reSortByColum('process', 0)).toBeUndefined(); 103 expect(tabPaneCpuByThread.reSortByColum('thread', 1)).toBeUndefined(); 104 }); 105 it('TabPaneCpuByThreadTest09', function () { 106 let e = [ 107 { 108 pis: 0, 109 tid: 0, 110 cpu: 0, 111 wallDuration: 100, 112 occurrences: 20, 113 }, 114 ]; 115 let cpuByThreadValue = [ 116 { 117 cpus: [0, 1], 118 }, 119 ]; 120 let cpuByThreadObject = { 121 cpu0: 0, 122 cpu0TimeStr: '0', 123 cpu0Ratio: '0', 124 }; 125 expect(tabPaneCpuByThread.updateCpuValues(e, cpuByThreadValue, cpuByThreadObject)).toBeUndefined(); 126 }); 127 it('TabPaneCpuByThreadTest10', function () { 128 expect(tabPaneCpuByThread.getTableColumns([0, 1, 2])).not.toBeUndefined(); 129 }); 130}); 131