From 6b7a4466c5e1be6fe56ae92004baf76ef7a967ad Mon Sep 17 00:00:00 2001 From: jiangdayuan Date: Tue, 11 Jan 2022 20:11:05 +0800 Subject: [PATCH] Revert "!104 Property Get/Set implementation" This reverts commit 5cc1b766f8ca196009b0c8ddecc960d2fb30464d, reversing changes made to 899c2b17d8983a6be8a0bfc5b0e4864501584668. Signed-off-by: jiangdayuan Change-Id: I4eb120b272c81e85f05161df39873410b87a5499 --- adapter/BUILD.gn | 1 - adapter/properties.cpp | 392 +++++++++--------- .../innerkits/include/hilog_base/log_base.h | 6 +- services/hilogd/etc/BUILD.gn | 16 - services/hilogd/etc/hilog.para | 22 - services/hilogd/etc/hilog.para.dac | 16 - test/BUILD.gn | 17 - test/moduletest/common/adapter_test.cpp | 185 --------- 8 files changed, 191 insertions(+), 464 deletions(-) delete mode 100755 services/hilogd/etc/hilog.para delete mode 100755 services/hilogd/etc/hilog.para.dac delete mode 100644 test/moduletest/common/adapter_test.cpp diff --git a/adapter/BUILD.gn b/adapter/BUILD.gn index 604454a..56fdf3c 100644 --- a/adapter/BUILD.gn +++ b/adapter/BUILD.gn @@ -33,5 +33,4 @@ ohos_shared_library("libhilog_os_adapter") { "system", "updater", ] - external_deps = [ "startup_l2:syspara" ] } diff --git a/adapter/properties.cpp b/adapter/properties.cpp index 0cfd1ca..f87ff5e 100644 --- a/adapter/properties.cpp +++ b/adapter/properties.cpp @@ -14,29 +14,24 @@ */ #include "properties.h" - -#include +#include "hilog/log.h" +#include +#include +#include +#include +#include +#include #include -#include +#include #include #include #include -#include #include -#include -#include -#include #include -#include -#include -#include -#include #include +#include #include - -#include -#include -#include +#include using namespace std; @@ -53,150 +48,41 @@ static pthread_mutex_t g_processFlowLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_domainFlowLock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_kmsgLock = PTHREAD_MUTEX_INITIALIZER; -static int LockByProp(uint32_t propType); -static void UnlockByProp(uint32_t propType); - -class PropertyTypeLocker { -public: - explicit PropertyTypeLocker(uint32_t propType) - : m_propType(propType) - , m_isLocked(false) - { - m_isLocked = !LockByProp(m_propType); - } - - ~PropertyTypeLocker() - { - if (m_isLocked) { - UnlockByProp(m_propType); - } - } - - bool isLocked() const - { - return m_isLocked; - } -private: - uint32_t m_propType; - bool m_isLocked; +using PropertyCache = struct { + const void* pinfo; + uint32_t serial; + char propertyValue[HILOG_PROP_VALUE_MAX]; }; -using RawPropertyData = std::array; - -template -class CacheData { -public: - using DataConverter = std::function; - - CacheData(DataConverter converter, const T& defaultValue, uint32_t propType, const std::string& suffix = "") - : m_value(defaultValue) - , m_defaultValue(defaultValue) - , m_propType(propType) - , m_converter(converter) - { - m_key = GetPropertyName(m_propType) + suffix; - } - - T getValue() - { - if (m_handle == -1) { - auto handle = FindParameter(m_key.c_str()); - if (handle == -1) { - return m_defaultValue; - } - m_handle = handle; - } - auto currentCommit = GetParameterCommitId(m_handle); - PropertyTypeLocker locker(m_propType); - if (locker.isLocked()) { - if (currentCommit != m_commit) { - updateValue(); - m_commit = currentCommit; - } - return m_value; - } else { - return getDirectValue(); - } - } -private: - bool getRawValue(char *value, unsigned int len) - { - auto res = GetParameterValue(m_handle, value, len); - if (res < 0) { - std::cerr << "CacheData -> GetParameterValue -> Can't get value for key: " << m_key; - std::cerr << " handle: " << m_handle << " Result: " << res << "\n"; - return false; - } - return true; - } - - T getDirectValue() - { - RawPropertyData tempData; - if (!getRawValue(tempData.data(), tempData.size())) { - return m_defaultValue; - } - return m_converter(tempData, m_defaultValue); - } - - void updateValue() - { - if (!getRawValue(m_rawData.data(), m_rawData.size())) { - m_value = m_defaultValue; - return; - } - m_value = m_converter(m_rawData, m_defaultValue); - } - - RawPropertyData m_rawData = {0}; - unsigned int m_handle = -1; - unsigned int m_commit = -1; - T m_value; - const T m_defaultValue; - const uint32_t m_propType; - std::string m_key; - DataConverter m_converter; +using SwitchCache = struct { + PropertyCache cache; + bool isOn; }; -using SwitchCache = CacheData; -using LogLevelCache = CacheData; +using LogLevelCache = struct { + PropertyCache cache; + uint16_t logLevel; +}; +using ProcessInfo = struct { + PropertyCache cache; + string propertyKey; + string process; + string processHashPre; + uint32_t processQuota; +}; void PropertyGet(const string &key, char *value, int len) { - if (len > HILOG_PROP_VALUE_MAX) { - std::cerr << "PropertyGet(): len exceed maximum.\n"; - return; - } - - auto handle = FindParameter(key.c_str()); - if (handle == -1) { + if (len < HILOG_PROP_VALUE_MAX) { return; } - - auto res = GetParameterValue(handle, value, len); - if (res < 0) { - std::cerr << "PropertyGet() -> GetParameterValue -> Can't get value for key: " << key; - std::cerr << " handle: " << handle << " Result: " << res << "\n"; - } + /* use OHOS interface */ } void PropertySet(const string &key, const char* value) { - auto len = value ? strlen(value) : 0; - if (len > HILOG_PROP_VALUE_MAX) { - std::cerr << "PropertyGet(): len exceed maximum.\n"; - return; - } - - auto result = SetParameter(key.c_str(), value); - if (result < 0) { - if (result == EC_INVALID) { - std::cerr << "PropertySet(): Invalid arguments.\n"; - } else { - std::cerr << "PropertySet(): Error: " << result << "\n"; - } - } + /* use OHOS interface */ } string GetProgName() @@ -302,14 +188,50 @@ static void UnlockByProp(uint32_t propType) } } -static bool textToBool(const RawPropertyData& data, bool defaultVal) +static void RefreshCacheBuf(PropertyCache *cache, const char *key) { - if (!strcmp(data.data(), "true")) { - return true; - } else if (!strcmp(data.data(), "false")) { - return false; + /* use OHOS interface */ +} + +static bool CheckCache(const PropertyCache *cache) +{ + return true; + /* use OHOS interface */ +} + +static bool GetSwitchCache(bool isFirst, SwitchCache& switchCache, uint32_t propType, bool defaultValue) +{ + int notLocked; + string key = GetPropertyName(propType); + + if (isFirst || CheckCache(&switchCache.cache)) { + notLocked = LockByProp(propType); + if (!notLocked) { + RefreshCacheBuf(&switchCache.cache, key.c_str()); + if (strcmp(switchCache.cache.propertyValue, "true") == 0) { + switchCache.isOn = true; + } else if (strcmp(switchCache.cache.propertyValue, "false") == 0) { + switchCache.isOn = false; + } else { + switchCache.isOn = defaultValue; + } + UnlockByProp(propType); + return switchCache.isOn; + } else { + SwitchCache tmpCache = {{nullptr, 0xffffffff, ""}, defaultValue}; + RefreshCacheBuf(&tmpCache.cache, key.c_str()); + if (strcmp(tmpCache.cache.propertyValue, "true") == 0) { + tmpCache.isOn = true; + } else if (strcmp(tmpCache.cache.propertyValue, "false") == 0) { + tmpCache.isOn = false; + } else { + tmpCache.isOn = defaultValue; + } + return tmpCache.isOn; + } + } else { + return switchCache.isOn; } - return defaultVal; } bool IsDebugOn() @@ -319,111 +241,173 @@ bool IsDebugOn() bool IsSingleDebugOn() { - static auto *switchCache = new SwitchCache(textToBool, false, PROP_SINGLE_DEBUG); - return switchCache->getValue(); + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; + static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; + bool isFirst = !isFirstFlag.test_and_set(); + return GetSwitchCache(isFirst, *switchCache, PROP_SINGLE_DEBUG, false); } bool IsPersistDebugOn() { - static auto *switchCache = new SwitchCache(textToBool, false, PROP_PERSIST_DEBUG); - return switchCache->getValue(); + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; + static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; + bool isFirst = !isFirstFlag.test_and_set(); + return GetSwitchCache(isFirst, *switchCache, PROP_PERSIST_DEBUG, false); } bool IsPrivateSwitchOn() { - static auto *switchCache = new SwitchCache(textToBool, true, PROP_PRIVATE); - return switchCache->getValue(); + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, true}; + static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; + bool isFirst = !isFirstFlag.test_and_set(); + return GetSwitchCache(isFirst, *switchCache, PROP_PRIVATE, true); } bool IsProcessSwitchOn() { - static auto *switchCache = new SwitchCache(textToBool, false, PROP_PROCESS_FLOWCTRL); - return switchCache->getValue(); + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; + static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; + bool isFirst = !isFirstFlag.test_and_set(); + return GetSwitchCache(isFirst, *switchCache, PROP_PROCESS_FLOWCTRL, false); } bool IsDomainSwitchOn() { - static auto *switchCache = new SwitchCache(textToBool, false, PROP_DOMAIN_FLOWCTRL); - return switchCache->getValue(); + static SwitchCache *switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; + static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; + bool isFirst = !isFirstFlag.test_and_set(); + return GetSwitchCache(isFirst, *switchCache, PROP_DOMAIN_FLOWCTRL, false); } bool IsKmsgSwitchOn() { - static auto *switchCache = new SwitchCache(textToBool, false, PROP_KMSG); - return switchCache->getValue(); + static SwitchCache* switchCache = new SwitchCache {{nullptr, 0xffffffff, ""}, false}; + static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; + bool isFirst = !isFirstFlag.test_and_set(); + return GetSwitchCache(isFirst, *switchCache, PROP_KMSG, false); } -static uint16_t textToLogLevel(const RawPropertyData& data, uint16_t defaultVal) +static uint16_t GetCacheLevel(char propertyChar) { - static const std::unordered_map logLevels = { - { 'd', LOG_DEBUG }, { 'D', LOG_DEBUG }, - { 'i', LOG_INFO }, { 'I', LOG_INFO }, - { 'w', LOG_WARN }, { 'W', LOG_WARN }, - { 'e', LOG_ERROR }, { 'E', LOG_ERROR }, - { 'f', LOG_FATAL }, { 'F', LOG_FATAL }, - }; - auto it = logLevels.find(data[0]); - if (it != logLevels.end()) { - return it->second; + uint16_t cacheLevel = LOG_LEVEL_MIN; + switch (propertyChar) { + case 'D': + case 'd': + cacheLevel = LOG_DEBUG; + break; + case 'I': + case 'i': + cacheLevel = LOG_INFO; + break; + case 'W': + case 'w': + cacheLevel = LOG_WARN; + break; + case 'E': + case 'e': + cacheLevel = LOG_ERROR; + break; + case 'F': + case 'f': + cacheLevel = LOG_FATAL; + break; + default: + break; } - return LOG_LEVEL_MIN; + return cacheLevel; } uint16_t GetGlobalLevel() { - static auto *logLevelCache = new LogLevelCache(textToLogLevel, LOG_LEVEL_MIN, PROP_GLOBAL_LOG_LEVEL); - return logLevelCache->getValue(); + string key = GetPropertyName(PROP_GLOBAL_LOG_LEVEL); + static LogLevelCache *levelCache = new LogLevelCache{{nullptr, 0xffffffff, ""}, LOG_LEVEL_MIN}; + static atomic_flag isFirstFlag = ATOMIC_FLAG_INIT; + int notLocked; + + if (!isFirstFlag.test_and_set() || CheckCache(&levelCache->cache)) { + notLocked = LockByProp(PROP_GLOBAL_LOG_LEVEL); + if (!notLocked) { + RefreshCacheBuf(&levelCache->cache, key.c_str()); + levelCache->logLevel = GetCacheLevel(levelCache->cache.propertyValue[0]); + UnlockByProp(PROP_GLOBAL_LOG_LEVEL); + return levelCache->logLevel; + } else { + LogLevelCache tmpCache = {{nullptr, 0xffffffff, ""}, LOG_LEVEL_MIN}; + RefreshCacheBuf(&tmpCache.cache, key.c_str()); + tmpCache.logLevel = GetCacheLevel(tmpCache.cache.propertyValue[0]); + return tmpCache.logLevel; + } + } else { + return levelCache->logLevel; + } } uint16_t GetDomainLevel(uint32_t domain) { - static auto *domainMap = new std::unordered_map(); + static unordered_map *domainMap = new unordered_map(); + unordered_map::iterator it; + string key = GetPropertyName(PROP_DOMAIN_LOG_LEVEL) + to_string(domain); + static shared_timed_mutex* mtx = new shared_timed_mutex; - std::decay::type::iterator it; { ReadLock lock(*mtx); it = domainMap->find(domain); } if (it == domainMap->end()) { // new domain InsertLock lock(*mtx); - it = domainMap->find(domain); // secured for two thread went across above condition - if (it == domainMap->end()) { - LogLevelCache* levelCache = new LogLevelCache(textToLogLevel, LOG_LEVEL_MIN, PROP_DOMAIN_LOG_LEVEL, - to_string(domain)); - auto result = domainMap->insert({ domain, levelCache }); - if (!result.second) { - std::cerr << "Can't insert new LogLevelCache for domain: " << domain << "\n"; - return LOG_LEVEL_MIN; - } - it = result.first; + LogLevelCache* levelCache = new LogLevelCache{{nullptr, 0xffffffff, ""}, LOG_LEVEL_MIN}; + RefreshCacheBuf(&levelCache->cache, key.c_str()); + levelCache->logLevel = GetCacheLevel(levelCache->cache.propertyValue[0]); + uint16_t lvl = levelCache->logLevel; + pair::iterator, bool> ret = domainMap->insert({ domain, levelCache }); + if (!ret.second) { + delete levelCache; + levelCache = nullptr; + } + return lvl; + } else { // existed domain + if (CheckCache(&it->second->cache)) { // changed + InsertLock lock(*mtx); + RefreshCacheBuf(&it->second->cache, key.c_str()); + it->second->logLevel = GetCacheLevel(it->second->cache.propertyValue[0]); + return it->second->logLevel; + } else { // not changed + return it->second->logLevel; } } - LogLevelCache* levelCache = it->second; - return levelCache->getValue(); } uint16_t GetTagLevel(const string& tag) { - static auto *tagMap = new std::unordered_map(); + static unordered_map *tagMap = new unordered_map(); + unordered_map::iterator it; + string key = GetPropertyName(PROP_TAG_LOG_LEVEL) + tag; + static shared_timed_mutex* mtx = new shared_timed_mutex; - std::decay::type::iterator it; { ReadLock lock(*mtx); it = tagMap->find(tag); } if (it == tagMap->end()) { // new tag InsertLock lock(*mtx); - it = tagMap->find(tag); // secured for two thread went across above condition - if (it == tagMap->end()) { - LogLevelCache* levelCache = new LogLevelCache(textToLogLevel, LOG_LEVEL_MIN, PROP_TAG_LOG_LEVEL, tag); - auto result = tagMap->insert({ tag, levelCache }); - if (!result.second) { - std::cerr << "Can't insert new LogLevelCache for tag: " << tag << "\n"; - return LOG_LEVEL_MIN; - } - it = result.first; + LogLevelCache* levelCache = new LogLevelCache{{nullptr, 0xffffffff, ""}, LOG_LEVEL_MIN}; + RefreshCacheBuf(&levelCache->cache, key.c_str()); + levelCache->logLevel = GetCacheLevel(levelCache->cache.propertyValue[0]); + uint16_t lvl = levelCache->logLevel; + pair::iterator, bool> ret = tagMap->insert({ tag, levelCache }); + if (!ret.second) { + delete(levelCache); + levelCache = nullptr; + } + return lvl; + } else { // existed tag + if (CheckCache(&it->second->cache)) { // changed + InsertLock lock(*mtx); + RefreshCacheBuf(&it->second->cache, key.c_str()); + it->second->logLevel = GetCacheLevel(it->second->cache.propertyValue[0]); + return it->second->logLevel; + } else { // not changed + return it->second->logLevel; } } - LogLevelCache* levelCache = it->second; - return levelCache->getValue(); } diff --git a/interfaces/native/innerkits/include/hilog_base/log_base.h b/interfaces/native/innerkits/include/hilog_base/log_base.h index 9ac15c4..d51e2eb 100644 --- a/interfaces/native/innerkits/include/hilog_base/log_base.h +++ b/interfaces/native/innerkits/include/hilog_base/log_base.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef HIVIEWDFX_HILOG_BASE_C_H -#define HIVIEWDFX_HILOG_BASE_C_H +#ifndef HIVIEWDFX_HILOG_C_H +#define HIVIEWDFX_HILOG_C_H #include #include @@ -74,4 +74,4 @@ bool HiLogBaseIsLoggable(unsigned int domain, const char *tag, LogLevel level); } #endif -#endif // HIVIEWDFX_HILOG_BASE_C_H +#endif // HIVIEWDFX_HILOG_C_H diff --git a/services/hilogd/etc/BUILD.gn b/services/hilogd/etc/BUILD.gn index 95420b7..1b1f0c1 100644 --- a/services/hilogd/etc/BUILD.gn +++ b/services/hilogd/etc/BUILD.gn @@ -15,8 +15,6 @@ import("//build/ohos.gni") group("hilogd_etc") { deps = [ - ":hilog.para", - ":hilog.para.dac", ":hilog_domains.conf", ":hilogd.cfg", ] @@ -34,17 +32,3 @@ ohos_prebuilt_etc("hilogd.cfg") { part_name = "hilog_service" subsystem_name = "hiviewdfx" } - -ohos_prebuilt_etc("hilog.para") { - source = "hilog.para" - relative_install_dir = "param" - part_name = "hilog_service" - subsystem_name = "hiviewdfx" -} - -ohos_prebuilt_etc("hilog.para.dac") { - source = "hilog.para.dac" - relative_install_dir = "param" - part_name = "hilog_service" - subsystem_name = "hiviewdfx" -} diff --git a/services/hilogd/etc/hilog.para b/services/hilogd/etc/hilog.para deleted file mode 100755 index 6d55603..0000000 --- a/services/hilogd/etc/hilog.para +++ /dev/null @@ -1,22 +0,0 @@ -# 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. - - -hilog.private.on=true -hilog.debug.on=false -persist.sys.hilog.kmsg.on=false -persist.sys.hilog.debug.on=false -hilog.flowctrl.pid.on=false -hilog.flowctrl.domain.on=false - -hilog.loggable.global=d diff --git a/services/hilogd/etc/hilog.para.dac b/services/hilogd/etc/hilog.para.dac deleted file mode 100755 index a970b98..0000000 --- a/services/hilogd/etc/hilog.para.dac +++ /dev/null @@ -1,16 +0,0 @@ -# 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. - - -hilog.="shell:log:755" -persist.sys.hilog.="shell:log:755" diff --git a/test/BUILD.gn b/test/BUILD.gn index 32bcf8a..a88c8fb 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -41,20 +41,3 @@ ohos_moduletest("HiLogNDKTest") { "//base/hiviewdfx/hilog/frameworks/native/include", ] } - -ohos_moduletest("HiLogAdapterTest") { - module_out_path = module_output_path - - sources = [ "moduletest/common/adapter_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "//base/hiviewdfx/hilog/adapter:libhilog_os_adapter", - "//third_party/googletest:gtest_main", - ] - - external_deps = [ "hilog_native:libhilog" ] - - include_dirs = [ "//base/hiviewdfx/hilog/adapter" ] -} diff --git a/test/moduletest/common/adapter_test.cpp b/test/moduletest/common/adapter_test.cpp deleted file mode 100644 index 336dd62..0000000 --- a/test/moduletest/common/adapter_test.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* - * 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 -#include -#include - -#include -#include -#include - -using namespace testing::ext; -using namespace std::chrono_literals; - -namespace { -class PropertiesTest : public testing::Test { -public: - static void SetUpTestCase() {} - static void TearDownTestCase() {} - void SetUp() {} - void TearDown() {} -}; - - -HWTEST_F(PropertiesTest, PropertiesTest1, TestSize.Level1) -{ - std::string key = "my_property"; - std::string value = "1234"; - PropertySet(key, value.data()); - - std::array prop = {0}; - PropertyGet(key, prop.data(), prop.size()); - - EXPECT_EQ(std::string(prop.data()), value); -} - -HWTEST_F(PropertiesTest, PropertiesTest2, TestSize.Level1) -{ - std::string key = "my_property"; - for (int i = 0; i < 10; ++i) { - std::string value = std::to_string(i); - PropertySet(key, value.data()); - - std::array prop = {0}; - PropertyGet(key, prop.data(), prop.size()); - - EXPECT_EQ(std::string(prop.data()), value); - } -} - -HWTEST_F(PropertiesTest, PropertiesInvalidParamsTest, TestSize.Level1) -{ - std::string key = "my_property"; - std::string value = "5678"; - PropertySet(key, value.data()); - - PropertyGet(key, nullptr, 0); - PropertySet(key, nullptr); - - std::array prop = {0}; - PropertyGet(key, prop.data(), prop.size()); - - EXPECT_EQ(std::string(prop.data()), value); -} - -HWTEST_F(PropertiesTest, PropertiesTooLongBufferTest, TestSize.Level1) -{ - std::string key = "my_property"; - std::string value = "5678"; - PropertySet(key, value.data()); - - std::array prop1 = {0}; - PropertyGet(key, prop1.data(), prop1.size()); - - std::string tooLongText = "0123456789"; - while (tooLongText.length() < HILOG_PROP_VALUE_MAX) { - tooLongText += tooLongText; - } - PropertySet(key, tooLongText.data()); - - std::array prop = {0}; - PropertyGet(key, prop.data(), prop.size()); - std::string currentValue = prop.data(); - EXPECT_EQ(currentValue, value); - EXPECT_NE(tooLongText, value); -} - -HWTEST_F(PropertiesTest, PropertiesNoKeyTest, TestSize.Level1) -{ - std::string key = "PropertiesNoKeyTest"; - - std::array prop = {0}; - PropertyGet(key, prop.data(), prop.size()); - - EXPECT_TRUE(std::string(prop.data()).empty()); -} - -HWTEST_F(PropertiesTest, SwitchTest, TestSize.Level1) -{ - PropertySet(GetPropertyName(PROP_PRIVATE), "true"); - PropertySet(GetPropertyName(PROP_PROCESS_FLOWCTRL), "true"); - PropertySet(GetPropertyName(PROP_DOMAIN_FLOWCTRL), "true"); - PropertySet(GetPropertyName(PROP_SINGLE_DEBUG), "true"); - PropertySet(GetPropertyName(PROP_KMSG), "true"); - PropertySet(GetPropertyName(PROP_PERSIST_DEBUG), "true"); - - EXPECT_TRUE(IsDebugOn()); - EXPECT_TRUE(IsSingleDebugOn()); - EXPECT_TRUE(IsPersistDebugOn()); - EXPECT_TRUE(IsPrivateSwitchOn()); - EXPECT_TRUE(IsProcessSwitchOn()); - EXPECT_TRUE(IsDomainSwitchOn()); - EXPECT_TRUE(IsKmsgSwitchOn()); - - PropertySet(GetPropertyName(PROP_PRIVATE), "false"); - PropertySet(GetPropertyName(PROP_PROCESS_FLOWCTRL), "false"); - PropertySet(GetPropertyName(PROP_DOMAIN_FLOWCTRL), "false"); - PropertySet(GetPropertyName(PROP_SINGLE_DEBUG), "false"); - PropertySet(GetPropertyName(PROP_KMSG), "false"); - PropertySet(GetPropertyName(PROP_PERSIST_DEBUG), "false"); - - EXPECT_FALSE(IsDebugOn()); - EXPECT_FALSE(IsSingleDebugOn()); - EXPECT_FALSE(IsPersistDebugOn()); - EXPECT_FALSE(IsPrivateSwitchOn()); - EXPECT_FALSE(IsProcessSwitchOn()); - EXPECT_FALSE(IsDomainSwitchOn()); - EXPECT_FALSE(IsKmsgSwitchOn()); - - PropertySet(GetPropertyName(PROP_SINGLE_DEBUG), "true"); - PropertySet(GetPropertyName(PROP_PERSIST_DEBUG), "false"); - EXPECT_TRUE(IsDebugOn()); - - PropertySet(GetPropertyName(PROP_SINGLE_DEBUG), "false"); - PropertySet(GetPropertyName(PROP_PERSIST_DEBUG), "true"); - EXPECT_TRUE(IsDebugOn()); -} - -HWTEST_F(PropertiesTest, LevelTest, TestSize.Level1) -{ - static const std::array charLevels = {"d", "D", "f", "F", "e", "E", "w", "W", "i", "I"}; - static const std::array expected = { - LOG_DEBUG, LOG_DEBUG, - LOG_FATAL, LOG_FATAL, - LOG_ERROR, LOG_ERROR, - LOG_WARN, LOG_WARN, - LOG_INFO, LOG_INFO, - }; - - for (size_t i = 0; i < charLevels.size(); ++i) { - PropertySet(GetPropertyName(PROP_GLOBAL_LOG_LEVEL), charLevels[i]); - EXPECT_EQ(GetGlobalLevel(), expected[i]); - } - PropertySet(GetPropertyName(PROP_GLOBAL_LOG_LEVEL), "z"); - EXPECT_EQ(GetGlobalLevel(), LOG_LEVEL_MIN); - - uint32_t domain = 12345; - for (size_t i = 0; i < charLevels.size(); ++i) { - PropertySet(GetPropertyName(PROP_DOMAIN_LOG_LEVEL) + std::to_string(domain), charLevels[i]); - EXPECT_EQ(GetDomainLevel(domain), expected[i]); - } - PropertySet(GetPropertyName(PROP_DOMAIN_LOG_LEVEL) + std::to_string(domain), "z"); - EXPECT_EQ(GetDomainLevel(domain), LOG_LEVEL_MIN); - - std::string tag = "test_tag"; - for (size_t i = 0; i < charLevels.size(); ++i) { - PropertySet(GetPropertyName(PROP_TAG_LOG_LEVEL) + tag, charLevels[i]); - EXPECT_EQ(GetTagLevel(tag), expected[i]); - } - PropertySet(GetPropertyName(PROP_TAG_LOG_LEVEL) + tag, "z"); - EXPECT_EQ(GetTagLevel(tag), LOG_LEVEL_MIN); -} -} // namespace -- Gitee