169570cc8Sopenharmony_ci/* 269570cc8Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 369570cc8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 469570cc8Sopenharmony_ci * you may not use this file except in compliance with the License. 569570cc8Sopenharmony_ci * You may obtain a copy of the License at 669570cc8Sopenharmony_ci * 769570cc8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 869570cc8Sopenharmony_ci * 969570cc8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1069570cc8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1169570cc8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1269570cc8Sopenharmony_ci * See the License for the specific language governing permissions and 1369570cc8Sopenharmony_ci * limitations under the License. 1469570cc8Sopenharmony_ci */ 1569570cc8Sopenharmony_ci 1669570cc8Sopenharmony_ci#include <gtest/gtest.h> 1769570cc8Sopenharmony_ci#include <csignal> 1869570cc8Sopenharmony_ci 1969570cc8Sopenharmony_ci#include "devicedebug_base.h" 2069570cc8Sopenharmony_ci#include "devicedebug_kill.h" 2169570cc8Sopenharmony_ci#include "devicedebug_stub.h" 2269570cc8Sopenharmony_ci 2369570cc8Sopenharmony_ciusing namespace testing; 2469570cc8Sopenharmony_ciusing namespace testing::ext; 2569570cc8Sopenharmony_ci 2669570cc8Sopenharmony_cinamespace OHOS { 2769570cc8Sopenharmony_ciclass DevicedebugKillTest : public testing::Test { 2869570cc8Sopenharmony_cipublic: 2969570cc8Sopenharmony_ci static void SetUpTestCase(); 3069570cc8Sopenharmony_ci static void TearDownTestCase(); 3169570cc8Sopenharmony_ci void SetUp(); 3269570cc8Sopenharmony_ci void TearDown(); 3369570cc8Sopenharmony_ci}; 3469570cc8Sopenharmony_ci 3569570cc8Sopenharmony_civoid DevicedebugKillTest::SetUpTestCase() 3669570cc8Sopenharmony_ci{ 3769570cc8Sopenharmony_ci GTEST_LOG_(INFO) << "Devicedebug_Kill_TEST SetUpTestCase"; 3869570cc8Sopenharmony_ci} 3969570cc8Sopenharmony_ci 4069570cc8Sopenharmony_civoid DevicedebugKillTest::TearDownTestCase() 4169570cc8Sopenharmony_ci{ 4269570cc8Sopenharmony_ci GTEST_LOG_(INFO) << "Devicedebug_Kill_TEST TearDownTestCase"; 4369570cc8Sopenharmony_ci} 4469570cc8Sopenharmony_ci 4569570cc8Sopenharmony_civoid DevicedebugKillTest::SetUp() 4669570cc8Sopenharmony_ci{ 4769570cc8Sopenharmony_ci GTEST_LOG_(INFO) << "Devicedebug_Kill_TEST SetUp"; 4869570cc8Sopenharmony_ci} 4969570cc8Sopenharmony_ci 5069570cc8Sopenharmony_civoid DevicedebugKillTest::TearDown() 5169570cc8Sopenharmony_ci{ 5269570cc8Sopenharmony_ci GTEST_LOG_(INFO) << "Devicedebug_Kill_TEST TearDown"; 5369570cc8Sopenharmony_ci} 5469570cc8Sopenharmony_ci 5569570cc8Sopenharmony_ci/** 5669570cc8Sopenharmony_ci* @tc.name: DevicedebugCmdKill_001 5769570cc8Sopenharmony_ci* @tc.desc: Verify develop mode and argc validate. 5869570cc8Sopenharmony_ci* @tc.type: FUNC 5969570cc8Sopenharmony_ci* @tc.require:issueIASN4F 6069570cc8Sopenharmony_ci* @tc.author: 6169570cc8Sopenharmony_ci*/ 6269570cc8Sopenharmony_ciHWTEST_F(DevicedebugKillTest, DevicedebugCmdKill_001, TestSize.Level0) 6369570cc8Sopenharmony_ci{ 6469570cc8Sopenharmony_ci GTEST_LOG_(INFO) << "DevicedebugCmdKill_001 test...."; 6569570cc8Sopenharmony_ci { 6669570cc8Sopenharmony_ci int argc = 3; 6769570cc8Sopenharmony_ci char argv0[] = "devicedebug"; 6869570cc8Sopenharmony_ci char argv1[] = "kill"; 6969570cc8Sopenharmony_ci char argv2[] = "-9"; 7069570cc8Sopenharmony_ci char* argv[] = {argv0, argv1, argv2}; 7169570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_NOT_IN_DEVELOPER_MODE); 7269570cc8Sopenharmony_ci DeveloperModeOpenSet(1); 7369570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_OPERATOR_ARGV_MISS); 7469570cc8Sopenharmony_ci } 7569570cc8Sopenharmony_ci { 7669570cc8Sopenharmony_ci int argc = 2; 7769570cc8Sopenharmony_ci char argv0[] = "devicedebug"; 7869570cc8Sopenharmony_ci char argv1[] = "-h"; 7969570cc8Sopenharmony_ci char* argv[] = {argv0, argv1}; 8069570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), 0); 8169570cc8Sopenharmony_ci } 8269570cc8Sopenharmony_ci { 8369570cc8Sopenharmony_ci DeveloperModeOpenSet(1); 8469570cc8Sopenharmony_ci int argc = 3; 8569570cc8Sopenharmony_ci char argv0[] = "devicedebug"; 8669570cc8Sopenharmony_ci char argv1[] = "kill"; 8769570cc8Sopenharmony_ci char argv2[] = "-9"; 8869570cc8Sopenharmony_ci char* argv[] = {argv0, argv1, argv2}; 8969570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_OPERATOR_ARGV_MISS); 9069570cc8Sopenharmony_ci } 9169570cc8Sopenharmony_ci} 9269570cc8Sopenharmony_ci 9369570cc8Sopenharmony_ci/** 9469570cc8Sopenharmony_ci* @tc.name: DevicedebugCmdKill_002 9569570cc8Sopenharmony_ci* @tc.desc: Verify signal validate. 9669570cc8Sopenharmony_ci* @tc.type: FUNC 9769570cc8Sopenharmony_ci* @tc.require:issueIASN4F 9869570cc8Sopenharmony_ci* @tc.author: 9969570cc8Sopenharmony_ci*/ 10069570cc8Sopenharmony_ciHWTEST_F(DevicedebugKillTest, DevicedebugCmdKill_002, TestSize.Level0) 10169570cc8Sopenharmony_ci{ 10269570cc8Sopenharmony_ci GTEST_LOG_(INFO) << "DevicedebugCmdKill_002 test...."; 10369570cc8Sopenharmony_ci 10469570cc8Sopenharmony_ci DeveloperModeOpenSet(1); 10569570cc8Sopenharmony_ci { 10669570cc8Sopenharmony_ci int argc = 4; 10769570cc8Sopenharmony_ci char argv0[] = "devicedebug"; 10869570cc8Sopenharmony_ci char argv1[] = "kill"; 10969570cc8Sopenharmony_ci char argv2[] = "-0"; 11069570cc8Sopenharmony_ci char argv3[] = "12111"; 11169570cc8Sopenharmony_ci char* argv[] = {argv0, argv1, argv2, argv3}; 11269570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_PARAM_INVALID); 11369570cc8Sopenharmony_ci } 11469570cc8Sopenharmony_ci { 11569570cc8Sopenharmony_ci int argc = 4; 11669570cc8Sopenharmony_ci char argv0[] = "devicedebug"; 11769570cc8Sopenharmony_ci char argv1[] = "kill"; 11869570cc8Sopenharmony_ci char argv2[] = "-65"; 11969570cc8Sopenharmony_ci char argv3[] = "12111"; 12069570cc8Sopenharmony_ci char* argv[] = {argv0, argv1, argv2, argv3}; 12169570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), DEVICEDEBUG_ERRNO_PARAM_INVALID); 12269570cc8Sopenharmony_ci } 12369570cc8Sopenharmony_ci} 12469570cc8Sopenharmony_ci 12569570cc8Sopenharmony_ci/** 12669570cc8Sopenharmony_ci* @tc.name: DevicedebugCmdKill_003 12769570cc8Sopenharmony_ci* @tc.desc: Verify devicedebug kill success. 12869570cc8Sopenharmony_ci* @tc.type: FUNC 12969570cc8Sopenharmony_ci* @tc.require:issueIASN4F 13069570cc8Sopenharmony_ci* @tc.author: 13169570cc8Sopenharmony_ci*/ 13269570cc8Sopenharmony_ciHWTEST_F(DevicedebugKillTest, DevicedebugCmdKill_003, TestSize.Level0) 13369570cc8Sopenharmony_ci{ 13469570cc8Sopenharmony_ci GTEST_LOG_(INFO) << "DevicedebugCmdKill_003 test...."; 13569570cc8Sopenharmony_ci 13669570cc8Sopenharmony_ci DeveloperModeOpenSet(1); 13769570cc8Sopenharmony_ci int argc = 4; 13869570cc8Sopenharmony_ci char argv0[] = "devicedebug"; 13969570cc8Sopenharmony_ci char argv1[] = "kill"; 14069570cc8Sopenharmony_ci char argv2[] = "-9"; 14169570cc8Sopenharmony_ci char argv3[] = "12111"; 14269570cc8Sopenharmony_ci char* argv[] = {argv0, argv1, argv2, argv3}; 14369570cc8Sopenharmony_ci { 14469570cc8Sopenharmony_ci AppSpawnClientInitRetSet(-1); 14569570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -1); 14669570cc8Sopenharmony_ci } 14769570cc8Sopenharmony_ci AppSpawnClientInitRetSet(0); 14869570cc8Sopenharmony_ci { 14969570cc8Sopenharmony_ci AppSpawnReqMsgCreateRetSet(-2); 15069570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -2); 15169570cc8Sopenharmony_ci } 15269570cc8Sopenharmony_ci AppSpawnReqMsgCreateRetSet(0); 15369570cc8Sopenharmony_ci { 15469570cc8Sopenharmony_ci AppSpawnReqMsgAddExtInfoRetSet(-3); 15569570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -3); 15669570cc8Sopenharmony_ci } 15769570cc8Sopenharmony_ci AppSpawnReqMsgAddExtInfoRetSet(0); 15869570cc8Sopenharmony_ci { 15969570cc8Sopenharmony_ci AppSpawnClientSendMsgRetSet(-4); 16069570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -4); 16169570cc8Sopenharmony_ci } 16269570cc8Sopenharmony_ci AppSpawnClientSendMsgRetSet(0); 16369570cc8Sopenharmony_ci { 16469570cc8Sopenharmony_ci AppSpawnClientSendMsgResultSet(-5); 16569570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), -5); 16669570cc8Sopenharmony_ci } 16769570cc8Sopenharmony_ci AppSpawnClientSendMsgResultSet(0); 16869570cc8Sopenharmony_ci { 16969570cc8Sopenharmony_ci EXPECT_EQ(DeviceDebugCmdKill(argc, argv), 0); 17069570cc8Sopenharmony_ci } 17169570cc8Sopenharmony_ci} 17269570cc8Sopenharmony_ci 17369570cc8Sopenharmony_ci}