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 #include "hidebug_base.h" 17 18 #include <hwext/gtest-ext.h> 19 #include <hwext/gtest-tag.h> 20 21 #include <cstdlib> 22 23 using namespace testing::ext; 24 25 namespace { 26 class HidebugTest : public ::testing::Test { 27 protected: SetUp()28 void SetUp() override {} TearDown()29 void TearDown() override 30 { 31 system("param set hiviewdfx.debugenv.hidebug_test 0"); 32 system("param set libc.hook_mode 0"); 33 } 34 }; 35 36 /** 37 * @tc.name: InitEnvironmentParam 38 * @tc.desc: test InitEnvironmentParam 39 * @tc.type: FUNC 40 */ 41 HWTEST_F(HidebugTest, InitEnvironmentParam1, TestSize.Level1) 42 { 43 system("param set hiviewdfx.debugenv.hidebug_test aaa:bbb"); 44 const char* inputName = "hidebug_test"; 45 EXPECT_TRUE(InitEnvironmentParam(inputName)); 46 } 47 48 /** 49 * @tc.name: InitEnvironmentParam 50 * @tc.desc: test InitEnvironmentParam for input is nullptr 51 * @tc.type: FUNC 52 */ 53 HWTEST_F(HidebugTest, InitEnvironmentParam2, TestSize.Level1) 54 { 55 system("param set hiviewdfx.debugenv.hidebug_test aaa:bbb"); 56 const char* inputName = nullptr; 57 EXPECT_FALSE(InitEnvironmentParam(inputName)); 58 } 59 60 /** 61 * @tc.name: InitEnvironmentParam 62 * @tc.desc: test InitEnvironmentParam for input is wrong 63 * @tc.type: FUNC 64 */ 65 HWTEST_F(HidebugTest, InitEnvironmentParam3, TestSize.Level1) 66 { 67 system("param set hiviewdfx.debugenv.hidebug_test aaa:bbb"); 68 const char* inputName = "hidebug_test/"; 69 EXPECT_FALSE(InitEnvironmentParam(inputName)); 70 } 71 72 /** 73 * @tc.name: InitEnvironmentParam 74 * @tc.desc: test InitEnvironmentParam for param set wrong 75 * @tc.type: FUNC 76 */ 77 HWTEST_F(HidebugTest, InitEnvironmentParam4, TestSize.Level1) 78 { 79 system("param set hiviewdfx.debugenv.hidebug_test error_input"); 80 const char* inputName = "hidebug_test"; 81 EXPECT_FALSE(InitEnvironmentParam(inputName)); 82 } 83 84 /** 85 * @tc.name: InitEnvironmentParam 86 * @tc.desc: test InitEnvironmentParam for libc.hook_mode 87 * @tc.type: FUNC 88 */ 89 HWTEST_F(HidebugTest, InitEnvironmentParam5, TestSize.Level1) 90 { 91 system("param set hiviewdfx.debugenv.hidebug_test aaa:bbb"); 92 system("param set libc.hook_mode startup:hidebug_test"); 93 const char* inputName = "hidebug_test"; 94 EXPECT_TRUE(InitEnvironmentParam(inputName)); 95 } 96 97 /** 98 * @tc.name: InitEnvironmentParam 99 * @tc.desc: test InitEnvironmentParam for libc.hook_mode param set fail 100 * @tc.type: FUNC 101 */ 102 HWTEST_F(HidebugTest, InitEnvironmentParam6, TestSize.Level1) 103 { 104 system("param set hiviewdfx.debugenv.hidebug_test error_input"); 105 system("param set libc.hook_mode error_set:hidebug_test"); 106 const char* inputName = "hidebug_test"; 107 EXPECT_FALSE(InitEnvironmentParam(inputName)); 108 } 109 110 /** 111 * @tc.name: InitEnvironmentParam 112 * @tc.desc: test InitEnvironmentParam for libc.hook_mode fail 113 * @tc.type: FUNC 114 */ 115 HWTEST_F(HidebugTest, InitEnvironmentParam7, TestSize.Level1) 116 { 117 system("param set hiviewdfx.debugenv.hidebug_test error_input"); 118 system("param set libc.hook_mode error_set:hidebug_test"); 119 const char* inputName = "hidebug_test"; 120 EXPECT_FALSE(InitEnvironmentParam(inputName)); 121 } 122 123 /** 124 * @tc.name: InitEnvironmentParam 125 * @tc.desc: test InitEnvironmentParam for libc.hook_mode input error 126 * @tc.type: FUNC 127 */ 128 HWTEST_F(HidebugTest, InitEnvironmentParam8, TestSize.Level1) 129 { 130 system("param set hiviewdfx.debugenv.hidebug_test aaa:bbb"); 131 system("param set libc.hook_mode error_set:hidebug_test"); 132 const char* inputName = "error_input"; 133 EXPECT_FALSE(InitEnvironmentParam(inputName)); 134 } 135 136 /** 137 * @tc.name: InitEnvironmentParam 138 * @tc.desc: test InitEnvironmentParam for libc.hook_mode param set wrong_proc 139 * @tc.type: FUNC 140 */ 141 HWTEST_F(HidebugTest, InitEnvironmentParam9, TestSize.Level1) 142 { 143 system("param set hiviewdfx.debugenv.hidebug_test error_input"); 144 system("param set libc.hook_mode start_up:wrong_proc"); 145 const char* inputName = "hidebug"; 146 EXPECT_FALSE(InitEnvironmentParam(inputName)); 147 } 148 } // namespace 149