1fb726d48Sopenharmony_ci/* 2fb726d48Sopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd. 3fb726d48Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb726d48Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb726d48Sopenharmony_ci * You may obtain a copy of the License at 6fb726d48Sopenharmony_ci * 7fb726d48Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb726d48Sopenharmony_ci * 9fb726d48Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb726d48Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb726d48Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb726d48Sopenharmony_ci * See the License for the specific language governing permissions and 13fb726d48Sopenharmony_ci * limitations under the License. 14fb726d48Sopenharmony_ci */ 15fb726d48Sopenharmony_ciimport { Top20ThreadCpuUsage } from '../../../../src/trace/component/schedulingAnalysis/Top20ThreadCpuUsage'; 16fb726d48Sopenharmony_ci// @ts-ignore 17fb726d48Sopenharmony_ciwindow.ResizeObserver = 18fb726d48Sopenharmony_ci window.ResizeObserver || 19fb726d48Sopenharmony_ci jest.fn().mockImplementation(() => ({ 20fb726d48Sopenharmony_ci disconnect: jest.fn(), 21fb726d48Sopenharmony_ci observe: jest.fn(), 22fb726d48Sopenharmony_ci unobserve: jest.fn(), 23fb726d48Sopenharmony_ci })); 24fb726d48Sopenharmony_ci 25fb726d48Sopenharmony_cidescribe('Top20ThreadCpuUsage Test', () => { 26fb726d48Sopenharmony_ci it('Top20ThreadCpuUsageTest01', () => { 27fb726d48Sopenharmony_ci let top20ThreadCpuUsage = new Top20ThreadCpuUsage(); 28fb726d48Sopenharmony_ci expect(top20ThreadCpuUsage).not.toBeUndefined(); 29fb726d48Sopenharmony_ci }); 30fb726d48Sopenharmony_ci it('Top20ThreadCpuUsageTest02', () => { 31fb726d48Sopenharmony_ci let top20ThreadCpuUsage = new Top20ThreadCpuUsage(); 32fb726d48Sopenharmony_ci let data = [ 33fb726d48Sopenharmony_ci { 34fb726d48Sopenharmony_ci pid: 101, 35fb726d48Sopenharmony_ci pName: 4, 36fb726d48Sopenharmony_ci tid: 311, 37fb726d48Sopenharmony_ci tName: '', 38fb726d48Sopenharmony_ci total: 112, 39fb726d48Sopenharmony_ci size: 'middle core', 40fb726d48Sopenharmony_ci no: '', 41fb726d48Sopenharmony_ci timeStr: '120.00kb', 42fb726d48Sopenharmony_ci }, 43fb726d48Sopenharmony_ci ]; 44fb726d48Sopenharmony_ci expect(top20ThreadCpuUsage.sortByColumn({ key: 'bigTimeStr' }, {}, data)).toBeUndefined(); 45fb726d48Sopenharmony_ci }); 46fb726d48Sopenharmony_ci it('Top20ThreadCpuUsageTest03', () => { 47fb726d48Sopenharmony_ci let top20ThreadCpuUsage = new Top20ThreadCpuUsage(); 48fb726d48Sopenharmony_ci top20ThreadCpuUsage.queryLogicWorker = jest.fn(); 49fb726d48Sopenharmony_ci expect(top20ThreadCpuUsage.queryData()).toBeUndefined(); 50fb726d48Sopenharmony_ci }); 51fb726d48Sopenharmony_ci it('Top20ThreadCpuUsageTest04', () => { 52fb726d48Sopenharmony_ci let top20ThreadCpuUsage = new Top20ThreadCpuUsage(); 53fb726d48Sopenharmony_ci let data = [ 54fb726d48Sopenharmony_ci { 55fb726d48Sopenharmony_ci pid: 32, 56fb726d48Sopenharmony_ci pName: 21, 57fb726d48Sopenharmony_ci tid: 224, 58fb726d48Sopenharmony_ci tName: 'thread1', 59fb726d48Sopenharmony_ci total: 1, 60fb726d48Sopenharmony_ci size: 'middle core', 61fb726d48Sopenharmony_ci no: '', 62fb726d48Sopenharmony_ci timeStr: '19.00kb', 63fb726d48Sopenharmony_ci }, 64fb726d48Sopenharmony_ci ]; 65fb726d48Sopenharmony_ci expect(top20ThreadCpuUsage.getArrayDataBySize('total', data)).toStrictEqual( 66fb726d48Sopenharmony_ci [ 67fb726d48Sopenharmony_ci {"no": "", "pName": 21, "pid": 32, "size": "big core", "tName": "thread1", "tid": 224, "timeStr": undefined, "total": undefined}, 68fb726d48Sopenharmony_ci {"no": "", "pName": 21, "pid": 32, "size": "middle core", "tName": "thread1", "tid": 224, "timeStr": undefined, "total": undefined}, 69fb726d48Sopenharmony_ci {"no": "", "pName": 21, "pid": 32, "size": "small core", "tName": "thread1", "tid": 224, "timeStr": undefined, "total": undefined} 70fb726d48Sopenharmony_ci ] 71fb726d48Sopenharmony_ci ); 72fb726d48Sopenharmony_ci }); 73fb726d48Sopenharmony_ci it('Top20ThreadCpuUsageTest05', () => { 74fb726d48Sopenharmony_ci let top20ThreadCpuUsage = new Top20ThreadCpuUsage(); 75fb726d48Sopenharmony_ci let data = [ 76fb726d48Sopenharmony_ci { 77fb726d48Sopenharmony_ci pid: 35, 78fb726d48Sopenharmony_ci pName: 651, 79fb726d48Sopenharmony_ci tid: 43, 80fb726d48Sopenharmony_ci tName: 'thread3', 81fb726d48Sopenharmony_ci total: 65, 82fb726d48Sopenharmony_ci size: 'middle core', 83fb726d48Sopenharmony_ci no: '', 84fb726d48Sopenharmony_ci timeStr: '123.0kb', 85fb726d48Sopenharmony_ci }, 86fb726d48Sopenharmony_ci ]; 87fb726d48Sopenharmony_ci expect(top20ThreadCpuUsage.sortByColumn({ key: 'midTimeStr' }, {}, data)).toBeUndefined(); 88fb726d48Sopenharmony_ci }); 89fb726d48Sopenharmony_ci it('Top20ThreadCpuUsageTest06', () => { 90fb726d48Sopenharmony_ci let top20ThreadCpuUsage = new Top20ThreadCpuUsage(); 91fb726d48Sopenharmony_ci let data = [ 92fb726d48Sopenharmony_ci { 93fb726d48Sopenharmony_ci pid: 32, 94fb726d48Sopenharmony_ci pName: 2342, 95fb726d48Sopenharmony_ci tid: 543, 96fb726d48Sopenharmony_ci tName: 'thread6', 97fb726d48Sopenharmony_ci total: 120, 98fb726d48Sopenharmony_ci size: 'middle core', 99fb726d48Sopenharmony_ci no: '', 100fb726d48Sopenharmony_ci timeStr: '133.320kb', 101fb726d48Sopenharmony_ci }, 102fb726d48Sopenharmony_ci ]; 103fb726d48Sopenharmony_ci expect(top20ThreadCpuUsage.sortByColumn({ key: 'smallTimeStr' }, {}, data)).toBeUndefined(); 104fb726d48Sopenharmony_ci }); 105fb726d48Sopenharmony_ci it('Top20ThreadCpuUsageTest07', () => { 106fb726d48Sopenharmony_ci let top20ThreadCpuUsage = new Top20ThreadCpuUsage(); 107fb726d48Sopenharmony_ci let data = [ 108fb726d48Sopenharmony_ci { 109fb726d48Sopenharmony_ci pid: 67, 110fb726d48Sopenharmony_ci pName: 161, 111fb726d48Sopenharmony_ci tid: 87, 112fb726d48Sopenharmony_ci tName: 'thread90', 113fb726d48Sopenharmony_ci total: 322, 114fb726d48Sopenharmony_ci size: 'middle core', 115fb726d48Sopenharmony_ci no: '', 116fb726d48Sopenharmony_ci timeStr: '190.32kb', 117fb726d48Sopenharmony_ci }, 118fb726d48Sopenharmony_ci ]; 119fb726d48Sopenharmony_ci expect(top20ThreadCpuUsage.sortByColumn({ key: 'bigPercent' }, {}, data)).toBeUndefined(); 120fb726d48Sopenharmony_ci }); 121fb726d48Sopenharmony_ci it('Top20ThreadCpuUsageTest08', () => { 122fb726d48Sopenharmony_ci let top20ThreadCpuUsage = new Top20ThreadCpuUsage(); 123fb726d48Sopenharmony_ci top20ThreadCpuUsage.queryLogicWorker = jest.fn(); 124fb726d48Sopenharmony_ci expect(top20ThreadCpuUsage.queryLogicWorker('', '', {})).toBeUndefined(); 125fb726d48Sopenharmony_ci }); 126fb726d48Sopenharmony_ci}); 127