1/* 2 * Copyright (c) 2024 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#include <gtest/gtest.h> 17#include <csignal> 18 19#include "devicedebug_base.h" 20#include "devicedebug_kill.h" 21#include "devicedebug_stub.h" 22 23using namespace testing; 24using namespace testing::ext; 25 26namespace OHOS { 27class DevicedebugKillTest : public testing::Test { 28public: 29 static void SetUpTestCase(); 30 static void TearDownTestCase(); 31 void SetUp(); 32 void TearDown(); 33}; 34 35void DevicedebugKillTest::SetUpTestCase() 36{ 37 GTEST_LOG_(INFO) << "Devicedebug_Kill_TEST SetUpTestCase"; 38} 39 40void DevicedebugKillTest::TearDownTestCase() 41{ 42 GTEST_LOG_(INFO) << "Devicedebug_Kill_TEST TearDownTestCase"; 43} 44 45void DevicedebugKillTest::SetUp() 46{ 47 GTEST_LOG_(INFO) << "Devicedebug_Kill_TEST SetUp"; 48} 49 50void DevicedebugKillTest::TearDown() 51{ 52 GTEST_LOG_(INFO) << "Devicedebug_Kill_TEST TearDown"; 53} 54 55/** 56* @tc.name: DevicedebugCmdKill_001 57* @tc.desc: Verify develop mode and argc validate. 58* @tc.type: FUNC 59* @tc.require:issueIASN4F 60* @tc.author: 61*/ 62HWTEST_F(DevicedebugKillTest, DevicedebugCmdKill_001, TestSize.Level0) 63{ 64 GTEST_LOG_(INFO) << "DevicedebugCmdKill_001 test...."; 65 { 66 int argc = 3; 67 char argv0[] = "devicedebug"; 68 char argv1[] = "kill"; 69 char argv2[] = "-9"; 70 char* argv[] = {argv0, argv1, argv2}; 71 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_NOT_IN_DEVELOPER_MODE); 72 DeveloperModeOpenSet(1); 73 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_OPERATOR_ARGV_MISS); 74 } 75 { 76 int argc = 2; 77 char argv0[] = "devicedebug"; 78 char argv1[] = "-h"; 79 char* argv[] = {argv0, argv1}; 80 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), 0); 81 } 82 { 83 DeveloperModeOpenSet(1); 84 int argc = 3; 85 char argv0[] = "devicedebug"; 86 char argv1[] = "kill"; 87 char argv2[] = "-9"; 88 char* argv[] = {argv0, argv1, argv2}; 89 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_OPERATOR_ARGV_MISS); 90 } 91} 92 93/** 94* @tc.name: DevicedebugCmdKill_002 95* @tc.desc: Verify signal validate. 96* @tc.type: FUNC 97* @tc.require:issueIASN4F 98* @tc.author: 99*/ 100HWTEST_F(DevicedebugKillTest, DevicedebugCmdKill_002, TestSize.Level0) 101{ 102 GTEST_LOG_(INFO) << "DevicedebugCmdKill_002 test...."; 103 104 DeveloperModeOpenSet(1); 105 { 106 int argc = 4; 107 char argv0[] = "devicedebug"; 108 char argv1[] = "kill"; 109 char argv2[] = "-0"; 110 char argv3[] = "12111"; 111 char* argv[] = {argv0, argv1, argv2, argv3}; 112 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_PARAM_INVALID); 113 } 114 { 115 int argc = 4; 116 char argv0[] = "devicedebug"; 117 char argv1[] = "kill"; 118 char argv2[] = "-65"; 119 char argv3[] = "12111"; 120 char* argv[] = {argv0, argv1, argv2, argv3}; 121 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_PARAM_INVALID); 122 } 123} 124 125/** 126* @tc.name: DevicedebugCmdKill_003 127* @tc.desc: Verify devicedebug kill success. 128* @tc.type: FUNC 129* @tc.require:issueIASN4F 130* @tc.author: 131*/ 132HWTEST_F(DevicedebugKillTest, DevicedebugCmdKill_003, TestSize.Level0) 133{ 134 GTEST_LOG_(INFO) << "DevicedebugCmdKill_003 test...."; 135 136 DeveloperModeOpenSet(1); 137 int argc = 4; 138 char argv0[] = "devicedebug"; 139 char argv1[] = "kill"; 140 char argv2[] = "-9"; 141 char argv3[] = "12111"; 142 char* argv[] = {argv0, argv1, argv2, argv3}; 143 { 144 AppSpawnClientInitRetSet(-1); 145 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -1); 146 } 147 AppSpawnClientInitRetSet(0); 148 { 149 AppSpawnReqMsgCreateRetSet(-2); 150 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -2); 151 } 152 AppSpawnReqMsgCreateRetSet(0); 153 { 154 AppSpawnReqMsgAddExtInfoRetSet(-3); 155 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -3); 156 } 157 AppSpawnReqMsgAddExtInfoRetSet(0); 158 { 159 AppSpawnClientSendMsgRetSet(-4); 160 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -4); 161 } 162 AppSpawnClientSendMsgRetSet(0); 163 { 164 AppSpawnClientSendMsgResultSet(-5); 165 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -5); 166 } 167 AppSpawnClientSendMsgResultSet(0); 168 { 169 EXPECT_EQ(DeviceDebugCmdKill(argc, argv), 0); 170 } 171} 172 173}