diff --git a/test/function/BUILD.gn b/test/function/BUILD.gn index 4b0c54b07f0bc421d0274dc5c8bf4e6ba71035f6..d2fccb89cc20b1aeaddf1e57c4698b388db05ca4 100644 --- a/test/function/BUILD.gn +++ b/test/function/BUILD.gn @@ -50,6 +50,7 @@ unittest("ai_test_function_door") { "async_process/async_process_function_test.cpp", "destroy/destroy_function_test.cpp", "init/init_function_test.cpp", + "plugin_label/plugin_label_test.cpp", "plugin_manager/plugin_manager_test.cpp", "prepare/prepare_function_test.cpp", "release/release_function_test.cpp", diff --git a/test/function/plugin_label/plugin_label_test.cpp b/test/function/plugin_label/plugin_label_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16284a7c5858392846c01e939014cdfa959973bf --- /dev/null +++ b/test/function/plugin_label/plugin_label_test.cpp @@ -0,0 +1,72 @@ +/* + * 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 + +#include "gtest/gtest.h" + +#include "plugin_manager/include/aie_plugin_info.h" +#include "plugin_manager/include/plugin_label.h" +#include "utils/log/aie_log.h" + +using namespace OHOS::AI; +using namespace testing::ext; + +namespace { + const std::string AID_DEMO_PLUGIN_SYNC = "cv_card_rectification"; + long long AID_DEMO_PLUGIN_VERSION = 20001001; +} + +class PluginLabelTest : public testing::Test { +public: + // SetUpTestCase:The preset action of the test suite is executed before the first TestCase + static void SetUpTestCase() {}; + + // TearDownTestCase:The test suite cleanup action is executed after the last TestCase + static void TearDownTestCase() {}; + + // SetUp:Execute before each test case + void SetUp() {}; + + // TearDown:Execute after each test case + void TearDown() {}; +}; + +static void TestPluginLabel(const std::string &aid, long long &version, std::string &libPath) +{ + PluginLabel *pluginLabel = PluginLabel::GetInstance(); + ASSERT_NE(pluginLabel, nullptr) << "pluginLabel test failed."; + + int retCode = pluginLabel->GetLibPath(aid, version, libPath); + if (retCode != RETCODE_SUCCESS) { + HILOGE("[Test]Failed to get lib path. return retCode:%d;", retCode); + return; + } + HILOGE("[Test]SUCCESS return retCode:%d;", retCode); +} + +/** + * @tc.name: TestPluginLabel001 + * @tc.desc: Test Get algorithm path. + * @tc.type: FUNC + * @tc.require: AR000F77ON + */ +static HWTEST_F(PluginLabelTest, TestPluginLabel001, TestSize.Level0) +{ + HILOGI("[Test]TestPluginLabel001."); + std::string libPath; + TestPluginLabel(AID_DEMO_PLUGIN_SYNC, AID_DEMO_PLUGIN_VERSION, libPath); +} \ No newline at end of file diff --git a/test/function/prepare/prepare_function_test.cpp b/test/function/prepare/prepare_function_test.cpp index 647d3106f04f858dd818e084c294151cdfc16532..1dde9770eb65dabbcb8f8cc75ec68c9df531c2ee 100644 --- a/test/function/prepare/prepare_function_test.cpp +++ b/test/function/prepare/prepare_function_test.cpp @@ -433,3 +433,65 @@ HWTEST_F(PrepareFunctionTest, TestCallback002, TestSize.Level1) AieClientDestroy(clientInfo); } + +/** + * @tc.name: TestRegisterCallbackProxy001 + * @tc.desc: Test preparing execution of certain plugin + * with 'isAsync = true' and 'callback != nullptr'. + * @tc.type: FUNC + * @tc.require: AR000F77NJ + */ +static HWTEST_F(PrepareFunctionTest, TestRegisterCallbackProxy001, TestSize.Level1) +{ + HILOGI("[Test]TestRegisterCallbackProxy001."); + char *str = "Async prepare inputData"; + char *inputData = str; + int len = strlen(str) + 1; + + ConfigInfo configInfo {.description = CONFIG_DESCRIPTION}; + + ClientInfo clientInfo = { + .clientVersion = CLIENT_INFO_VERSION, + .clientId = INVALID_CLIENT_ID, + .sessionId = SESSION_ID, + .serverUid = INVALID_UID, + .clientUid = INVALID_UID, + .extendLen = len, + .extendMsg = (unsigned char*)inputData, + }; + + AlgorithmInfo algoInfo = { + .clientVersion = ALGORITHM_INFO_CLIENT_VERSION, + .isAsync = true, + .algorithmType = ALGORITHM_ASYNC_TYPE, + .algorithmVersion = ALGORITHM_VERSION, + .isCloud = true, + .operateId = OPERATE_ID, + .requestId = REQUEST_ID, + .extendLen = len, + .extendMsg = (unsigned char*)inputData, + }; + + ServiceDeadCb cb = ServiceDeadCb(); + int initRetCode = AieClientInit(configInfo, clientInfo, algoInfo, &cb); + ASSERT_EQ(initRetCode, RETCODE_SUCCESS); + ASSERT_TRUE(clientInfo.clientId > 0); + + DataInfo inputInfo = { + .data = (unsigned char*)inputData, + .length = len, + }; + + DataInfo outputInfo = { + .data = nullptr, + .length = 0 + }; + ClientCallback callback = ClientCallback(); + int prepareRetCode = AieClientPrepare(clientInfo, algoInfo, inputInfo, outputInfo, &callback); + ASSERT_NE(prepareRetCode, RETCODE_SUCCESS); + ASSERT_EQ(outputInfo.data, nullptr); + + AieClientRelease(clientInfo, algoInfo, inputInfo); + + AieClientDestroy(clientInfo); +}