提交 5366820b 编写于 作者: O openharmony_ci 提交者: Gitee

!167 修改测试套以支持共享内存【master】

Merge pull request !167 from liushijiu/addshm
......@@ -61,6 +61,8 @@ static void GetClientInfo(ClientInfo &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,
};
......@@ -213,4 +215,4 @@ HWTEST_F(AieClientAsyncProcessFunctionTest, testAieClientAsyncProcessFunction020
HILOGI("[Test]testAieClientAsyncProcessFunction0201.");
bool isAsyncProcessInputInfoNull = GetRandomBool();
TestAieClientAsyncProcess(false, isAsyncProcessInputInfoNull, false, false);
}
\ No newline at end of file
}
......@@ -52,6 +52,8 @@ static void GetClientInfo(ClientInfo &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,
};
......@@ -235,4 +237,4 @@ HWTEST_F(AieClientDestroyFunctionTest, testAieClientDestroyFunction003, Function
{
HILOGI("[Test]testAieClientDestroyFunction003.");
TestAieClientDestroy(true);
}
\ No newline at end of file
}
......@@ -56,6 +56,8 @@ static void GetClientInfo(ClientInfo &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,
};
......@@ -195,4 +197,4 @@ HWTEST_F(AieClientInitFunctionTest, testAieClientInitFunction0301, Function | Me
HILOGI("[Test]testAieClientInitFunction0301.");
bool isAsync = GetRandomBool();
TestAieClientInit(CONFIG_DESCRIPTION, isAsync, false);
}
\ No newline at end of file
}
......@@ -55,6 +55,8 @@ static void GetClientInfo(ClientInfo &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,
};
......@@ -276,4 +278,4 @@ HWTEST_F(AieClientPrepareFunctionTest, testAieClientPrepareFunction0204, Functio
{
HILOGI("[Test]testAieClientPrepareFunction0204.");
TestAieClientPrepare(true, true, true, false, false);
}
\ No newline at end of file
}
......@@ -52,6 +52,8 @@ static void GetClientInfo(ClientInfo &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,
};
......@@ -225,4 +227,4 @@ HWTEST_F(AieClientReleaseFunctionTest, testAieClientReleaseFunction004, Function
{
HILOGI("[Test]testAieClientReleaseFunction004.");
TestAieClientRelease(true, true);
}
\ No newline at end of file
}
......@@ -60,6 +60,8 @@ static void GetClientInfo(ClientInfo &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,
};
......@@ -325,4 +327,4 @@ HWTEST_F(AieClientSetOptionFunctionTest, testAieClientSetOptionFunction0202, Fun
HILOGI("[Test]testAieClientSetOptionFunction0202.");
bool isAsync = GetRandomBool();
TestAieClientSetOptionWithoutPrepare(isAsync, false);
}
\ No newline at end of file
}
......@@ -56,6 +56,8 @@ static void GetClientInfo(ClientInfo &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,
};
......@@ -213,4 +215,4 @@ HWTEST_F(AieClientSyncProcessFunctionTest, testAieClientSyncProcessFunction0201,
HILOGI("[Test]testAieClientSyncProcessFunction0201.");
bool isSyncProcessInputInfoNull = GetRandomBool();
TestAieClientSyncProcess(true, isSyncProcessInputInfoNull, false, false);
}
\ No newline at end of file
}
......@@ -16,24 +16,15 @@
#ifndef SAMPLE_PLUGIN_1_H
#define SAMPLE_PLUGIN_1_H
#include <cstring>
#include "plugin/i_plugin.h"
namespace OHOS {
namespace AI {
class SamplePlugin1 : public IPlugin {
const long long ALG_VERSION = 1;
const char *ALG_NAME = "SAMPLE_PLUGIN_1";
const char * const PLUGIN_INFER_MODEL = "SYNC";
const char *DEFAULT_OPTION_DATA = "default option data";
unsigned char *optionData = nullptr;
int optionLength = 0;
public:
SamplePlugin1();
~SamplePlugin1();
~SamplePlugin1() override;
const long long GetVersion() const override;
......@@ -52,6 +43,9 @@ public:
int SetOption(int optionType, const DataInfo &inputInfo) override;
int GetOption(int optionType, const DataInfo &inputInfo, DataInfo &outputInfo) override;
private:
DataInfo optionData_ {};
};
}
}
......
......@@ -23,17 +23,10 @@
namespace OHOS {
namespace AI {
class SamplePlugin2 : public IPlugin {
const long long ALG_VERSION = 1;
const char *ALG_NAME = "SAMPLE_PLUGIN_2";
const char * const PLUGIN_INFER_MODEL = "ASYNC";
const char *DEFAULT_OPTION_DATA = "default option data";
unsigned char *optionData = nullptr;
int optionLength = 0;
public:
SamplePlugin2();
~SamplePlugin2();
~SamplePlugin2() override;
const long long GetVersion() const override;
......@@ -52,6 +45,9 @@ public:
int SetOption(int optionType, const DataInfo &inputInfo) override;
int GetOption(int optionType, const DataInfo &inputInfo, DataInfo &outputInfo) override;
private:
DataInfo optionData_ {};
};
}
}
......
......@@ -24,15 +24,53 @@
namespace OHOS {
namespace AI {
namespace {
constexpr long long ALG_VERSION = 1;
const char *ALG_NAME = "SAMPLE_PLUGIN_1";
const char * const PLUGIN_INFER_MODEL = "SYNC";
const char * const DEFAULT_PROCESS_STRING = "sample_plugin_1 SyncProcess default data";
void FreeDataInfo(DataInfo *dataInfo)
{
if (dataInfo != nullptr && dataInfo->data != nullptr) {
free(dataInfo->data);
dataInfo->data = nullptr;
dataInfo->length = 0;
}
}
int ReturnDataCopyOrDefaultData(const DataInfo &inputInfo, DataInfo &outputInfo)
{
errno_t retCode;
DataInfo sourceData {};
if (inputInfo.length <= 0 || inputInfo.data == nullptr) {
sourceData.data = reinterpret_cast<unsigned char*>(const_cast<char*>(DEFAULT_PROCESS_STRING));
sourceData.length = strlen(DEFAULT_PROCESS_STRING) + 1;
} else {
sourceData = inputInfo;
}
outputInfo.length = sourceData.length;
outputInfo.data = reinterpret_cast<unsigned char*>(malloc(sourceData.length));
if (outputInfo.data == nullptr) {
HILOGE("[SamplePlugin1]malloc failed.");
return RETCODE_FAILURE;
}
retCode = memcpy_s(outputInfo.data, outputInfo.length, sourceData.data, sourceData.length);
if (retCode != EOK) {
HILOGE("[SamplePlugin1]memcpy_s failed[%d].", retCode);
FreeDataInfo(&outputInfo);
return RETCODE_FAILURE;
}
return RETCODE_SUCCESS;
}
} // anonymous namespace
SamplePlugin1::SamplePlugin1() = default;
SamplePlugin1::~SamplePlugin1()
{
if (optionData != nullptr) {
free(optionData);
optionData = nullptr;
optionLength = 0;
}
FreeDataInfo(&optionData_);
}
const long long SamplePlugin1::GetVersion() const
......@@ -53,116 +91,53 @@ const char *SamplePlugin1::GetInferMode() const
int SamplePlugin1::SyncProcess(IRequest *request, IResponse *&response)
{
DataInfo inputInfo = request->GetMsg();
if (inputInfo.data != nullptr) {
HILOGE("[SamplePlugin2]inputInfo data is %p.", inputInfo.data);
if (inputInfo.data != nullptr && inputInfo.length <= 0) {
HILOGE("[SamplePlugin1]inputInfo data is invalid.");
return RETCODE_FAILURE;
}
response = IResponse::Create(request);
CHK_RET(response == nullptr, RETCODE_FAILURE);
const char *str = "sample_plugin_1 SyncProcess outputInfo";
char *outputData = const_cast<char*>(str);
int len = strlen(str) + 1;
DataInfo outputInfo = {
.data = (unsigned char*)outputData,
.length = len,
};
DataInfo outputInfo {};
int retCode = ReturnDataCopyOrDefaultData(inputInfo, outputInfo);
response->SetResult(outputInfo);
response->SetRetCode(RETCODE_SUCCESS);
return RETCODE_SUCCESS;
response->SetRetCode(retCode);
return retCode;
}
int SamplePlugin1::AsyncProcess(IRequest *request, IPluginCallback *callback)
{
DataInfo inputInfo = request->GetMsg();
if (inputInfo.data != nullptr) {
HILOGE("[SamplePlugin2]inputInfo data is %p.", inputInfo.data);
}
IResponse *response = IResponse::Create(request);
CHK_RET(response == nullptr, RETCODE_FAILURE);
const char *str = "sample_plugin_1 AsyncProcess outputInfo";
char *outputData = const_cast<char*>(str);
int len = strlen(str) + 1;
DataInfo outputInfo = {
.data = (unsigned char*)outputData,
.length = len,
};
response->SetResult(outputInfo);
response->SetRetCode(RETCODE_SUCCESS);
int retCode = callback->OnEvent(ON_PLUGIN_SUCCEED, response);
return retCode;
HILOGE("[SamplePlugin1]Sync plugin, can't run AsyncProcess.");
return RETCODE_FAILURE;
}
int SamplePlugin1::Prepare(long long transactionId, const DataInfo &inputInfo, DataInfo &outputInfo)
{
const char *str = "sample_plugin_1 Prepare outputInfo";
char *outputData = const_cast<char*>(str);
int len = strlen(str) + 1;
outputInfo = {
.data = (unsigned char*)outputData,
.length = len,
};
return RETCODE_SUCCESS;
return ReturnDataCopyOrDefaultData(inputInfo, outputInfo);
}
int SamplePlugin1::Release(bool isFullUnload, long long transactionId, const DataInfo &inputInfo)
{
if (optionData != nullptr) {
free(optionData);
optionData = nullptr;
optionLength = 0;
}
FreeDataInfo(&optionData_);
return RETCODE_SUCCESS;
}
int SamplePlugin1::SetOption(int optionType, const DataInfo &inputInfo)
{
if (optionData != nullptr) {
free(optionData);
optionData = nullptr;
optionLength = 0;
}
FreeDataInfo(&optionData_);
if (inputInfo.data == nullptr) {
return RETCODE_SUCCESS;
}
optionLength = inputInfo.length;
optionData = (unsigned char *)malloc(sizeof(unsigned char) * optionLength);
if (optionData == nullptr) {
HILOGE("[SamplePlugin1]Failed to request memory.");
return RETCODE_OUT_OF_MEMORY;
}
errno_t retCode = memcpy_s(optionData, optionLength, inputInfo.data, optionLength);
if (retCode != EOK) {
HILOGE("[SamplePlugin1]Failed to memory copy, retCode[%d].", retCode);
free(optionData);
optionData = nullptr;
return RETCODE_MEMORY_COPY_FAILURE;
}
return RETCODE_SUCCESS;
return ReturnDataCopyOrDefaultData(inputInfo, optionData_);
}
int SamplePlugin1::GetOption(int optionType, const DataInfo &inputInfo, DataInfo &outputInfo)
{
if (optionData == nullptr) {
optionLength = strlen(DEFAULT_OPTION_DATA) + 1;
optionData = (unsigned char *)malloc(sizeof(unsigned char) * optionLength);
if (optionData == nullptr) {
HILOGE("[SamplePlugin1]Failed to request memory.");
return RETCODE_OUT_OF_MEMORY;
}
errno_t retCode = memcpy_s(optionData, optionLength, DEFAULT_OPTION_DATA, optionLength);
if (retCode != EOK) {
HILOGE("[SamplePlugin1]Failed to memory copy, retCode[%d].", retCode);
free(optionData);
optionData = nullptr;
return RETCODE_MEMORY_COPY_FAILURE;
}
}
outputInfo = {
.data = optionData,
.length = optionLength
};
return RETCODE_SUCCESS;
return ReturnDataCopyOrDefaultData(optionData_, outputInfo);
}
PLUGIN_INTERFACE_IMPL(SamplePlugin1);
......
......@@ -24,15 +24,53 @@
namespace OHOS {
namespace AI {
namespace {
constexpr long long ALG_VERSION = 1;
const char *ALG_NAME = "SAMPLE_PLUGIN_2";
const char * const PLUGIN_INFER_MODEL = "ASYNC";
const char * const DEFAULT_PROCESS_STRING = "sample_plugin_2 AsyncProcess default data";
void FreeDataInfo(DataInfo *dataInfo)
{
if (dataInfo != nullptr && dataInfo->data != nullptr) {
free(dataInfo->data);
dataInfo->data = nullptr;
dataInfo->length = 0;
}
}
int ReturnDataCopyOrDefaultData(const DataInfo &inputInfo, DataInfo &outputInfo)
{
errno_t retCode;
DataInfo sourceData {};
if (inputInfo.length <= 0 || inputInfo.data == nullptr) {
sourceData.data = reinterpret_cast<unsigned char*>(const_cast<char*>(DEFAULT_PROCESS_STRING));
sourceData.length = strlen(DEFAULT_PROCESS_STRING) + 1;
} else {
sourceData = inputInfo;
}
outputInfo.length = sourceData.length;
outputInfo.data = reinterpret_cast<unsigned char*>(malloc(sourceData.length));
if (outputInfo.data == nullptr) {
HILOGE("[SamplePlugin2]malloc failed.");
return RETCODE_FAILURE;
}
retCode = memcpy_s(outputInfo.data, outputInfo.length, sourceData.data, sourceData.length);
if (retCode != EOK) {
HILOGE("[SamplePlugin2]memcpy_s failed[%d].", retCode);
FreeDataInfo(&outputInfo);
return RETCODE_FAILURE;
}
return RETCODE_SUCCESS;
}
} // anonymous namespace
SamplePlugin2::SamplePlugin2() = default;
SamplePlugin2::~SamplePlugin2()
{
if (optionData != nullptr) {
free(optionData);
optionData = nullptr;
optionLength = 0;
}
FreeDataInfo(&optionData_);
}
const long long SamplePlugin2::GetVersion() const
......@@ -52,117 +90,54 @@ const char *SamplePlugin2::GetInferMode() const
int SamplePlugin2::SyncProcess(IRequest *request, IResponse *&response)
{
DataInfo inputInfo = request->GetMsg();
if (inputInfo.data != nullptr) {
HILOGE("[SamplePlugin2]inputInfo data is %p.", inputInfo.data);
}
response = IResponse::Create(request);
CHK_RET(response == nullptr, RETCODE_FAILURE);
const char *str = "sample_plugin_2 Process outputInfo";
char *outputData = const_cast<char*>(str);
int len = strlen(str) + 1;
DataInfo outputInfo = {
.data = (unsigned char*)outputData,
.length = len,
};
response->SetResult(outputInfo);
response->SetRetCode(RETCODE_SUCCESS);
return RETCODE_SUCCESS;
HILOGE("[SamplePlugin2]Async plugin, can't run SyncProcess.");
return RETCODE_FAILURE;
}
int SamplePlugin2::AsyncProcess(IRequest *request, IPluginCallback *callback)
{
DataInfo inputInfo = request->GetMsg();
if (inputInfo.data != nullptr) {
HILOGE("[SamplePlugin2]inputInfo data is %p.", inputInfo.data);
if (inputInfo.data != nullptr && inputInfo.length <= 0) {
HILOGE("[SamplePlugin2]inputInfo data is invalid.");
return RETCODE_FAILURE;
}
IResponse *response = IResponse::Create(request);
CHK_RET(response == nullptr, RETCODE_FAILURE);
const char *str = "sample_plugin_2 AsyncProcess outputInfo";
char *outputData = const_cast<char*>(str);
int len = strlen(str) + 1;
DataInfo outputInfo = {
.data = (unsigned char*)outputData,
.length = len,
};
DataInfo outputInfo {};
int retCode = ReturnDataCopyOrDefaultData(inputInfo, outputInfo);
response->SetResult(outputInfo);
response->SetRetCode(RETCODE_SUCCESS);
int retCode = callback->OnEvent(ON_PLUGIN_SUCCEED, response);
return retCode;
response->SetRetCode(retCode);
return callback->OnEvent(ON_PLUGIN_SUCCEED, response);
}
int SamplePlugin2::Prepare(long long transactionId, const DataInfo &inputInfo, DataInfo &outputInfo)
{
const char *str = "sample_plugin_2 Prepare outputInfo";
char *outputData = const_cast<char*>(str);
int len = strlen(str) + 1;
outputInfo = {
.data = (unsigned char*)outputData,
.length = len,
};
return RETCODE_SUCCESS;
return ReturnDataCopyOrDefaultData(inputInfo, outputInfo);
}
int SamplePlugin2::Release(bool isFullUnload, long long transactionId, const DataInfo &inputInfo)
{
if (optionData != nullptr) {
free(optionData);
optionData = nullptr;
optionLength = 0;
}
FreeDataInfo(&optionData_);
return RETCODE_SUCCESS;
}
int SamplePlugin2::SetOption(int optionType, const DataInfo &inputInfo)
{
if (optionData != nullptr) {
free(optionData);
optionData = nullptr;
optionLength = 0;
}
FreeDataInfo(&optionData_);
if (inputInfo.data == nullptr) {
return RETCODE_SUCCESS;
}
optionLength = inputInfo.length;
optionData = (unsigned char *)malloc(sizeof(unsigned char) * optionLength);
if (optionData == nullptr) {
HILOGE("[SamplePlugin2]Failed to request memory.");
return RETCODE_OUT_OF_MEMORY;
}
errno_t retCode = memcpy_s(optionData, optionLength, inputInfo.data, optionLength);
if (retCode != EOK) {
HILOGE("[SamplePlugin2]Failed to memory copy, retCode[%d].", retCode);
free(optionData);
optionData = nullptr;
return RETCODE_MEMORY_COPY_FAILURE;
}
return RETCODE_SUCCESS;
return ReturnDataCopyOrDefaultData(inputInfo, optionData_);
}
int SamplePlugin2::GetOption(int optionType, const DataInfo &inputInfo, DataInfo &outputInfo)
{
if (optionData == nullptr) {
optionLength = strlen(DEFAULT_OPTION_DATA) + 1;
optionData = (unsigned char *)malloc(sizeof(unsigned char) * optionLength);
if (optionData == nullptr) {
HILOGE("[SamplePlugin1]Failed to request memory.");
return RETCODE_OUT_OF_MEMORY;
}
errno_t retCode = memcpy_s(optionData, optionLength, DEFAULT_OPTION_DATA, optionLength);
if (retCode != EOK) {
HILOGE("[SamplePlugin1]Failed to memory copy, retCode[%d].", retCode);
free(optionData);
optionData = nullptr;
return RETCODE_MEMORY_COPY_FAILURE;
}
}
outputInfo = {
.data = optionData,
.length = optionLength
};
return RETCODE_SUCCESS;
return ReturnDataCopyOrDefaultData(optionData_, outputInfo);
}
PLUGIN_INTERFACE_IMPL(SamplePlugin2);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册