提交 46a81305 编写于 作者: C chenxuihui

napi xts add

Signed-off-by: Nchenxuihui <chenxuhui2@huawei.com>
上级 2b4dfdd8
......@@ -16,10 +16,12 @@ group("hiviewdfxtestacts") {
if (is_standard_system) {
deps = [
"bytracetest:ActsBytraceJsTest",
"hiappeventtest/hiappeventcpptest:HiAppEventCPPTest",
"hiappeventtest/hiappeventjstest:ActsHiAppeventTest",
"hicheckertest/hicheckerjstest:hicheckerjstest",
"hidebugtest/hidebugtestjstest:ActsHiDebugTest",
"hilogjstest:ActsHilogJsTest",
"hilogtest/hilogjstest:ActsHilogJsTest",
"hilogtest/hilogndktest:hilogndktest",
"hitracechainjstest:ActsHiTraceChainJsTest",
"hitracechaintest:ActsHiTraceChainTest",
"hiview/faultlogger/faultloggerjs:faultloggerjs_test",
......
# 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/HiAppEventCPPTest"
###############################################################################
config("hilogtest_config") {
visibility = [ ":*" ]
include_dirs = [
"//utils/native/base/include/",
"../../utils/native",
"//base/hiviewdfx/hilog/interfaces/native/innerkits/include",
"//base/hiviewdfx/hiappevent/interfaces/native/kits/include/hiappevent",
"//base/hiviewdfx/hiappevent/frameworks/native/libhiappevent/include",
]
}
ohos_moduletest_suite("HiAppEventCPPTest") {
module_out_path = module_output_path
sources = [ "HiAppEventCPPTest.cpp" ]
deps = [
"../../utils/native:utilskit",
"//base/hiviewdfx/hiappevent/frameworks/native/libhiappevent:libhiappevent_base",
"//base/hiviewdfx/hiappevent/frameworks/native/ndk:hiappevent_ndk",
"//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
configs = [ ":hilogtest_config" ]
}
{
"kits": [
{
"push": [
"HiAppEventCPPTest->/data/local/tmp/HiAppEventCPPTest"
],
"type": "PushKit"
}
],
"driver": {
"native-test-timeout": "120000",
"type": "CppTest",
"module-name": "HiAppEventCPPTest",
"runtime-hint": "1s",
"native-test-device-path": "/data/local/tmp"
},
"description": "Configuration for HiAppEventCPPTest Tests"
}
\ No newline at end of file
# Copyright (C) 2022 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/hilogndktest"
config("hilogndktest_config") {
visibility = [ ":*" ]
include_dirs = [
"//base/hiviewdfx/hilog/interfaces/native/kits/include",
"//utils/native/base/include/",
]
}
ohos_moduletest_suite("hilogndktest") {
module_out_path = module_output_path
sources = [ "hilogndktest.cpp" ]
deps = [
"//base/hiviewdfx/hilog/frameworks/hilog_ndk:hilog_ndk",
"//base/hiviewdfx/hilog/interfaces/native/kits:libhilog_ndk",
"//utils/native/base:utils",
"//third_party/googletest:gtest_main",
]
configs = [ ":hilogndktest_config" ]
}
{
"description": "Configuration for hilogndktest demo Tests",
"driver": {
"type": "CppTest",
"native-test-timeout": "120000",
"module-name": "hilogndktest",
"runtime-hint": "ls",
"native-test-device-path": "/data/local/tmp"
},
"kits": [
{
"push": [
"hilogndktest->/data/local/tmp/hilogndktest"
],
"type": "PushKit"
}
]
}
/**
* Copyright (c) 2020-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 <gtest/gtest.h>
#include "hilog/log.h"
#undef LOG_DOMAIN
#undef LOG_TAG
#define LOG_DOMAIN 0xD003e00
using namespace std;
using namespace testing::ext;
class hilogndktest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
void hilogndktest::SetUp()
{
}
void hilogndktest::TearDown()
{
}
void hilogndktest::SetUpTestCase()
{
}
void hilogndktest::TearDownTestCase()
{
}
/**
* @tc.number : DFX_DFT_HILOGNDK_0100
* @tc.name : HILOGNDK_TEST
* @tc.desc : HILOGNDK_TEST
*/
HWTEST_F(hilogndktest, OH_LOG_Print_CHECK, Function | MediumTest | Level1)
{
LogType type = LOG_APP;
LogLevel level = LOG_ERROR;
int ret = OH_LOG_Print(type, level, 0xD003e00, "testtag0testtag1testtag2", "string:for hilog test %{private}s", "name");
ASSERT_TRUE(ret == 85);
}
/**
* @tc.number : DFX_DFT_HILOGNDK_0200
* @tc.name : HILOGNDK_TEST
* @tc.desc : HILOGNDK_TEST
*/
HWTEST_F(hilogndktest, OH_LOG_IsLoggable_CHECK, Function | MediumTest | Level1)
{
LogLevel level = LOG_DEBUG;
const char *LOG_TAG = "testtag0testtag0testtag0testta";
bool res = OH_LOG_IsLoggable(0xD003e00, LOG_TAG, level);
ASSERT_TRUE(res == false);
}
# Copyright (C) 2021-2022 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-2022 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) &&
(cmd.find("hiperf") == std::string::npos) && (cmd.find("hisysevent") == std::string::npos) &&
(cmd.find("mkdir") == std::string::npos) && (cmd.find("dd") == 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;
}
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;
}
bool result = false;
unsigned long matchcnt = 0;
for (unsigned long i = 0; i < para.size(); i++) {
if (int(info.find(para[i])) >= 0) {
matchcnt++;
}
}
std::cout<< matchcnt <<std::endl;
if (matchcnt == para.size()) {
result = true;
}
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-2022 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 HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_
#define HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_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 // HIVIEWDFX_UTILS_NATIVE_FILE_UTILS_H_
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册