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 {SpRecordTrace} from '../../../dist/trace/component/SpRecordTrace.js'; 18 19// @ts-ignore 20window.ResizeObserver = window.ResizeObserver || 21 jest.fn().mockImplementation(() => ({ 22 disconnect: jest.fn(), 23 observe: jest.fn(), 24 unobserve: jest.fn(), 25 })); 26 27describe('SpRecordTrace Test', () => { 28 document.body.innerHTML = ` 29 <sp-application><sp-record-trace id="aaa"></sp-record-trace></sp-application> 30 `; 31 let spRecordTrace = document.querySelector('#aaa') as SpRecordTrace; 32 it('SpRecordTraceTest01', function () { 33 expect(SpRecordTrace.initHtml).not.toBe(''); 34 }); 35 36 it('SpRecordTraceTest02', function () { 37 SpRecordTrace.patentNode = jest.fn(() => true); 38 expect(SpRecordTrace.initElements).toBeUndefined(); 39 }); 40 41 it('SpRecordTraceTest04', function () { 42 let traceEvents = (SpRecordTrace.createTraceEvents = [ 43 'Scheduling details', 44 'CPU Frequency and idle states', 45 'High frequency memory', 46 'Advanced ftrace config', 47 'Syscalls', 48 'Board voltages & frequency', 49 ]); 50 expect(traceEvents[0].indexOf('binder/binder_lock')).toBe(-1); 51 }); 52 53 it('SpRecordTraceTest05', function () { 54 spRecordTrace.spAllocations = jest.fn(() => undefined); 55 spRecordTrace.spAllocations.appProcess = jest.fn(() => ''); 56 spRecordTrace.spAllocations.appProcess.indexOf = jest.fn(() => ''); 57 spRecordTrace.spAllocations.appProcess.lastIndexOf = jest.fn(() => 1); 58 spRecordTrace.spAllocations.appProcess.slice = jest.fn(() => 1); 59 expect(spRecordTrace.createNativePluginConfig(1)).toEqual({ 60 configData: { 61 blocked: true, 62 fileName: '', 63 filterSize: undefined, 64 fpUnwind: undefined, 65 maxStackDepth: undefined, 66 pid: 1, 67 processName: '', 68 saveFile: false, 69 smbPages: undefined, 70 stringCompressed: true, 71 }, 72 pluginName: 'nativehook', 73 sampleInterval: 1000, 74 }); 75 }); 76 77 it('SpRecordTraceTest06', function () { 78 expect(spRecordTrace.createFpsPluginConfig()).not.toBeUndefined(); 79 }); 80 it('SpRecordTraceTest07', function () { 81 expect(spRecordTrace.vs).not.toBeUndefined(); 82 }); 83 it('SpRecordTraceTest08', function () { 84 spRecordTrace.vs = true; 85 expect(spRecordTrace.vs).toBeTruthy(); 86 }); 87 88 it('SpRecordTraceTest10', function () { 89 let devs = { 90 length: 1, 91 }; 92 expect(spRecordTrace.compareArray(devs)).toBeTruthy(); 93 }); 94 it('SpRecordTraceTest09', function () { 95 spRecordTrace.vs = false; 96 expect(spRecordTrace.vs).toBeFalsy(); 97 }); 98 it('SpRecordTraceTest11', function () { 99 let devs = { 100 length: 1, 101 }; 102 expect(spRecordTrace.compareArray(!devs)).toBeTruthy(); 103 }); 104 it('SpRecordTraceTest12', function () { 105 spRecordTrace.showHint = true; 106 expect(spRecordTrace.showHint).toBeUndefined(); 107 }); 108 it('SpRecordTraceTest13', function () { 109 spRecordTrace.showHint = false; 110 expect(spRecordTrace.showHint).toBeUndefined(); 111 }); 112 it('SpRecordTraceTest14', function () { 113 let event = { 114 isTrusted: true, 115 device: { 116 serialNumber: 'string', 117 }, 118 }; 119 expect(spRecordTrace.usbDisConnectionListener(event)).toBeUndefined(); 120 }); 121 it('SpRecordTraceTest15', function () { 122 let traceResult = { 123 indexOf: jest.fn(() => undefined), 124 }; 125 126 expect(spRecordTrace.isSuccess(traceResult)).toBe(1); 127 }); 128 it('SpRecordTraceTest16', function () { 129 expect(spRecordTrace.createSessionRequest()).toStrictEqual({ 130 pluginConfigs: [], 131 requestId: 1, 132 sessionConfig: { 133 buffers: [{ pages: 16384, policy: 0 }], 134 keepAliveTime: 0, 135 resultFile: '/data/local/tmp/hiprofiler_data.htrace', 136 resultMaxSize: 0, 137 sampleDuration: 30000, 138 sessionMode: 0, 139 }, 140 }); 141 }); 142 it('SpRecordTraceTest17', function () { 143 let that = { 144 createProcessPlugin: jest.fn(() => undefined), 145 createCpuPlugin: jest.fn(() => undefined), 146 createDiskIOPlugin: jest.fn(() => undefined), 147 createNetworkPlugin: jest.fn(() => undefined), 148 }; 149 let request = { 150 pluginConfigs: { 151 push: jest.fn(() => undefined), 152 }, 153 }; 154 expect(spRecordTrace.createMonitorPlugin(that, request)).toBeUndefined(); 155 }); 156 it('SpRecordTraceTest18', function () { 157 expect(spRecordTrace.createNetworkPlugin()).toStrictEqual({ 158 configData: {}, 159 pluginName: 'network-plugin', 160 sampleInterval: 1000, 161 }); 162 }); 163 it('SpRecordTraceTest19', function () { 164 expect(spRecordTrace.createDiskIOPlugin()).toStrictEqual({ 165 configData: { reportIoStats: 'IO_REPORT' }, 166 pluginName: 'diskio-plugin', 167 sampleInterval: 1000, 168 }); 169 }); 170 it('SpRecordTraceTest20', function () { 171 expect(spRecordTrace.createCpuPlugin()).toStrictEqual({ 172 configData: { pid: 0, reportProcessInfo: true }, 173 pluginName: 'cpu-plugin', 174 sampleInterval: 1000, 175 }); 176 }); 177 it('SpRecordTraceTest21', function () { 178 expect(spRecordTrace.createProcessPlugin()).toStrictEqual({ 179 configData: { 180 report_cpu: true, 181 report_diskio: true, 182 report_process_tree: true, 183 report_pss: true, 184 }, 185 pluginName: 'process-plugin', 186 sampleInterval: 1000, 187 }); 188 }); 189 it('SpRecordTraceTest22', function () { 190 let traceConfig = { 191 forEach: jest.fn(() => undefined), 192 }; 193 expect(spRecordTrace.createTraceEvents(traceConfig)).toStrictEqual([]); 194 }); 195 it('SpRecordTraceTest23', function () { 196 spRecordTrace.spRecordPerf = jest.fn(() => undefined); 197 spRecordTrace.spRecordPerf.getPerfConfig = jest.fn(() => undefined); 198 expect(spRecordTrace.createHiperConfig()).toStrictEqual({ 199 configData: { 200 isRoot: false, 201 outfileName: '/data/local/tmp/perf.data', 202 recordArgs: '-f undefined -a --cpu-limit undefined -e hw-cpu-cycles --call-stack undefined -j undefined', 203 }, 204 pluginName: 'hiperf-plugin', 205 sampleInterval: NaN, 206 }); 207 }); 208 209 it('SpRecordTraceTest24', function () { 210 expect(spRecordTrace.isSuccess('Signal')).toBe(2); 211 }); 212 213 it('SpRecordTraceTest25', function () { 214 expect(spRecordTrace.isSuccess('The device is abnormal')).toBe(-1); 215 }); 216 217 it('SpRecordTraceTest26', function () { 218 expect(spRecordTrace.isSuccess('')).toBe(0); 219 }); 220 it('SpRecordTraceTest27', function () { 221 expect(spRecordTrace.synchronizeDeviceList()).toBeUndefined(); 222 }); 223 it('SpRecordTraceTest28', function () { 224 expect(spRecordTrace.freshMenuItemsStatus('Trace command')).toBeUndefined(); 225 }); 226 it('SpRecordTraceTest29', function () { 227 expect(spRecordTrace.buttonDisable(true)).toBeUndefined(); 228 }); 229 it('SpRecordTraceTest30', function () { 230 expect(spRecordTrace.startRefreshDeviceList()).toBeUndefined(); 231 }); 232 it('SpRecordTraceTest31', function () { 233 expect(spRecordTrace.freshConfigMenuDisable(true)).toBeUndefined(); 234 }); 235 it('SpRecordTraceTest31', function () { 236 expect(spRecordTrace.createSdkConfig()).toStrictEqual( 237 {"configData": {}, "pluginName": "", "sampleInterval": 5000} 238 ); 239 }); 240 it('SpRecordTraceTest32', function () { 241 expect(spRecordTrace.createHtracePluginConfig()).toStrictEqual( 242 { 243 "configData": { 244 "bufferSizeKb": 20480, 245 "clock": "boot", 246 "debugOn": false, 247 "flushIntervalMs": 1000, 248 "flushThresholdKb": 4096, 249 "ftraceEvents": [ 250 "sched/sched_switch", 251 "power/suspend_resume", 252 "sched/sched_wakeup", 253 "sched/sched_wakeup_new", 254 "sched/sched_waking", 255 "sched/sched_process_exit", 256 "sched/sched_process_free", 257 "task/task_newtask", 258 "task/task_rename", 259 "power/cpu_frequency", 260 "power/cpu_idle", 261 ], 262 "hitraceApps": [], 263 "hitraceCategories": [ 264 "ability", 265 "ace", 266 "app", 267 "ark", 268 "binder", 269 "disk", 270 "freq", 271 "graphic", 272 "idle", 273 "irq", 274 "memreclaim", 275 "mmc", 276 "multimodalinput", 277 "ohos", 278 "pagecache", 279 "rpc", 280 "sched", 281 "sync", 282 "window", 283 "workq", 284 "zaudio", 285 "zcamera", 286 "zimage", 287 "zmedia", 288 ], 289 "hitraceTime": 30, 290 "parseKsyms": true, 291 "rawDataPrefix": "", 292 "traceDurationMs": 0, 293 "tracePeriodMs": 200, 294 }, 295 "pluginName": "ftrace-plugin", 296 "sampleInterval": 1000, 297 } 298 ); 299 }); 300 it('SpRecordTraceTest33', function () { 301 expect(spRecordTrace.createArkTsConfig()).toStrictEqual( 302 {"configData": {"capture_numeric_value": false,'cpu_profiler_interval':1000, 303 "interval": 0,'enable_cpu_profiler': false, "pid": 0, "track_allocations": false, "type": -1}, 304 "pluginName": "arkts-plugin", "sampleInterval": 5000} 305 ); 306 }); 307 it('SpRecordTraceTest34', function () { 308 expect(spRecordTrace.createMemoryPluginConfig(1,true,true,true)).toStrictEqual( 309 { 310 "configData": { 311 "pid": [ 312 0, 313 ], 314 "reportAppMemByMemoryService": false, 315 "reportAppMemInfo": false, 316 "reportProcessMemInfo": true, 317 "reportProcessTree": true, 318 "reportSmapsMemInfo": true, 319 "reportSysmemMemInfo": true, 320 "reportDmaMemInfo": true, 321 "reportGpuDumpInfo": true, 322 "reportGpuMemInfo": true, 323 "reportSysmemVmemInfo": true, 324 "reportPurgeableAshmemInfo": true, 325 "sysMeminfoCounters": [ 326 "PMEM_MEM_TOTAL", 327 "PMEM_MEM_FREE", 328 "PMEM_BUFFERS", 329 "PMEM_CACHED", 330 "PMEM_SHMEM", 331 "PMEM_SLAB", 332 "PMEM_SWAP_TOTAL", 333 "PMEM_SWAP_FREE", 334 "PMEM_MAPPED", 335 "PMEM_VMALLOC_USED", 336 "PMEM_PAGE_TABLES", 337 "PMEM_KERNEL_STACK", 338 "PMEM_ACTIVE", 339 "PMEM_INACTIVE", 340 "PMEM_UNEVICTABLE", 341 "PMEM_VMALLOC_TOTAL", 342 "PMEM_SLAB_UNRECLAIMABLE", 343 "PMEM_CMA_TOTAL", 344 "PMEM_CMA_FREE", 345 "PMEM_KERNEL_RECLAIMABLE", 346 ], 347 "sysVmeminfoCounters": [], 348 }, 349 "pluginName": "memory-plugin", 350 "sampleInterval": 1000, 351 } 352 ); 353 }); 354 it('SpRecordTraceTest35', function () { 355 expect(spRecordTrace.createSystemConfig()).toStrictEqual( 356 {"configData": {"cmdLine": "hiebpf --duration 30 --max_stack_depth 10", "outfileName": "/data/local/tmp/ebpf.data"}, "pluginName": "hiebpf-plugin", "sampleInterval": 1000} 357 ); 358 }); 359 it('SpRecordTraceTest36', function () { 360 expect(spRecordTrace.createSystemConfig({},1)).toStrictEqual( 361 {"configData": {"cmdLine": "hiebpf --duration 30 --max_stack_depth 10", "outfileName": "/data/local/tmp/ebpf.data"}, "pluginName": "hiebpf-plugin", "sampleInterval": 1000}); 362 }); 363 it('SpRecordTraceTest37', function () { 364 spRecordTrace.record_template = 'record_template'; 365 expect(spRecordTrace.record_template).toBeTruthy(); 366 }); 367}); 368