提交 c5745947 编写于 作者: Q quxianfei

dfx cpp delete

Signed-off-by: Nquxianfei <quxianfei@huawei.com>
上级 327e88c1
......@@ -14,14 +14,6 @@ import("//build/ohos_var.gni")
group("hiviewdfxtestacts") {
testonly = true
if (is_standard_system) {
deps = [
"faultloggertest/faultloggercpptest:ActsFaultLoggerTest",
"hiappeventtest/hiappeventjstest:ActsHiAppEventJsTest",
"hicollietest/hicolliecpptest:ActsHiCollieCppTest",
"hilogtest/libhilogtest:libhilogtestacts",
"hisyseventtest/hisyseventcpptest:ActsHiSysEventCPPTest",
"hitracetest/hitracecpptest:ActsHitraceCPPTest",
"hitracetest/hitracectest:ActsHitraceCTest",
]
deps = [ "hiappeventtest/hiappeventjstest:ActsHiAppEventJsTest" ]
}
}
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hits/faultloggertest"
###############################################################################
config("faultloggertest_config") {
visibility = [ ":*" ]
include_dirs = [
"../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"genfault.h",
]
}
ohos_moduletest_suite("ActsFaultLoggerTest") {
module_out_path = module_output_path
sources = [
"faultloggertest.cpp",
"genfault.cpp",
]
deps = [
"../../utils/native:utilskit",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
configs = [ ":faultloggertest_config" ]
}
{
"kits": [
{
"push": [
"ActsFaultLoggerTest->/data/local/tmp/ActsFaultLoggerTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsFaultLoggerTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsFaultLoggerTest Tests"
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdarg>
#include <ctime>
#include <gtest/gtest.h>
#include <pthread.h>
#include "genfault.h"
#include "file_utils.h"
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0xD003200
#define LOG_TAG "FAULTLOGGERTEST"
using namespace OHOS;
using namespace HiviewDFX;
using namespace testing::ext;
using namespace std;
class faultloggertest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
pid_t DoTestProcess(int faulttype);
int status;
private:
};
void faultloggertest::SetUp()
{
}
void faultloggertest::TearDown()
{
}
void faultloggertest::SetUpTestCase()
{
}
void faultloggertest::TearDownTestCase()
{
}
pid_t faultloggertest::DoTestProcess(int faulttype)
{
printf("DoTestProcess, param is %d\r\n", faulttype);
pid_t pid;
pid = fork();
printf("pid is %d\r\n", pid);
switch (pid) {
case -1:
std::cout<<"for pid failed"<<std::endl;
break;
case 0:
GenFault(faulttype);
break;
default:
break;
}
wait(&status);
printf("sub process end with status %d\r\n", status);
return pid;
}
/*
* @tc.name faultlogger Detect a cpp crash happen
* @tc.number DFX_DFR_FaultLogger_0100
* @tc.desc inject a cppcrash fault and check faultlogger can detect the fault
*/
HWTEST_F(faultloggertest, Faultlogger_Faultdetect, Function|MediumTest|Level1)
{
pid_t pid = DoTestProcess(3);
printf("pid is %d\r\n", pid);
printf("sub process end with status %d\r\n", faultloggertest::status);
ASSERT_FALSE(status == 0);
sleep(1);
std::vector<std::string> faultfilelist;
faultfilelist = getfileinpath("/data/log/faultlog/temp/");
printf("sizeof faultfilelist is %d\r\n", faultfilelist.size());
bool result = false;
for (std::string filename : faultfilelist) {
printf("file list is %s\r\n", filename.c_str());
if (filename.find("cppcrash-" + to_string(pid)) != string::npos) {
result = true;
break;
}
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name faultlogger log file check
* @tc.number DFX_DFR_FaultLogger_0100
* @tc.desc inject a cppcrash fault and check faultlogger file
*/
HWTEST_F(faultloggertest, Faultlogger_Faultdetect1, Function|MediumTest|Level1)
{
pid_t pid = DoTestProcess(3);
printf("pid is %d\r\n", pid);
printf("sub process end with status %d\r\n", faultloggertest::status);
sleep(1);
std::vector<std::string> faultfilelist;
faultfilelist = getfileinpath("/data/log/faultlog/temp/");
printf("sizeof faultfilelist is %d\r\n", faultfilelist.size());
bool result = false;
std::string faultloggerfile = "";
for (std::string filename : faultfilelist) {
if (filename.find("cppcrash-" + to_string(pid)) != std::string::npos) {
printf("file list is %s\r\n", filename.c_str());
faultloggerfile = filename;
break;
}
}
string fileinfo;
fileinfo = ReadFile("/data/log/faultlog/temp/" + faultloggerfile);
std::vector<std::string> para = {"Pid:" + to_string(pid), "Uid:0",
"Process name:", "/data/local/tmp/faultloggertest",
"Reason:Signal:SIGILL", "Fault thread Info:",
"Tid:" + to_string(pid), "Name:faultloggertest"};
if (!fileinfo.empty()) {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "Faultlogger_Faultdetect1 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "Faultlogger_Faultdetect1 end" << endl;
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
#include <stdlib.h>
#include <string.h>
#include <thread>
#include <unistd.h>
typedef enum {
FAULT_HEAP = 1,
FAULT_STACK = 2,
FAULT_NULLPTR = 3,
}FaultType;
void FaultHeap(int value)
{
int* arraytest = new int[123];
delete []arraytest;
printf("%d", arraytest[value]);
}
void FaultStack(int value)
{
int arraytest[123];
printf("value of i is %d", arraytest[value]);
}
void FaultNullPointer()
{
const int num = 80;
int *i = nullptr;
*i = num;
}
void GenFault(int faulttype)
{
printf("genFault, param is %d\r\n", faulttype);
switch (faulttype) {
case FAULT_HEAP:
FaultHeap(125);
case FAULT_STACK:
FaultStack(125);
case FAULT_NULLPTR:
FaultNullPointer();
break;
}
}
#endif
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "file_utils.h"
void GenFault(int faulttype);
\ No newline at end of file
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hits/HiCollieCppTest"
###############################################################################
config("xcollie_config") {
visibility = [ ":*" ]
include_dirs = [
"../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/hiviewdfx/hicollie/interfaces/native/innerkits/include",
]
}
ohos_moduletest_suite("ActsHiCollieCppTest") {
module_out_path = module_output_path
sources = [ "HiCollieCppTest.cpp" ]
deps = [
"../../utils/native:utilskit",
"//base/hiviewdfx/hicollie/interfaces/native/innerkits:libhicollie",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
configs = [ ":xcollie_config" ]
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <regex>
#include <gtest/gtest.h>
#include <unistd.h>
#include <sys/wait.h>
#include "xcollie/xcollie.h"
#include "xcollie/xcollie_checker.h"
#include "xcollie/xcollie_define.h"
#include "ctime"
#include "file_utils.h"
using namespace testing;
using namespace testing::ext;
using namespace std;
using namespace OHOS::HiviewDFX;
namespace {
int g_type = 1;
int g_blockTime;
int g_waitTime;
int g_setTimeout;
int g_updateTime = -1;
int g_cancelTimeout = -1;
}
class HiCollieCppTest : public testing::Test {
public:
int callbackCnt_;
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
string ReadFileList(string basePath, string param);
bool ReadHilogcatredirectFile(string path, string context);
void XcollieTestInstance(string testItem);
void DoXCollieTest();
void TimeCallback(void *data);
void SetCallbackCnt(int cnt);
HiCollieCppTest();
~HiCollieCppTest();
private:
};
HiCollieCppTest::HiCollieCppTest():callbackCnt_(0)
{
}
HiCollieCppTest::~HiCollieCppTest()
{
}
void HiCollieCppTest::SetUp()
{
std::cout << "SetUp" << std::endl;
}
void HiCollieCppTest::TearDown()
{
std::cout << "TearDown" << std::endl;
g_updateTime = -1;
g_cancelTimeout = -1;
}
void HiCollieCppTest::SetUpTestCase()
{
std::cout << "SetUpTestCase" << std::endl;
}
void HiCollieCppTest::TearDownTestCase()
{
std::cout << "TearDownTestCase" << std::endl;
}
void HiCollieCppTest::TimeCallback(void *data)
{
callbackCnt_++;
}
void HiCollieCppTest::SetCallbackCnt(int cnt)
{
callbackCnt_ = cnt;
}
class XCollieCheckerAssist : public XCollieChecker {
using XCollieChecker::XCollieChecker;
virtual void CheckLock()
{
// sleep 35 seconds
sleep(35);
}
};
void HiCollieCppTest::DoXCollieTest()
{
pid_t pid;
int status;
// Fork a child process for leak injection
pid = fork();
if (pid == -1) {
cout<<"fail to fork!"<<endl;
exit(1);
} else if (pid == 0) {
XcollieTestInstance("WATCHDOG");
sleep(g_blockTime);
exit(0);
} else {
wait(&status);
}
}
void HiCollieCppTest::XcollieTestInstance(string testItem)
{
cout<<"XcollieTestInstance start"<<endl;
if (testItem == "TIMEOUT") {
int id = XCollie::GetInstance().SetTimer("TimeoutTimer", g_setTimeout, nullptr, nullptr, g_type);
if (g_updateTime != -1) {
bool ret = XCollie::GetInstance().UpdateTimer(id, g_updateTime);
if (ret) {
cout<<"Update timer succeed,reset as "<<g_updateTime<<endl;
} else {
cout<<"Update timer failed!"<<endl;
}
}
if (g_cancelTimeout != -1) {
XCollie::GetInstance().CancelTimer(id);
}
sleep(g_blockTime);
XCollie::GetInstance().CancelTimer(id);
} else if (testItem == "WATCHDOG") {
const OHOS::sptr<XCollieChecker> checker = new XCollieCheckerAssist("checker");
XCollie::GetInstance().RegisterXCollieChecker(checker, g_type);
sleep(g_waitTime);
}
}
/**
* @tc.name Verify that when the native layer is blocked by the main thread of
* the monitored service, the service restarts after 60 seconds
* @tc.number DFX_DFR_Xcollie_Watchdog_0001
* @tc.desc Verify that the native layer is blocked by the main thread of the monitored service
*/
HWTEST_F(HiCollieCppTest, Xcollie_watchdog_test, Function|MediumTest|Level1) {
GTEST_LOG_(INFO) << "Xcollie_watchdog_test start" << endl;
g_type = XCOLLIE_THREAD;
g_blockTime = 61;
g_waitTime = 20;
DoXCollieTest();
string cmd = "";
bool result = false;
sleep(90);
std::vector<std::string> cmdret;
cmd = "ps -A |grep HiCollieCppTest";
unsigned long cmdretlen;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
if (cmdretlen == 1) {
result = true;
} else {
GTEST_LOG_(INFO) << "failed to get xcollie log." << endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "Xcollie_watchdog_test end" << endl;
}
/**
* @tc.name Verify that the native layer service deadlock and
* main thread blocking are monitored at the same time
* @tc.number DFX_DFR_Xcollie_Watchdog_0002
* @tc.desc Verify that the native layer service deadlock and main thread blocking
*/
HWTEST_F(HiCollieCppTest, Xcollie_watchdog_test1, Function|MediumTest|Level1) {
GTEST_LOG_(INFO) << "Xcollie_watchdog_test1 start" << endl;
string cmd = "";
bool result = false;
g_type = XCOLLIE_LOCK|XCOLLIE_THREAD;
g_blockTime = 61;
g_waitTime = 20;
DoXCollieTest();
sleep(90);
std::vector<std::string> cmdret;
cmd = "ps -A |grep HiCollieCppTest";
unsigned long cmdretlen;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
if (cmdretlen == 1) {
result = true;
} else {
GTEST_LOG_(INFO) << "failed to get xcollie log." << endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "Xcollie_watchdog_test1 end" << endl;
}
/**
* @tc.name When a deadlock occurs in the monitored service of the native layer,
* the service restarts after 60 seconds
* @tc.number DFX_DFR_Xcollie_Watchdog_0003
* @tc.desc Verify that deadlock occurs in the monitored service of the native layer
*/
HWTEST_F(HiCollieCppTest, Xcollie_watchdog_test2, Function|MediumTest|Level1) {
GTEST_LOG_(INFO) << "Xcollie_watchdog_test2 start" << endl;
g_type = XCOLLIE_LOCK;
g_blockTime = 30;
g_waitTime = 75;
DoXCollieTest();
string cmd = "";
bool result = false;
sleep(110);
std::vector<std::string> cmdret;
cmd = "ps -A |grep HiCollieCppTest";
unsigned long cmdretlen;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
if (cmdretlen == 1) {
result = true;
} else {
GTEST_LOG_(INFO) << "failed to get xcollie log." << endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "Xcollie_watchdog_test2 end" << endl;
}
/**
* @tc.name verification of callback funcitons
* @tc.number DFX_DFR_Xcollie_Timeout_0001
* @tc.desc callback funcitons
*/
HWTEST_F(HiCollieCppTest, Xcollie_Timeout_test, Function|MediumTest|Level1) {
GTEST_LOG_(INFO) << "Xcollie_Timeout_test start" << endl;
g_type = XCOLLIE_FLAG_NOOP;
SetCallbackCnt(0);
auto func = [this](void *data) {
this->TimeCallback(data);
};
int last = XCollie::GetInstance().SetTimer("TimeoutTimer", 61, func, nullptr, g_type);
ASSERT_TRUE(last != INVALID_ID);
GTEST_LOG_(INFO) << "Xcollie_Timeout_test end" << endl;
}
/**
* @tc.name UpdateTimer interface test
* @tc.number DFX_DFR_Xcollie_interface_0001
* @tc.desc interface test
*/
HWTEST_F(HiCollieCppTest, Xcollie_interface_test, Function|MediumTest|Level1)
{
int id = XCollie::GetInstance().SetTimer("TimeoutTimerTest", 1, nullptr, nullptr, XCOLLIE_FLAG_NOOP);
ASSERT_NE(id, INVALID_ID);
bool result = XCollie::GetInstance().UpdateTimer(id, 1);
ASSERT_TRUE(result);
}
/**
* @tc.name UpdateTimer interface test, id is invalid
* @tc.number DFX_DFR_Xcollie_interface_0002
* @tc.desc interface test
*/
HWTEST_F(HiCollieCppTest, Xcollie_interface_test1, Function|MediumTest|Level1)
{
int id = -1;
int timeout = 100;
bool result = XCollie::GetInstance().UpdateTimer(id, timeout);
ASSERT_FALSE(result);
}
/**
* @tc.name UpdateTimer interface test, timeout is 0
* @tc.number DFX_DFR_Xcollie_interface_0003
* @tc.desc interface test
*/
HWTEST_F(HiCollieCppTest, Xcollie_interface_test2, Function|MediumTest|Level1)
{
bool result = XCollie::GetInstance().UpdateTimer(10, 0);
ASSERT_FALSE(result);
}
/**
* @tc.name SetTimer interface test, timeout is 0
* @tc.number DFX_DFR_Xcollie_interface_0004
* @tc.desc interface test
*/
HWTEST_F(HiCollieCppTest, Xcollie_interface_test3, Function|MediumTest|Level1)
{
int id = XCollie::GetInstance().SetTimer("Timer", 0, nullptr, nullptr, XCOLLIE_FLAG_NOOP);
ASSERT_EQ(id, INVALID_ID);
}
/**
* @tc.name SetTimer interface test, timeout is negative.
* @tc.number DFX_DFR_Xcollie_interface_0005
* @tc.desc interface test
*/
HWTEST_F(HiCollieCppTest, Xcollie_interface_test4, Function|MediumTest|Level1)
{
int id = XCollie::GetInstance().SetTimer("Timer", -2, nullptr, nullptr, XCOLLIE_FLAG_NOOP);
ASSERT_TRUE(id != INVALID_ID);
}
/**
* @tc.name SetTimer interface test, service name is very long.
* @tc.number DFX_DFR_Xcollie_interface_0006
* @tc.desc interface test
*/
HWTEST_F(HiCollieCppTest, Xcollie_interface_test5, Function|MediumTest|Level1)
{
std::string name = "abcd";
for (int i = 0; i < 1000; i++) {
name += "abcd";
}
int id = XCollie::GetInstance().SetTimer(name, 5, nullptr, nullptr, XCOLLIE_FLAG_NOOP);
ASSERT_TRUE(id != INVALID_ID);
}
/**
* @tc.name SetTimer interface test, when type is invalid.
* @tc.number DFX_DFR_Xcollie_interface_0007
* @tc.desc interface test
*/
HWTEST_F(HiCollieCppTest, Xcollie_interface_test6, Function|MediumTest|Level1)
{
int id = XCollie::GetInstance().SetTimer("Timer", 5, nullptr, nullptr, XCOLLIE_FLAG_NOOP + 100);
ASSERT_TRUE(id != INVALID_ID);
}
\ No newline at end of file
{
"kits": [
{
"push": [
"ActsHiCollieCppTest->/data/local/tmp/ActsHiCollieCppTest"
],
"type": "PushKit",
"post-push": [
"chmod -R 777 /data/local/tmp/*"
]
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsHiCollieCppTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsHiCollieCppTest Tests"
}
\ No newline at end of file
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
group("libhilogtestacts") {
testonly = true
deps = [
"hilogtest:ActsHilogTest",
"libhilogCPPtest:ActsLibhilogCPPTest",
"libhilogCtest:ActsLibhilogCTest",
]
}
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hits/hilogtest"
###############################################################################
config("hilogtest_config") {
visibility = [ ":*" ]
include_dirs = [
"../../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
]
}
ohos_moduletest_suite("ActsHilogTest") {
module_out_path = module_output_path
sources = [ "hilogtest.cpp" ]
deps = [
"../../../utils/native:utilskit",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
#external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
configs = [ ":hilogtest_config" ]
}
{
"kits": [
{
"push": [
"ActsHilogTest->/data/local/tmp/ActsHilogTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsHilogTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsHilogTest Tests"
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdarg>
#include <ctime>
#include <gtest/gtest.h>
#include <list>
#include <ostream>
#include <pthread.h>
#include <queue>
#include <regex>
#include <securec.h>
#include <streambuf>
#include <sys/time.h>
#include <thread>
#include "file_utils.h"
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0xD003200
#define LOG_TAG "HILOGTOOLTEST"
#define MAX_LINE 1024*10
using namespace OHOS;
using namespace HiviewDFX;
using namespace testing::ext;
using namespace std;
class hilogtest : public testing::Test {
public:
string input = "";
string result = "";
string expect = "";
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
string gHilogtoolExecutable = "hilog ";
string g_logContent = "123456789_1234567890_public and private log test is:\
%{public}d, %{private}lf, %{public}.2f, %s, %{private}c\n";
string g_commonContent = "03200/HILOGTOOLTEST: 123456789_1234567890_public and private log test is:";
private:
};
void hilogtest::SetUp()
{
}
void hilogtest::TearDown()
{
}
void hilogtest::SetUpTestCase()
{
ExeCmd("hilog -p on");
ExeCmd("hilog -Q domainoff");
ExeCmd("hilog -Q pidoff");
ExeCmd("hilog -b debug");
ExeCmd("hilog -b debug -D 218116608");
ExeCmd("hilog -b debug -T HILOGTOOLTEST");
ExeCmd("hilog -r -t all");
ExeCmd("hilog -G 1m -t all");
ExeCmd("hilog -S -t all");
ExeCmd("hilog -S -D 218116608");
}
void hilogtest::TearDownTestCase()
{
ExeCmd("hilog -p on");
ExeCmd("hilog -Q domainoff");
ExeCmd("hilog -Q pidoff");
ExeCmd("hilog -b debug");
ExeCmd("hilog -b debug -D 218116608");
ExeCmd("hilog -b debug -T HILOGTOOLTEST");
ExeCmd("hilog -r -t all");
ExeCmd("hilog -G 1m -t all");
ExeCmd("hilog -S -t all");
ExeCmd("hilog -S -D 218116608");
std::cout << "TearDownTestCase" << std::endl;
}
/*
* @tc.name one-time read
* @tc.number DFX_DFT_HilogCPP_0840
* @tc.desc one-time read
*/
HWTEST_F(hilogtest, Hilogtool_exit, Function|MediumTest|Level3)
{
CleanCmd();
std::string saveFile= "/data/local/tmp/test_data_31.txt";
std::string cmd1 = gHilogtoolExecutable + " -r";
std::string cmdResult;
CmdRun(cmd1, cmdResult);
LogType type = LOG_APP;
int i = 0;
while (i++ <= 5) {
usleep(1000);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string cmd2 = gHilogtoolExecutable + "-T HILOGTOOLTEST -x";
SaveCmdOutput(cmd2, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != "") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_exit error" << std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name The log tool can read app log types at a time.
* @tc.number DFX_DFT_HilogCPP_0860
* @tc.desc The log tool can read app log types at a time.
*/
HWTEST_F(hilogtest, Hilogtool_type_app, Function|MediumTest|Level3)
{
CleanCmd();
std::string saveFile= "/data/local/tmp/test_data_33_1.txt";
LogType type = LOG_APP;
int i = 0;
while (i++ <= 5) {
usleep(1000);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string cmd = gHilogtoolExecutable + " -t app -x ";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != " ") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_type_app error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name The log tool can read core log types at a time.
* @tc.number DFX_DFT_HilogCPP_0870
* @tc.desc The log tool can read core log types at a time
*/
HWTEST_F(hilogtest, Hilogtool_type_core, Function|MediumTest|Level3)
{
CleanCmd();
std::string saveFile= "/data/local/tmp/test_data_33_2.txt";
LogType type = LOG_CORE;
int i = 0;
while (i++ <= 5) {
usleep(1000);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string cmd = gHilogtoolExecutable + " -t core -x ";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != "") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_type_app error"<<std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name The log tool can read init log types at a time.
* @tc.number DFX_DFT_HilogCPP_0880
* @tc.desc The log tool can read init log types at a time.
*/
HWTEST_F(hilogtest, Hilogtool_type_init, Function|MediumTest|Level3)
{
CleanCmd();
std::string saveFile= "/data/local/tmp/test_data_33_3.txt";
LogType type = LOG_INIT;
int i = 0;
while (i++ <= 5) {
usleep(1000);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string cmd = gHilogtoolExecutable + " -t init -x ";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != "") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_type_init error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name The log tool can read Hilogtool_type_multiple log types at a time.
* @tc.number DFX_DFT_HilogCPP_0890
* @tc.desc The log tool can read Hilogtool_type_multiple log types at a time.
*/
HWTEST_F(hilogtest, Hilogtool_type_multiple, Function|MediumTest|Level2)
{
CleanCmd();
std::string saveFile= "/data/local/tmp/test_data_33_4.txt";
LogType type = LOG_INIT;
int i = 0;
while (i++ <= 3) {
usleep(1000);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
type = LOG_INIT;
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
type = LOG_APP;
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string cmd = gHilogtoolExecutable + "-D 0xd003200 -t app core init -x ";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != "") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_type_multiple error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name show local time
* @tc.number DFX_DFT_HilogCPP_0950
* @tc.desc show local time
*/
HWTEST_F(hilogtest, Hilogtool_time, Function|MediumTest|Level3)
{
std::string cmd = gHilogtoolExecutable + " -a 1 -v time ";
std::string saveFile= "/data/local/tmp/test_data_35_1.txt";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::regex pattern(
"(0\\d{1}|1[0-2])-(0\\d{1}|[12]\\d{1}|3[01])\\s(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}:([0-5]\\d{1})(\\.(\\d){0,3})?$");
std::cout << hilogInfo.substr(0, 18);
string timeBuffer = hilogInfo.substr(0, 18);
std::smatch match;
bool ismatch = regex_match(timeBuffer, match, pattern);
if (ismatch) {
std::cout<<"match successed"<<std::endl;
result = true;
} else {
std::cout<<"match failed"<<std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name show the time from 1970
* @tc.number DFX_DFT_HilogCPP_0960
* @tc.desc show the time from 1970
*/
HWTEST_F(hilogtest, Hilogtool_epoch, Function|MediumTest|Level4)
{
std::string cmd = gHilogtoolExecutable + " -a 1 -v epoch ";
std::string saveFile= "/data/local/tmp/test_data_35_2.txt";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::regex pattern("[^0-9]");
std::cout << hilogInfo.substr(0, 19);
string timeBuffer = hilogInfo.substr(0, 19);
std::smatch match;
bool ismatch = regex_search(timeBuffer, match, pattern);
if (ismatch) {
std::cout << "match successed" << std::endl;
result = true;
} else {
std::cout <<"match failed"<< std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name show the time from last restart
* @tc.number DFX_DFT_HilogCPP_0970
* @tc.desc show the time from last restart
*/
HWTEST_F(hilogtest, Hilogtool_monotonic, Function|MediumTest|Level3)
{
std::string cmd = gHilogtoolExecutable + " -a 1 -v monotonic";
std::string saveFile= "/data/local/tmp/test_data_35_3.txt";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::regex pattern("[^0-9]");
std::cout << hilogInfo.substr(0, 14);
string timeBuffer = hilogInfo.substr(0, 14);
std::smatch match;
bool ismatch = regex_search(timeBuffer, match, pattern);
if (ismatch) {
std::cout << "match successed" << std::endl;
result = true;
} else {
std::cout << "match failed" << std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Displays time in microsecond accuracy
* @tc.number DFX_DFT_HilogCPP_0980
* @tc.desc Displays time in microsecond accuracy
*/
HWTEST_F(hilogtest, Hilogtool_usec, Function|MediumTest|Level4)
{
std::string cmd = gHilogtoolExecutable + " -a 1 -v usec";
std::string saveFile= "/data/local/tmp/test_data_35_4.txt";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::regex pattern(
"(0\\d{1}|1[0-2])-(0\\d{1}|[12]\\d{1}|3[01])\\s(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}:([0-5]\\d{1})(\\.(\\d){0,6})?$");
std::cout << hilogInfo.substr(0, 21);
string timeBuffer = hilogInfo.substr(0, 21);
std::smatch match;
bool ismatch = regex_match(timeBuffer, match, pattern);
if (ismatch) {
std::cout << "match successed" << std::endl;
result = true;
} else {
std::cout << "match failed" << std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Displays time in nanosecond precision.
* @tc.number DFX_DFT_HilogCPP_0990
* @tc.desc Displays time in nanosecond precision.
*/
HWTEST_F(hilogtest, Hilogtool_nsec, Function|MediumTest|Level4)
{
std::string cmd = gHilogtoolExecutable + " -a 1 -v nsec";
std::string saveFile= "/data/local/tmp/test_data_35_5.txt";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::regex pattern(
"(0\\d{1}|1[0-2])-(0\\d{1}|[12]\\d{1}|3[01])\\s(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}:([0-5]\\d{1})(\\.(\\d){0,9})?$");
std::cout << hilogInfo.substr(0, 24);
string timeBuffer = hilogInfo.substr(0, 24);
std::smatch match;
bool ismatch = regex_match(timeBuffer, match, pattern);
if (ismatch) {
std::cout << "match successed"<< std::endl;
result = true;
} else {
std::cout << "match failed"<< std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name added year to the displayed time.
* @tc.number DFX_DFT_HilogCPP_1000
* @tc.desc added year to the displayed time.
*/
HWTEST_F(hilogtest, Hilogtool_year, Function|MediumTest|Level4)
{
std::string cmd = gHilogtoolExecutable + " -a 1 -v year";
char saveFile356[] = "/data/local/tmp/test_data_35_6.txt";
SaveCmdOutput(cmd, saveFile356);
string hilogInfo = ReadFile(saveFile356);
bool result = false;
std::regex pattern(
"(\\d{4})-(0\\d{1}|1[0-2])-(0\\d{1}|[12]\\d{1}|3[01])\\s(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}:([0-5]\\d{1})(\\.(\\d){0,3})?$");
std::cout << hilogInfo.substr(0, 23);
string timeBuffer = hilogInfo.substr(0, 23);
std::smatch match;
bool ismatch = regex_match(timeBuffer, match, pattern);
if (ismatch) {
std::cout << "match successed"<< std::endl;
result = true;
} else {
std::cout << "match failed"<< std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name show the local time zone
* @tc.number DFX_DFT_HilogCPP_1010
* @tc.desc show the local time zone
*/
HWTEST_F(hilogtest, Hilogtool_zone, Function|MediumTest|Level4)
{
std::string cmd = gHilogtoolExecutable + " -a 1 -v zone";
std::string saveFile= "/data/local/tmp/test_data_35_7.txt";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::regex pattern(
"(.*)(0\\d{1}|1[0-2])-(0\\d{1}|[12]\\d{1}|3[01])\\s(0\\d{1}|1\\d{1}|2[0-3]):[0-5]\\d{1}:([0-5]\\d{1})");
std::cout << hilogInfo.substr(0, 20);
string timeBuffer = hilogInfo.substr(0, 20);
std::smatch match;
bool ismatch = regex_match(timeBuffer, match, pattern);
if (ismatch) {
std::cout << "match successed"<< std::endl;
result = true;
} else {
std::cout << "match failed"<< std::endl;
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Filtering by regular expression, The expression is empty.
* @tc.number DFX_DFT_HilogCPP_1870
* @tc.desc Filtering by regular expression, The expression is empty.
*/
HWTEST_F(hilogtest, Hilogtool_regex_null, Function|MediumTest|Level3)
{
CleanCmd();
std::string cmd = gHilogtoolExecutable + " -x -e \"\"";
// " -type app core init -x "
std::string saveFile= "/data/local/tmp/test_data_46_1.txt";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != " ") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_regex_null error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Filtering by regular expression
* @tc.number DFX_DFT_HilogCPP_1880
* @tc.desc Filtering by regular expression
*/
HWTEST_F(hilogtest, Hilogtool_regex, Function|MediumTest|Level3)
{
CleanCmd();
std::string cmd1 = gHilogtoolExecutable + " -x -e \"^(123)\"";
char saveFile462[] = "/data/local/tmp/test_data_46_2.txt";
SaveCmdOutput(cmd1, saveFile462);
string hilogInfo = ReadFile(saveFile462);
bool result = false;
std::vector<std::string> para = {"03200/HILOGTOOLTEST"};
if (hilogInfo != "") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_regex error";
}
ASSERT_TRUE(true == result);
CleanCmd();
std::string cmd2 = gHilogtoolExecutable + " -x -e \"^(www)\"";
char saveFile463[] = "test_data_46_3.txt";
SaveCmdOutput(cmd2, saveFile463);
hilogInfo = ReadFile(saveFile463);
if (hilogInfo != " ") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_regex error";
}
ASSERT_TRUE(false == result);
}
/*
* @tc.name show the first 1 row
* @tc.number DFX_DFT_HilogCPP_1890
* @tc.desc show the first 1 row
*/
HWTEST_F(hilogtest, Hilogtool_head_1, Function|MediumTest|Level3)
{
CleanCmd();
LogType type = LOG_INIT;
int cnt =20;
int i = 0;
while (i++ <= cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string cmd = gHilogtoolExecutable + " -a 1 -x ";
std::string saveFile = "/data/local/tmp/test_data_47_1.txt";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != " ") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_n error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name show first 20 rows
* @tc.number DFX_DFT_HilogCPP_1900
* @tc.desc show first 20 rows
*/
HWTEST_F(hilogtest, Hilogtool_head_20, Function|MediumTest|Level4)
{
CleanCmd();
LogType type = LOG_INIT;
int cnt =20;
int i = 0;
while (i++ <= cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string saveFile= "/data/local/tmp/test_data_47_2.txt";
std::string cmd = gHilogtoolExecutable + " -a 20 -x ";
SaveCmdOutput(cmd, saveFile);
int n = GetTxtLine(saveFile);
ASSERT_TRUE(n == 20);
}
/*
* @tc.name show the last 1 row
* @tc.number DFX_DFT_HilogCPP_1910
* @tc.desc show the last 1 row
*/
HWTEST_F(hilogtest, Hilogtool_tail_1, Function|MediumTest|Level4)
{
CleanCmd();
LogType type = LOG_INIT;
int cnt =20;
int i = 0;
while (i++ <= cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string saveFile= "/data/local/tmp/test_data_47_3.txt";
std::string cmd = gHilogtoolExecutable + "-t init -z 1";
SaveCmdOutput(cmd, saveFile);
sleep(2);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != " ") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_n error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name show last 20 rows
* @tc.number DFX_DFT_HilogCPP_1920
* @tc.desc show last 20 rows
*/
HWTEST_F(hilogtest, Hilogtool_tail_20, Function|MediumTest|Level4)
{
CleanCmd();
LogType type = LOG_INIT;
int cnt =20;
int i = 0;
while (i++ <= cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string saveFile= "/data/local/tmp/test_data_47_4.txt";
std::string cmd = gHilogtoolExecutable + "-t init -z 20";
SaveCmdOutput(cmd, saveFile);
int n = GetTxtLine(saveFile);
ASSERT_TRUE(n == 20);
}
/*
* @tc.name The filtering parameter is empty.
* @tc.number DFX_DFT_HilogCPP_1930
* @tc.desc The filtering parameter is empty.
*/
HWTEST_F(hilogtest, Hilogtool_filter_null, Function|MediumTest|Level4)
{
CleanCmd();
LogType type = LOG_INIT;
int cnt =20;
int i = 0;
while (i++ <= cnt) {
usleep(1000);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string saveFile= "/data/local/tmp/test_data_48_1.txt";
std::string cmd = gHilogtoolExecutable + " -t init -x";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != "") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_filter error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Filter level only.
* @tc.number DFX_DFT_HilogCPP_1960
* @tc.desc Filter level only.
*/
HWTEST_F(hilogtest, Hilogtool_filter_level, Function|MediumTest|Level4)
{
CleanCmd();
LogType type = LOG_INIT;
int cnt =20;
int i = 0;
while (i++ <= cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string saveFile= "/data/local/tmp/test_data_48_4.txt";
std::string cmd = gHilogtoolExecutable + " -t init -L D -x";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != "") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_filter error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Filter domain only.
* @tc.number DFX_DFT_HilogCPP_1970
* @tc.desc Filter domain only.
*/
HWTEST_F(hilogtest, Hilogtool_filter_domain, Function|MediumTest|Level3)
{
CleanCmd();
LogType type = LOG_INIT;
int cnt =20;
int i = 0;
while (i++ <= cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string saveFile= "/data/local/tmp/test_data_48_3.txt";
std::string cmd = gHilogtoolExecutable + " -t init -D 0xd003200 -x";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != "") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_filter error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Filter tag only.
* @tc.number DFX_DFT_HilogCPP_1980
* @tc.desc Filter tag only.
*/
HWTEST_F(hilogtest, Hilogtool_filter_tag, Function|MediumTest|Level4)
{
CleanCmd();
LogType type = LOG_INIT;
int cnt = 20;
int i = 0;
while (i++ <= cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string saveFile= "/data/local/tmp/test_data_48_5.txt";
std::string cmd = gHilogtoolExecutable + " -T HILOGTOOLTEST -x";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != " ") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_filter error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Filter Multi-parameter
* @tc.number DFX_DFT_HilogCPP_1990
* @tc.desc Filter Multi-parameter
*/
HWTEST_F(hilogtest, Hilogtool_filter_multiple, Function|MediumTest|Level2)
{
CleanCmd();
LogType type = LOG_INIT;
int i = 0;
int cnt = 20;
while (i++ <= cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string saveFile= "/data/local/tmp/test_data_48_6.txt";
std::string cmd = gHilogtoolExecutable + \
" -T HILOGTOOLTEST -L D -x";
SaveCmdOutput(cmd, saveFile);
string hilogInfo = ReadFile(saveFile);
bool result = false;
std::vector<std::string> para = {g_commonContent};
if (hilogInfo != " ") {
result = CheckInfo(para, hilogInfo);
} else {
std::cout << "Hilogtool_filter error";
}
ASSERT_TRUE(true == result);
}
/*
* @tc.name Logs are not duplicated and are not lost.
* @tc.number DFX_DFT_HilogCPP_2080
* @tc.desc Logs are not duplicated and are not lost.
*/
HWTEST_F(hilogtest, Hilogtool_count, Function|MediumTest|Level2)
{
CleanCmd();
std::string saveFile= "/data/local/tmp/test_data_30.txt";
std::string cmd1 = gHilogtoolExecutable + " -r";
std::string cmdResult;
CmdRun(cmd1, cmdResult);
LogType type = LOG_APP;
int i = 0;
int cnt = 1000;
while (i++ < cnt) {
usleep(1);
HILOG_DEBUG(type, g_logContent.c_str(), i, 1.00001, 2.333333, "sse", 'a');
}
std::string cmd2 = gHilogtoolExecutable + "-t app -T HILOGTOOLTEST -x";
SaveCmdOutput(cmd2, saveFile);
ASSERT_TRUE(cnt == GetTxtLine(saveFile));
ifstream in(saveFile);
std::string filename;
std::string line;
std::vector<string> mVec;
if (in) {
while (getline(in, line)) {
mVec.push_back(line);
}
} else {
std::cout << "no such file" << std::endl;
}
sort(mVec.begin(), mVec.end());
vector<string>::iterator endUnique = unique(mVec.begin(), mVec.end());
vector<string> vec;
while (endUnique != mVec.end()) {
vec.push_back(*endUnique++);
}
ASSERT_TRUE(0 == vec.size());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1020
* @tc.desc Querying the buffer size of default log types (Ccore and app)
*/
HWTEST_F(hilogtest, buff_size_default, Function|MediumTest|Level2)
{
result = ExecuteCmd("hilog -g");
expect = "core buffer size is 1M\napp buffer size is 1M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1030
* @tc.desc Queries the buffer size of a specified type (core).
*/
HWTEST_F(hilogtest, buff_size_core, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -g -t core");
expect = "core buffer size is 1M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1040
* @tc.desc Queries the buffer size of a specified type (app).
*/
HWTEST_F(hilogtest, buff_size_app, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -g -t app");
expect = "app buffer size is 1M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1050
* @tc.desc Queries the buffer size of a specified type (init).
*/
HWTEST_F(hilogtest, buff_size_init, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -g -t init");
expect = "init buffer size is 1M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1060
* @tc.desc Queries the buffer size of multiple types
*/
HWTEST_F(hilogtest, buff_size_multiple, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -g -t 'core app'");
expect = "core buffer size is 1M\napp buffer size is 1M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1070
* @tc.desc Queries the buffer size of all types
*/
HWTEST_F(hilogtest, buff_size_all, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -g -t all");
expect = "core buffer size is 1M\napp buffer size is 1M\ninit buffer size is 1M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1080
* @tc.desc Queries the buffer size of a nonexistent type
*/
HWTEST_F(hilogtest, buff_size_illegal, Function|MediumTest|Level4)
{
bool ret = true;
result = ExecuteCmd("hilog -g -t abc");
ret = result.find("Invalid log type") != std::string::npos;
EXPECT_EQ(ret, true);
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1090
* @tc.desc Queries the buffer size of multiple types, including nonexistent types.
*/
HWTEST_F(hilogtest, buff_size_illegal2, Function|MediumTest|Level4)
{
bool ret = true;
result = ExecuteCmd("hilog -g -t 'core abc'");
ret = result.find("Invalid log type") != std::string::npos;
EXPECT_EQ(ret, true);
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1100
* @tc.desc Set the buffer size without unit. (The default log type is core and app.)
*/
HWTEST_F(hilogtest, buff_resize_byte, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 200");
expect = "core buffer size is 200B\napp buffer size is 200B\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1110
* @tc.desc Set the buffer size to **b.
*/
HWTEST_F(hilogtest, buff_resize_byte2, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 200b");
expect = "core buffer size is 200B\napp buffer size is 200B\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1120
* @tc.desc Set the buffer size to **B
*/
HWTEST_F(hilogtest, buff_resize_byte3, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 200B");
expect = "core buffer size is 200B\napp buffer size is 200B\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1130
* @tc.desc Set the buffer size to **k
*/
HWTEST_F(hilogtest, buff_resize_kbyte, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 2k");
expect = "core buffer size is 2K\napp buffer size is 2K\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1140
* @tc.desc Set the buffer size to **K
*/
HWTEST_F(hilogtest, buff_resize_kbyte2, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 2K");
expect = "core buffer size is 2K\napp buffer size is 2K\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1150
* @tc.desc Set the buffer size to **m
*/
HWTEST_F(hilogtest, buff_resize_mbyte, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 2m");
expect = "core buffer size is 2M\napp buffer size is 2M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1160
* @tc.desc Set the buffer size to **M
*/
HWTEST_F(hilogtest, buff_resize_mbyte2, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 2M");
expect = "core buffer size is 2M\napp buffer size is 2M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1170
* @tc.desc Set the buffer size to **g
*/
HWTEST_F(hilogtest, buff_resize_gbyte, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 1g");
expect = "core buffer size is 1G\napp buffer size is 1G\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1180
* @tc.desc Set the buffer size to **G
*/
HWTEST_F(hilogtest, buff_resize_gbyte2, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 1G");
expect = "core buffer size is 1G\napp buffer size is 1G\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1190
* @tc.desc Set the buffer size to 0
*/
HWTEST_F(hilogtest, buff_resize_illegal, Function|MediumTest|Level4)
{
bool ret = true;
result = ExecuteCmd("hilog -G 0");
ret = result.find("Invalid buffer size") != std::string::npos;
EXPECT_EQ(ret, true);
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1200
* @tc.desc Set the buffer size to exceed the maximum length
*/
HWTEST_F(hilogtest, buff_resize_illegal2, Function|MediumTest|Level3)
{
bool ret = true;
result = ExecuteCmd("hilog -G 2g");
ret = result.find("Invalid buffer size") != std::string::npos;
EXPECT_EQ(ret, true);
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1210
* @tc.desc Set the buffer size according to a single log type (core)
*/
HWTEST_F(hilogtest, buff_resize_core, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 2m -t core");
expect = "core buffer size is 2M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1220
* @tc.desc Set the buffer size according to a single log type (app)
*/
HWTEST_F(hilogtest, buff_resize_app, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 2m -t app");
expect = "app buffer size is 2M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1230
* @tc.desc Set the buffer size according to a single log type (init)
*/
HWTEST_F(hilogtest, buff_resize_init, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -G 2m -t init");
expect = "init buffer size is 2M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1240
* @tc.desc Set the buffer size according to multiple log types
*/
HWTEST_F(hilogtest, buff_resize_multyple, Function|MediumTest|Level2)
{
result = ExecuteCmd("hilog -G 2m -t 'core app'");
expect = "core buffer size is 2M\napp buffer size is 2M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1250
* @tc.desc Set the buffer size of all log types
*/
HWTEST_F(hilogtest, buff_resize_all, Function|MediumTest|Level4)
{
result = ExecuteCmd("hilog -G 1m -t all");
expect = "core buffer size is 1M\napp buffer size is 1M\ninit buffer size is 1M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1260
* @tc.desc Set the non-existent log type buffer size
*/
HWTEST_F(hilogtest, buff_resize_illegal_type, Function|MediumTest|Level4)
{
bool ret = true;
result = ExecuteCmd("hilog -G 2m -t abc");
ret = result.find("Invalid log type") != std::string::npos;
EXPECT_EQ(ret, true);
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1270
* @tc.desc Set multiple log types, including non-existent log types
*/
HWTEST_F(hilogtest, buff_resize_illegal_type2, Function|MediumTest|Level4)
{
bool ret = true;
result = ExecuteCmd("hilog -G 2m -t 'core abc'");
ret = result.find("Invalid log type") != std::string::npos;
EXPECT_EQ(ret, true);
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1280
* @tc.desc Re-query the buffer size after the setting operation
*/
HWTEST_F(hilogtest, buff_resize_check, Function|MediumTest|Level3)
{
// re query after set
result = ExecuteCmd("hilog -g -t all");
expect = "core buffer size is 1M\napp buffer size is 1M\ninit buffer size is 1M\n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1290
* @tc.desc The size of the core buffer is set to 200 bytes, and the size of logs exceeds 200 bytes.
*/
HWTEST_F(hilogtest, buff_resize_check_core, Function|MediumTest|Level3)
{
int i = 1;
ExeCmd("hilog -G 200 -t core");
ExeCmd("hilog -r -t all");
i = 1;
while (i <= 10) {
HILOG_FATAL(LOG_CORE, "123456789_1234567890_public and private log test is: \
%{public}d, %{public}lf, %{public}.2f, %{public}s, %{public}c", i, 1.00001, 2.333333, "sse", 'a');
i++;
}
result = ExecuteCmd("hilog -x -t core |wc -l");
expect = "10";
EXPECT_LT(stoi(result), stoi(expect));
// end recover default
ExeCmd("hilog -r -t all");
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1300
* @tc.desc The size of the app buffer is set to 200 bytes, and the size of logs exceeds 200 bytes.
*/
HWTEST_F(hilogtest, buff_resize_check_app, Function|MediumTest|Level4)
{
int i = 1;
ExeCmd("hilog -G 200 -t app");
ExeCmd("hilog -r -t all");
i = 1;
while (i <= 10) {
HILOG_FATAL(LOG_APP, "123456789_1234567890_public and private log test is: \
%{public}d, %{public}lf, %{public}.2f, %{public}s, %{public}c", i, 1.00001, 2.333333, "sse", 'a');
i++;
}
result = ExecuteCmd("hilog -x -t app |wc -l");
expect = "10";
EXPECT_LT(stoi(result), stoi(expect));
// end recover default
ExeCmd("hilog -r -t all");
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name buffer size test
* @tc.number DFX_DFT_HilogCPP_1310
* @tc.desc The size of the init buffer is set to 200 bytes, and the size of logs exceeds 200 bytes.
*/
HWTEST_F(hilogtest, buff_resize_check_init, Function|MediumTest|Level4)
{
int i = 1;
ExeCmd("hilog -G 200 -t init");
ExeCmd("hilog -r -t all");
i = 1;
while (i <= 10) {
HILOG_FATAL(LOG_INIT, "123456789_1234567890_public and private log test is: \
%{public}d, %{public}lf, %{public}.2f, %{public}s, %{public}c", i, 1.00001, 2.333333, "sse", 'a');
i++;
}
result = ExecuteCmd("hilog -x -t init |wc -l");
expect = "10";
EXPECT_LT(stoi(result), stoi(expect));
// end recover default
ExeCmd("hilog -r -t all");
ExeCmd("hilog -G 1m -t all");
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1320
* @tc.desc Query the statistics of the core log
*/
HWTEST_F(hilogtest, statistic_info_query_core, Function|MediumTest|Level2)
{
bool ret = true;
int i = 1;
ExeCmd("hilog -r -t all");
ExeCmd("hilog -S -t core");
// write and read
i = 1;
while (i <= 1000) {
HILOG_FATAL(LOG_CORE, "123456789_1234567890_public and private log test is: \
%{public}d, %{public}lf, %{public}.2f, %{public}s, %{public}c", i, 1.00001, 2.333333, "sse", 'a');
i++;
}
ExeCmd("hilog -x -t core >/dev/null 2>&1");
result = ExecuteCmd("hilog -s -t core");
std::regex reg("core print log length is [1-9]\\w+\ncore cache log length is [1-9]\\w+\n\
core dropped log lines is \\w+\n");
ret = std::regex_match(result, reg);
EXPECT_EQ(ret, true);
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1330
* @tc.desc Query the statistics of the app log
*/
HWTEST_F(hilogtest, statistic_info_query_app, Function|MediumTest|Level3)
{
bool ret = true;
int i = 1;
ExeCmd("hilog -r -t all");
ExeCmd("hilog -S -t app");
// write and read
i = 1;
while (i <= 1000) {
HILOG_FATAL(LOG_APP, "123456789_1234567890_public and private log test is: \
%{public}d, %{public}lf, %{public}.2f, %{public}s, %{public}c", i, 1.00001, 2.333333, "sse", 'a');
i++;
}
ExeCmd("hilog -x -t app >/dev/null 2>&1");
result = ExecuteCmd("hilog -s -t app");
std::regex reg("app print log length is [1-9]\\w+\napp cache log length is [1-9]\\w+\n\
app dropped log lines is \\w+\n");
ret = std::regex_match(result, reg);
EXPECT_EQ(ret, true);
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1340
* @tc.desc Query the statistics of the init log
*/
HWTEST_F(hilogtest, statistic_info_query_init, Function|MediumTest|Level3)
{
bool ret = true;
int i = 1;
ExeCmd("hilog -r -t all");
ExeCmd("hilog -S -t init");
// write and read
i = 1;
while (i <= 1000) {
HILOG_FATAL(LOG_INIT, "123456789_1234567890_public and private log test is: \
%{public}d, %{public}lf, %{public}.2f, %{public}s, %{public}c", i, 1.00001, 2.333333, "sse", 'a');
i++;
}
ExeCmd("hilog -x -t init >/dev/null 2>&1");
result = ExecuteCmd("hilog -s -t init");
std::regex reg("init print log length is [1-9]\\w+\ninit cache log length is [1-9]\\w+\n\
init dropped log lines is \\w+\n");
ret = std::regex_match(result, reg);
EXPECT_EQ(ret, true);
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1350
* @tc.desc Clear the statistics of the core log
*/
HWTEST_F(hilogtest, statistic_info_clear_core, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -S -t core");
expect = "core statistic info clear success \n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1360
* @tc.desc Clear the statistics of the app log
*/
HWTEST_F(hilogtest, statistic_info_clear_app, Function|MediumTest|Level4)
{
result = ExecuteCmd("hilog -S -t app");
expect = "app statistic info clear success \n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1370
* @tc.desc Clear the statistics of the init log
*/
HWTEST_F(hilogtest, statistic_info_clear_init, Function|MediumTest|Level4)
{
result = ExecuteCmd("hilog -S -t init");
expect = "init statistic info clear success \n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1380
* @tc.desc Query statistics of non-existent log
*/
HWTEST_F(hilogtest, statistic_info_query_illegal, Function|MediumTest|Level3)
{
bool ret = true;
result = ExecuteCmd("hilog -s -t abc");
ret = result.find("Invalid log type") != std::string::npos;
EXPECT_EQ(ret, true);
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1390
* @tc.desc Clear statistics of non-existent log
*/
HWTEST_F(hilogtest, statistic_info_clear_illegal, Function|MediumTest|Level4)
{
bool ret = true;
result = ExecuteCmd("hilog -S -t abc");
ret = result.find("Invalid log type") != std::string::npos;
EXPECT_EQ(ret, true);
}
/*
* @tc.name Querying and clearing statistics by log
* @tc.number DFX_DFT_HilogCPP_1400
* @tc.desc Re-query after clearing
*/
HWTEST_F(hilogtest, statistic_info_check, Function|MediumTest|Level3)
{
bool ret = true;
// re query after clear
ExeCmd("hilog -S -t core");
result = ExecuteCmd("hilog -s -t core");
std::regex reg("core print log length is \\w+\ncore cache log length is \\w+\n\
core dropped log lines is \\w+\n");
ret = std::regex_match(result, reg);
EXPECT_EQ(ret, true);
}
/*
* @tc.name Querying and clearing statistics by domain
* @tc.number DFX_DFT_HilogCPP_1410
* @tc.desc Query the statistics of the specified domain
*/
HWTEST_F(hilogtest, statistic_info_query_domain, Function|MediumTest|Level2)
{
bool ret = true;
int i = 1;
ExeCmd("hilog -r -t all");
ExeCmd("hilog -S -D 218116608");
// write and read
i = 1;
while (i <= 1000) {
HILOG_FATAL(LOG_CORE, "123456789_1234567890_public and private log test is: \
%{public}d, %{public}lf, %{public}.2f, %{public}s, %{public}c", i, 1.00001, 2.333333, "sse", 'a');
i++;
}
ExeCmd("hilog -x -t core >/dev/null 2>&1");
result = ExecuteCmd("hilog -s -D 218116608");
std::regex reg("218116608 print log length is [1-9]\\w+\n218116608 cache log length is [1-9]\\w+\n\
218116608 dropped log lines is \\w+\n");
ret = std::regex_match(result, reg);
EXPECT_EQ(ret, true);
}
/*
* @tc.name Querying and clearing statistics by domain
* @tc.number DFX_DFT_HilogCPP_1420
* @tc.desc Clear the statistics of the specified domain
*/
HWTEST_F(hilogtest, statistic_info_clear_domain, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -S -D 218116608");
expect = "218116608 statistic info clear success \n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Querying and clearing statistics by domain
* @tc.number DFX_DFT_HilogCPP_1430
* @tc.desc Query the statistics of nonexistent domain
*/
HWTEST_F(hilogtest, statistic_info_query_domain2, Function|MediumTest|Level3)
{
bool ret = true;
int i = 1;
ExeCmd("hilog -r -t all");
ExeCmd("hilog -S -D 218116608");
// write and read
i = 1;
while (i <= 1000) {
HILOG_FATAL(LOG_CORE, "123456789_1234567890_public and private log test is: \
%{public}d, %{public}lf, %{public}.2f, %{public}s, %{public}c", i, 1.00001, 2.333333, "sse", 'a');
i++;
}
ExeCmd("hilog -x -t core >/dev/null 2>&1");
result = ExecuteCmd("hilog -s -D 1");
std::regex reg("1 print log length is \\w+\n1 cache log length is \\w+\n1 dropped log lines is \\w+\n");
ret = std::regex_match(result, reg);
EXPECT_EQ(ret, true);
}
/*
* @tc.name Querying and clearing statistics by domain
* @tc.number DFX_DFT_HilogCPP_1440
* @tc.desc Clear the statistics of nonexistent domain
*/
HWTEST_F(hilogtest, statistic_info_clear_domain2, Function|MediumTest|Level4)
{
result = ExecuteCmd("hilog -S -D 1");
expect = "1 statistic info clear success \n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Clearing the logs of the corresponding buffer by log type
* @tc.number DFX_DFT_HilogCPP_1630
* @tc.desc Clear the default logs (core、app)
*/
HWTEST_F(hilogtest, log_clear_default, Function|MediumTest|Level2)
{
result = ExecuteCmd("hilog -r");
expect = "core log clear success \napp log clear success \n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Clearing the logs of the corresponding buffer by log type
* @tc.number DFX_DFT_HilogCPP_1640
* @tc.desc Clear the core log
*/
HWTEST_F(hilogtest, log_clear_core, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -r -t core");
expect = "core log clear success \n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Clearing the logs of the corresponding buffer by log type
* @tc.number DFX_DFT_HilogCPP_1650
* @tc.desc Clear the app log
*/
HWTEST_F(hilogtest, log_clear_app, Function|MediumTest|Level4)
{
result = ExecuteCmd("hilog -r -t app");
expect = "app log clear success \n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Clearing the logs of the corresponding buffer by log type
* @tc.number DFX_DFT_HilogCPP_1660
* @tc.desc Clear the init log
*/
HWTEST_F(hilogtest, log_clear_inti, Function|MediumTest|Level4)
{
result = ExecuteCmd("hilog -r -t init");
expect = "init log clear success \n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Clearing the logs of the corresponding buffer by log type
* @tc.number DFX_DFT_HilogCPP_1670
* @tc.desc Clear multiple types of logs
*/
HWTEST_F(hilogtest, log_clear_multiple, Function|MediumTest|Level3)
{
result = ExecuteCmd("hilog -r -t 'core app'");
expect = "core log clear success \napp log clear success \n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Clearing the logs of the corresponding buffer by log type
* @tc.number DFX_DFT_HilogCPP_1680
* @tc.desc Clear all types of logs.
*/
HWTEST_F(hilogtest, log_clear_all, Function|MediumTest|Level4)
{
result = ExecuteCmd("hilog -r -t all");
expect = "core log clear success \napp log clear success \ninit log clear success \n\n";
EXPECT_STREQ(result.c_str(), expect.c_str());
}
/*
* @tc.name Clearing the logs of the corresponding buffer by log type
* @tc.number DFX_DFT_HilogCPP_1690
* @tc.desc Clear nonexistent types of logs
*/
HWTEST_F(hilogtest, log_clear_illegal, Function|MediumTest|Level4)
{
bool ret = true;
result = ExecuteCmd("hilog -r -t abc");
ret = result.find("Invalid log type") != std::string::npos;
EXPECT_EQ(ret, true);
}
/*
* @tc.name Clearing the logs of the corresponding buffer by log type
* @tc.number DFX_DFT_HilogCPP_1700
* @tc.desc Clear multiple types of logs including nonexistent types
*/
HWTEST_F(hilogtest, log_clear_illegal2, Function|MediumTest|Level4)
{
bool ret = true;
result = ExecuteCmd("hilog -r -t 'abc core'");
ret = result.find("Invalid log type") != std::string::npos;
EXPECT_EQ(ret, true);
}
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hits/LibhilogCPPtest"
###############################################################################
config("hilogtest_config") {
visibility = [ ":*" ]
include_dirs = [
"../../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
]
}
ohos_moduletest_suite("ActsLibhilogCPPTest") {
module_out_path = module_output_path
sources = [ "LibhilogCPPtest.cpp" ]
deps = [
"../../../utils/native:utilskit",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
#external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
configs = [ ":hilogtest_config" ]
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdarg>
#include <ctime>
#include <ostream>
#include <streambuf>
#include <queue>
#include <securec.h>
#include <pthread.h>
#include <sys/time.h>
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#include <gtest/gtest.h>
#include "file_utils.h"
using namespace OHOS;
using namespace HiviewDFX;
using namespace testing::ext;
#define MAX_LINE ((1024) * (10))
#define MAXBUFFSIZE 1024
class LibhilogCPPtest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
private:
};
void LibhilogCPPtest::SetUp()
{
CleanCmd();
}
void LibhilogCPPtest::TearDown()
{
}
void LibhilogCPPtest::SetUpTestCase()
{
}
void LibhilogCPPtest::TearDownTestCase()
{
std::cout << "TearDownTestCase" << std::endl;
}
/**
* @tc.name Provides user-mode interfaces(CPP)INFO
* @tc.number DFX_DFT_HilogCPP_0100
* @tc.desc Provides user-mode interfaces(CPP)INFO
*/
HWTEST_F(LibhilogCPPtest, HILOG_INFO_CPP, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
int i = 1;
HiLog::Info(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,"
"%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"I 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name Provides user-mode interfaces(CPP)debug
* @tc.number DFX_DFT_HilogCPP_0090
* @tc.desc Provides user-mode interfaces(CPP)debug
*/
HWTEST_F(LibhilogCPPtest, HILOG_DEBUG_CPP, Function|MediumTest|Level0)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
int i = 1;
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Debug(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,"
"%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"D 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
sleep(1);
CmdRun("hilog -L D -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name Provides user-mode interfaces(CPP)warning
* @tc.number DFX_DFT_HilogCPP_0130
* @tc.desc Provides user-mode interfaces(CPP)warning
*/
HWTEST_F(LibhilogCPPtest, HILOG_WARNING_CPP, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
int i = 1;
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Warn(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,%{private}lf,"
"%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"W 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name Provides user-mode interfaces(CPP)error
* @tc.number DFX_DFT_HilogCPP_0110
* @tc.desc Provides user-mode interfaces(CPP)error
*/
HWTEST_F(LibhilogCPPtest, HILOG_ERROR_CPP, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
int i = 1;
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Error(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,"
"%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"E 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name Provides user-mode interfaces(CPP)fatal
* @tc.number DFX_DFT_HilogCPP_0120
* @tc.desc Provides user-mode interfaces(CPP)fatal
*/
HWTEST_F(LibhilogCPPtest, HILOG_FATAL_CPP, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
int i = 1;
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "123456789_1234567890_publicandprivatelogHWTEST_Fis:%{public}d,"
"%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"F 03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST: \
123456789_1234567890_publicandprivatelogHWTEST_Fis:1,<private>,2.33,<private>,<private>"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.desc libhilog-log integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2090
* @tc.desc libhilog-log integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "INTEGER:%{private}d,%{public}d,%d;", 1, 1, 1);
std::string expected{"INTEGER:<private>,1,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log long integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2100
* @tc.desc libhilog-log long integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_LONG_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "INTEGER_long:%{private}ld,%{public}ld,%ld;", 2147483647L, 2147483647L, 2147483647L);
std::string expected{"INTEGER_long:<private>,2147483647,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log fixed-length integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2110
* @tc.desc libhilog-log fixed-length integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_4_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "INTEGER_4:%{private}4d,%{public}4d,%4d;", 2000, 2000, 2000);
std::string expected{"INTEGER_4:<private>,2000,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log short integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2120
* @tc.desc libhilog-log short integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_SHORT_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "INTEGER_short:%{private}hd,%{public}hd,%hd;", (short)1024, (short)1024, (short)1024);
std::string expected{"INTEGER_short:<private>,1024,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log unsigned integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2130
* @tc.desc libhilog-log unsigned integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_UN_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "INTEGER_un:%{private}u,%{public}u,%u;", 2147483647u, 2147483647u, 2147483647u);
std::string expected{"INTEGER_un:<private>,2147483647,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2140
* @tc.desc libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_LONG_UN_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "INTEGER_long_un:%{private}lu,%{public}lu,%lu;", 7483647ul, 2147483647ul, 2147483647ul);
std::string expected{"INTEGER_long_un:<private>,2147483647,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2150
* @tc.desc libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_4_UN_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "INTEGER_4_un:%{private}4u,%{public}4u,%4u;", 4000, 4000, 4000);
std::string expected{"INTEGER_4_un:<private>,4000,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2160
* @tc.desc libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_INTEGER_SHORT_UN_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "INTEGER_short_un:%{private}hu,%{public}hu,%hu;", (unsigned short)65535,
(unsigned short)65535, (unsigned short)65535);
std::string expected{"INTEGER_short_un:<private>,65535,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log float type identifier format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2170
* @tc.desc libhilog-log float type identifier format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "FLOAT:%{private}f,%{public}f,%f;", 1.01, 1.01, 1.01);
std::string expected{"FLOAT:<private>,1.010000,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log long float type identifier format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2180
* @tc.desc libhilog-log long float type identifier format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_LONG_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "FLOAT_long:%{private}lf,%{public}lf,%lf;", 2.147483647, 2.147483647, 2.147483647);
std::string expected{"FLOAT_long:<private>,2.147484,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting of fixed-width floating-point identifiers in
* the decimal part of the log ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2190
* @tc.desc libhilog-Formatting of fixed-width floating-point identifiers in
* the decimal part of the log ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_POINT2_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "FLOAT_.2:%{private}.2f,%{public}.2f,%.2f;", 2.147483647, 2.147483647, 2.147483647);
std::string expected{"FLOAT_.2:<private>,2.15,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting of floating-point identifiers for
* the decimal part and integer part of the log ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2200
* @tc.desc libhilog-Formatting of floating-point identifiers for
* the decimal part and integer part of the log ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_FLOAT_3POINT2_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "FLOAT_3.2:%{private}3.2f,%{public}4.1f,%2.6f;", 32.147483647, 321.147483647, 23.147483647);
std::string expected{"FLOAT_3.2:<private>,321.1,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting log characters ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2210
* @tc.desc libhilog-Formatting log characters ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_CHAR_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "CHAR:%{private}c,%{public}c,%c;", 'a', 'b', 'c');
std::string expected{"CHAR:<private>,b,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting log octal identifier ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2250
* @tc.desc libhilog-Formatting log octal identifier ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_OCTAL_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "OCTAL:%{private}o,%{public}o,%o;", 15, 16, 17);
std::string expected{"OCTAL:<private>,20,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting log long octal identifier ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2260
* @tc.desc libhilog-Formatting log long octal identifier ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_OCTAL_LONG_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "OCTAL_long:%{private}lo,%{public}lo,%lo;", 18ul, 19ul, 20ul);
std::string expected{"OCTAL_long:<private>,23,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2270
* @tc.desc libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_HEX_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "HEX:%{private}x,%{public}x,%x;", 15, 16, 17);
std::string expected{"HEX:<private>,10,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2280
* @tc.desc libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_HEX_UPPER_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "HEX_#:%{private}#x,%{public}#x,%#x;", 18, 19, 20);
std::string expected{"HEX_#:<private>,0x13,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs are formatted with long hexadecimal identifiers
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2290
* @tc.desc libhilog-Logs are formatted with long hexadecimal identifiers
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_HEX_LONG_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "HEX_long:%{private}lx,%{public}lx,%lx;", 21l, 22l, 23l);
std::string expected{"HEX_long:<private>,16,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs are formatted with uppercase hexadecimal flags
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2300
* @tc.desc libhilog-Logs are formatted with uppercase hexadecimal flags
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_HEX_X_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "HEX_X:%{private}X,%{public}X,%X;", 24u, 25u, 26u);
std::string expected{"HEX_X:<private>,19,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2310
* @tc.desc libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_HEX_UPPER_X_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "HEX_#X:%{private}#X,%{public}#X,%#X;", 27, 28, 28);
std::string expected{"HEX_#X:<private>,0X1C,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs are formatted with uppercase long hexadecimal identifiers
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2320
* @tc.desc libhilog-Logs are formatted with uppercase long hexadecimal identifiers
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_HEX_LONG_UPPER_X_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "HEX_long_X:%{private}lX,%{public}lX,%lX;", 30ul, 31ul, 32ul);
std::string expected{"HEX_long_X:<private>,1F,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2220
* @tc.desc libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_STR_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "STRING:%{private}s,%{public}s,%s;", "STRING1", "STRING2", "STRING3");
std::string expected{"STRING:<private>,STRING2,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2240
* @tc.desc libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_STR_EMPTY_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "STRING_empty:%{private}s,%{public}s,%s;", "", "", "");
std::string expected{"STRING_empty:<private>,,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2230
* @tc.desc libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_STR_CHINESE_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "STRING_Chinese:%{private}s,%{public}s,%s;", "中文", "中文", "中文");
std::string expected{"STRING_Chinese:<private>,中文,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2330
* @tc.desc libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_E_DOUBLE_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "DOUBLE_e:%{private}e,%{public}e,%e;", 1e-30, 2.231e10, 3.999e-13);
std::string expected{"DOUBLE_e:<private>,2.231000e+10,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith scientific notation capitalized identifiers
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2340
* @tc.desc libhilog-Formatting Log whith scientific notation capitalized identifiers
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_E_UPPER_DOUBLE_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "DOUBLE_E:%{private}E,%{public}E,%E;", 4.88E2, 5.676767e-2, 6.17E13);
std::string expected{"DOUBLE_E:<private>,5.676767E-02,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2350
* @tc.desc libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_E_AUTO_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "AUTO:%{private}g,%{public}g,%g;", 1e-30, 2.231e10, 3.999e-13);
std::string expected{"AUTO:<private>,2.231e+10,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized
* identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogCPP_2360
* @tc.desc libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized
* identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCPPtest, HILOG_E_UPPER_AUTO_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "AUTO_E:%{private}G,%{public}G,%G;", 4.88E2, 5.676767e-2, 6.17E13);
std::string expected{"AUTO_E:<private>,0.0567677,<private>;"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-The {private} flag parameter of mixed log formatting is hidden
* @tc.number DFX_DFT_HilogCPP_31
* @tc.desc libhilog-The {private} flag parameter of mixed log formatting is hidden
*/
HWTEST_F(LibhilogCPPtest, HILOG_PRIVATE_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "private:%{private}d,%{private}lf,%{private}.2f,%{private}s,%{private}c",
1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"private:<private>,<private>,<private>,<private>,<private>"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-The parameters identified by {public} in mixed log formatting are displayed
* @tc.number DFX_DFT_HilogCPP_31
* @tc.desc libhilog-The parameters identified by {public} in mixed log formatting are displayed
*/
HWTEST_F(LibhilogCPPtest, HILOG_PUBLIC_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "public:%{public}d,%{public}lf,%{public}.2f,%{public}s,%{public}c",
1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"public:1,1.000010,2.33,sse,a"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Parameters without any privacy flag are not displayed in mixed log formatting
* @tc.number DFX_DFT_HilogCPP_31
* @tc.desc libhilog-Parameters without any privacy flag are not displayed in mixed log formatting
*/
HWTEST_F(LibhilogCPPtest, HILOG_NO_SIGN_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "no_sign:%d,%lf,%.2f,%s,%c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"no_sign:<private>,<private>,<private>,<private>,<private>"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Log privacy flags are used together, and parameters are
* correctly displayed or hidden
* @tc.number DFX_DFT_HilogCPP_31
* @tc.desc libhilog-Log privacy flags are used together, and parameters are
* correctly displayed or hidden
*/
HWTEST_F(LibhilogCPPtest, HILOG_MIX_CPP, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tag = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tag;
HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"MIX:1,<private>,2.33,<private>,<private>"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log are not truncated with normal length tag
* @tc.number DFX_DFT_HilogCPP_0280
* @tc.desc libhilog-log are not truncated with normal length tag
*/
HWTEST_F(LibhilogCPPtest, TAG_CHECK_CPP, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tagNormal;
HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log are truncated with too long tag
* @tc.number DFX_DFT_HilogCPP_0290
* @tc.desc libhilog-log are truncated with too long tag
*/
HWTEST_F(LibhilogCPPtest, TAG_OVER_CHECK_CPP, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd003200;
const char *tagToolong = "HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0"
"HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0HWTEST_Ftag0";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tagToolong;
HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST_:"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST_", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log domain
* @tc.number DFX_DFT_HilogCPP_0270
* @tc.desc libhilog-log domain
*/
HWTEST_F(LibhilogCPPtest, DOMAIN_CHECK_CPP, Function|MediumTest|Level1)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
const unsigned int domain = 0xd001111;
const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tagNormal;
HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"01111/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log LOG_APP type test
* @tc.number DFX_DFT_HilogCPP_0280
* @tc.desc libhilog-log LOG_APP type test
*/
HWTEST_F(LibhilogCPPtest, TYPE_APP_CHECK_CPP, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_APP;
const unsigned int domain = 0xd003200;
const char *tagNormal = "HWTEST_Ftag0HWTEST_Ftag0HWTEST";
HiLogLabel a;
a.type = type;
a.domain = domain;
a.tag = tagNormal;
HiLog::Fatal(a, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"03200/HWTEST_Ftag0HWTEST_Ftag0HWTEST:"};
sleep(1);
CmdRun("hilog -x | grep HWTEST_Ftag0HWTEST_Ftag0HWTEST", cmdRunResult);
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
{
"kits": [
{
"push": [
"ActsLibhilogCPPTest->/data/local/tmp/ActsLibhilogCPPTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsLibhilogCPPTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsLibhilogCPPTest Tests"
}
\ No newline at end of file
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hits/libhilogCtest"
###############################################################################
config("hilogtest_config") {
visibility = [ ":*" ]
include_dirs = [
"../../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
]
}
ohos_moduletest_suite("ActsLibhilogCTest") {
module_out_path = module_output_path
sources = [ "libhilogCtest.cpp" ]
deps = [
"../../../utils/native:utilskit",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
#external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
configs = [ ":hilogtest_config" ]
}
{
"kits": [
{
"push": [
"ActsLibhilogCTest->/data/local/tmp/ActsLibhilogCTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsLibhilogCTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsLibhilogCTest Tests"
}
\ No newline at end of file
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdarg>
#include <ctime>
#include <ostream>
#include <streambuf>
#include <queue>
#include <securec.h>
#include <pthread.h>
#include <sys/time.h>
#include "hilog/log_c.h"
#include "hilog/log_cpp.h"
#include <gtest/gtest.h>
#include "file_utils.h"
#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0xD003E00
#define LOG_TAG "testtag0testtag0testtag0testta"
using namespace std;
using namespace testing::ext;
class LibhilogCtest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
private:
};
void LibhilogCtest::SetUp()
{
CleanCmd();
}
void LibhilogCtest::TearDown()
{
}
void LibhilogCtest::SetUpTestCase()
{
}
void LibhilogCtest::TearDownTestCase()
{
std::cout << "TearDownTestCase" << std::endl;
}
/**
* @tc.name Provides user-mode interfaces(C)INFO
* @tc.number DFX_DFT_HilogC_0180
* @tc.desc Provides user-mode interfaces(C)INFO
*/
HWTEST_F(LibhilogCtest, HILOG_INFO, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
int i = 1;
HILOG_INFO(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,"
"%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"I 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<"cmdRunResult = " + cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.desc Provides user-mode interfaces(C)debug
* @tc.number DFX_DFT_HilogC_0170
* @tc.desc Provides user-mode interfaces(C)debug
*/
HWTEST_F(LibhilogCtest, HILOG_DEBUG, Function|MediumTest|Level1)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
int i = 1;
HILOG_DEBUG(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf,"
"%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"D 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name Provides user-mode interfaces(C)warning
* @tc.number DFX_DFT_HilogC_0210
* @tc.desc Provides user-mode interfaces(C)warning
*/
HWTEST_F(LibhilogCtest, HILOG_WARNING, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
int i = 1;
HILOG_WARN(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,"
"%{private}lf,%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"W 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.desc Provides user-mode interfaces(C)error
* @tc.number DFX_DFT_HilogC_0190
* @tc.desc Provides user-mode interfaces(C)error
*/
HWTEST_F(LibhilogCtest, HILOG_ERROR, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
int i = 1;
HILOG_ERROR(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf,"
"%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"E 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name Provides user-mode interfaces(C)fatal
* @tc.number DFX_DFT_HilogC_0200
* @tc.desc Provides user-mode interfaces(C)fatal
*/
HWTEST_F(LibhilogCtest, HILOG_FATAL, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
int i = 1;
HILOG_FATAL(type, "123456789_1234567890_publicandprivatelogtestis:%{public}d,%{private}lf,"
"%{public}.2f,%s,%{private}c", i, 1.00001, 2.333333, "sse", 'a');
std::string expected{"F 03e00/testtag0testtag0testtag0testta: \
123456789_1234567890_publicandprivatelogtestis:1,<private>,2.33,<private>,<private>"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0360
* @tc.desc libhilog-log integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_INTEGER, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "INTEGER:%{private}d,%{public}d,%d;", 1, 1, 1);
std::string expected{"INTEGER:<private>,1,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log long integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0370
* @tc.desc libhilog-log long integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_INTEGER_LONG, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "INTEGER_long:%{private}ld,%{public}ld,%ld;", 2147483647L, 2147483647L, 2147483647L);
std::string expected{"INTEGER_long:<private>,2147483647,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log fixed-length integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0380
* @tc.desc libhilog-log fixed-length integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_INTEGER_4, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "INTEGER_4:%{private}4d,%{public}4d,%4d;", 2000, 2000, 2000);
std::string expected{"INTEGER_4:<private>,2000,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log short integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0390
* @tc.desc libhilog-log short integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_INTEGER_SHORT, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "INTEGER_short:%{private}hd,%{public}hd,%hd;", (short)1024, (short)1024, (short)1024);
std::string expected{"INTEGER_short:<private>,1024,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log unsigned integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0400
* @tc.desc libhilog-log unsigned integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_INTEGER_UN, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "INTEGER_un:%{private}u,%{public}u,%u;", 2147483647u, 2147483647u, 2147483647u);
std::string expected{"INTEGER_un:<private>,2147483647,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0410
* @tc.desc libhilog-log unsigned long integer type identifier format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_INTEGER_LONG_UN, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "INTEGER_long_un:%{private}lu,%{public}lu,%lu;", 7483647lu, 2147483647lu, 2147483647lu);
std::string expected{"INTEGER_long_un:<private>,2147483647,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0420
* @tc.desc libhilog-log unsigned fixed-length integer format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_INTEGER_4_UN, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "INTEGER_4_un:%{private}4u,%{public}4u,%4u;", 4000u, 4000u, 4000u);
std::string expected{"INTEGER_4_un:<private>,4000,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0430
* @tc.desc libhilog-log unsigned short integer type identifier format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_INTEGER_SHORT_UN, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "INTEGER_short_un:%{private}hu,%{public}hu,%hu;",
(unsigned short)65535, (unsigned short)65535, (unsigned short)65535);
std::string expected{"INTEGER_short_un:<private>,65535,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log float type identifier format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0440
* @tc.desc libhilog-log float type identifier format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_FLOAT, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "FLOAT:%{private}f,%{public}f,%f;", 1.01, 1.01, 1.01);
std::string expected{"FLOAT:<private>,1.010000,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log long float type identifier format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0450
* @tc.desc libhilog-log long float type identifier format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_FLOAT_LONG, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "FLOAT_long:%{private}lf,%{public}lf,%lf;", 2.147483647, 2.147483647, 2.147483647);
std::string expected{"FLOAT_long:<private>,2.147484,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting of fixed-width floating-point identifiers in
* the decimal part of the log ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0460
* @tc.desc libhilog-Formatting of fixed-width floating-point identifiers in
* the decimal part of the log ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_FLOAT_POINT2, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "FLOAT_.2:%{private}.2f,%{public}.2f,%.2f;", 2.147483647, 2.147483647, 2.147483647);
std::string expected{"FLOAT_.2:<private>,2.15,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting of floating-point identifiers for
* the decimal part and integer part of the log ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0470
* @tc.desc libhilog-Formatting of floating-point identifiers for
* the decimal part and integer part of the log ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_FLOAT_3POINT2, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "FLOAT_3.2:%{private}3.2f,%{public}4.1f,%2.6f;", 32.147483647, 321.147483647, 23.147483647);
std::string expected{"FLOAT_3.2:<private>,321.1,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting log characters ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0480
* @tc.desc libhilog-Formatting log characters ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_CHAR, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "CHAR:%{private}c,%{public}c,%c;", 'a', 'b', 'c');
std::string expected{"CHAR:<private>,b,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting log octal identifier ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0520
* @tc.desc libhilog-Formatting log octal identifier ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_OCTAL, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "OCTAL:%{private}o,%{public}o,%o;", 15, 16, 17);
std::string expected{"OCTAL:<private>,20,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting log long octal identifier ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0530
* @tc.desc libhilog-Formatting log long octal identifier ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_OCTAL_LONG, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "OCTAL_long:%{private}lo,%{public}lo,%lo;", 022l, 023l, 024l);
std::string expected{"OCTAL_long:<private>,23,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0540
* @tc.desc libhilog-Formatting log hexadecimal identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_HEX, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "HEX:%{private}x,%{public}x,%x;", 0x0F, 0x10, 0x11);
std::string expected{"HEX:<private>,10,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0550
* @tc.desc libhilog-Logs with prefixes in hexadecimal format ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_HEX_UPPER, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "HEX_#:%{private}#x,%{public}#x,%#x;", 0x12, 0x13, 0x14);
std::string expected{"HEX_#:<private>,0x13,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs are formatted with long hexadecimal identifiers
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0560
* @tc.desc libhilog-Logs are formatted with long hexadecimal identifiers
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_HEX_LONG, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "HEX_long:%{private}lx,%{public}lx,%lx;", 0x15l, 0x16l, 0x17l);
std::string expected{"HEX_long:<private>,16,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs are formatted with uppercase hexadecimal flags
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0570
* @tc.desc libhilog-Logs are formatted with uppercase hexadecimal flags
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_HEX_X, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "HEX_X:%{private}X,%{public}X,%X;", 0x18, 0x19, 0x1A);
std::string expected{"HEX_X:<private>,19,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0580
* @tc.desc libhilog-Logs are formatted with uppercase and prefixes in hexadecimal format
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_HEX_UPPER_X, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "HEX_#X:%{private}#X,%{public}#X,%#X;", 0x1B, 0x1C, 0x1C);
std::string expected{"HEX_#X:<private>,0X1C,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Logs are formatted with uppercase long hexadecimal identifiers
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0590
* @tc.desc libhilog-Logs are formatted with uppercase long hexadecimal identifiers
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_HEX_LONG_UPPER_X, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "HEX_long_X:%{private}lX,%{public}lX,%lX;", 0x1El, 0x1Fl, 0x20l);
std::string expected{"HEX_long_X:<private>,1F,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0490
* @tc.desc libhilog-Formatting Log whith string identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_STR, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "STRING:%{private}s,%{public}s,%s;", "STRING1", "STRING2", "STRING3");
std::string expected{"STRING:<private>,STRING2,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0510
* @tc.desc libhilog-Formatting Log whith empty string identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_STR_EMPTY, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "STRING_empty:%{private}s,%{public}s,%s;", "", "", "");
std::string expected{"STRING_empty:<private>,,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0500
* @tc.desc libhilog-Formatting Log whith Chinese identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_STR_CHINESE, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "STRING_Chinese:%{private}s,%{public}s,%s;", "中文", "中文", "中文");
std::string expected{"STRING_Chinese:<private>,中文,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0600
* @tc.desc libhilog-Formatting Log whith scientific notation identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_E_DOUBLE, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "DOUBLE_e:%{private}e,%{public}e,%e;", 1e-30, 2.231e10, 3.999e-13);
std::string expected{"DOUBLE_e:<private>,2.231000e+10,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith scientific notation capitalized identifiers
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0610
* @tc.desc libhilog-Formatting Log whith scientific notation capitalized identifiers
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_E_UPPER_DOUBLE, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "DOUBLE_E:%{private}E,%{public}E,%E;", 4.88E2, 5.676767e-2, 6.17E13);
std::string expected{"DOUBLE_E:<private>,5.676767E-02,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers
* ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0620
* @tc.desc libhilog-Formatting Log whith scientific notation(%g AUTO) identifiers
* ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_E_AUTO, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "AUTO:%{private}g,%{public}g,%g;", 1e-30, 2.231e10, 3.999e-13);
std::string expected{"AUTO:<private>,2.231e+10,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized
* identifiers ({public}, {private}, no identifier)
* @tc.number DFX_DFT_HilogC_0630
* @tc.desc libhilog-libhilog-Formatting Log whith scientific notation(%g AUTO) capitalized
* identifiers ({public}, {private}, no identifier)
*/
HWTEST_F(LibhilogCtest, HILOG_E_UPPER_AUTO, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "AUTO_E:%{private}G,%{public}G,%G;", 4.88E2, 5.676767e-2, 6.17E13);
std::string expected{"AUTO_E:<private>,0.0567677,<private>;"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-The {private} flag parameter of mixed log formatting is hidden
* @tc.number DFX_DFT_HilogC_3100
* @tc.desc libhilog-The {private} flag parameter of mixed log formatting is hidden
*/
HWTEST_F(LibhilogCtest, HILOG_PRIVATE, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "private:%{private}d,%{private}lf,%{private}.2f,"
"%{private}s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"private:<private>,<private>,<private>,<private>,<private>"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-The parameters identified by {public} in mixed log formatting are displayed
* @tc.number DFX_DFT_HilogC_3200
* @tc.desc libhilog-The parameters identified by {public} in mixed log formatting are displayed
*/
HWTEST_F(LibhilogCtest, HILOG_PUBLIC, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "public:%{public}d,%{public}lf,%{public}.2f,%{public}s,%{public}c",
1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"public:1,1.000010,2.33,sse,a"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Parameters without any privacy flag are not displayed in mixed log formatting
* @tc.number DFX_DFT_HilogC_3300
* @tc.desc libhilog-Parameters without any privacy flag are not displayed in mixed log formatting
*/
HWTEST_F(LibhilogCtest, HILOG_NO_SIGN, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "no_sign:%d,%lf,%.2f,%s,%c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"no_sign:<private>,<private>,<private>,<private>,<private>"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-Log privacy flags are used together, and parameters are
* correctly displayed or hidden
* @tc.number DFX_DFT_HilogC_3400
* @tc.desc libhilog-Log privacy flags are used together, and parameters are
* correctly displayed or hidden
*/
HWTEST_F(LibhilogCtest, HILOG_MIX, Function|MediumTest|Level3)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"MIX:1,<private>,2.33,<private>,<private>"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log are not truncated with normal length tag
* @tc.number DFX_DFT_HilogC_0280
* @tc.desc libhilog-log are not truncated with normal length tag
*/
HWTEST_F(LibhilogCtest, TAG_CHECK, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"03e00/testtag0testtag0testtag0testta:"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log are not truncated with normal length tag
* @tc.number DFX_DFT_HilogC_0280
* @tc.desc libhilog-log are not truncated with normal length tag
*/
HWTEST_F(LibhilogCtest, TYPE_APP_CHECK, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_APP;
HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"03e00/testtag0testtag0testtag0testta:"};
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testta", cmdRunResult);
std::cout<<cmdRunResult<<std::endl;
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log are truncated with too long tag
* @tc.number DFX_DFT_HilogC_0290
* @tc.desc libhilog-log are truncated with too long tag
*/
HWTEST_F(LibhilogCtest, TAG_OVER_CHECK, Function|MediumTest|Level2)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
#undef LOG_TAG
#define LOG_TAG "testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0testtag0"
HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"03e00/testtag0testtag0testtag0testtag:"};
sleep(1);
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testtag", cmdRunResult);
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
/**
* @tc.name libhilog-log domain
* @tc.number DFX_DFT_HilogC_0270
* @tc.desc libhilog-log domain
*/
HWTEST_F(LibhilogCtest, DOMAIN_CHECK, Function|MediumTest|Level1)
{
std::string cmdRunResult;
LogType type = LOG_CORE;
#undef LOG_DOMAIN
#define LOG_DOMAIN 0xD001111
HILOG_FATAL(type, "MIX:%{public}d,%{private}lf,%{public}.2f,%s,%{private}c", 1, 1.00001, 2.333333, "sse", 'a');
std::string expected{"01111/testtag0testtag0testtag0testtag:"};
sleep(1);
CmdRun("timeout 3 hilog | grep testtag0testtag0testtag0testtag", cmdRunResult);
std::cout<<"expected = " + expected<<std::endl;
ASSERT_TRUE(cmdRunResult.find(expected) != std::string::npos);
}
\ No newline at end of file
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hit/HiSysEventCPPTest"
###############################################################################
config("hilogtest_config") {
visibility = [ ":*" ]
include_dirs = [
"../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits/include",
]
}
ohos_moduletest_suite("ActsHiSysEventCPPTest") {
module_out_path = module_output_path
sources = [ "HiSysEventCPPTest.cpp" ]
deps = [
"../../utils/native:utilskit",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits:libhisysevent",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
configs = [ ":hilogtest_config" ]
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "hilog/log.h"
#include <gtest/gtest.h>
#include "file_utils.h"
#include "hisysevent.h"
using namespace testing;
using namespace testing::ext;
using namespace std;
using namespace OHOS::HiviewDFX;
namespace {
string g_key = "key";
string g_reDiRectTimeout = "6";
string g_hiLogRedirect = "/data/local/tmp/hilogredirect.log";
}
class HiSysEventCPPTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
void RedHiSysEventLog(std::string &hilogredirect, std::string &timeout);
private:
};
void HiSysEventCPPTest::SetUp()
{
std::cout << "SetUp" << std::endl;
CleanCmd();
}
void HiSysEventCPPTest::TearDown()
{
std::cout << "TearDown" << std::endl;
std::vector<std::string> cmdret;
string cmd = "rm " + g_hiLogRedirect;
ExecCmdWithRet(cmd, cmdret);
}
void HiSysEventCPPTest::SetUpTestCase()
{
std::cout << "SetUpTestCase" << std::endl;
std::vector<std::string> cmdret;
string cmd = "mkdir /data/local/tmp/";
ExecCmdWithRet(cmd, cmdret);
}
void HiSysEventCPPTest::TearDownTestCase()
{
std::cout << "TearDownTestCase" << std::endl;
}
void HiSysEventCPPTest::RedHiSysEventLog(std::string &hilogredirect, std::string &timeout)
{
unsigned long i;
std::vector<std::string> cmdret;
unsigned long cmdretlen;
std::string cmd = "rm " + hilogredirect;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
for (i = 0; i < cmdretlen; i++) {
std::cout<<cmdret[i].c_str()<<std::endl;
}
cmd = "timeout " + timeout + " hilog | grep HISYSEVENT >" + hilogredirect;
std::cout<<cmd<<std::endl;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
for (i = 0; i < cmdretlen; i++) {
std::cout<<cmdret[i].c_str()<<std::endl;
}
}
/**
* @tc.name HiSysEvent Native Write Interface Test, Reported When the KeyValue Is of the
* boolean Type and the bool Value Is False
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0100
* @tc.desc The keyvalue is of the boolean type and the bool value is false.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0100, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 start" << endl;
bool result = false;
bool param = false;
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::AAFWK;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo;
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"AAFWK", "eventNameDemo", "\"type_\":1", "\"key\":0"};
if (!fileinfo.empty()) {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0100 end" << endl;
}
/**
* @tc.name HiSysEvent Native Write Interface Test, Reported When the KeyValue Is of
* the boolean Type and the bool Value Is False
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0200
* @tc.desc The keyvalue is of the boolean type and the bool value is true.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0200, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 start" << endl;
bool result = false;
bool param = true;
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::APPEXECFWK;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"APPEXECFWK", "eventNameDemo", "\"type_\":1", "\"key\":1"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0200 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Boolean List Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0300
* @tc.desc The value of keyvalue is a boolean list.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0300, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 start" << endl;
bool result = false;
bool param = false;
std::vector<bool> test;
test.push_back(param);
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::ACCOUNT;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"ACCOUNT", "eventNameDemo", "\"type_\":1", "\"key\":[0]"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0300 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Char Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0400
* @tc.desc The keyvalue is of the char type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0400, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 start" << endl;
bool result = false;
char param = 'a';
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::OTHERS;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"OTHERS", "eventNameDemo", "\"type_\":1", "\"key\":97"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0400 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0500
* @tc.desc keyvalue is of the char list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0500, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 start" << endl;
bool result = false;
char param = 'a';
std::vector<char> test;
test.push_back(param);
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::WEARABLE;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"WEARABLE", "eventNameDemo", "\"type_\":1", "\"key\":[97]"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0500 end" << endl;
}
/**
* @tc.name HiSysEvent Natvie Write Interface Test, Reported When the KeyValue Is of the Double Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0600
* @tc.desc The keyvalue is of the double type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0600, Function|MediumTest|Level2)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 start" << endl;
bool result = false;
double param = 30949.374;
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::WEARABLE_HARDWARE;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"WEARABLEHW", "eventNameDemo", "\"type_\":1", "\"key\":30949.4"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0600 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0700
* @tc.desc keyvalue is of the char list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0700, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 start" << endl;
bool result = false;
double param = 30949.374;
std::vector<double> test;
test.push_back(param);
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::USB;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"USB", "eventNameDemo", "\"type_\":1", "\"key\":[30949.4]"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0700 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Floating Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0800
* @tc.desc The keyvalue is of the float type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0800, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 start" << endl;
bool result = false;
float param = 230.47;
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::UPDATE;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"UPDATE", "eventNameDemo", "\"type_\":1", "\"key\":230.47"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0800 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Char List Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_0900
* @tc.desc keyvalue is of the char list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_0900, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 start" << endl;
bool result = false;
float param = 230.47;
std::vector<float> test;
test.push_back(param);
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::TELEPHONY;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"TELEPHONY", "eventNameDemo", "\"type_\":1", "\"key\":[230.47]"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0900 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Keyvalue of the Int Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1000
* @tc.desc The keyvalue is of the int type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1000, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 start" << endl;
bool result = false;
int param = 100;
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::STARTUP;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"STARTUP", "eventNameDemo", "\"type_\":1", "\"key\":100"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1000 end" << endl;
}
/**
* @tc.name HiSysEvent Natvie Write Interface Test, Reporting of the int List of KeyValues
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1100
* @tc.desc keyvalue is of the int list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1100, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 start" << endl;
bool result = false;
int param = 100;
std::vector<int> test;
test.push_back(param);
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SOURCE_CODE_TRANSFORMER;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"SRCTRANSFORMER", "eventNameDemo", "\"type_\":1", "\"key\":[100]"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1100 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Long Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1200
* @tc.desc The keyvalue is of the long type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1200, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 start" << endl;
bool result = false;
long param = 1000000;
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SENSORS;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"SENSORS", "eventNameDemo", "\"type_\":1", "\"key\":1000000"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1200 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of the Long Key Value
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1300
* @tc.desc The keyvalue is of the long list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1300, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 start" << endl;
bool result = false;
long param = 1000000;
std::vector<long> test;
test.push_back(param);
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::SECURITY;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"SECURITY", "eventNameDemo", "\"type_\":1", "\"key\":[1000000]"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1300 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the Short Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1400
* @tc.desc The keyvalue is of the short type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1400, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0250 start" << endl;
bool result = false;
short param = 10;
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::ROUTER;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::FAULT;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"ROUTER", "eventNameDemo", "\"type_\":1", "\"key\":10"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1400 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1400 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of Short Key Values
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1500
* @tc.desc The keyvalue is of the short list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1500, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 start" << endl;
bool result = false;
short param = 10;
std::vector<short> test;
test.push_back(param);
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::POWERMGR;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"POWERMGR", "eventNameDemo", "\"type_\":2", "\"key\":[10]"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1500 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the Key Value of the String Type
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1600
* @tc.desc The keyvalue is of the string type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1600, Function|MediumTest|Level2)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 start" << endl;
bool result = false;
string param = "abc";
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::NOTIFICATION;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::STATISTIC;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"NOTIFICATION", "eventNameDemo", "\"type_\":2", "\"key\":\"abc\""};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1600 end" << endl;
}
/**
* @tc.name Testing the HiSysEvent Natvie Write Interface, Reporting the List of Short Key Values
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1700
* @tc.desc The keyvalue is of the short list type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1700, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 start" << endl;
bool result = false;
string param = "abc";
std::vector<string> test;
test.push_back(param);
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MODAL_INPUT;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::SECURITY;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"MULTIMODALINPUT", "eventNameDemo", "\"type_\":3", "\"key\":[\"abc\"]"};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1700 end" << endl;
}
/**
* @tc.name HiSysEvent Natvie Write Interface Test, Reporting the List of 20 List Parameters When the Key Value Is String
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_1800
* @tc.desc The keyvalue is reported as a string list. There are 20 list parameters.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_1800, Function|MediumTest|Level4)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_0290 start" << endl;
bool result = false;
string param = "abc";
std::vector<string> test;
for (int i = 0; i < 20; i++) {
test.push_back(param);
}
string str = "\"key\":[";
for (int i = 0; i < 19; i++) {
str = str + "\"abc\",";
}
str = str + "\"abc\"]";
GTEST_LOG_(INFO) << str << endl;
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MULTI_MEDIA;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::SECURITY;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, test);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"MULTIMEDIA", "eventNameDemo", "\"type_\":3", str};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_1800 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_1800 end" << endl;
}
/**
* @tc.name In the HiSysEvent Natvie Write interface test, 32 parameters are reported for each type of keyvalue.
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_2000
* @tc.desc The keyvalue parameter has 32 parameters for each type.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_2000, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 start" << endl;
bool result = false;
string param = "abc";
string str = "";
for (int i=0; i < 31; i++){
str = str + "\"key\":\"abc\",";
}
str += "\"key\":\"abc\"";
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::MSDP;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype,
g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
g_key, param, g_key, param, g_key, param, g_key, param, g_key, param, g_key, param,
g_key, param, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"MSDP", "eventNameDemo", "\"type_\":4", str};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2000 end" << endl;
}
/**
* @tc.name In the test of the HiSysEvent Natvie Write interface, the key value is a string of 256 characters.
* @tc.number DFX_DFT_HiviewKit_HiSysEvent_Native_2200
* @tc.desc The keyvalue is a string of 256 characters.
*/
HWTEST_F(HiSysEventCPPTest, DFX_DFT_HiviewKit_HiSysEvent_Native_2200, Function|MediumTest|Level3)
{
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 start" << endl;
bool result = false;
string param = "";
for (int i = 0; i < 256; i++) {
param += "a";
}
string domain = OHOS::HiviewDFX::HiSysEvent::Domain::LOCATION;
OHOS::HiviewDFX::HiSysEvent::EventType eventtype = OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR;
OHOS::HiviewDFX::HiSysEvent::Write(domain, "eventNameDemo", eventtype, g_key, param);
RedHiSysEventLog(g_hiLogRedirect, g_reDiRectTimeout);
string fileinfo = "";
fileinfo = ReadFile(g_hiLogRedirect);
std::vector<std::string> para = {"LOCATION", "eventNameDemo", "\"type_\":4", g_key, param};
if (fileinfo != "") {
result = CheckInfo(para, fileinfo);
} else {
std::cout << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 file error" << std::endl;
}
ASSERT_TRUE(result);
GTEST_LOG_(INFO) << "DFX_DFT_HiviewKit_HiSysEvent_Native_2200 end" << endl;
}
{
"kits": [
{
"push": [
"ActsHiSysEventCPPTest->/data/local/tmp/ActsHiSysEventCPPTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsHiSysEventCPPTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsHiSysEventCPPTest Tests"
}
\ No newline at end of file
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hits/HitraceCPPtest"
###############################################################################
config("hitrace_config") {
visibility = [ ":*" ]
include_dirs = [
"../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include",
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits/include",
]
}
ohos_moduletest_suite("ActsHitraceCPPTest") {
module_out_path = module_output_path
sources = [ "HitraceCPPtest.cpp" ]
deps = [
"../../utils/native:utilskit",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/hiviewdfx/hisysevent/interfaces/native/innerkits:libhisysevent",
"//base/hiviewdfx/hitrace/interfaces/native/innerkits:libhitrace",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
configs = [ ":hitrace_config" ]
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdarg>
#include <ctime>
#include <gtest/gtest.h>
#include <pthread.h>
#include "hitrace/hitrace.h"
#include "hitrace/hitraceid.h"
#include "hitrace/trace.h"
#include "file_utils.h"
using namespace OHOS;
using namespace HiviewDFX;
using namespace testing;
using namespace testing::ext;
using namespace std;
class HitraceCPPtest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
private:
};
void HitraceCPPtest::SetUp()
{
}
void HitraceCPPtest::TearDown()
{
}
void HitraceCPPtest::SetUpTestCase()
{
}
void HitraceCPPtest::TearDownTestCase()
{
}
/**
* @tc.name HiTrace C++ interface test
* @tc.number DFX_DFT_HiTrace_CPP_0001
* @tc.desc HiTrace C++ interface test
*/
HWTEST_F(HitraceCPPtest, Hitrace_interface, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface start" << endl;
HiTraceFlag hitraceflag = HITRACE_FLAG_INCLUDE_ASYNC;
HiTraceId hiTraceId = HiTrace::Begin("test", HITRACE_FLAG_INCLUDE_ASYNC);
HiTrace::SetId(hiTraceId);
hiTraceId = HiTrace::GetId();
ASSERT_TRUE(hiTraceId.IsValid());
hiTraceId.EnableFlag(hitraceflag);
ASSERT_TRUE(hiTraceId.IsFlagEnabled(hitraceflag));
int hitraceflags = HITRACE_FLAG_FAULT_TRIGGER;
hiTraceId.SetFlags(hitraceflags);
hitraceflags = hiTraceId.GetFlags();
ASSERT_TRUE(hitraceflags == HITRACE_FLAG_FAULT_TRIGGER);
uint64_t chainId = 10000;
hiTraceId.SetChainId(chainId);
chainId = hiTraceId.GetChainId();
ASSERT_TRUE(chainId == 10000);
uint64_t spanId = 12345678;
hiTraceId.SetSpanId(spanId);
spanId = hiTraceId.GetSpanId();
ASSERT_TRUE(spanId == 12345678);
HiTraceId childId = HiTrace::CreateSpan();
EXPECT_EQ(1, childId.IsValid());
/* set child id to thread id */
HiTrace::SetId(childId);
/* continue to create child span */
HiTraceId grandChildId = HiTrace::CreateSpan();
EXPECT_EQ(1, grandChildId.IsValid());
EXPECT_EQ(grandChildId.GetFlags(), childId.GetFlags());
EXPECT_EQ(grandChildId.GetChainId(), childId.GetChainId());
EXPECT_EQ(grandChildId.GetParentSpanId(), childId.GetSpanId());
grandChildId.SetChainId(chainId);
chainId = grandChildId.GetChainId();
ASSERT_TRUE(chainId == 10000);
grandChildId.SetSpanId(spanId);
spanId = grandChildId.GetSpanId();
ASSERT_TRUE(spanId == 12345678);
HiTrace::ClearId();
HiTraceId clearId = HiTrace::GetId();
EXPECT_EQ(0, clearId.IsValid());
HiTrace::End(hiTraceId);
GTEST_LOG_(INFO) << "Hitrace_interface end" << endl;
}
/**
* @tc.name HiTrace C++ Begin interface, when flag is invalid.
* @tc.number DFX_DFT_HiTrace_CPP_0002
* @tc.desc HiTrace C++ interface test
*/
HWTEST_F(HitraceCPPtest, Hitrace_interface1, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface1 start" << endl;
/* begin with invalid flag */
HiTraceId invalidFlagId = HiTrace::Begin("invalid param", HITRACE_FLAG_MAX+1);
EXPECT_EQ(0, invalidFlagId.IsValid());
HiTrace::End(invalidFlagId);
invalidFlagId = HiTrace::Begin("invalid param", -1);
EXPECT_EQ(0, invalidFlagId.IsValid());
HiTrace::End(invalidFlagId);
GTEST_LOG_(INFO) << "Hitrace_interface1 end" << endl;
}
/**
* @tc.name HiTrace C++ Begin interface, when name is invalid.
* @tc.number DFX_DFT_HiTrace_CPP_0003
* @tc.desc HiTrace C++ interface test
*/
HWTEST_F(HitraceCPPtest, Hitrace_interface2, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface2 start" << endl;
/* begin with invalid name */
HiTraceId invalidNameId = HiTrace::Begin("", HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, invalidNameId.IsValid());
HiTrace::End(invalidNameId);
GTEST_LOG_(INFO) << "Hitrace_interface2 end" << endl;
}
/**
* @tc.name HiTrace C++ Begin interface, when name is very long.
* @tc.number DFX_DFT_HiTrace_CPP_0004
* @tc.desc HiTrace C++ interface test
*/
HWTEST_F(HitraceCPPtest, Hitrace_interface3, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface3 start" << endl;
std::string name = "test";
for (int i = 0; i < 1000; i++) {
name += "test";
}
HiTraceId traceId = HiTrace::Begin(name, HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, traceId.IsValid());
HiTrace::End(traceId);
GTEST_LOG_(INFO) << "Hitrace_interface3 end" << endl;
}
/**
* @tc.name Repeated call Begin interface.
* @tc.number DFX_DFT_HiTrace_CPP_0005
* @tc.desc HiTrace C++ interface test
*/
HWTEST_F(HitraceCPPtest, Hitrace_interface4, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface4 start" << endl;
HiTraceId traceId = HiTrace::Begin("test", HITRACE_FLAG_TP_INFO);
HiTraceId traceId1 = HiTrace::Begin("test1", HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, traceId.IsValid());
EXPECT_EQ(0, traceId1.IsValid());
HiTrace::End(traceId);
HiTrace::End(traceId1);
GTEST_LOG_(INFO) << "Hitrace_interface4 end" << endl;
}
/**
* @tc.name End invalid traceid
* @tc.number DFX_DFT_HiTrace_CPP_0006
* @tc.desc HiTrace C++ interface test
*/
HWTEST_F(HitraceCPPtest, Hitrace_interface5, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface5 start" << endl;
HiTraceId traceId = HiTrace::Begin("test", HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, traceId.IsValid());
HiTraceId invalidId;
invalidId.SetChainId(1000);
invalidId.SetSpanId(1000);
HiTrace::End(invalidId);
HiTraceId wrongEndId = HiTrace::GetId();
EXPECT_EQ(1, wrongEndId.IsValid());
ASSERT_TRUE(wrongEndId.GetChainId() == traceId.GetChainId());
EXPECT_EQ(1, wrongEndId.IsFlagEnabled(HITRACE_FLAG_TP_INFO));
HiTrace::End(traceId);
GTEST_LOG_(INFO) << "Hitrace_interface5 end" << endl;
}
/**
* @tc.name End traceId that has ended.
* @tc.number DFX_DFT_HiTrace_CPP_0007
* @tc.desc HiTrace C++ interface test
*/
HWTEST_F(HitraceCPPtest, Hitrace_interface6, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface6 start" << endl;
HiTraceId traceId = HiTrace::Begin("invalid param1", HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, traceId.IsValid());
HiTrace::End(traceId);
traceId = HiTrace::GetId();
EXPECT_EQ(0, traceId.IsValid());
HiTrace::End(traceId);
traceId = HiTrace::GetId();
EXPECT_EQ(0, traceId.IsValid());
GTEST_LOG_(INFO) << "Hitrace_interface6 end" << endl;
}
\ No newline at end of file
{
"kits": [
{
"push": [
"ActsHitraceCPPTest->/data/local/tmp/ActsHitraceCPPTest"
],
"type": "PushKit",
"post-push": [
"chmod -R 777 /data/local/tmp/*"
]
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsHitraceCPPTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsHitraceCPPTest Tests"
}
\ No newline at end of file
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//test/xts/tools/build/suite.gni")
module_output_path = "hits/HitraceCtest"
###############################################################################
config("hitrace_config") {
visibility = [ ":*" ]
include_dirs = [
"../../utils/native",
"//utils/native/base/include/",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/hiviewdfx/hitrace/interfaces/native/innerkits/include",
]
}
ohos_moduletest_suite("ActsHitraceCTest") {
module_out_path = module_output_path
sources = [ "HitraceCtest.cpp" ]
deps = [
"../../utils/native:utilskit",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/hiviewdfx/hitrace/interfaces/native/innerkits:libhitrace",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
configs = [ ":hitrace_config" ]
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <cstdarg>
#include <gtest/gtest.h>
#include "hitrace/hitracec.h"
#include "file_utils.h"
using namespace testing::ext;
using namespace std;
class HitraceCtest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
private:
};
void HitraceCtest::SetUp()
{
}
void HitraceCtest::TearDown()
{
}
void HitraceCtest::SetUpTestCase()
{
}
void HitraceCtest::TearDownTestCase()
{
}
/**
* @tc.name HiTrace C interface test
* @tc.number DFX_DFT_HiTrace_0001
* @tc.desc HiTrace C interface test
*/
HWTEST_F(HitraceCtest, HitraceC_interface, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "HitraceC_interface start" << endl;
HiTraceIdStruct hiTraceId;
HiTraceFlag hitraceflag = HITRACE_FLAG_INCLUDE_ASYNC;
hiTraceId = HiTraceBegin("test", HITRACE_FLAG_INCLUDE_ASYNC);
HiTraceSetId(&hiTraceId);
hiTraceId = HiTraceGetId();
ASSERT_TRUE(HiTraceIsValid(&hiTraceId));
HiTraceEnableFlag(&hiTraceId, hitraceflag);
ASSERT_TRUE(HiTraceIsFlagEnabled(&hiTraceId, hitraceflag));
int hitraceflags = HITRACE_FLAG_FAULT_TRIGGER;
HiTraceSetFlags(&hiTraceId, hitraceflags);
hitraceflags = HiTraceGetFlags(&hiTraceId);
ASSERT_TRUE(hitraceflags == HITRACE_FLAG_FAULT_TRIGGER);
uint64_t chainId = 10000;
HiTraceSetChainId(&hiTraceId, chainId);
chainId = HiTraceGetChainId(&hiTraceId);
ASSERT_TRUE(chainId==10000);
uint64_t spanId = 12345678;
HiTraceSetSpanId(&hiTraceId, spanId);
spanId = HiTraceGetSpanId(&hiTraceId);
ASSERT_TRUE(spanId == 12345678);
HiTraceIdStruct childId = HiTraceCreateSpan();
ASSERT_TRUE(HiTraceIsValid(&childId));
/* set child id to thread id */
HiTraceSetId(&childId);
/* continue to create child span */
HiTraceIdStruct grandChildId = HiTraceCreateSpan();
ASSERT_TRUE(HiTraceIsValid(&grandChildId));
EXPECT_EQ(HiTraceGetFlags(&grandChildId), HiTraceGetFlags(&childId));
EXPECT_EQ(HiTraceGetChainId(&grandChildId), HiTraceGetChainId(&childId));
EXPECT_EQ(HiTraceGetParentSpanId(&grandChildId), HiTraceGetSpanId(&childId));
HiTraceSetChainId(&grandChildId, chainId);
chainId = HiTraceGetChainId(&grandChildId);
ASSERT_TRUE(chainId==10000);
HiTraceSetSpanId(&grandChildId, spanId);
spanId = HiTraceGetSpanId(&grandChildId);
ASSERT_TRUE(spanId==12345678);
HiTraceClearId();
hiTraceId = HiTraceGetId();
ASSERT_FALSE(HiTraceIsValid(&hiTraceId));
HiTraceEnd(&hiTraceId);
GTEST_LOG_(INFO) << "HitraceC_interface end" << endl;
}
/**
* @tc.name HiTraceBegin interface test, when flag is invalid
* @tc.number DFX_DFT_HiTrace_0002
* @tc.desc HiTrace C interface test
*/
HWTEST_F(HitraceCtest, HitraceC_interface1, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "HitraceC_interface1 start" << endl;
/* begin with invalid flag */
HiTraceIdStruct invalidFlagId = HiTraceBegin("invalid param", HITRACE_FLAG_MAX+1);
EXPECT_EQ(0, HiTraceIsValid(&invalidFlagId));
HiTraceEnd(&invalidFlagId);
invalidFlagId = HiTraceBegin("invalid param1", -1);
EXPECT_EQ(0, HiTraceIsValid(&invalidFlagId));
HiTraceEnd(&invalidFlagId);
GTEST_LOG_(INFO) << "HitraceC_interface1 end" << endl;
}
/**
* @tc.name HiTraceBegin interface test, when name is invalid.
* @tc.number DFX_DFT_HiTrace_0003
* @tc.desc HiTrace C interface test
*/
HWTEST_F(HitraceCtest, HitraceC_interface2, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "HitraceC_interface2 start" << endl;
/* begin with invalid name */
HiTraceIdStruct invalidNameId = HiTraceBegin("", HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, HiTraceIsValid(&invalidNameId));
HiTraceEnd(&invalidNameId);
GTEST_LOG_(INFO) << "HitraceC_interface2 end" << endl;
}
/**
* @tc.name HiTraceBegin interface test, when name is very long.
* @tc.number DFX_DFT_HiTrace_0004
* @tc.desc HiTrace C++ interface test
*/
HWTEST_F(HitraceCtest, Hitrace_interface3, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface3 start" << endl;
char name[4096] = "test";
for (int i = 0; i < 1000; i++)
{
strcat(name, "test");
}
HiTraceIdStruct traceId = HiTraceBegin(name, HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, HiTraceIsValid(&traceId));
HiTraceEnd(&traceId);
GTEST_LOG_(INFO) << "Hitrace_interface3 end" << endl;
}
/**
* @tc.name Repeated call HiTraceBegin interface test.
* @tc.number DFX_DFT_HiTrace_0005
* @tc.desc HiTrace C interface test
*/
HWTEST_F(HitraceCtest, Hitrace_interface4, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "Hitrace_interface4 start" << endl;
HiTraceIdStruct traceId = HiTraceBegin("test", HITRACE_FLAG_TP_INFO);
HiTraceIdStruct traceId1 = HiTraceBegin("test1", HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, HiTraceIsValid(&traceId));
EXPECT_EQ(0, HiTraceIsValid(&traceId1));
HiTraceEnd(&traceId);
HiTraceEnd(&traceId1);
GTEST_LOG_(INFO) << "Hitrace_interface4 end" << endl;
}
/**
* @tc.name End invalid traceid test.
* @tc.number DFX_DFT_HiTrace_0006
* @tc.desc HiTrace C interface test
*/
HWTEST_F(HitraceCtest, HitraceC_interface5, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "HitraceC_interface5 start" << endl;
HiTraceIdStruct traceId = HiTraceBegin("test", HITRACE_FLAG_TP_INFO);
HiTraceIdStruct invalidId = {0};
EXPECT_EQ(1, HiTraceIsValid(&traceId));
HiTraceEnd(&invalidId);
HiTraceIdStruct wrongEndId = HiTraceGetId();
EXPECT_EQ(1, HiTraceIsValid(&wrongEndId));
EXPECT_EQ(HiTraceGetChainId(&wrongEndId), HiTraceGetChainId(&traceId));
EXPECT_EQ(1, HiTraceIsFlagEnabled(&wrongEndId, HITRACE_FLAG_TP_INFO));
HiTraceEnd(&traceId);
GTEST_LOG_(INFO) << "HitraceC_interface5 end" << endl;
}
/**
* @tc.name End traceId that has ended.
* @tc.number DFX_DFT_HiTrace_0007
* @tc.desc HiTrace C interface test
*/
HWTEST_F(HitraceCtest, HitraceC_interface6, Function|MediumTest|Level1)
{
GTEST_LOG_(INFO) << "HitraceC_interface6 start" << endl;
HiTraceIdStruct traceId = HiTraceBegin("test", HITRACE_FLAG_TP_INFO);
EXPECT_EQ(1, HiTraceIsValid(&traceId));
HiTraceEnd(&traceId);
traceId = HiTraceGetId();
EXPECT_EQ(0, HiTraceIsValid(&traceId));
HiTraceEnd(&traceId);
traceId = HiTraceGetId();
EXPECT_EQ(0, HiTraceIsValid(&traceId));
GTEST_LOG_(INFO) << "HitraceC_interface6 end" << endl;
}
\ No newline at end of file
{
"kits": [
{
"push": [
"ActsHitraceCTest->/data/local/tmp/ActsHitraceCTest"
],
"type": "PushKit",
"post-push": [
"chmod -R 777 /data/local/tmp/*"
]
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "ActsHitraceCTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for ActsHitraceCTest Tests"
}
\ No newline at end of file
# Copyright (C) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//test/xts/tools/build/suite.gni")
###############################################################################
config("utils_config") {
visibility = [ ":*" ]
include_dirs = [
"//third_party/cJSON/",
"//third_party/zlib/",
"//utils/native/base/",
]
}
sources_common = [ "file_utils.cpp" ]
ohos_static_library("utilskit") {
sources = sources_common
configs = [ ":utils_config" ]
#external_deps = [ "hilog:libhilog" ]
deps = [
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//base/hiviewdfx/hiview/base:hiviewbase",
"//utils/native/base:utils",
]
}
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
#include "file_utils.h"
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <chrono>
#include <dirent.h>
#include <condition_variable>
#include <vector>
#include "include/securec.h"
#include "string_util.h"
using namespace OHOS::HiviewDFX;
int ExecCmdWithRet(std::string cmd, std::vector<std::string> &resvec)
{
if (cmd.size() == 0) {
return 0;
}
std::cout<< "cmd is " + cmd <<std::endl;
if ((cmd.find("hilog") == std::string::npos) && (cmd.find("hidumper") == std::string::npos)
&& (cmd.find("ps") == std::string::npos) && (cmd.find("rm") == std::string::npos)) {
std::cout<<"unsupport cmd!" + cmd <<std::endl;
return 0;
}
resvec.clear();
FILE *pp = popen(cmd.c_str(), "r");
if (pp == nullptr) {
return -1;
}
char tmp[1024];
while (fgets(tmp, sizeof(tmp), pp) != nullptr) {
if (tmp[strlen(tmp) - 1] == '\n') {
tmp[strlen(tmp) - 1] = '\0';
}
resvec.push_back(tmp);
}
pclose(pp);
return resvec.size();
}
void ExeCmd(std::string cmd)
{
std::vector<std::string> cmdret;
ExecCmdWithRet(cmd, cmdret);
}
void CmdRun(std::string cmd, std::string &result)
{
std::vector<std::string> cmdret;
int resultlen;
int i = 0;
std::string rst;
resultlen = ExecCmdWithRet(cmd, cmdret);
while (i < resultlen) {
rst = rst + cmdret[i];
i = i + 1;
}
result = rst;
}
void CleanCmd()
{
std::string cmdResult;
std::string cleanCmd = "hilog -r";
CmdRun(cleanCmd, cmdResult);
std::cout << cmdResult;
sleep(1);
}
std::string ExecuteCmd(std::string cmd)
{
std::vector<std::string> cmdret;
int resultlen;
int i = 0;
std::string rst;
resultlen = ExecCmdWithRet(cmd, cmdret);
while (i < resultlen) {
rst = rst + cmdret[i] + "\n";
i = i + 1;
}
return rst;
}
void SaveCmdOutput(std::string cmd, std::string saveFile)
{
std::fstream fstr(saveFile, std::ios::out);
std::string cmdRet = ExecuteCmd(cmd);
fstr << cmdRet;
fstr.close();
}
void RedirecthiLog(std::string &hilogredirect, std::string &timeout)
{
unsigned long i;
std::vector<std::string> cmdret;
unsigned long cmdretlen;
std::string cmd = "rm " + hilogredirect;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
for (i = 0; i < cmdretlen; i++) {
std::cout<<cmdret[i].c_str()<<std::endl;
}
cmd = "timeout " + timeout + " hilog >" + hilogredirect;
std::cout<<cmd<<std::endl;
cmdretlen = ExecCmdWithRet(cmd, cmdret);
for (i = 0; i < cmdretlen; i++) {
std::cout<<cmdret[i].c_str()<<std::endl;
}
}
bool CheckInfo(std::vector<std::string> &para, std::string info)
{
if (info.empty()) {
return false;
}
std::vector<std::string> splitStr;
StringUtil::SplitStr(info, "\n", splitStr, false, false);
unsigned long matchcnt;
bool result = false;
std::string eventinfoline;
std::cout<<info<<std::endl;
matchcnt = 0;
for (std::vector<std::string>::iterator iter = splitStr.begin(); iter != splitStr.end(); ++iter) {
eventinfoline = std::string (iter->c_str());
for (unsigned long i = 0; i < para.size(); i++) {
std::cout<<para[i]<<std::endl;
if (int(eventinfoline.find(para[i])) >= 0) {
matchcnt++;
}
}
std::cout<<"Expect1:"<<std::endl;
if (matchcnt == para.size()) {
std::cout<<"Expect2:"<<std::endl;
result = true;
break;
}
}
return result;
}
bool CompareString(const std::string& x, const std::string& y)
{
int len = x.length() - 1;
while (x[len] == y[len] && len >= 0) {
len--;
}
if (len >= 0 && x[len] > y[len]) {
return false;
}
return true;
}
int GetTxtLine(std::string filename)
{
FILE *fd = fopen(filename.c_str(), "r");
int count = 0;
if (fd != nullptr) {
while (!feof(fd)) {
if (fgetc(fd) == '\n') {
count++;
}
}
}
std::cout << count << std::endl;
if (fd != nullptr) {
fclose(fd);
}
return count;
}
std::string ReadFile(std::string filename)
{
std::ifstream ifile(filename);
std::ostringstream buf;
char ch;
if (ifile.fail()) {
std::cout<<"open file fail!"<<std::endl;
return "";
}
while (buf && ifile.get(ch)) {
buf.put(ch);
}
ifile.close();
return buf.str();
}
std::vector<std::string> getfileinpath(std::string path)
{
std::vector<std::string> filelist;
DIR *dir;
struct dirent *pdirent;
dir = opendir(path.c_str());
if (dir != nullptr) {
while ((pdirent = readdir(dir)) != nullptr) {
if (strncmp(pdirent->d_name, ".", strlen(pdirent->d_name)) == 0 ||
strncmp(pdirent->d_name, "..", strlen(pdirent->d_name)) == 0) {
continue;
} else if (pdirent->d_type == 4) {
continue;
} else {
filelist.push_back(pdirent->d_name);
}
}
closedir(dir);
}
return filelist;
}
#endif
/*
* Copyright (C) 2021 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TEST_COMMON_H
#define TEST_COMMON_H
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include <chrono>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <vector>
bool CheckInfo(std::vector<std::string> &para, std::string eventinfo);
int ExecCmdWithRet(std::string cmd, std::vector<std::string> &resvec);
std::string ReadFile(std::string filename);
void RedirecthiLog(std::string &hilogredirect, std::string &timeout);
void ExeCmd(std::string cmd);
void CmdRun(std::string cmd, std::string &result);
std::string ExecuteCmd(std::string cmd);
bool CompareString(const std::string& x, const std::string& y);
int GetTxtLine(std::string filename);
std::string ReadFile(std::string filename);
void CleanCmd();
std::string ReadOneLine(std::string m_path, char* rBuf, int n);
void SaveCmdOutput(std::string cmd, std::string saveFile);
std::vector<std::string> getfileinpath(std::string path);
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册