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 19window.ResizeObserver = window.ResizeObserver || 20 jest.fn().mockImplementation(() => ({ 21 disconnect: jest.fn(), 22 observe: jest.fn(), 23 unobserve: jest.fn(), 24 })); 25 26describe('SpRecordTrace Test', () => { 27 document.body.innerHTML = ` 28 <sp-application><sp-record-trace id="aaa"></sp-record-trace></sp-application> 29 ` 30 let spRecordTrace = document.querySelector('#aaa') as SpRecordTrace 31 it('SpRecordTraceTest01', function () { 32 expect(SpRecordTrace.initHtml).not.toBe('') 33 }); 34 35 it('SpRecordTraceTest02', function () { 36 SpRecordTrace.patentNode=jest.fn(()=>true); 37 expect(SpRecordTrace.initElements).toBeUndefined() 38 }); 39 40 it('SpRecordTraceTest04', function () { 41 let traceEvents = SpRecordTrace.createTraceEvents = ['Scheduling details', 'CPU Frequency and idle states', 42 'High frequency memory', 'Advanced ftrace config', 'Syscalls' , 'Board voltages & frequency']; 43 expect(traceEvents[0].indexOf('binder/binder_lock')).toBe(-1) 44 }); 45 46 it('SpRecordTraceTest05', function () { 47 spRecordTrace.spAllocations = jest.fn(()=>undefined) 48 spRecordTrace.spAllocations.appProcess = jest.fn(()=>"") 49 spRecordTrace.spAllocations.appProcess.indexOf = jest.fn(()=>"") 50 spRecordTrace.spAllocations.appProcess.lastIndexOf = jest.fn(()=>1) 51 spRecordTrace.spAllocations.appProcess.slice = jest.fn(()=>1) 52 expect(spRecordTrace.createNativePluginConfig(1)).toEqual({"configData": {"fileName": "", 53 "filterSize": undefined, "fpUnwind": undefined, "mallocFreeMatchingCnt": 1000, 54 "mallocFreeMatchingInterval": 1000, "maxStackDepth": undefined, "pid": 1,"processName": "", 55 "saveFile": false, "smbPages": undefined, "stringCompressed": true}, "pluginName": "nativehook", "sampleInterval": 1000}) 56 }); 57 58 it('SpRecordTraceTest06', function () { 59 expect(spRecordTrace.createFpsPluginConfig()).not.toBeUndefined() 60 }); 61 it('SpRecordTraceTest07', function () { 62 expect(spRecordTrace.vs).not.toBeUndefined() 63 }); 64 it('SpRecordTraceTest08', function () { 65 spRecordTrace.vs = true 66 expect(spRecordTrace.vs).toBeTruthy() 67 }); 68 69 it('SpRecordTraceTest10', function () { 70 let devs = { 71 length:1, 72 } 73 expect(spRecordTrace.compareArray(devs)).toBeTruthy() 74 }); 75 it('SpRecordTraceTest09', function () { 76 spRecordTrace.vs = false 77 expect(spRecordTrace.vs).toBeFalsy() 78 }); 79 it('SpRecordTraceTest11', function () { 80 let devs = { 81 length:1, 82 } 83 expect(spRecordTrace.compareArray(!devs)).toBeTruthy() 84 }); 85 it('SpRecordTraceTest12', function () { 86 spRecordTrace.showHint = true 87 expect(spRecordTrace.showHint).toBeUndefined() 88 }); 89 it('SpRecordTraceTest13', function () { 90 spRecordTrace.showHint = false 91 expect(spRecordTrace.showHint).toBeUndefined() 92 }); 93 it('SpRecordTraceTest14', function () { 94 let event = { 95 isTrusted:true, 96 device: { 97 serialNumber:"string" 98 } 99 } 100 expect(spRecordTrace.usbDisConnectionListener(event)).toBeUndefined() 101 }); 102 it('SpRecordTraceTest15', function () { 103 let traceResult = { 104 indexOf:jest.fn(()=>undefined) 105 } 106 107 expect(spRecordTrace.isSuccess(traceResult)).toBe(1) 108 }); 109 it('SpRecordTraceTest16', function () { 110 expect(spRecordTrace.createSessionRequest()).toStrictEqual({"pluginConfigs": [], "requestId": 1, "sessionConfig": {"buffers": 111 [{"pages": 16384, "policy": 0}], "keepAliveTime": 0, "resultFile": "/data/local/tmp/hiprofiler_data.htrace", "resultMaxSize": 0, 112 "sampleDuration": 50000, "sessionMode": 0}}) 113 }); 114 it('SpRecordTraceTest17', function () { 115 let that = { 116 createProcessPlugin:jest.fn(()=>undefined), 117 createCpuPlugin:jest.fn(()=>undefined), 118 createDiskIOPlugin:jest.fn(()=>undefined), 119 createNetworkPlugin:jest.fn(()=>undefined), 120 } 121 let request = { 122 pluginConfigs:{ 123 push:jest.fn(()=>undefined), 124 } 125 } 126 expect(spRecordTrace.createMonitorPlugin(that, request)).toBeUndefined() 127 }); 128 it('SpRecordTraceTest18', function () { 129 expect(spRecordTrace.createNetworkPlugin()).toStrictEqual({"configData": {"testFile": "/data/local/tmp/"}, 130 "pluginName": "network-plugin", "sampleInterval": 1000}) 131 }); 132 it('SpRecordTraceTest19', function () { 133 expect(spRecordTrace.createDiskIOPlugin()).toStrictEqual({"configData": {"reportIoStats": "IO_REPORT"}, 134 "pluginName": "diskio-plugin", "sampleInterval": 1000}) 135 }); 136 it('SpRecordTraceTest20', function () { 137 expect(spRecordTrace.createCpuPlugin()).toStrictEqual({"configData": {"pid": 0, "reportProcessInfo": true}, 138 "pluginName": "cpu-plugin", "sampleInterval": 1000}) 139 }); 140 it('SpRecordTraceTest21', function () { 141 expect(spRecordTrace.createProcessPlugin()).toStrictEqual({"configData": {"report_cpu": true, 142 "report_diskio": true, "report_process_tree": true, "report_pss": true}, "pluginName": "process-plugin", "sampleInterval": 1000}) 143 }); 144 it('SpRecordTraceTest22', function () { 145 let traceConfig = { 146 forEach:jest.fn(()=>undefined) 147 } 148 expect(spRecordTrace.createTraceEvents(traceConfig)).toStrictEqual([]) 149 }); 150 it('SpRecordTraceTest23', function () { 151 spRecordTrace.spRecordPerf = jest.fn(()=>undefined) 152 spRecordTrace.spRecordPerf.getPerfConfig = jest.fn(()=>undefined) 153 expect(spRecordTrace.createHiperConfig()).toStrictEqual({"configData": {"isRoot": false, 154 "outfileName": "/data/local/tmp/perf.data", "recordArgs": "-f undefined -a --cpu-limit undefined -e hw-cpu-cycles --call-stack undefined -j undefined"}, "pluginName": "hiperf-plugin", "sampleInterval": NaN}) 155 }); 156 157 it('SpRecordTraceTest24', function () { 158 expect(spRecordTrace.isSuccess('Signal')).toBe(2) 159 }); 160 161 it('SpRecordTraceTest25', function () { 162 expect(spRecordTrace.isSuccess('The device is abnormal')).toBe(-1); 163 }); 164 165 it('SpRecordTraceTest26', function () { 166 expect(spRecordTrace.isSuccess('')).toBe(0); 167 }); 168 169}) 170