From d0ccc88d06cf1587289376d9e23e334d48132531 Mon Sep 17 00:00:00 2001 From: wangyongzhong2 Date: Fri, 24 Nov 2023 18:15:58 +0800 Subject: [PATCH] code refine Signed-off-by: wangyongzhong2 --- frameworks/datatransmitmgr/dev_slinfo_adpt.c | 13 +++---- frameworks/datatransmitmgr/dev_slinfo_list.c | 5 ++- .../datatransmitmgr_fuzzer.cpp | 6 ---- .../datatransmitmgr_fuzzer.h | 7 ++++ .../datatransmitmgr_fuzzer/project.xml | 2 +- .../unittest/datatransmitmgr/DevSLMgrTest.cpp | 36 +++++++++++-------- test/unittest/datatransmitmgr/DevSLMgrTest.h | 21 ----------- 7 files changed, 36 insertions(+), 54 deletions(-) diff --git a/frameworks/datatransmitmgr/dev_slinfo_adpt.c b/frameworks/datatransmitmgr/dev_slinfo_adpt.c index bc7c90d..a7b4182 100644 --- a/frameworks/datatransmitmgr/dev_slinfo_adpt.c +++ b/frameworks/datatransmitmgr/dev_slinfo_adpt.c @@ -14,11 +14,8 @@ */ #include "dev_slinfo_adpt.h" - #include - #include "securec.h" - #include "dev_slinfo_list.h" #include "dev_slinfo_log.h" #include "dev_slinfo_mgr.h" @@ -47,7 +44,7 @@ static int32_t DlopenSDK(void) { g_deviceSecLevelHandle = dlopen("libdslm_sdk.z.so", RTLD_LAZY | RTLD_NODELETE); if (g_deviceSecLevelHandle == NULL) { - DATA_SEC_LOG_ERROR("Failed to load libdevicesecmgrsdktmp: %s", dlerror()); + DATA_SEC_LOG_ERROR("failed to load libdevicesecmgrsdktmp: %s", dlerror()); return DEVSL_ERROR; } @@ -69,7 +66,7 @@ static int32_t InitDeviceSecEnv(void) if (requestDeviceSecurityInfo == NULL) { dlclose(g_deviceSecLevelHandle); g_deviceSecLevelHandle = NULL; - DATA_SEC_LOG_ERROR("Failed to find symbol: %s", dlerror()); + DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); return DEVSL_ERROR; } FreeDeviceSecurityInfoFunction freeDeviceSecurityInfo = (FreeDeviceSecurityInfoFunction)dlsym( @@ -77,7 +74,7 @@ static int32_t InitDeviceSecEnv(void) if (freeDeviceSecurityInfo == NULL) { dlclose(g_deviceSecLevelHandle); g_deviceSecLevelHandle = NULL; - DATA_SEC_LOG_ERROR("Failed to find symbol: %s", dlerror()); + DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); return DEVSL_ERROR; } GetDeviceSecurityLevelValueFunction getDeviceSecurityLevelValue = (GetDeviceSecurityLevelValueFunction)dlsym( @@ -85,7 +82,7 @@ static int32_t InitDeviceSecEnv(void) if (getDeviceSecurityLevelValue == NULL) { dlclose(g_deviceSecLevelHandle); g_deviceSecLevelHandle = NULL; - DATA_SEC_LOG_ERROR("Failed to find symbol: %s", dlerror()); + DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); return DEVSL_ERROR; } RequestDeviceSecurityInfoAsyncFunction requestDeviceSecurityInfoAsync = @@ -93,7 +90,7 @@ static int32_t InitDeviceSecEnv(void) if (requestDeviceSecurityInfoAsync == NULL) { dlclose(g_deviceSecLevelHandle); g_deviceSecLevelHandle = NULL; - DATA_SEC_LOG_ERROR("Failed to find symbol: %s", dlerror()); + DATA_SEC_LOG_ERROR("failed to find symbol: %s", dlerror()); return DEVSL_ERROR; } (void)memset_s(&g_deviceSecEnv, sizeof(g_deviceSecEnv), 0, sizeof(g_deviceSecEnv)); diff --git a/frameworks/datatransmitmgr/dev_slinfo_list.c b/frameworks/datatransmitmgr/dev_slinfo_list.c index 0b8086e..165d744 100644 --- a/frameworks/datatransmitmgr/dev_slinfo_list.c +++ b/frameworks/datatransmitmgr/dev_slinfo_list.c @@ -14,10 +14,8 @@ */ #include "dev_slinfo_list.h" - #include #include "securec.h" - #include "dev_slinfo_adpt.h" #include "dev_slinfo_log.h" @@ -155,7 +153,8 @@ void LookupCallback(struct DATASLListParams *list, DEVSLQueryParams *queryParams int32_t InitPthreadMutex(void) { - int32_t ret = pthread_mutex_init(&g_mutex, NULL); + int32_t ret; + ret = pthread_mutex_init(&g_mutex, NULL); return ret; } diff --git a/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/datatransmitmgr_fuzzer.cpp b/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/datatransmitmgr_fuzzer.cpp index 961e4e6..c3fca28 100644 --- a/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/datatransmitmgr_fuzzer.cpp +++ b/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/datatransmitmgr_fuzzer.cpp @@ -15,16 +15,10 @@ #include "datatransmitmgr_fuzzer.h" -#include #include #include -#include -#include -#include -#include #include "securec.h" - #include "dev_slinfo_mgr.h" namespace OHOS { diff --git a/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/datatransmitmgr_fuzzer.h b/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/datatransmitmgr_fuzzer.h index 9bf7309..0a69ca9 100644 --- a/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/datatransmitmgr_fuzzer.h +++ b/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/datatransmitmgr_fuzzer.h @@ -16,6 +16,13 @@ #ifndef DATATRANSMITMGR_FUZZER_H #define DATATRANSMITMGR_FUZZER_H +#include +#include +#include +#include +#include +#include + #define FUZZ_PROJECT_NAME "datatransmitmgr_fuzzer" #endif \ No newline at end of file diff --git a/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/project.xml b/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/project.xml index 833d01c..db52ac0 100644 --- a/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/project.xml +++ b/test/fuzztest/datatransmitmgr/datatransmitmgr_fuzzer/project.xml @@ -18,7 +18,7 @@ 1000 - 300 + 30 4096 diff --git a/test/unittest/datatransmitmgr/DevSLMgrTest.cpp b/test/unittest/datatransmitmgr/DevSLMgrTest.cpp index 4b81f9e..2e5fd64 100644 --- a/test/unittest/datatransmitmgr/DevSLMgrTest.cpp +++ b/test/unittest/datatransmitmgr/DevSLMgrTest.cpp @@ -13,22 +13,33 @@ * limitations under the License. */ -#include "DevSLMgrTest.h" - -#include #include #include #include - -#include "accesstoken_kit.h" +#include +#include "gtest/gtest.h" #include "file_ex.h" -#include "nativetoken_kit.h" #include "securec.h" #include "softbus_bus_center.h" +#include "dev_slinfo_adpt.h" +#include "DevSLMgrTest.h" +#include "DevslinfoListTest.h" +#include "nativetoken_kit.h" #include "token_setproc.h" +#include "accesstoken_kit.h" -#include "DevslinfoListTest.h" -#include "dev_slinfo_adpt.h" +using namespace testing::ext; +class DevSLMgrTest : public testing::Test { +public: + DevSLMgrTest(); + ~DevSLMgrTest(); + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +private: + static bool isEnforcing_; +}; static const int32_t DEV_SEC_LEVEL_ERR = 100; static const int32_t LIST_LENGTH = 128; @@ -42,9 +53,7 @@ struct DeviceSecurityInfo { extern "C" { extern void OnApiDeviceSecInfoCallback(const DeviceIdentify *identify, struct DeviceSecurityInfo *info); } -namespace OHOS { -namespace Security { -namespace DevSLMgrTest { + static void NativeTokenGet() { uint64_t tokenId; @@ -468,7 +477,4 @@ static HWTEST_F(DevSLMgrTest, TestGetHighestSecLevelExcept005, TestSize.Level1) ClearList(g_tmpList); g_tmpList = nullptr; DATASL_OnStop(); -} -} // namespace DevSLMgrTest -} // namespace Security -} // namespace OHOS \ No newline at end of file +} \ No newline at end of file diff --git a/test/unittest/datatransmitmgr/DevSLMgrTest.h b/test/unittest/datatransmitmgr/DevSLMgrTest.h index 27d35b2..472e5d2 100644 --- a/test/unittest/datatransmitmgr/DevSLMgrTest.h +++ b/test/unittest/datatransmitmgr/DevSLMgrTest.h @@ -16,25 +16,4 @@ #ifndef DATASECURITYLEVEL_TEST_H #define DATASECURITYLEVEL_TEST_H -#include - -namespace OHOS { -namespace Security { -namespace DevSLMgrTest { -using namespace testing::ext; -class DevSLMgrTest : public testing::Test { -public: - DevSLMgrTest(); - ~DevSLMgrTest(); - static void SetUpTestCase(); - static void TearDownTestCase(); - void SetUp() override; - void TearDown() override; -private: - static bool isEnforcing_; -}; -} // namespace DevSLMgrTest -} // namespace Security -} // namespace OHOS - #endif \ No newline at end of file -- Gitee