From e724c8f6e641509ad7d7c13c91a65d8dc7f9936c Mon Sep 17 00:00:00 2001 From: 15929983503 Date: Thu, 23 Mar 2023 19:47:15 +0800 Subject: [PATCH] hilogtestjs add debug lable Signed-off-by: 15929983503 --- hiviewdfx/BUILD.gn | 1 - hiviewdfx/hilogtest/hilogjstest/BUILD.gn | 4 ++ .../hilogjstest/src/main/config.json | 8 ++- .../hilogjstest/src/main/cpp/BUILD.gn | 55 ++++++++++++++ .../hilogjstest/src/main/cpp/CMakeLists.txt | 11 +++ .../hilogjstest/src/main/cpp/hilogndk.cpp | 67 +++++++++++++++++ .../src/main/cpp/types/libentry/index.d.ts | 1 + .../src/main/cpp/types/libentry/package.json | 4 ++ .../js/TestRunner/OpenHarmonyTestRunner.js | 2 +- .../src/main/js/test/HilogJsTest.js | 30 +++++++- hiviewdfx/hilogtest/hilogndktest/BUILD.gn | 34 --------- hiviewdfx/hilogtest/hilogndktest/Test.json | 18 ----- .../hilogtest/hilogndktest/hilogndktest.cpp | 72 ------------------- 13 files changed, 175 insertions(+), 132 deletions(-) create mode 100644 hiviewdfx/hilogtest/hilogjstest/src/main/cpp/BUILD.gn create mode 100644 hiviewdfx/hilogtest/hilogjstest/src/main/cpp/CMakeLists.txt create mode 100644 hiviewdfx/hilogtest/hilogjstest/src/main/cpp/hilogndk.cpp create mode 100644 hiviewdfx/hilogtest/hilogjstest/src/main/cpp/types/libentry/index.d.ts create mode 100644 hiviewdfx/hilogtest/hilogjstest/src/main/cpp/types/libentry/package.json delete mode 100755 hiviewdfx/hilogtest/hilogndktest/BUILD.gn delete mode 100755 hiviewdfx/hilogtest/hilogndktest/Test.json delete mode 100644 hiviewdfx/hilogtest/hilogndktest/hilogndktest.cpp diff --git a/hiviewdfx/BUILD.gn b/hiviewdfx/BUILD.gn index f60ba0bb4..e01b9090e 100644 --- a/hiviewdfx/BUILD.gn +++ b/hiviewdfx/BUILD.gn @@ -26,7 +26,6 @@ group("hiviewdfxtestacts") { "hilogtest/hilogdomainofftest:ActsHilogDomainOffJsTest", "hilogtest/hilogdomainontest:ActsHilogDomainOnJsTest", "hilogtest/hilogjstest:ActsHilogJsTest", - "hilogtest/hilogndktest:ActsHilogndkTest", "hisyseventtest/hisyseventjstest:ActsHiSysEventJsTest", "hitracechainjstest:ActsHiTraceChainJsTest", "hitracemetertest:ActsHitraceMeterTest", diff --git a/hiviewdfx/hilogtest/hilogjstest/BUILD.gn b/hiviewdfx/hilogtest/hilogjstest/BUILD.gn index cbe588eb1..802ddeed7 100755 --- a/hiviewdfx/hilogtest/hilogjstest/BUILD.gn +++ b/hiviewdfx/hilogtest/hilogjstest/BUILD.gn @@ -21,6 +21,10 @@ ohos_js_hap_suite("ActsHilogJsTest") { certificate_profile = "./signature/openharmony_sx.p7b" hap_name = "ActsHilogJsTest" + js_build_mode = "debug" + shared_libraries = [ + "./src/main/cpp:hilogndk", + ] } ohos_js_assets("hilog_js_assets") { js2abc = true diff --git a/hiviewdfx/hilogtest/hilogjstest/src/main/config.json b/hiviewdfx/hilogtest/hilogjstest/src/main/config.json index eb5af745d..9307a07e6 100755 --- a/hiviewdfx/hilogtest/hilogjstest/src/main/config.json +++ b/hiviewdfx/hilogtest/hilogjstest/src/main/config.json @@ -11,13 +11,15 @@ "target": 5 } }, - "deviceConfig": {}, + "deviceConfig": { + "default" :{"debug" : true} + }, "module": { "package": "ohos.acts.hiviewdfx.hilog.function", "name": ".entry", "deviceType": [ - "tablet", - "default", + "tablet", + "default", "phone" ], "distro": { diff --git a/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/BUILD.gn b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/BUILD.gn new file mode 100644 index 000000000..ae9a7f0af --- /dev/null +++ b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/BUILD.gn @@ -0,0 +1,55 @@ +# 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("//build/config/ohos/config.gni") +import("//build/ohos.gni") +import("//foundation/arkui/napi/napi.gni") + +config("config") { + visibility = [ ":*" ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Wunused-variable", + ] +} + +config("public_config") { +} + +ohos_shared_library("hilogndk") { + sources = [ "./hilogndk.cpp" ] + if (!(product_name == "m40")) { + if (target_cpu == "arm") { + libs = [ "${clang_base_path}/../libcxx-ndk/lib/arm-linux-ohos/c++/libc++_shared.so" ] + } else if (target_cpu == "arm64") { + libs = [ "${clang_base_path}/../libcxx-ndk/lib/aarch64-linux-ohos/c++/libc++_shared.so" ] + } else { + libs = [] + } + } + + include_dirs = [ "//test/xts/acts/hiviewdfx/hilogtest/hilogjstest/src/main/cpp", + "//base/hiviewdfx/hilog/interfaces/native/kits/include", ] + configs = [ ":config" ] + + deps = [ + "//foundation/arkui/napi:ace_napi", + "//base/hiviewdfx/hilog/frameworks/hilog_ndk:hilog_ndk", + "//base/hiviewdfx/hilog/interfaces/native/kits:libhilog_ndk", + ] + + output_extension = "so" +} diff --git a/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/CMakeLists.txt b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/CMakeLists.txt new file mode 100644 index 000000000..4d883edba --- /dev/null +++ b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/CMakeLists.txt @@ -0,0 +1,11 @@ +# the minimum version of CMake. +cmake_minimum_required(VERSION 3.4.1) +project(XComponent) + +set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) + +include_directories(${NATIVERENDER_ROOT_PATH} + ${NATIVERENDER_ROOT_PATH}/include) + +add_library(hilogndk SHARED hilogndk.cpp) +target_link_libraries(hilogndk PUBLIC libace_napi.z.so libc++.a libhilog_ndk.z.so ) \ No newline at end of file diff --git a/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/hilogndk.cpp b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/hilogndk.cpp new file mode 100644 index 000000000..7c728f574 --- /dev/null +++ b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/hilogndk.cpp @@ -0,0 +1,67 @@ +/* + * 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. + */ + +#include "napi/native_api.h" +#include "hilog/log.h" + +static napi_value OhIsLoggableTest(napi_env env, napi_callback_info info) +{ + napi_value res = nullptr; + bool isLoggable = OH_LOG_IsLoggable(0x3200, "testTag", LOG_DEBUG); + napi_get_boolean(env, isLoggable, &res); + return res; +} + +static napi_value OhPrintTest(napi_env env, napi_callback_info info) +{ + napi_value res = nullptr; + LogType type = LOG_APP; + LogLevel level = LOG_ERROR; + int retLen = OH_LOG_Print(type, level, 0x3200, "testTag", "string for hilog test"); + bool ret = (retLen > 0) ? true : false; + napi_get_boolean(env, ret, &res); + return res; +} + + + +EXTERN_C_START +static napi_value Init(napi_env env, napi_value exports) +{ + napi_property_descriptor desc[] = { + { "ohIsLoggableTest", nullptr, OhIsLoggableTest, + nullptr, nullptr, nullptr, napi_default, nullptr }, + { "ohPrintTest", nullptr, OhPrintTest, + nullptr, nullptr, nullptr, napi_default, nullptr } + }; + napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc); + return exports; +} +EXTERN_C_END + +static napi_module demoModule = { + .nm_version =1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = Init, + .nm_modname = "libhilogndk", + .nm_priv = ((void*)0), + .reserved = { 0 }, +}; + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module_register(&demoModule); +} diff --git a/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/types/libentry/index.d.ts b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/types/libentry/index.d.ts new file mode 100644 index 000000000..86c88c289 --- /dev/null +++ b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/types/libentry/index.d.ts @@ -0,0 +1 @@ +export const OhIsLoggableTest: () => object; \ No newline at end of file diff --git a/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/types/libentry/package.json b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/types/libentry/package.json new file mode 100644 index 000000000..233420388 --- /dev/null +++ b/hiviewdfx/hilogtest/hilogjstest/src/main/cpp/types/libentry/package.json @@ -0,0 +1,4 @@ +{ + "name": "libhilogndk.so", + "types": "./index.d.ts" +} \ No newline at end of file diff --git a/hiviewdfx/hilogtest/hilogjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js b/hiviewdfx/hilogtest/hilogjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js index b9e78ce7c..2d910487c 100644 --- a/hiviewdfx/hilogtest/hilogjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js +++ b/hiviewdfx/hilogtest/hilogjstest/src/main/js/TestRunner/OpenHarmonyTestRunner.js @@ -41,7 +41,7 @@ function translateParamsToString(parameters) { var testAbilityName = abilityDelegatorArguments.parameters['-p'] + '.TestAbility' - var cmd = 'aa start -d 0 -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName + var cmd = 'aa start -a ' + testAbilityName + ' -b ' + abilityDelegatorArguments.bundleName cmd += ' ' + translateParamsToString(abilityDelegatorArguments.parameters) var debug = abilityDelegatorArguments.parameters["-D"] console.info('debug value : '+debug) diff --git a/hiviewdfx/hilogtest/hilogjstest/src/main/js/test/HilogJsTest.js b/hiviewdfx/hilogtest/hilogjstest/src/main/js/test/HilogJsTest.js index a14697dae..517cc8272 100644 --- a/hiviewdfx/hilogtest/hilogjstest/src/main/js/test/HilogJsTest.js +++ b/hiviewdfx/hilogtest/hilogjstest/src/main/js/test/HilogJsTest.js @@ -14,6 +14,7 @@ */ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '@ohos/hypium' import hilog from '@ohos.hilog' +import hilogndk from "libhilogndk.so" export default function HilogJsTest() { describe('HilogJsTest', function () { @@ -120,7 +121,7 @@ describe('HilogJsTest', function () { it('testHilogJsApi06', 2, function () { console.info('testHilogJsApi06 start'); const res = hilog.isLoggable(0x3200, "HILOGTEST", hilog.LogLevel.DEBUG); - expect(res).assertEqual(false); + expect(res).assertEqual(true); console.info('testHilogJsApi06 end'); }) @@ -136,7 +137,7 @@ describe('HilogJsTest', function () { for (var i = 0; i < 1000; i++){ tag += "HILOGTEST" } - expect(res).assertEqual(false); + expect(res).assertEqual(true); console.info('testHilogJsApi07 end'); }) @@ -148,7 +149,7 @@ describe('HilogJsTest', function () { it('testHilogJsApi08', 2, function () { console.info('testHilogJsApi08 start'); const res = hilog.isLoggable(0x3200, "", hilog.LogLevel.DEBUG); - expect(res).assertEqual(false); + expect(res).assertEqual(true); console.info('testHilogJsApi08 end'); }) @@ -415,5 +416,28 @@ describe('HilogJsTest', function () { console.info('testHilogJsApi26 end'); }) + /** + * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_3900 + * @tc.name hitrace interface test + * @tc.desc hitrace begin interface test. + */ + it('testHilogJsApi27', 2, function () { + console.info('testHilogJsApi27 start'); + const res = hilogndk.ohIsLoggableTest(); + expect(res).assertEqual(true); + console.info('testHilogJsApi27 end'); + }) + + /** + * @tc.number DFX_DFT_Hiview_Libhilog_Hilog_JS_4000 + * @tc.name hitrace interface test + * @tc.desc hitrace begin interface test. + */ + it('testHilogJsApi28', 2, function () { + console.info('testHilogJsApi28 start'); + const res = hilogndk.ohPrintTest(); + expect(res).assertEqual(true); + console.info('testHilogJsApi28 end'); + }) }) } diff --git a/hiviewdfx/hilogtest/hilogndktest/BUILD.gn b/hiviewdfx/hilogtest/hilogndktest/BUILD.gn deleted file mode 100755 index 133a0b8e4..000000000 --- a/hiviewdfx/hilogtest/hilogndktest/BUILD.gn +++ /dev/null @@ -1,34 +0,0 @@ -# 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/ActsHilogndkTest" - -config("hilogndktest_config") { - visibility = [ ":*" ] - include_dirs = [ - "//base/hiviewdfx/hilog/interfaces/native/kits/include", - "//commonlibrary/c_utils/base/include/", - ] -} -ohos_moduletest_suite("ActsHilogndkTest") { - module_out_path = module_output_path - sources = [ "hilogndktest.cpp" ] - external_deps = [ "c_utils:utils" ] - deps = [ - "//base/hiviewdfx/hilog/frameworks/hilog_ndk:hilog_ndk", - "//base/hiviewdfx/hilog/interfaces/native/kits:libhilog_ndk", - "//third_party/googletest:gtest_main", - ] - configs = [ ":hilogndktest_config" ] -} diff --git a/hiviewdfx/hilogtest/hilogndktest/Test.json b/hiviewdfx/hilogtest/hilogndktest/Test.json deleted file mode 100755 index 80b3f1499..000000000 --- a/hiviewdfx/hilogtest/hilogndktest/Test.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "description": "Configuration for hilogndktest demo Tests", - "driver": { - "type": "CppTest", - "native-test-timeout": "120000", - "module-name": "ActsHilogndkTest", - "runtime-hint": "ls", - "native-test-device-path": "/data/local/tmp" - }, - "kits": [ - { - "push": [ - "ActsHilogndkTest->/data/local/tmp/ActsHilogndkTest" - ], - "type": "PushKit" - } - ] -} diff --git a/hiviewdfx/hilogtest/hilogndktest/hilogndktest.cpp b/hiviewdfx/hilogtest/hilogndktest/hilogndktest.cpp deleted file mode 100644 index f1e8e1d80..000000000 --- a/hiviewdfx/hilogtest/hilogndktest/hilogndktest.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 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 -#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); -} - -- GitLab