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 { 17 SystemCpuSummary, 18 SystemDiskIOSummary, 19 ProcessHistory, 20 LiveProcess, 21 SystemNetworkSummary, 22 SystemMemorySummary, 23 Dma 24} from '../../../src/trace/bean/AbilityMonitor'; 25 26jest.mock('../../../src/trace/bean/NativeHook', () => { 27 return {}; 28}); 29 30describe('AbilityMonitor Test', () => { 31 let systemCpuSummary = new SystemCpuSummary(); 32 let systemDiskIOSummary = new SystemDiskIOSummary(); 33 let processHistory = new ProcessHistory(); 34 let liveProcess = new LiveProcess(); 35 let systemNetworkSummary = new SystemNetworkSummary(); 36 let systemMemorySummary = new SystemMemorySummary(); 37 let dma = new Dma() 38 39 it('SystemCpuSummaryTest', function () { 40 systemCpuSummary = { 41 startTime: -1, 42 startTimeStr: 'startTimeStr', 43 duration: -1, 44 durationStr: 'durationStr', 45 totalLoad: -1, 46 totalLoadStr: 'totalLoadStr', 47 userLoad: -1, 48 userLoadStr: 'userLoadStr', 49 systemLoad: -1, 50 systemLoadStr: 'systemLoadStr', 51 threads: -1, 52 threadsStr: 'threadsStr', 53 }; 54 55 expect(systemCpuSummary).not.toBeUndefined(); 56 expect(systemCpuSummary).toMatchInlineSnapshot( 57{ 58 startTime: expect.any(Number), 59 startTimeStr: expect.any(String), 60 duration: expect.any(Number), 61 durationStr: expect.any(String), 62 totalLoad: expect.any(Number), 63 totalLoadStr: expect.any(String), 64 userLoad: expect.any(Number), 65 userLoadStr: expect.any(String), 66 systemLoad: expect.any(Number), 67 systemLoadStr: expect.any(String), 68 threads: expect.any(Number), 69 threadsStr: expect.any(String) }, ` 70{ 71 "duration": Any<Number>, 72 "durationStr": Any<String>, 73 "startTime": Any<Number>, 74 "startTimeStr": Any<String>, 75 "systemLoad": Any<Number>, 76 "systemLoadStr": Any<String>, 77 "threads": Any<Number>, 78 "threadsStr": Any<String>, 79 "totalLoad": Any<Number>, 80 "totalLoadStr": Any<String>, 81 "userLoad": Any<Number>, 82 "userLoadStr": Any<String>, 83} 84`); 85 }); 86 87 it('SystemCpuSummaryTest', function () { 88 systemDiskIOSummary = { 89 startTime: 1, 90 startTimeStr: 'startTimeStr', 91 duration: 1, 92 durationStr: 'durationStr', 93 dataRead: 1, 94 dataReadStr: 'dataReadStr', 95 dataReadSec: 1, 96 dataReadSecStr: 'dataReadSecStr', 97 dataWrite: 1, 98 dataWriteStr: 'dataWriteStr', 99 dataWriteSec: 1, 100 dataWriteSecStr: 'dataWriteSecStr', 101 readsIn: 1, 102 readsInStr: 'readsInStr', 103 readsInSec: 1, 104 readsInSecStr: 'readsInSecStr', 105 writeOut: 1, 106 writeOutStr: 'writeOutStr', 107 writeOutSec: 1, 108 writeOutSecStr: 'writeOutSecStr', 109 }; 110 expect(systemDiskIOSummary).not.toBeUndefined(); 111 expect(systemDiskIOSummary).toMatchInlineSnapshot(` 112{ 113 "dataRead": 1, 114 "dataReadSec": 1, 115 "dataReadSecStr": "dataReadSecStr", 116 "dataReadStr": "dataReadStr", 117 "dataWrite": 1, 118 "dataWriteSec": 1, 119 "dataWriteSecStr": "dataWriteSecStr", 120 "dataWriteStr": "dataWriteStr", 121 "duration": 1, 122 "durationStr": "durationStr", 123 "readsIn": 1, 124 "readsInSec": 1, 125 "readsInSecStr": "readsInSecStr", 126 "readsInStr": "readsInStr", 127 "startTime": 1, 128 "startTimeStr": "startTimeStr", 129 "writeOut": 1, 130 "writeOutSec": 1, 131 "writeOutSecStr": "writeOutSecStr", 132 "writeOutStr": "writeOutStr", 133} 134`); 135 }); 136 137 138 it('ProcessHistoryTest', function () { 139 processHistory = { 140 processId: -1, 141 alive: '', 142 firstSeen: '', 143 lastSeen: '', 144 processName: '', 145 responsibleProcess: '', 146 userName: '', 147 cpuTime: '', 148 }; 149 expect(processHistory).not.toBeUndefined(); 150 expect(processHistory).toMatchInlineSnapshot( 151{ 152 processId: expect.any(Number), 153 alive: expect.any(String), 154 firstSeen: expect.any(String), 155 lastSeen: expect.any(String), 156 processName: expect.any(String), 157 responsibleProcess: expect.any(String), 158 userName: expect.any(String), 159 cpuTime: expect.any(String) }, ` 160{ 161 "alive": Any<String>, 162 "cpuTime": Any<String>, 163 "firstSeen": Any<String>, 164 "lastSeen": Any<String>, 165 "processId": Any<Number>, 166 "processName": Any<String>, 167 "responsibleProcess": Any<String>, 168 "userName": Any<String>, 169} 170`); 171 }); 172 173 it('LiveProcessTest', function () { 174 liveProcess = { 175 processId: -1, 176 processName: '', 177 responsibleProcess: '', 178 userName: '', 179 cpu: '', 180 threads: -1, 181 }; 182 expect(liveProcess).not.toBeUndefined(); 183 expect(liveProcess).toMatchInlineSnapshot( 184{ 185 processId: expect.any(Number), 186 processName: expect.any(String), 187 responsibleProcess: expect.any(String), 188 userName: expect.any(String), 189 cpu: expect.any(String), 190 threads: expect.any(Number) }, ` 191{ 192 "cpu": Any<String>, 193 "processId": Any<Number>, 194 "processName": Any<String>, 195 "responsibleProcess": Any<String>, 196 "threads": Any<Number>, 197 "userName": Any<String>, 198} 199`); 200 }); 201 202 it('SystemNetworkSummaryTest', function () { 203 systemNetworkSummary = { 204 startTime: -1, 205 startTimeStr: '', 206 duration: -1, 207 durationStr: '', 208 dataReceived: -1, 209 dataReceivedStr: '', 210 dataReceivedSec: -1, 211 dataReceivedSecStr: '', 212 dataSend: -1, 213 dataSendStr: '', 214 dataSendSec: -1, 215 dataSendSecStr: '', 216 packetsIn: -1, 217 packetsInSec: -1, 218 packetsOut: -1, 219 packetsOutSec: -1, 220 }; 221 expect(systemNetworkSummary).not.toBeUndefined(); 222 expect(systemNetworkSummary).toMatchInlineSnapshot( 223{ 224 startTime: expect.any(Number), 225 startTimeStr: expect.any(String), 226 duration: expect.any(Number), 227 durationStr: expect.any(String), 228 dataReceived: expect.any(Number), 229 dataReceivedStr: expect.any(String), 230 dataReceivedSec: expect.any(Number), 231 dataReceivedSecStr: expect.any(String), 232 dataSend: expect.any(Number), 233 dataSendStr: expect.any(String), 234 dataSendSec: expect.any(Number), 235 dataSendSecStr: expect.any(String), 236 packetsIn: expect.any(Number), 237 packetsInSec: expect.any(Number), 238 packetsOut: expect.any(Number), 239 packetsOutSec: expect.any(Number) }, ` 240{ 241 "dataReceived": Any<Number>, 242 "dataReceivedSec": Any<Number>, 243 "dataReceivedSecStr": Any<String>, 244 "dataReceivedStr": Any<String>, 245 "dataSend": Any<Number>, 246 "dataSendSec": Any<Number>, 247 "dataSendSecStr": Any<String>, 248 "dataSendStr": Any<String>, 249 "duration": Any<Number>, 250 "durationStr": Any<String>, 251 "packetsIn": Any<Number>, 252 "packetsInSec": Any<Number>, 253 "packetsOut": Any<Number>, 254 "packetsOutSec": Any<Number>, 255 "startTime": Any<Number>, 256 "startTimeStr": Any<String>, 257} 258`); 259 }); 260 261 it('systemMemorySummaryTest', function () { 262 systemMemorySummary = { 263 startTime: -1, 264 startTimeStr: '', 265 duration: -1, 266 durationStr: '', 267 memoryTotal: -1, 268 memoryTotalStr: '', 269 cached: -1, 270 cachedStr: '', 271 swapTotal: -1, 272 swapTotalStr: '', 273 appMemory: -1, 274 cachedFiles: -1, 275 compressed: -1, 276 memoryUsed: -1, 277 wiredMemory: -1, 278 swapUsed: -1, 279 }; 280 expect(systemMemorySummary).not.toBeUndefined(); 281 expect(systemMemorySummary).toMatchInlineSnapshot( 282{ 283 startTime: expect.any(Number), 284 startTimeStr: expect.any(String), 285 duration: expect.any(Number), 286 durationStr: expect.any(String), 287 memoryTotal: expect.any(Number), 288 memoryTotalStr: expect.any(String), 289 cached: expect.any(Number), 290 cachedStr: expect.any(String), 291 swapTotal: expect.any(Number), 292 swapTotalStr: expect.any(String), 293 appMemory: expect.any(Number), 294 cachedFiles: expect.any(Number), 295 compressed: expect.any(Number), 296 memoryUsed: expect.any(Number), 297 wiredMemory: expect.any(Number), 298 swapUsed: expect.any(Number) }, ` 299{ 300 "appMemory": Any<Number>, 301 "cached": Any<Number>, 302 "cachedFiles": Any<Number>, 303 "cachedStr": Any<String>, 304 "compressed": Any<Number>, 305 "duration": Any<Number>, 306 "durationStr": Any<String>, 307 "memoryTotal": Any<Number>, 308 "memoryTotalStr": Any<String>, 309 "memoryUsed": Any<Number>, 310 "startTime": Any<Number>, 311 "startTimeStr": Any<String>, 312 "swapTotal": Any<Number>, 313 "swapTotalStr": Any<String>, 314 "swapUsed": Any<Number>, 315 "wiredMemory": Any<Number>, 316} 317`); 318 }); 319 it('DmaTest', function () { 320 dma = { 321 processId: -1, 322 timeStamp:'', 323 startNs:-1, 324 expTaskComm: '', 325 avgSize: -1, 326 minSize:-1, 327 maxSize: -1, 328 bufName:'', 329 expName: '', 330 size: -1, 331 processName: '', 332 process: '', 333 fd: -1, 334 ino: -1, 335 expPid: -1, 336 flag: -1, 337 avgSizes: '', 338 minSizes: '', 339 maxSizes: '', 340 sizes: '', 341 sumSize: -1, 342 sumSizes: '', 343 }; 344 expect(dma).not.toBeUndefined(); 345 expect(dma).toMatchInlineSnapshot(` 346{ 347 "avgSize": -1, 348 "avgSizes": "", 349 "bufName": "", 350 "expName": "", 351 "expPid": -1, 352 "expTaskComm": "", 353 "fd": -1, 354 "flag": -1, 355 "ino": -1, 356 "maxSize": -1, 357 "maxSizes": "", 358 "minSize": -1, 359 "minSizes": "", 360 "process": "", 361 "processId": -1, 362 "processName": "", 363 "size": -1, 364 "sizes": "", 365 "startNs": -1, 366 "sumSize": -1, 367 "sumSizes": "", 368 "timeStamp": "", 369} 370`); 371 }); 372}); 373