提交 22f9c9e3 编写于 作者: O openharmony_ci 提交者: Gitee

!226 AI子系统ai engine用例代码优化,提交master

Merge pull request !226 from Gloria Yin/yinge20210519master
......@@ -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
......
......@@ -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<char*>(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<char*>(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<char*>(str);
int length = strlen(str) + 1;
dataInfo = {
.data = reinterpret_cast<unsigned char *>(data),
.length = length,
};
}
return dataInfo;
}
/**
* Tests AieClientAsyncProcess().
*
......
......@@ -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<char*>(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<char*>(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<char*>(str);
int length = strlen(str) + 1;
dataInfo = {
.data = reinterpret_cast<unsigned char *>(data),
.length = length,
};
}
return dataInfo;
}
/**
* Tests AieClientDestroy. Invoke sequence: AieClientInit-AieClientPrepare-AieClientSyncProcess/AieClientAsyncProcess
* -AieClientRelease-AieClientDestroy.
......
......@@ -20,6 +20,7 @@
#include <string>
#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<char*>(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<char*>(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);
......
......@@ -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<char*>(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<char*>(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<char*>(str);
int length = strlen(str) + 1;
dataInfo = {
.data = reinterpret_cast<unsigned char *>(data),
.length = length,
};
}
return dataInfo;
}
/**
* Tests the input parameters algorithmInfo and inputInfo in AieClientPrepare().
*
......
......@@ -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<char*>(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<char*>(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<char*>(str);
int length = strlen(str) + 1;
dataInfo = {
.data = reinterpret_cast<unsigned char *>(data),
.length = length,
};
}
return dataInfo;
}
/**
* Tests AieClientRelease.
* Invoke sequence: AieClientInit-AieClientPrepare-AieClientSyncProcess/AieClientAsyncProcess-AieClientRelease.
......
......@@ -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<char*>(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<char*>(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<char*>(str);
int length = strlen(str) + 1;
dataInfo = {
.data = reinterpret_cast<unsigned char *>(data),
.length = length,
};
}
return dataInfo;
}
/**
* Tests TestAieClientSetOption.
* Invoke sequence: AieClientInit-AieClientPrepare-AieClientSetOption-AieClientGetOption.
......
......@@ -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<char*>(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<char*>(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<char*>(str);
int length = strlen(str) + 1;
dataInfo = {
.data = reinterpret_cast<unsigned char *>(data),
.length = length,
};
}
return dataInfo;
}
/**
* Tests AieClientSyncProcess().
*
......
......@@ -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<char*>(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<char*>(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<char*>(str);
int length = strlen(str) + 1;
dataInfo = {
.data = reinterpret_cast<unsigned char *>(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<char *>(malloc(length));
dataInfo = {
.data = reinterpret_cast<unsigned char *>(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().
*
......
/*
* 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 <cstring>
#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<char*>(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<char*>(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<char*>(str);
int length = strlen(str) + 1;
dataInfo = {
.data = reinterpret_cast<unsigned char *>(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<char *>(malloc(length));
dataInfo = {
.data = reinterpret_cast<unsigned char *>(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
/*
* 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 <cstring>
#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
/*
* 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 <iostream>
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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册