1 /* 2 * Copyright (c) 2021 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 package ohos.devtools.services.hiperf; 17 18 import ohos.devtools.datasources.utils.monitorconfig.entity.ConfigInfo; 19 import ohos.devtools.datasources.utils.monitorconfig.entity.PerfConfig; 20 import ohos.devtools.datasources.utils.session.entity.SessionInfo; 21 import ohos.devtools.datasources.utils.session.service.SessionManager; 22 import org.junit.Assert; 23 import org.junit.Before; 24 import org.junit.Test; 25 26 /** 27 * HiPerf Command Test 28 * 29 * @since 2021/2/1 9:31 30 */ 31 public class HiPerfCommandTest { 32 private SessionInfo sessionInfo; 33 private HiPerfCommand hiPerfCommand; 34 35 /** 36 * functional testing init 37 * 38 * @tc.name: init 39 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_init 40 * @tc.desc: init 41 * @tc.type: functional testing 42 * @tc.require: SR-010 43 */ 44 @Before init()45 public void init() { 46 sessionInfo = SessionInfo.builder().sessionId(1).sessionName("Test").pid(2).processName("processName").build(); 47 } 48 49 /** 50 * hiPerf Command Test 51 * 52 * @tc.name: hiPerfCommandTest01 53 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_hiPerfCommandTest01 54 * @tc.desc: hiPerf Command Test 55 * @tc.type: functional testing 56 * @tc.require: SR-010 57 */ 58 @Test hiPerfCommandTest01()59 public void hiPerfCommandTest01() { 60 String fileStorePath = this.getClass().getResource("/Demo.hprof").toString(); 61 hiPerfCommand = new HiPerfCommand(1, false, "1", fileStorePath); 62 Assert.assertNotNull(hiPerfCommand); 63 } 64 65 /** 66 * hiPerf Command Test 67 * 68 * @tc.name: hiPerfCommandTest02 69 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_hiPerfCommandTest02 70 * @tc.desc: hiPerf Command Test 71 * @tc.type: functional testing 72 * @tc.require: SR-010 73 */ 74 @Test hiPerfCommandTest02()75 public void hiPerfCommandTest02() { 76 String fileStorePath = this.getClass().getResource("/Demo.hprof").toString(); 77 hiPerfCommand = new HiPerfCommand(0, false, "1", fileStorePath); 78 Assert.assertNotNull(hiPerfCommand); 79 } 80 81 /** 82 * hiPerf Command Test 83 * 84 * @tc.name: hiPerfCommandTest03 85 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_hiPerfCommandTest03 86 * @tc.desc: hiPerf Command Test 87 * @tc.type: functional testing 88 * @tc.require: SR-010 89 */ 90 @Test hiPerfCommandTest03()91 public void hiPerfCommandTest03() { 92 String fileStorePath = this.getClass().getResource("/Demo.hprof").toString(); 93 hiPerfCommand = new HiPerfCommand(0, false, null, fileStorePath); 94 Assert.assertNotNull(hiPerfCommand); 95 } 96 97 /** 98 * hiPerf Command Test 99 * 100 * @tc.name: hiPerfCommandTest04 101 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_hiPerfCommandTest04 102 * @tc.desc: hiPerf Command Test 103 * @tc.type: functional testing 104 * @tc.require: SR-010 105 */ 106 @Test hiPerfCommandTest04()107 public void hiPerfCommandTest04() { 108 hiPerfCommand = new HiPerfCommand(0, false, "1", null); 109 Assert.assertNotNull(hiPerfCommand); 110 } 111 112 /** 113 * hiPerf Command Test 114 * 115 * @tc.name: hiPerfCommandTest05 116 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_hiPerfCommandTest05 117 * @tc.desc: hiPerf Command Test 118 * @tc.type: functional testing 119 * @tc.require: SR-010 120 */ 121 @Test hiPerfCommandTest05()122 public void hiPerfCommandTest05() { 123 hiPerfCommand = new HiPerfCommand(0, false, null, null); 124 Assert.assertNotNull(hiPerfCommand); 125 } 126 127 /** 128 * execute Report Test 129 * 130 * @tc.name: executeRecordTest01 131 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_executeReportTest01 132 * @tc.desc: execute Report Test 133 * @tc.type: functional testing 134 * @tc.require: SR-010 135 */ 136 @Test executeRecordTest01()137 public void executeRecordTest01() { 138 SessionManager.getInstance().getProfilingSessions().put(1L, sessionInfo); 139 String fileStorePath = this.getClass().getResource("/PerfDemo.trace").toString(); 140 hiPerfCommand = new HiPerfCommand(1, false, "1", fileStorePath); 141 PerfConfig perfConfig = ConfigInfo.getInstance().getPerfConfig(true); 142 hiPerfCommand.executeRecord(perfConfig); 143 Assert.assertTrue(true); 144 } 145 146 /** 147 * execute Report Test 148 * 149 * @tc.name: executeRecordTest02 150 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_executeReportTest02 151 * @tc.desc: execute Report Test 152 * @tc.type: functional testing 153 * @tc.require: SR-010 154 */ 155 @Test executeRecordTest02()156 public void executeRecordTest02() { 157 SessionManager.getInstance().getProfilingSessions().put(1L, sessionInfo); 158 hiPerfCommand = new HiPerfCommand(1, false, "1", null); 159 PerfConfig perfConfig = ConfigInfo.getInstance().getPerfConfig(false); 160 hiPerfCommand.executeRecord(perfConfig); 161 Assert.assertTrue(true); 162 } 163 164 /** 165 * execute Report Test 166 * 167 * @tc.name: executeRecordTest03 168 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_executeReportTest03 169 * @tc.desc: execute Report Test 170 * @tc.type: functional testing 171 * @tc.require: SR-010 172 */ 173 @Test executeRecordTest03()174 public void executeRecordTest03() { 175 SessionManager.getInstance().getProfilingSessions().put(1L, sessionInfo); 176 String fileStorePath = this.getClass().getResource("/PerfDemo.trace").toString(); 177 hiPerfCommand = new HiPerfCommand(1, true, "1", fileStorePath); 178 PerfConfig perfConfig = ConfigInfo.getInstance().getPerfConfig(false); 179 hiPerfCommand.executeRecord(perfConfig); 180 Assert.assertTrue(true); 181 } 182 183 /** 184 * execute Report Test 185 * 186 * @tc.name: executeRecordTest04 187 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_executeReportTest04 188 * @tc.desc: execute Report Test 189 * @tc.type: functional testing 190 * @tc.require: SR-010 191 */ 192 @Test executeRecordTest04()193 public void executeRecordTest04() { 194 SessionManager.getInstance().getProfilingSessions().put(1L, sessionInfo); 195 String fileStorePath = this.getClass().getResource("/PerfDemo.trace").toString(); 196 hiPerfCommand = new HiPerfCommand(1, false, "2", fileStorePath); 197 PerfConfig perfConfig = ConfigInfo.getInstance().getPerfConfig(false); 198 hiPerfCommand.executeRecord(perfConfig); 199 Assert.assertTrue(true); 200 } 201 202 /** 203 * execute Report Test 204 * 205 * @tc.name: executeRecordTest05 206 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_executeReportTest05 207 * @tc.desc: execute Report Test 208 * @tc.type: functional testing 209 * @tc.require: SR-010 210 */ 211 @Test executeRecordTest05()212 public void executeRecordTest05() { 213 SessionManager.getInstance().getProfilingSessions().put(1L, sessionInfo); 214 String fileStorePath = this.getClass().getResource("/Demo.hprof").toString(); 215 hiPerfCommand = new HiPerfCommand(1, false, "2", fileStorePath); 216 PerfConfig perfConfig = ConfigInfo.getInstance().getPerfConfig(false); 217 hiPerfCommand.executeRecord(perfConfig); 218 Assert.assertTrue(true); 219 } 220 221 /** 222 * stop Record Test 223 * 224 * @tc.name: stopRecordTest 225 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_stopRecordTest 226 * @tc.desc: stop Record Test 227 * @tc.type: functional testing 228 * @tc.require: SR-010 229 */ 230 @Test stopRecordTest()231 public void stopRecordTest() { 232 String fileStorePath = this.getClass().getResource("/Demo.hprof").toString(); 233 hiPerfCommand = new HiPerfCommand(1, false, "2", fileStorePath); 234 hiPerfCommand.stopRecord(); 235 } 236 237 /** 238 * execute Report Test 239 * 240 * @tc.name: executeReportTest 241 * @tc.number: OHOS_JAVA_perf_HiPerfCommandTest_executeReportTest 242 * @tc.desc: execute Report Test 243 * @tc.type: functional testing 244 * @tc.require: SR-010 245 */ 246 @Test executeReportTest()247 public void executeReportTest() { 248 String fileStorePath = this.getClass().getResource("/Demo.hprof").toString(); 249 hiPerfCommand = new HiPerfCommand(1, false, "2", fileStorePath); 250 hiPerfCommand.executeReport(); 251 } 252 }