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 */ 15import { TraceRow } from '../../../../src/trace/component/trace/base/TraceRow'; 16import { 17 eBPFChart, 18 EBPFChartStruct, EBPFRender, 19} from '../../../../src/trace/database/ui-worker/ProcedureWorkerEBPF'; 20jest.mock('../../../../src/trace/database/ui-worker/ProcedureWorker', () => { 21 return {}; 22}); 23jest.mock('../../../../src/trace/component/SpSystemTrace', () => { 24 return {}; 25}); 26describe('ProcedureWorkerFileSystem Test', () => { 27 it('ProcedureWorkerFileSystemTest01', function () { 28 let frame = { 29 x: 20, 30 width: 100, 31 y: 20, 32 height: 100, 33 }; 34 expect(eBPFChart([{ length: 1 }], 1, 2, 1, frame, true, true, true)).toBeUndefined(); 35 }); 36 37 it('ProcedureWorkerFileSystemTest02', function () { 38 let frame = { 39 x: 20, 40 y: 20, 41 width: 100, 42 height: 100, 43 }; 44 expect(eBPFChart([{ length: 0 }], 1, 2, 1, frame, false, false, false)).toBeUndefined(); 45 }); 46 47 it('ProcedureWorkerFileSystemTest03', function () { 48 let frame = { 49 x: 40, 50 width: 440, 51 y: 24, 52 height: 500, 53 }; 54 let fileSystemDataList = new Array(); 55 fileSystemDataList.push({ 56 startTime: 60, 57 dur: 110, 58 frame: { x: 40, y: 59, width: 140, height: 142 }, 59 }); 60 fileSystemDataList.push({ startTime: 14, dur: 41 }); 61 eBPFChart([{ length: 0 }], 1, 2, 1, frame, true, false, false); 62 }); 63 64 it('ProcedureWorkerFileSystemTest03', function () { 65 let frame = { 66 x: 24, 67 y: 21, 68 width: 121, 69 height: 230, 70 }; 71 let eBPFFilters = new Array(); 72 eBPFFilters.push({ 73 startTime: 20, 74 dur: 11, 75 frame: { x: 10, y: 91, width: 40, height: 540 }, 76 }); 77 eBPFFilters.push({ startTime: 41, dur: 141 }); 78 eBPFChart([{ length: 0 }], 1, 2, 1, frame, true, false, false); 79 }); 80 81 it('ProcedureWorkerFileSystemTest04', function () { 82 let node = { 83 frame: { 84 x: 60, 85 y: 24, 86 width: 440, 87 height: 460, 88 }, 89 startNS: 100, 90 value: 980, 91 startTs: 63, 92 dur: 21, 93 height: 222, 94 }; 95 let frame = { 96 x: 2, 97 y: 21, 98 width: 15, 99 height: 84, 100 }; 101 expect(EBPFChartStruct.setFrame(node, 2, 1, 2, frame)).toBeUndefined(); 102 }); 103 104 it('ProcedureWorkerFileSystemTest05', function () { 105 let node = { 106 frame: { 107 x: 80, 108 y: 20, 109 width: 330, 110 height: 330, 111 }, 112 startNS: 2, 113 value: 61, 114 startTs: 32, 115 dur: 8, 116 height: 10, 117 }; 118 let frame = { 119 x: 66, 120 y: 2, 121 width: 600, 122 height: 188, 123 }; 124 expect(EBPFChartStruct.setFrame(node, 2, 1, 2, frame)).toBeUndefined(); 125 }); 126 127 it('ProcedureWorkerFileSystemTest06', function () { 128 expect(EBPFChartStruct.computeHeightNoGroup([{ length: 1 }], 10)).toEqual([ 129 { 130 dur: 10, 131 group10Ms: false, 132 height: 18, 133 size: 1, 134 startNS: 0, 135 }, 136 { dur: 0, group10Ms: false, height: 0, size: 0, startNS: 10 }, 137 ]); 138 }); 139 it('ProcedureWorkerFileSystemTest07 ', function () { 140 let eBPFRender = new EBPFRender(); 141 let eBPFReq = { 142 lazyRefresh: true, 143 type: '', 144 startNS: 2, 145 endNS: 3, 146 totalNS: 1, 147 frame: { 148 x: 11, 149 y: 11, 150 width: 70, 151 height: 90, 152 }, 153 useCache: false, 154 range: { 155 refresh: 'refresh', 156 }, 157 canvas: '', 158 context: { 159 font: '12px sans-serif', 160 fillStyle: '#a1697d', 161 globalAlpha: 0, 162 measureText: jest.fn(() => true), 163 clearRect: jest.fn(() => true), 164 stroke: jest.fn(() => true), 165 closePath: jest.fn(() => false), 166 beginPath: jest.fn(() => true), 167 fillRect: jest.fn(() => false), 168 fillText: jest.fn(() => true), 169 }, 170 isHover: '', 171 hoverX: 0, 172 params: '', 173 wakeupBean: undefined, 174 id: 1, 175 x: 12, 176 y: 11, 177 width: 102, 178 height: 102, 179 }; 180 window.postMessage = jest.fn(() => true); 181 expect(eBPFRender.renderMainThread(eBPFReq,new TraceRow<EBPFChartStruct>())).toBeUndefined() 182 expect(eBPFRender.render(eBPFReq,[],[])).toBeUndefined() 183 }); 184}); 185