106f6ba60Sopenharmony_ci/* 206f6ba60Sopenharmony_ci * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. 306f6ba60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 406f6ba60Sopenharmony_ci * you may not use this file except in compliance with the License. 506f6ba60Sopenharmony_ci * You may obtain a copy of the License at 606f6ba60Sopenharmony_ci * 706f6ba60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 806f6ba60Sopenharmony_ci * 906f6ba60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1006f6ba60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1106f6ba60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1206f6ba60Sopenharmony_ci * See the License for the specific language governing permissions and 1306f6ba60Sopenharmony_ci * limitations under the License. 1406f6ba60Sopenharmony_ci */ 1506f6ba60Sopenharmony_ci 1606f6ba60Sopenharmony_ci#include <cstdio> 1706f6ba60Sopenharmony_ci 1806f6ba60Sopenharmony_ci#include <gtest/gtest.h> 1906f6ba60Sopenharmony_ci 2006f6ba60Sopenharmony_ci#include "command_helper.h" 2106f6ba60Sopenharmony_ci 2206f6ba60Sopenharmony_ciusing namespace testing::ext; 2306f6ba60Sopenharmony_ciusing namespace std; 2406f6ba60Sopenharmony_cinamespace OHOS { 2506f6ba60Sopenharmony_cinamespace Developtools { 2606f6ba60Sopenharmony_cinamespace Hiebpf { 2706f6ba60Sopenharmony_ciclass CommandHelperTest : public ::testing::Test { 2806f6ba60Sopenharmony_cipublic: 2906f6ba60Sopenharmony_ci static void SetUpTestCase() {}; 3006f6ba60Sopenharmony_ci static void TearDownTestCase() {}; 3106f6ba60Sopenharmony_ci 3206f6ba60Sopenharmony_ci void SetUp() {} 3306f6ba60Sopenharmony_ci void TearDown() {} 3406f6ba60Sopenharmony_ci}; 3506f6ba60Sopenharmony_ci 3606f6ba60Sopenharmony_ci/** 3706f6ba60Sopenharmony_ci * @tc.name: Start 3806f6ba60Sopenharmony_ci * @tc.desc: Test CommandHelper Start 3906f6ba60Sopenharmony_ci * @tc.type: FUNC 4006f6ba60Sopenharmony_ci */ 4106f6ba60Sopenharmony_ciHWTEST_F(CommandHelperTest, Start, TestSize.Level1) 4206f6ba60Sopenharmony_ci{ 4306f6ba60Sopenharmony_ci int argc = 1; 4406f6ba60Sopenharmony_ci char arg1[] = "hiebpf"; 4506f6ba60Sopenharmony_ci char* argv1[] = {arg1}; 4606f6ba60Sopenharmony_ci char **argv = argv1; 4706f6ba60Sopenharmony_ci auto commandHelper = CommandHelper::GetInstance(); 4806f6ba60Sopenharmony_ci int ret = commandHelper.Start(&argc, &argv, "help"); 4906f6ba60Sopenharmony_ci EXPECT_EQ(ret, 0); 5006f6ba60Sopenharmony_ci 5106f6ba60Sopenharmony_ci argc++; 5206f6ba60Sopenharmony_ci char arg2[] = "h"; 5306f6ba60Sopenharmony_ci char* argv2[] = {arg1, arg2}; 5406f6ba60Sopenharmony_ci argv = argv2; 5506f6ba60Sopenharmony_ci ret = commandHelper.Start(&argc, &argv, "none"); 5606f6ba60Sopenharmony_ci EXPECT_EQ(ret, 0); 5706f6ba60Sopenharmony_ci 5806f6ba60Sopenharmony_ci ret = commandHelper.Start(&argc, &argv, "help"); 5906f6ba60Sopenharmony_ci EXPECT_EQ(ret, -1); 6006f6ba60Sopenharmony_ci} 6106f6ba60Sopenharmony_ci 6206f6ba60Sopenharmony_ci/** 6306f6ba60Sopenharmony_ci * @tc.name: DoHelp 6406f6ba60Sopenharmony_ci * @tc.desc: Test CommandHelper DoHelp 6506f6ba60Sopenharmony_ci * @tc.type: FUNC 6606f6ba60Sopenharmony_ci */ 6706f6ba60Sopenharmony_ciHWTEST_F(CommandHelperTest, DoHelp, TestSize.Level1) 6806f6ba60Sopenharmony_ci{ 6906f6ba60Sopenharmony_ci testing::internal::CaptureStdout(); 7006f6ba60Sopenharmony_ci auto commandHelper = CommandHelper::GetInstance(); 7106f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_EXCLUDE_TRACER]); 7206f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_MAX_STACK_DEPTH]); 7306f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_DURATION]); 7406f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_EVENTS]); 7506f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_PIDS]); 7606f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_DUMP_EVENTS]); 7706f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_UNWIND_STACK]); 7806f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_BPF_LOG_LEVEL]); 7906f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_BPF_LOG_FILE]); 8006f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_LIBBPF_LOG_LEVEL]); 8106f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_LIBBPF_LOG_FILE]); 8206f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_HHLOG_LEVEL]); 8306f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_HHLOG_FILE]); 8406f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_SERVER_START]); 8506f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::ARG_SERVER_STOP]); 8606f6ba60Sopenharmony_ci commandHelper.DoHelp(commandHelper.SUPPORTED_ARGS[CommandHelper::NR_SUPPORTED_ARGS]); 8706f6ba60Sopenharmony_ci std::string out = testing::internal::GetCapturedStdout(); 8806f6ba60Sopenharmony_ci EXPECT_EQ(out.empty(), false); 8906f6ba60Sopenharmony_ci EXPECT_TRUE(out.find(commandHelper.SUPPORTED_ARGS[CommandHelper::NR_SUPPORTED_ARGS]) != std::string::npos); 9006f6ba60Sopenharmony_ci} 9106f6ba60Sopenharmony_ci} // namespace Hiebpf 9206f6ba60Sopenharmony_ci} // namespace Developtools 9306f6ba60Sopenharmony_ci} // namespace OHOS 94