diff --git a/ai_lite/ai_engine_posix/base/BUILD.gn b/ai_lite/ai_engine_posix/base/BUILD.gn index 1d35bc3aabef6c3bfb4e30c9ee2fd16935fd8902..44e4405731ac51f1e0edb71aeabe7671a89ba428 100644 --- a/ai_lite/ai_engine_posix/base/BUILD.gn +++ b/ai_lite/ai_engine_posix/base/BUILD.gn @@ -17,6 +17,7 @@ hcpptest_suite("ActsAiEngineTest") { suite_name = "acts" sources = [ # Utils files + "src/utils/aie_client_common.cpp", "src/utils/utils.cpp", # AieClient Function Test Cases diff --git a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientAsyncProcessFunctionTest.cpp b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientAsyncProcessFunctionTest.cpp index ebcc51cbbecfc8bd9f92282b2f0332ced1e36214..704b1b4d5b9e1fed48e0ceddc8e6806a9af3f51c 100644 --- a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientAsyncProcessFunctionTest.cpp +++ b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientAsyncProcessFunctionTest.cpp @@ -24,6 +24,7 @@ #include "protocol/struct_definition/aie_info_define.h" #include "server_executor/include/server_executor.h" #include "utils/aie_client_callback.h" +#include "utils/aie_client_common.h" #include "utils/aie_client_const.h" #include "utils/aie_macros.h" #include "utils/log/aie_log.h" @@ -40,82 +41,6 @@ namespace { class AieClientAsyncProcessFunctionTest : public testing::Test {}; -/** - * Constructs ConfigInfo parameters. - */ -static void GetConfigInfo(ConfigInfo &configInfo) -{ - configInfo = {.description = CONFIG_DESCRIPTION}; -} - -/** - * Constructs ClientInfo parameters. - */ -static void GetClientInfo(ClientInfo &clientInfo) -{ - const char *str = CLIENT_EXTEND_MSG; - char *extendMsg = const_cast(str); - int len = strlen(str) + 1; - - clientInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .clientId = INVALID_CLIENT_ID, - .sessionId = INVALID_SESSION_ID, - .serverUid = INVALID_UID, - .clientUid = INVALID_UID, - .extendLen = len, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs AlgorithmInfo parameters. - */ -static void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) -{ - const char *str = ALGORITHM_EXTEND_MSG; - char *extendMsg = const_cast(str); - int extendLen = strlen(str) + 1; - - algorithmInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .isAsync = isAsync, - .algorithmType = algorithmType, - .algorithmVersion = ALGORITHM_VERSION_VALID, - .isCloud = GetRandomBool(), - .operateId = GetRandomInt(65535), - .requestId = GetRandomInt(65535), - .extendLen = extendLen, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs DataInfo. - */ -static DataInfo GetDataInfo(bool isDataInfoNull = true, const char *dataString = DATA_INFO_DEFAULT) -{ - // Sets default dataInfo to null. - DataInfo dataInfo = { - .data = nullptr, - .length = 0, - }; - - // Sets dataInfo to specified value. - if (!isDataInfoNull) { - const char *str = dataString; - char *data = const_cast(str); - int length = strlen(str) + 1; - - dataInfo = { - .data = reinterpret_cast(data), - .length = length, - }; - } - - return dataInfo; -} - /** * Tests AieClientAsyncProcess(). * diff --git a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientDestroyFunctionTest.cpp b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientDestroyFunctionTest.cpp index ba37afdd9586f122e116ece641ee042f606b74b0..a10bb26a0aaf9e6d3bec22f3d4a13aadbbb14247 100644 --- a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientDestroyFunctionTest.cpp +++ b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientDestroyFunctionTest.cpp @@ -20,6 +20,7 @@ #include "client_executor/include/i_aie_client.inl" #include "protocol/struct_definition/aie_info_define.h" #include "utils/aie_client_callback.h" +#include "utils/aie_client_common.h" #include "utils/aie_client_const.h" #include "utils/log/aie_log.h" #include "utils/service_dead_cb.h" @@ -31,82 +32,6 @@ using namespace OHOS::AI; class AieClientDestroyFunctionTest : public testing::Test {}; -/** - * Constructs ConfigInfo parameters. - */ -static void GetConfigInfo(ConfigInfo &configInfo) -{ - configInfo = {.description = CONFIG_DESCRIPTION}; -} - -/** - * Constructs ClientInfo parameters. - */ -static void GetClientInfo(ClientInfo &clientInfo) -{ - const char *str = CLIENT_EXTEND_MSG; - char *extendMsg = const_cast(str); - int len = strlen(str) + 1; - - clientInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .clientId = INVALID_CLIENT_ID, - .sessionId = INVALID_SESSION_ID, - .serverUid = INVALID_UID, - .clientUid = INVALID_UID, - .extendLen = len, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs AlgorithmInfo parameters. - */ -static void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) -{ - const char *str = ALGORITHM_EXTEND_MSG; - char *extendMsg = const_cast(str); - int extendLen = strlen(str) + 1; - - algorithmInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .isAsync = isAsync, - .algorithmType = algorithmType, - .algorithmVersion = ALGORITHM_VERSION_VALID, - .isCloud = GetRandomBool(), - .operateId = GetRandomInt(65535), - .requestId = GetRandomInt(65535), - .extendLen = extendLen, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs DataInfo. - */ -static DataInfo GetDataInfo(bool isDataInfoNull = true, const char* dataString = DATA_INFO_DEFAULT) -{ - // Sets default dataInfo to null. - DataInfo dataInfo = { - .data = nullptr, - .length = 0, - }; - - // Sets dataInfo to specified value. - if (!isDataInfoNull) { - const char *str = dataString; - char *data = const_cast(str); - int length = strlen(str) + 1; - - dataInfo = { - .data = reinterpret_cast(data), - .length = length, - }; - } - - return dataInfo; -} - /** * Tests AieClientDestroy. Invoke sequence: AieClientInit-AieClientPrepare-AieClientSyncProcess/AieClientAsyncProcess * -AieClientRelease-AieClientDestroy. diff --git a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientInitFunctionTest.cpp b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientInitFunctionTest.cpp index c7db5ccd35bbc84d924df9def5668e3e2eea17da..25cdcb5b7f8a5872977fb05fa10b4e5651adab43 100644 --- a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientInitFunctionTest.cpp +++ b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientInitFunctionTest.cpp @@ -20,6 +20,7 @@ #include #include "client_executor/include/i_aie_client.inl" +#include "utils/aie_client_common.h" #include "utils/aie_client_const.h" #include "utils/service_dead_cb.h" #include "utils/utils.h" @@ -35,56 +36,6 @@ namespace { class AieClientInitFunctionTest : public testing::Test {}; -/** - * Constructs ConfigInfo parameters. - */ -static void GetConfigInfo(ConfigInfo &configInfo, const char *description) -{ - configInfo = {.description = description}; -} - -/** - * Constructs ClientInfo parameters. - */ -static void GetClientInfo(ClientInfo &clientInfo) -{ - const char *str = CLIENT_EXTEND_MSG; - char *extendMsg = const_cast(str); - int len = strlen(str) + 1; - - clientInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .clientId = INVALID_CLIENT_ID, - .sessionId = INVALID_SESSION_ID, - .serverUid = INVALID_UID, - .clientUid = INVALID_UID, - .extendLen = len, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs AlgorithmInfo parameters. - */ -static void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) -{ - const char *str = ALGORITHM_EXTEND_MSG; - char *extendMsg = const_cast(str); - int extendLen = strlen(str) + 1; - - algorithmInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .isAsync = isAsync, - .algorithmType = algorithmType, - .algorithmVersion = ALGORITHM_VERSION_VALID, - .isCloud = GetRandomBool(), - .operateId = GetRandomInt(65535), - .requestId = GetRandomInt(65535), - .extendLen = extendLen, - .extendMsg = (unsigned char*)extendMsg, - }; -} - /** * Tests AieClientInit. * @@ -96,7 +47,7 @@ static void TestAieClientInit(const char *configDesc, bool isAsync, bool isDeadC { // Step 0: Defines variables. ConfigInfo configInfo; - GetConfigInfo(configInfo, configDesc); + GetConfigInfo2(configInfo, configDesc); ClientInfo clientInfo; GetClientInfo(clientInfo); diff --git a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientPrepareFunctionTest.cpp b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientPrepareFunctionTest.cpp index 8fad5d6cb0f97d07c6885c0a508d0f14ea9c7a00..79ee67ddbfb9d67fba7a076d626cdee2f722faa5 100644 --- a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientPrepareFunctionTest.cpp +++ b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientPrepareFunctionTest.cpp @@ -21,6 +21,7 @@ #include "protocol/retcode_inner/aie_retcode_inner.h" #include "server_executor/include/server_executor.h" #include "utils/aie_client_callback.h" +#include "utils/aie_client_common.h" #include "utils/aie_client_const.h" #include "utils/aie_macros.h" #include "utils/constants/constants.h" @@ -34,82 +35,6 @@ using namespace OHOS::AI; class AieClientPrepareFunctionTest : public testing::Test {}; -/** - * Constructs ConfigInfo parameters. - */ -static void GetConfigInfo(ConfigInfo &configInfo) -{ - configInfo = {.description = CONFIG_DESCRIPTION}; -} - -/** - * Constructs ClientInfo parameters. - */ -static void GetClientInfo(ClientInfo &clientInfo) -{ - const char *str = CLIENT_EXTEND_MSG; - char *extendMsg = const_cast(str); - int len = strlen(str) + 1; - - clientInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .clientId = INVALID_CLIENT_ID, - .sessionId = INVALID_SESSION_ID, - .serverUid = INVALID_UID, - .clientUid = INVALID_UID, - .extendLen = len, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs AlgorithmInfo parameters. - */ -static void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) -{ - const char *str = ALGORITHM_EXTEND_MSG; - char *extendMsg = const_cast(str); - int extendLen = strlen(str) + 1; - - algorithmInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .isAsync = isAsync, - .algorithmType = algorithmType, - .algorithmVersion = ALGORITHM_VERSION_VALID, - .isCloud = GetRandomBool(), - .operateId = GetRandomInt(65535), - .requestId = GetRandomInt(65535), - .extendLen = extendLen, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs DataInfo. - */ -static DataInfo GetDataInfo(bool isDataInfoNull = true, const char *dataString = DATA_INFO_DEFAULT) -{ - // Sets default dataInfo to null. - DataInfo dataInfo = { - .data = nullptr, - .length = 0, - }; - - // Sets dataInfo to specified value. - if (!isDataInfoNull) { - const char *str = dataString; - char *data = const_cast(str); - int length = strlen(str) + 1; - - dataInfo = { - .data = reinterpret_cast(data), - .length = length, - }; - } - - return dataInfo; -} - /** * Tests the input parameters algorithmInfo and inputInfo in AieClientPrepare(). * @@ -278,4 +203,4 @@ HWTEST_F(AieClientPrepareFunctionTest, testAieClientPrepareFunction0204, Functio { HILOGI("[Test]testAieClientPrepareFunction0204."); TestAieClientPrepare(true, true, true, false, false); -} +} \ No newline at end of file diff --git a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientReleaseFunctionTest.cpp b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientReleaseFunctionTest.cpp index b9903238f40fad4b21e65c92911409c763486c63..8703ab913d1b4bd09027664b9be91b4ac7a90fc8 100644 --- a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientReleaseFunctionTest.cpp +++ b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientReleaseFunctionTest.cpp @@ -20,6 +20,7 @@ #include "client_executor/include/i_aie_client.inl" #include "protocol/struct_definition/aie_info_define.h" #include "utils/aie_client_callback.h" +#include "utils/aie_client_common.h" #include "utils/aie_client_const.h" #include "utils/log/aie_log.h" #include "utils/service_dead_cb.h" @@ -31,82 +32,6 @@ using namespace OHOS::AI; class AieClientReleaseFunctionTest : public testing::Test {}; -/** - * Constructs ConfigInfo parameters. - */ -static void GetConfigInfo(ConfigInfo &configInfo) -{ - configInfo = {.description = CONFIG_DESCRIPTION}; -} - -/** - * Constructs ClientInfo parameters. - */ -static void GetClientInfo(ClientInfo &clientInfo) -{ - const char *str = CLIENT_EXTEND_MSG; - char *extendMsg = const_cast(str); - int len = strlen(str) + 1; - - clientInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .clientId = INVALID_CLIENT_ID, - .sessionId = INVALID_SESSION_ID, - .serverUid = INVALID_UID, - .clientUid = INVALID_UID, - .extendLen = len, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs AlgorithmInfo parameters. - */ -static void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) -{ - const char *str = ALGORITHM_EXTEND_MSG; - char *extendMsg = const_cast(str); - int extendLen = strlen(str) + 1; - - algorithmInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .isAsync = isAsync, - .algorithmType = algorithmType, - .algorithmVersion = ALGORITHM_VERSION_VALID, - .isCloud = GetRandomBool(), - .operateId = GetRandomInt(65535), - .requestId = GetRandomInt(65535), - .extendLen = extendLen, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs DataInfo. - */ -static DataInfo GetDataInfo(bool isDataInfoNull = true, const char* dataString = DATA_INFO_DEFAULT) -{ - // Sets default dataInfo to null. - DataInfo dataInfo = { - .data = nullptr, - .length = 0, - }; - - // Sets dataInfo to specified value. - if (!isDataInfoNull) { - const char *str = dataString; - char *data = const_cast(str); - int length = strlen(str) + 1; - - dataInfo = { - .data = reinterpret_cast(data), - .length = length, - }; - } - - return dataInfo; -} - /** * Tests AieClientRelease. * Invoke sequence: AieClientInit-AieClientPrepare-AieClientSyncProcess/AieClientAsyncProcess-AieClientRelease. @@ -227,4 +152,4 @@ HWTEST_F(AieClientReleaseFunctionTest, testAieClientReleaseFunction004, Function { HILOGI("[Test]testAieClientReleaseFunction004."); TestAieClientRelease(true, true); -} +} \ No newline at end of file diff --git a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSetOptionFunctionTest.cpp b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSetOptionFunctionTest.cpp index bcf5a31ab31100c0b8da8306ed3ffed56e67775d..9ec27f0e6312f14ed5898504dbeffcf8e7187d97 100644 --- a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSetOptionFunctionTest.cpp +++ b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSetOptionFunctionTest.cpp @@ -20,6 +20,7 @@ #include "client_executor/include/i_aie_client.inl" #include "protocol/retcode_inner/aie_retcode_inner.h" #include "utils/aie_client_callback.h" +#include "utils/aie_client_common.h" #include "utils/aie_client_const.h" #include "utils/aie_macros.h" #include "utils/log/aie_log.h" @@ -39,82 +40,6 @@ namespace { class AieClientSetOptionFunctionTest : public testing::Test {}; -/** - * Constructs ConfigInfo parameters. - */ -static void GetConfigInfo(ConfigInfo &configInfo) -{ - configInfo = {.description = CONFIG_DESCRIPTION}; -} - -/** - * Constructs ClientInfo parameters. - */ -static void GetClientInfo(ClientInfo &clientInfo) -{ - const char *str = CLIENT_EXTEND_MSG; - char *extendMsg = const_cast(str); - int len = strlen(str) + 1; - - clientInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .clientId = INVALID_CLIENT_ID, - .sessionId = INVALID_SESSION_ID, - .serverUid = INVALID_UID, - .clientUid = INVALID_UID, - .extendLen = len, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs AlgorithmInfo parameters. - */ -static void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) -{ - const char *str = ALGORITHM_EXTEND_MSG; - char *extendMsg = const_cast(str); - int extendLen = strlen(str) + 1; - - algorithmInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .isAsync = isAsync, - .algorithmType = algorithmType, - .algorithmVersion = ALGORITHM_VERSION_VALID, - .isCloud = GetRandomBool(), - .operateId = GetRandomInt(INT_LENGTH), - .requestId = GetRandomInt(INT_LENGTH), - .extendLen = extendLen, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs DataInfo. - */ -static DataInfo GetDataInfo(bool isDataInfoNull = true, const char* dataString = DATA_INFO_DEFAULT) -{ - // Sets default dataInfo to null. - DataInfo dataInfo = { - .data = nullptr, - .length = 0, - }; - - // Sets dataInfo to specified value. - if (!isDataInfoNull) { - const char *str = dataString; - char *data = const_cast(str); - int length = strlen(str) + 1; - - dataInfo = { - .data = reinterpret_cast(data), - .length = length, - }; - } - - return dataInfo; -} - /** * Tests TestAieClientSetOption. * Invoke sequence: AieClientInit-AieClientPrepare-AieClientSetOption-AieClientGetOption. @@ -327,4 +252,4 @@ HWTEST_F(AieClientSetOptionFunctionTest, testAieClientSetOptionFunction0202, Fun HILOGI("[Test]testAieClientSetOptionFunction0202."); bool isAsync = GetRandomBool(); TestAieClientSetOptionWithoutPrepare(isAsync, false); -} +} \ No newline at end of file diff --git a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessFunctionTest.cpp b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessFunctionTest.cpp index 09dfde2ccdb585b15088f7ab9bcc331b38dfc02f..54be57cfd37ceca383dd336cb5ebbccc80455e3d 100644 --- a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessFunctionTest.cpp +++ b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessFunctionTest.cpp @@ -20,6 +20,7 @@ #include "client_executor/include/i_aie_client.inl" #include "platform/time/include/time.h" #include "utils/aie_client_callback.h" +#include "utils/aie_client_common.h" #include "utils/aie_client_const.h" #include "utils/log/aie_log.h" #include "utils/service_dead_cb.h" @@ -35,82 +36,6 @@ namespace { class AieClientSyncProcessFunctionTest : public testing::Test {}; -/** - * Constructs ConfigInfo parameters. - */ -static void GetConfigInfo(ConfigInfo &configInfo) -{ - configInfo = {.description = CONFIG_DESCRIPTION}; -} - -/** - * Constructs ClientInfo parameters. - */ -static void GetClientInfo(ClientInfo &clientInfo) -{ - const char *str = CLIENT_EXTEND_MSG; - char *extendMsg = const_cast(str); - int len = strlen(str) + 1; - - clientInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .clientId = INVALID_CLIENT_ID, - .sessionId = INVALID_SESSION_ID, - .serverUid = INVALID_UID, - .clientUid = INVALID_UID, - .extendLen = len, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs AlgorithmInfo parameters. - */ -static void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) -{ - const char *str = ALGORITHM_EXTEND_MSG; - char *extendMsg = const_cast(str); - int extendLen = strlen(str) + 1; - - algorithmInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .isAsync = isAsync, - .algorithmType = algorithmType, - .algorithmVersion = ALGORITHM_VERSION_VALID, - .isCloud = GetRandomBool(), - .operateId = GetRandomInt(65535), - .requestId = GetRandomInt(65535), - .extendLen = extendLen, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs DataInfo. - */ -static DataInfo GetDataInfo(bool isDataInfoNull = true, const char* dataString = DATA_INFO_DEFAULT) -{ - // Sets default dataInfo to null. - DataInfo dataInfo = { - .data = nullptr, - .length = 0, - }; - - // Sets dataInfo to specified value. - if (!isDataInfoNull) { - const char *str = dataString; - char *data = const_cast(str); - int length = strlen(str) + 1; - - dataInfo = { - .data = reinterpret_cast(data), - .length = length, - }; - } - - return dataInfo; -} - /** * Tests AieClientSyncProcess(). * @@ -215,4 +140,4 @@ HWTEST_F(AieClientSyncProcessFunctionTest, testAieClientSyncProcessFunction0201, HILOGI("[Test]testAieClientSyncProcessFunction0201."); bool isSyncProcessInputInfoNull = GetRandomBool(); TestAieClientSyncProcess(true, isSyncProcessInputInfoNull, false, false); -} +} \ No newline at end of file diff --git a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessShareMemoryFunctionTest.cpp b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessShareMemoryFunctionTest.cpp index 4573c3dbe64eb418ebf6d0dec0a63cc32c75c20d..58ed1e1337d3c10ba0514b742d247dd269b93237 100644 --- a/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessShareMemoryFunctionTest.cpp +++ b/ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessShareMemoryFunctionTest.cpp @@ -20,6 +20,7 @@ #include "client_executor/include/i_aie_client.inl" #include "platform/time/include/time.h" #include "utils/aie_client_callback.h" +#include "utils/aie_client_common.h" #include "utils/aie_client_const.h" #include "utils/log/aie_log.h" #include "utils/service_dead_cb.h" @@ -31,132 +32,10 @@ using namespace OHOS::AI; namespace { const int WAIT_CALLBACK_TIME_MS = 2000; - const int INT_1 = 1; - const int INT_2 = 2; - const int INT_1024 = 1024; } class AieClientSyncProcessShareMemoryFunctionTest : public testing::Test {}; -/** - * Constructs ConfigInfo parameters. - */ -static void GetConfigInfo(ConfigInfo &configInfo) -{ - configInfo = {.description = CONFIG_DESCRIPTION}; -} - -/** - * Constructs ClientInfo parameters. - */ -static void GetClientInfo(ClientInfo &clientInfo) -{ - const char *str = CLIENT_EXTEND_MSG; - char *extendMsg = const_cast(str); - int len = strlen(str) + 1; - - clientInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .clientId = INVALID_CLIENT_ID, - .sessionId = INVALID_SESSION_ID, - .serverUid = INVALID_UID, - .clientUid = INVALID_UID, - .extendLen = len, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs AlgorithmInfo parameters. - */ -static void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) -{ - const char *str = ALGORITHM_EXTEND_MSG; - char *extendMsg = const_cast(str); - int extendLen = strlen(str) + 1; - - algorithmInfo = { - .clientVersion = CLIENT_VERSION_VALID, - .isAsync = isAsync, - .algorithmType = algorithmType, - .algorithmVersion = ALGORITHM_VERSION_VALID, - .isCloud = GetRandomBool(), - .operateId = GetRandomInt(65535), - .requestId = GetRandomInt(65535), - .extendLen = extendLen, - .extendMsg = (unsigned char*)extendMsg, - }; -} - -/** - * Constructs DataInfo. - */ -static DataInfo GetDataInfo(bool isDataInfoNull = true, const char* dataString = DATA_INFO_DEFAULT) -{ - // Sets default dataInfo to null. - DataInfo dataInfo = { - .data = nullptr, - .length = 0, - }; - - // Sets dataInfo to specified value. - if (!isDataInfoNull) { - const char *str = dataString; - char *data = const_cast(str); - int length = strlen(str) + 1; - - dataInfo = { - .data = reinterpret_cast(data), - .length = length, - }; - } - - return dataInfo; -} - -/** - * Constructs DataInfo with a big length data. - */ -static DataInfo GetBigDataInfo(bool isDataInfoNull = true) -{ - // Sets default dataInfo to null. - DataInfo dataInfo = { - .data = nullptr, - .length = 0, - }; - - // Sets dataInfo to specified value. - if (!isDataInfoNull) { - -#ifdef __LINUX__ - int length = INT_2 * INT_1024 * INT_1024; // 2 MB long data, the unit is Byte here. -#else // liteos device has no enough remaining memory to contain 2MB long data. - int length = INT_1 * INT_1024 * INT_1024; // 1 MB long data, the unit is Byte here. -#endif - - char *data = reinterpret_cast(malloc(length)); - - dataInfo = { - .data = reinterpret_cast(data), - .length = length, - }; - } - - return dataInfo; -} - -/** - * Release DataInfo. - */ -static void FreeDataInfo(DataInfo &dataInfo) -{ - if (dataInfo.data != nullptr) { - free(dataInfo.data); - dataInfo.data = nullptr; - dataInfo.length = 0; - } -} - /** * Tests AieClientSyncProcess(). * diff --git a/ai_lite/ai_engine_posix/base/src/utils/aie_client_common.cpp b/ai_lite/ai_engine_posix/base/src/utils/aie_client_common.cpp new file mode 100644 index 0000000000000000000000000000000000000000..11973a215782e2e448e57a55b094f6649e0fd833 --- /dev/null +++ b/ai_lite/ai_engine_posix/base/src/utils/aie_client_common.cpp @@ -0,0 +1,156 @@ +/* + * 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 "client_executor/include/i_aie_client.inl" +#include "utils/aie_client_const.h" +#include "utils/log/aie_log.h" +#include "utils/utils.h" + +using namespace OHOS::AI; + +namespace { + const int INT_1 = 1; + const int INT_2 = 2; + const int INT_1024 = 1024; + const int INT_65535 = 65535; +} + +/** + * Constructs ConfigInfo parameters. + */ +void GetConfigInfo(ConfigInfo &configInfo) +{ + configInfo = {.description = CONFIG_DESCRIPTION}; +} + +/** + * Constructs ConfigInfo parameters,including specified description. + */ +void GetConfigInfo2(ConfigInfo &configInfo, const char *description) +{ + configInfo = {.description = description}; +} + +/** + * Constructs ClientInfo parameters. + */ +void GetClientInfo(ClientInfo &clientInfo) +{ + const char *str = CLIENT_EXTEND_MSG; + char *extendMsg = const_cast(str); + int len = strlen(str) + 1; + + clientInfo = { + .clientVersion = CLIENT_VERSION_VALID, + .clientId = INVALID_CLIENT_ID, + .sessionId = INVALID_SESSION_ID, + .serverUid = INVALID_UID, + .clientUid = INVALID_UID, + .extendLen = len, + .extendMsg = (unsigned char*)extendMsg, + }; +} + +/** + * Constructs AlgorithmInfo parameters. + */ +void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType) +{ + const char *str = ALGORITHM_EXTEND_MSG; + char *extendMsg = const_cast(str); + int extendLen = strlen(str) + 1; + + algorithmInfo = { + .clientVersion = CLIENT_VERSION_VALID, + .isAsync = isAsync, + .algorithmType = algorithmType, + .algorithmVersion = ALGORITHM_VERSION_VALID, + .isCloud = GetRandomBool(), + .operateId = GetRandomInt(INT_65535), + .requestId = GetRandomInt(INT_65535), + .extendLen = extendLen, + .extendMsg = (unsigned char*)extendMsg, + }; +} + +/** + * Constructs DataInfo. + */ +DataInfo GetDataInfo(bool isDataInfoNull = true, const char *dataString = DATA_INFO_DEFAULT) +{ + // Sets default dataInfo to null. + DataInfo dataInfo = { + .data = nullptr, + .length = 0, + }; + + // Sets dataInfo to specified value. + if (!isDataInfoNull) { + const char *str = dataString; + char *data = const_cast(str); + int length = strlen(str) + 1; + + dataInfo = { + .data = reinterpret_cast(data), + .length = length, + }; + } + + return dataInfo; +} + +/** + * Constructs DataInfo with a big length data. + */ +DataInfo GetBigDataInfo(bool isDataInfoNull = true) +{ + // Sets default dataInfo to null. + DataInfo dataInfo = { + .data = nullptr, + .length = 0, + }; + + // Sets dataInfo to specified value. + if (!isDataInfoNull) { +#ifdef __LINUX__ + int length = INT_2 * INT_1024 * INT_1024; // 2 MB long data, the unit is Byte here. +#else // liteos device has no enough remaining memory to contain 2MB long data. + int length = INT_1 * INT_1024 * INT_1024; // 1 MB long data, the unit is Byte here. +#endif + + char *data = reinterpret_cast(malloc(length)); + + dataInfo = { + .data = reinterpret_cast(data), + .length = length, + }; + } + + return dataInfo; +} + +/** + * Release DataInfo. + */ +void FreeDataInfo(DataInfo &dataInfo) +{ + if (dataInfo.data != nullptr) { + free(dataInfo.data); + dataInfo.data = nullptr; + dataInfo.length = 0; + } +} \ No newline at end of file diff --git a/ai_lite/ai_engine_posix/base/src/utils/aie_client_common.h b/ai_lite/ai_engine_posix/base/src/utils/aie_client_common.h new file mode 100644 index 0000000000000000000000000000000000000000..008fb1dbf53fdfe12bd078e091aec0a5098f0281 --- /dev/null +++ b/ai_lite/ai_engine_posix/base/src/utils/aie_client_common.h @@ -0,0 +1,61 @@ +/* + * 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 AIE_CLIENT_COMMON_H +#define AIE_CLIENT_COMMON_H + +#include + +#include "client_executor/include/i_aie_client.inl" +#include "utils/aie_client_const.h" +#include "utils/log/aie_log.h" +#include "utils/utils.h" + +/** + * Constructs ConfigInfo parameters. + */ +void GetConfigInfo(ConfigInfo &configInfo); + +/** + * Constructs ConfigInfo parameters,including specified description. + */ +void GetConfigInfo2(ConfigInfo &configInfo, const char *description); + +/** + * Constructs ClientInfo parameters. + */ +void GetClientInfo(ClientInfo &clientInfo); + +/** + * Constructs AlgorithmInfo parameters. + */ +void GetSyncAlgorithmInfo(AlgorithmInfo &algorithmInfo, bool isAsync, int algorithmType); + +/** + * Constructs DataInfo. + */ +DataInfo GetDataInfo(bool isDataInfoNull = true, const char *dataString = DATA_INFO_DEFAULT); + +/** + * Constructs DataInfo with a big length data. + */ +DataInfo GetBigDataInfo(bool isDataInfoNull = true); + +/** + * Release DataInfo. + */ +void FreeDataInfo(DataInfo &dataInfo); + +#endif \ No newline at end of file diff --git a/ai_lite/ai_engine_posix/base/src/utils/aie_client_perf_baseline.h b/ai_lite/ai_engine_posix/base/src/utils/aie_client_perf_baseline.h deleted file mode 100644 index 9312b63d6a49f641635ef20dc59e88a64aa812f4..0000000000000000000000000000000000000000 --- a/ai_lite/ai_engine_posix/base/src/utils/aie_client_perf_baseline.h +++ /dev/null @@ -1,106 +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. - */ - -#ifndef AIE_CLIENT_PERF_BASELINE_H -#define AIE_CLIENT_PERF_BASELINE_H - -#include - -namespace AI_ENGINE_TEST { -/** - * Configures which type of device to be test. - */ -const int DEVICE_TYPE_L1 = 1; -const int DEVICE_TYPE_L2 = 2; -const int DEVICE_TYPE = DEVICE_TYPE_L1; - -/** - * PerfBaseline to test. - */ -struct PerfBaseline { - int T01; // us, AieClientInit - int T02; // us, AieClientPrepare - int T03; // us, AieClientASyncProcess - int T04; // us, AieClientSyncProcess - int T05; // us, AieClientRelease - int T06; // us, AieClientDestroy - int T07; // us, AieClientSetOption - int T08; // us, AieClientGetOption -}; - -const int PERF_BASELINE_L1_AIE_CLIENT_INIT = 100000; -const int PERF_BASELINE_L1_AIE_CLIENT_PREPARE = 300000; -const int PERF_BASELINE_L1_AIE_CLIENT_ASYNC_PROCESS = 150000; -const int PERF_BASELINE_L1_AIE_CLIENT_SYNC_PROCESS = 100000; -const int PERF_BASELINE_L1_AIE_CLIENT_RELEASE = 300000; -const int PERF_BASELINE_L1_AIE_CLIENT_DESTROY = 100000; -const int PERF_BASELINE_L1_AIE_CLIENT_SET_OPTION = 100000; -const int PERF_BASELINE_L1_AIE_CLIENT_GET_OPTION = 100000; - -PerfBaseline L1 = { - .T01 = PERF_BASELINE_L1_AIE_CLIENT_INIT, // us, AieClientInit - .T02 = PERF_BASELINE_L1_AIE_CLIENT_PREPARE, // us, AieClientPrepare - .T03 = PERF_BASELINE_L1_AIE_CLIENT_ASYNC_PROCESS, // us, AieClientASyncProcess - .T04 = PERF_BASELINE_L1_AIE_CLIENT_SYNC_PROCESS, // us, AieClientSyncProcess - .T05 = PERF_BASELINE_L1_AIE_CLIENT_RELEASE, // us, AieClientRelease - .T06 = PERF_BASELINE_L1_AIE_CLIENT_DESTROY, // us, AieClientDestroy - .T07 = PERF_BASELINE_L1_AIE_CLIENT_SET_OPTION, // us, AieClientSetOption - .T08 = PERF_BASELINE_L1_AIE_CLIENT_GET_OPTION, // us, AieClientGetOption -}; - -const int PERF_BASELINE_L2_AIE_CLIENT_INIT = 500; -const int PERF_BASELINE_L2_AIE_CLIENT_PREPARE = 500; -const int PERF_BASELINE_L2_AIE_CLIENT_ASYNC_PROCESS = 500; -const int PERF_BASELINE_L2_AIE_CLIENT_SYNC_PROCESS = 500; -const int PERF_BASELINE_L2_AIE_CLIENT_RELEASE = 500; -const int PERF_BASELINE_L2_AIE_CLIENT_DESTROY = 500; -const int PERF_BASELINE_L2_AIE_CLIENT_SET_OPTION = 500; -const int PERF_BASELINE_L2_AIE_CLIENT_GET_OPTION = 500; - -PerfBaseline L2 = { - .T01 = PERF_BASELINE_L2_AIE_CLIENT_INIT, // us, AieClientInit - .T02 = PERF_BASELINE_L2_AIE_CLIENT_PREPARE, // us, AieClientPrepare - .T03 = PERF_BASELINE_L2_AIE_CLIENT_ASYNC_PROCESS, // us, AieClientASyncProcess - .T04 = PERF_BASELINE_L2_AIE_CLIENT_SYNC_PROCESS, // us, AieClientSyncProcess - .T05 = PERF_BASELINE_L2_AIE_CLIENT_RELEASE, // us, AieClientRelease - .T06 = PERF_BASELINE_L2_AIE_CLIENT_DESTROY, // us, AieClientDestroy - .T07 = PERF_BASELINE_L2_AIE_CLIENT_SET_OPTION, // us, AieClientSetOption - .T08 = PERF_BASELINE_L2_AIE_CLIENT_GET_OPTION, // us, AieClientGetOption -}; - -/** - * Gets Performance BaseLine according to deviceType. - */ -PerfBaseline GetPerformanceBaseLine(int deviceType) -{ - PerfBaseline aieClientPerfBase; - switch (deviceType) { - case DEVICE_TYPE_L1: { - aieClientPerfBase = L1; - break; - } - case DEVICE_TYPE_L2: { - aieClientPerfBase = L2; - break; - } - default: { - aieClientPerfBase = L1; - break; - } - } - return aieClientPerfBase; -} -} -#endif // AIE_CLIENT_PERF_BASELINE_H \ No newline at end of file