Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Xts Acts
提交
81fb2f6b
X
Xts Acts
项目概览
OpenHarmony
/
Xts Acts
1 年多 前同步成功
通知
9
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
X
Xts Acts
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
81fb2f6b
编写于
5月 17, 2021
作者:
O
openharmony_ci
提交者:
Gitee
5月 17, 2021
浏览文件
操作
浏览文件
下载
差异文件
!207 AI子系统用例从master同步到release
Merge pull request !207 from Gloria Yin/20210517yinge
上级
c14c50a6
468dc30a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
715 addition
and
5 deletion
+715
-5
ai_lite/ai_engine_posix/base/BUILD.gn
ai_lite/ai_engine_posix/base/BUILD.gn
+3
-2
ai_lite/ai_engine_posix/base/Test.json
ai_lite/ai_engine_posix/base/Test.json
+2
-2
ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessShareMemoryFunctionTest.cpp
...ie_client/AieClientSyncProcessShareMemoryFunctionTest.cpp
+246
-0
ai_lite/ai_engine_posix/base/src/sample/BUILD.gn
ai_lite/ai_engine_posix/base/src/sample/BUILD.gn
+64
-0
ai_lite/ai_engine_posix/base/src/sample/include/sample_plugin_1.h
...ai_engine_posix/base/src/sample/include/sample_plugin_1.h
+53
-0
ai_lite/ai_engine_posix/base/src/sample/include/sample_plugin_2.h
...ai_engine_posix/base/src/sample/include/sample_plugin_2.h
+55
-0
ai_lite/ai_engine_posix/base/src/sample/source/sample_plugin_1.cpp
...i_engine_posix/base/src/sample/source/sample_plugin_1.cpp
+145
-0
ai_lite/ai_engine_posix/base/src/sample/source/sample_plugin_2.cpp
...i_engine_posix/base/src/sample/source/sample_plugin_2.cpp
+145
-0
build_lite/BUILD.gn
build_lite/BUILD.gn
+2
-1
未找到文件。
ai_lite/ai_engine_posix/base/BUILD.gn
浏览文件 @
81fb2f6b
...
...
@@ -27,6 +27,7 @@ hcpptest_suite("ActsAiEngineTest") {
"src/aie_client/AieClientReleaseFunctionTest.cpp",
"src/aie_client/AieClientSetOptionFunctionTest.cpp",
"src/aie_client/AieClientSyncProcessFunctionTest.cpp",
"src/aie_client/AieClientSyncProcessShareMemoryFunctionTest.cpp",
# pluginManager Function Test Cases
"src/plugin_manager/PluginManagerFunctionTest.cpp",
...
...
@@ -57,9 +58,9 @@ hcpptest_suite("ActsAiEngineTest") {
"//foundation/ai/engine/services/client:client",
"//foundation/ai/engine/services/common/platform/dl_operation:dlOperation",
"//foundation/ai/engine/services/server/plugin_manager:plugin_manager",
"//foundation/ai/engine/test/sample:sample_plugin_1",
"//foundation/ai/engine/test/sample:sample_plugin_2",
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
"//test/xts/acts/ai_lite/ai_engine_posix/base/src/sample:sample_plugin_1_sync",
"//test/xts/acts/ai_lite/ai_engine_posix/base/src/sample:sample_plugin_2_async",
]
cflags = [ "-Wno-error" ]
ldflags = [ "-lstdc++" ]
...
...
ai_lite/ai_engine_posix/base/Test.json
浏览文件 @
81fb2f6b
...
...
@@ -13,13 +13,13 @@
"mount"
:
[
{
"source"
:
"testcases/ai"
,
"target"
:
"/test_root/ai/engine"
"target"
:
"/test_root/ai/
ai_
engine"
}
]
}
],
"driver"
:
{
"type"
:
"CppTestLite"
,
"execute"
:
"/test_root/ai/engine/ActsAiEngineTest.bin"
"execute"
:
"/test_root/ai/
ai_
engine/ActsAiEngineTest.bin"
}
}
\ No newline at end of file
ai_lite/ai_engine_posix/base/src/aie_client/AieClientSyncProcessShareMemoryFunctionTest.cpp
0 → 100644
浏览文件 @
81fb2f6b
/*
* 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 "gtest/gtest.h"
#include <cstring>
#include <unistd.h>
#include "client_executor/include/i_aie_client.inl"
#include "platform/time/include/time.h"
#include "utils/aie_client_callback.h"
#include "utils/aie_client_const.h"
#include "utils/log/aie_log.h"
#include "utils/service_dead_cb.h"
#include "utils/utils.h"
using
namespace
::
testing
;
using
namespace
testing
::
ext
;
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().
*
* isAsync The value of the input parameter AlgorithmInfo.isAsync of AieClientInit.
* isSyncProcessInputInfoNull Whether the input parameter InputInfo of AieClientSyncProcess is null or not.
* isSyncProcessSuccess Whether the expected result of AieClientSyncProcess is successful or not.
* isExpectedSyncProcessOutputInfoNotNull Whether the expected cb of AieClientSyncProcess is not null or not.
*/
static
void
TestAieClientSyncProcess
(
bool
isAsync
,
bool
isSyncProcessInputInfoNull
,
bool
isSyncProcessSuccess
,
bool
isExpectedSyncProcessOutputInfoNotNull
)
{
// Step 0: Defines variables.
ConfigInfo
configInfo
;
GetConfigInfo
(
configInfo
);
ClientInfo
clientInfo
;
GetClientInfo
(
clientInfo
);
AlgorithmInfo
algorithmInfo
;
int
algorithmType
=
isAsync
?
ALGORITHM_TYPE_ASYNC
:
ALGORITHM_TYPE_SYNC
;
GetSyncAlgorithmInfo
(
algorithmInfo
,
isAsync
,
algorithmType
);
ServiceDeadCb
*
cb
=
nullptr
;
AIE_NEW
(
cb
,
ServiceDeadCb
());
// Step 1: Invokes AieClientInit.
int
initReturnCode
=
AieClientInit
(
configInfo
,
clientInfo
,
algorithmInfo
,
cb
);
EXPECT_EQ
(
RETCODE_SUCCESS
,
initReturnCode
)
<<
"AieClientInit is failed!"
;
EXPECT_EQ
(
true
,
clientInfo
.
clientId
>
0
)
<<
"clientId("
<<
std
::
to_string
(
clientInfo
.
clientId
)
<<
") is incorrect!"
;
EXPECT_EQ
(
true
,
clientInfo
.
sessionId
>
0
)
<<
"sessionId("
<<
std
::
to_string
(
clientInfo
.
sessionId
)
<<
") is incorrect!"
;
// Step 2: Invokes AieClientPrepare.
bool
isPrepareInputInfoNull
=
GetRandomBool
();
DataInfo
prepareInputInfo
=
GetDataInfo
(
isPrepareInputInfoNull
,
INPUT_INFO_PREPARE
);
DataInfo
prepareOutputInfo
=
GetDataInfo
();
ClientCallback
*
callback
=
nullptr
;
if
(
isAsync
)
{
AIE_NEW
(
callback
,
ClientCallback
());
}
int
prepareReturnCode
=
AieClientPrepare
(
clientInfo
,
algorithmInfo
,
prepareInputInfo
,
prepareOutputInfo
,
callback
);
EXPECT_EQ
(
RETCODE_SUCCESS
,
prepareReturnCode
)
<<
"AieClientPrepare is failed!"
;
EXPECT_EQ
(
true
,
prepareOutputInfo
.
data
!=
nullptr
)
<<
"Prepare outputInfo is incorrect!"
;
// Step 3: Invokes AieClientSyncProcess.
DataInfo
syncProcessInputInfo
=
GetBigDataInfo
(
isSyncProcessInputInfoNull
);
DataInfo
syncProcessOutputInfo
=
GetDataInfo
();
int
syncProcessReturnCode
=
AieClientSyncProcess
(
clientInfo
,
algorithmInfo
,
syncProcessInputInfo
,
syncProcessOutputInfo
);
EXPECT_EQ
(
isSyncProcessSuccess
,
syncProcessReturnCode
==
RETCODE_SUCCESS
)
<<
"AieClientSyncProcess is failed!"
;
EXPECT_EQ
(
isExpectedSyncProcessOutputInfoNotNull
,
syncProcessOutputInfo
.
data
!=
nullptr
)
<<
"AieClientSyncProcess outputInfo is incorrect!"
;
// Step 4: Sleeps.
StepSleepMs
(
WAIT_CALLBACK_TIME_MS
);
// Step 5: Invokes AieClientRelease.
DataInfo
releaseInputInfo
=
GetDataInfo
(
false
,
INPUT_INFO_RELEASE
);
int
releaseReturnCode
=
AieClientRelease
(
clientInfo
,
algorithmInfo
,
releaseInputInfo
);
EXPECT_EQ
(
RETCODE_SUCCESS
,
releaseReturnCode
)
<<
"AieClientRelease is failed!"
;
// Step 6: Invokes AieClientDestroy.
int
destroyReturnCode
=
AieClientDestroy
(
clientInfo
);
EXPECT_EQ
(
RETCODE_SUCCESS
,
destroyReturnCode
)
<<
"AieClientDestroy is failed!"
;
// Step 7: Deletes callback.
AIE_DELETE
(
cb
);
AIE_DELETE
(
callback
);
// Step 8: Release data info.
FreeDataInfo
(
syncProcessInputInfo
);
FreeDataInfo
(
syncProcessOutputInfo
);
}
/**
* @tc.number : SUB_AI_AIDistributedAbility_HiAiEngine_Lite_Function_HiAiAPI_AIEClient_AieClientSyncProcessShareMemory_0100
* @tc.name : 01. algorithmInfo中isAsync=false,inputInfo不为空,调用AieClientSyncProcess返回成功_共享内存传大数据
* @tc.desc : [C- SOFTWARE -0200]
*/
HWTEST_F
(
AieClientSyncProcessShareMemoryFunctionTest
,
testAieClientSyncProcessShareMemoryFunction0101
,
Function
|
MediumTest
|
Level3
)
{
HILOGI
(
"[Test]testAieClientSyncProcessShareMemoryFunction0101."
);
TestAieClientSyncProcess
(
false
,
false
,
true
,
true
);
}
\ No newline at end of file
ai_lite/ai_engine_posix/base/src/sample/BUILD.gn
0 → 100644
浏览文件 @
81fb2f6b
# 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.
import("//build/lite/config/component/lite_component.gni")
source_set("syncDemoPluginCode") {
sources = [ "source/sample_plugin_1.cpp" ]
cflags = [ "-fPIC" ]
cflags_cc = cflags
include_dirs = [
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog",
"//foundation/ai/engine/services/common",
"//foundation/ai/engine/services/server",
"//foundation/ai/engine/test",
"//third_party/bounds_checking_function/include",
]
}
lite_component("sample_plugin_1_sync") {
target_type = "shared_library"
cflags = [ "-fPIC" ]
cflags_cc = cflags
features = [ ":syncDemoPluginCode" ]
deps = [
"//foundation/ai/engine/services/common/protocol/data_channel:data_channel",
]
}
source_set("asyncDemoPluginCode") {
sources = [ "source/sample_plugin_2.cpp" ]
cflags = [ "-fPIC" ]
cflags_cc = cflags
include_dirs = [
"//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog",
"//foundation/ai/engine/services/common",
"//foundation/ai/engine/services/server",
"//foundation/ai/engine/test",
"//third_party/bounds_checking_function/include",
]
}
lite_component("sample_plugin_2_async") {
target_type = "shared_library"
cflags = [ "-fPIC" ]
cflags_cc = cflags
features = [ ":asyncDemoPluginCode" ]
deps = [
"//foundation/ai/engine/services/common/protocol/data_channel:data_channel",
]
}
ai_lite/ai_engine_posix/base/src/sample/include/sample_plugin_1.h
0 → 100644
浏览文件 @
81fb2f6b
/*
* 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 SAMPLE_PLUGIN_1_H
#define SAMPLE_PLUGIN_1_H
#include "plugin/i_plugin.h"
namespace
OHOS
{
namespace
AI
{
class
SamplePlugin1
:
public
IPlugin
{
public:
SamplePlugin1
();
~
SamplePlugin1
()
override
;
const
long
long
GetVersion
()
const
override
;
const
char
*
GetName
()
const
override
;
const
char
*
GetInferMode
()
const
override
;
int
SyncProcess
(
IRequest
*
request
,
IResponse
*&
response
)
override
;
int
AsyncProcess
(
IRequest
*
request
,
IPluginCallback
*
callback
)
override
;
int
Prepare
(
long
long
transactionId
,
const
DataInfo
&
inputInfo
,
DataInfo
&
outputInfo
)
override
;
int
Release
(
bool
isFullUnload
,
long
long
transactionId
,
const
DataInfo
&
inputInfo
)
override
;
int
SetOption
(
int
optionType
,
const
DataInfo
&
inputInfo
)
override
;
int
GetOption
(
int
optionType
,
const
DataInfo
&
inputInfo
,
DataInfo
&
outputInfo
)
override
;
private:
DataInfo
optionData_
{};
};
}
}
#endif // SAMPLE_PLUGIN_1_H
ai_lite/ai_engine_posix/base/src/sample/include/sample_plugin_2.h
0 → 100644
浏览文件 @
81fb2f6b
/*
* 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 SAMPLE_PLUGIN_2_H
#define SAMPLE_PLUGIN_2_H
#include <cstring>
#include "plugin/i_plugin.h"
namespace
OHOS
{
namespace
AI
{
class
SamplePlugin2
:
public
IPlugin
{
public:
SamplePlugin2
();
~
SamplePlugin2
()
override
;
const
long
long
GetVersion
()
const
override
;
const
char
*
GetName
()
const
override
;
const
char
*
GetInferMode
()
const
override
;
int
SyncProcess
(
IRequest
*
request
,
IResponse
*&
response
)
override
;
int
AsyncProcess
(
IRequest
*
request
,
IPluginCallback
*
callback
)
override
;
int
Prepare
(
long
long
transactionId
,
const
DataInfo
&
inputInfo
,
DataInfo
&
outputInfo
)
override
;
int
Release
(
bool
isFullUnload
,
long
long
transactionId
,
const
DataInfo
&
inputInfo
)
override
;
int
SetOption
(
int
optionType
,
const
DataInfo
&
inputInfo
)
override
;
int
GetOption
(
int
optionType
,
const
DataInfo
&
inputInfo
,
DataInfo
&
outputInfo
)
override
;
private:
DataInfo
optionData_
{};
};
}
}
#endif // SAMPLE_PLUGIN_2_H
ai_lite/ai_engine_posix/base/src/sample/source/sample_plugin_1.cpp
0 → 100644
浏览文件 @
81fb2f6b
/*
* 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 "sample/include/sample_plugin_1.h"
#include <cstring>
#include "securec.h"
#include "protocol/retcode_inner/aie_retcode_inner.h"
#include "utils/log/aie_log.h"
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
()
{
FreeDataInfo
(
&
optionData_
);
}
const
long
long
SamplePlugin1
::
GetVersion
()
const
{
return
ALG_VERSION
;
}
const
char
*
SamplePlugin1
::
GetName
()
const
{
return
ALG_NAME
;
}
const
char
*
SamplePlugin1
::
GetInferMode
()
const
{
return
PLUGIN_INFER_MODEL
;
}
int
SamplePlugin1
::
SyncProcess
(
IRequest
*
request
,
IResponse
*&
response
)
{
DataInfo
inputInfo
=
request
->
GetMsg
();
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
);
DataInfo
outputInfo
{};
int
retCode
=
ReturnDataCopyOrDefaultData
(
inputInfo
,
outputInfo
);
response
->
SetResult
(
outputInfo
);
response
->
SetRetCode
(
retCode
);
return
retCode
;
}
int
SamplePlugin1
::
AsyncProcess
(
IRequest
*
request
,
IPluginCallback
*
callback
)
{
HILOGE
(
"[SamplePlugin1]Sync plugin, can't run AsyncProcess."
);
return
RETCODE_FAILURE
;
}
int
SamplePlugin1
::
Prepare
(
long
long
transactionId
,
const
DataInfo
&
inputInfo
,
DataInfo
&
outputInfo
)
{
return
ReturnDataCopyOrDefaultData
(
inputInfo
,
outputInfo
);
}
int
SamplePlugin1
::
Release
(
bool
isFullUnload
,
long
long
transactionId
,
const
DataInfo
&
inputInfo
)
{
FreeDataInfo
(
&
optionData_
);
return
RETCODE_SUCCESS
;
}
int
SamplePlugin1
::
SetOption
(
int
optionType
,
const
DataInfo
&
inputInfo
)
{
FreeDataInfo
(
&
optionData_
);
if
(
inputInfo
.
data
==
nullptr
)
{
return
RETCODE_SUCCESS
;
}
return
ReturnDataCopyOrDefaultData
(
inputInfo
,
optionData_
);
}
int
SamplePlugin1
::
GetOption
(
int
optionType
,
const
DataInfo
&
inputInfo
,
DataInfo
&
outputInfo
)
{
return
ReturnDataCopyOrDefaultData
(
optionData_
,
outputInfo
);
}
PLUGIN_INTERFACE_IMPL
(
SamplePlugin1
);
}
}
ai_lite/ai_engine_posix/base/src/sample/source/sample_plugin_2.cpp
0 → 100644
浏览文件 @
81fb2f6b
/*
* 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 "sample/include/sample_plugin_2.h"
#include <cstring>
#include "securec.h"
#include "protocol/retcode_inner/aie_retcode_inner.h"
#include "utils/log/aie_log.h"
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
()
{
FreeDataInfo
(
&
optionData_
);
}
const
long
long
SamplePlugin2
::
GetVersion
()
const
{
return
ALG_VERSION
;
}
const
char
*
SamplePlugin2
::
GetName
()
const
{
return
ALG_NAME
;
}
const
char
*
SamplePlugin2
::
GetInferMode
()
const
{
return
PLUGIN_INFER_MODEL
;
}
int
SamplePlugin2
::
SyncProcess
(
IRequest
*
request
,
IResponse
*&
response
)
{
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
&&
inputInfo
.
length
<=
0
)
{
HILOGE
(
"[SamplePlugin2]inputInfo data is invalid."
);
return
RETCODE_FAILURE
;
}
IResponse
*
response
=
IResponse
::
Create
(
request
);
CHK_RET
(
response
==
nullptr
,
RETCODE_FAILURE
);
DataInfo
outputInfo
{};
int
retCode
=
ReturnDataCopyOrDefaultData
(
inputInfo
,
outputInfo
);
response
->
SetResult
(
outputInfo
);
response
->
SetRetCode
(
retCode
);
return
callback
->
OnEvent
(
ON_PLUGIN_SUCCEED
,
response
);
}
int
SamplePlugin2
::
Prepare
(
long
long
transactionId
,
const
DataInfo
&
inputInfo
,
DataInfo
&
outputInfo
)
{
return
ReturnDataCopyOrDefaultData
(
inputInfo
,
outputInfo
);
}
int
SamplePlugin2
::
Release
(
bool
isFullUnload
,
long
long
transactionId
,
const
DataInfo
&
inputInfo
)
{
FreeDataInfo
(
&
optionData_
);
return
RETCODE_SUCCESS
;
}
int
SamplePlugin2
::
SetOption
(
int
optionType
,
const
DataInfo
&
inputInfo
)
{
FreeDataInfo
(
&
optionData_
);
if
(
inputInfo
.
data
==
nullptr
)
{
return
RETCODE_SUCCESS
;
}
return
ReturnDataCopyOrDefaultData
(
inputInfo
,
optionData_
);
}
int
SamplePlugin2
::
GetOption
(
int
optionType
,
const
DataInfo
&
inputInfo
,
DataInfo
&
outputInfo
)
{
return
ReturnDataCopyOrDefaultData
(
optionData_
,
outputInfo
);
}
PLUGIN_INTERFACE_IMPL
(
SamplePlugin2
);
}
}
build_lite/BUILD.gn
浏览文件 @
81fb2f6b
...
...
@@ -71,7 +71,7 @@ lite_component("acts_component") {
"//test/xts/acts/communication_lite/softbus_posix:ActsSoftBusTest",
"//test/xts/acts/communication_lite/lwip_posix:ActsLwipTest",
"//test/xts/acts/ai_lite
:ActsAi
Test",
"//test/xts/acts/ai_lite
/ai_engine_posix/base:ActsAiEngine
Test",
"//test/xts/acts/global_lite:ActsGlobalTest",
"//test/xts/acts/sensors_lite:sensorstest",
]
...
...
@@ -86,6 +86,7 @@ lite_component("acts_component") {
"//test/xts/acts/distributed_schedule_lite/samgr_posix:ActsSamgrTest",
"//test/xts/acts/appexecfwk_lite/bundle_mgr_posix:ActsBundleMgrTest",
"//test/xts/acts/aafwk_lite/ability_posix:ActsAbilityMgrTest",
"//test/xts/acts/ai_lite/ai_engine_posix/base:ActsAiEngineTest",
]
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录