• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gtest/gtest.h"
17 #include <cstring>
18 #include <unistd.h>
19 
20 #include "plugin_manager/include/aie_plugin_info.h"
21 #include "plugin_manager/include/i_plugin_manager.h"
22 #include "utils/aie_client_const.h"
23 #include "utils/log/aie_log.h"
24 
25 using namespace ::testing;
26 using namespace testing::ext;
27 using namespace OHOS::AI;
28 
29 namespace {
30     std::string AID_DEMO_PLUGIN_SYNC = "sample_plugin_1"; // defined by ALGORITHM_ID_SAMPLE_1 in aie_plugin_info.h
31     std::string AID_DEMO_PLUGIN_ASYNC = "sample_plugin_2"; // defined by ALGORITHM_ID_SAMPLE_2 in aie_plugin_info.h
32     std::string AID_PLUGIN_INVALID = "invalid_plugin";
33 }
34 
35 class PluginManagerFunctionTest : public testing::Test {};
36 
TestPluginManager(std::string aid,bool isExceptedLoadPluginSuccess)37 static void TestPluginManager(std::string aid, bool isExceptedLoadPluginSuccess)
38 {
39     // Step 1: Create an instance.
40     IPluginManager *pluginManager = IPluginManager::GetPluginManager();
41 
42     // Step 2: Invoke pluginManager->GetPlugin.
43     long long version = ALGORITHM_VERSION_VALID;
44     std::shared_ptr<Plugin> plugin = nullptr;
45     int ret = pluginManager->GetPlugin(aid, version, plugin);
46     HILOGE("[Test]ret is %d.", ret);
47     EXPECT_EQ(isExceptedLoadPluginSuccess, plugin != nullptr) << "pluginManager->GetPlugin test failed.";
48 
49     if (plugin != nullptr) {
50         const char *name = plugin->GetPluginAlgorithm()->GetName();
51         HILOGD("[Test]The plugin name [%s].", name);
52         EXPECT_EQ(isExceptedLoadPluginSuccess, name != nullptr) << "Get plugin name failed.";
53     }
54 
55     // Step 3: Unload the plugin.
56     pluginManager->UnloadPlugin(aid, version);
57 
58     // Step 4: Destroy the plugin.
59     pluginManager->Destroy();
60 }
61 
TestPluginManagerUnloadPlugin(std::string aid)62 static void TestPluginManagerUnloadPlugin(std::string aid)
63 {
64     bool isPass = false;
65     long long version = ALGORITHM_VERSION_VALID;
66     IPluginManager *pluginManager2 = IPluginManager::GetPluginManager();
67     pluginManager2->UnloadPlugin(aid, version);
68     isPass = true;
69     EXPECT_EQ(true, isPass) << "UnloadPlugin test failed.";
70 }
71 
72 /**
73  * @tc.number : SUB_AI_AIDistributedAbility_HiAiEngine_Lite_Function_HiAiSupportPlugin_1100
74  * @tc.name   : 011. 系统中已预置算法插件(同步),加载、卸载插件成功
75  * @tc.desc   : [C- SOFTWARE -0200]
76  */
77 HWTEST_F(PluginManagerFunctionTest, testPluginManagerFunction0101, Function | MediumTest | Level3)
78 {
79     HILOGI("[Test]testPluginManagerFunction0101.");
80     TestPluginManager(AID_DEMO_PLUGIN_SYNC, true);
81 }
82 
83 /**
84  * @tc.number : SUB_AI_AIDistributedAbility_HiAiEngine_Lite_Function_HiAiSupportPlugin_1200
85  * @tc.name   : 012. 系统中已预置算法插件(异步),加载、卸载插件成功
86  * @tc.desc   : [C- SOFTWARE -0200]
87  */
88 HWTEST_F(PluginManagerFunctionTest, testPluginManagerFunction0102, Function | MediumTest | Level3)
89 {
90     HILOGI("[Test]testPluginManagerFunction0102.");
91     TestPluginManager(AID_DEMO_PLUGIN_ASYNC, true);
92 }
93 
94 /**
95  * @tc.number : SUB_AI_AIDistributedAbility_HiAiEngine_Lite_Function_HiAiSupportPlugin_1300
96  * @tc.name   : 013. 系统中未预置插件,加载插件失败
97  * @tc.desc   : [C- SOFTWARE -0200]
98  */
99 HWTEST_F(PluginManagerFunctionTest, testPluginManagerFunction0103, Function | MediumTest | Level3)
100 {
101     HILOGI("[Test]testPluginManagerFunction0103.");
102     TestPluginManager(AID_PLUGIN_INVALID, false);
103 }
104 
105 /**
106  * @tc.number : SUB_AI_AIDistributedAbility_HiAiEngine_Lite_Function_HiAiSupportPlugin_2100
107  * @tc.name   : 021. 系统中已预置算法插件(同步),不加载插件,直接卸载插件,不发生crash
108  * @tc.desc   : [C- SOFTWARE -0200]
109  */
110 HWTEST_F(PluginManagerFunctionTest, testPluginManagerFunction0201, Function | MediumTest | Level3)
111 {
112     HILOGI("[Test]testPluginManagerFunction0201.");
113     TestPluginManagerUnloadPlugin(AID_DEMO_PLUGIN_SYNC);
114 }
115 
116 /**
117  * @tc.number : SUB_AI_AIDistributedAbility_HiAiEngine_Lite_Function_HiAiSupportPlugin_2200
118  * @tc.name   : 022. 系统中已预置算法插件(异步),不加载插件,直接卸载插件,不发生crash
119  * @tc.desc   : [C- SOFTWARE -0200]
120  */
121 HWTEST_F(PluginManagerFunctionTest, testPluginManagerFunction0202, Function | MediumTest | Level3)
122 {
123     HILOGI("[Test]testPluginManagerFunction0202.");
124     TestPluginManagerUnloadPlugin(AID_DEMO_PLUGIN_ASYNC);
125 }
126 
127 /**
128  * @tc.number : SUB_AI_AIDistributedAbility_HiAiEngine_Lite_Function_HiAiSupportPlugin_2300
129  * @tc.name   : 023. 系统中未预置插件,不加载插件,直接卸载插件,不发生crash
130  * @tc.desc   : [C- SOFTWARE -0200]
131  */
132 HWTEST_F(PluginManagerFunctionTest, testPluginManagerFunction0203, Function | MediumTest | Level3)
133 {
134     HILOGI("[Test]testPluginManagerFunction0203.");
135     TestPluginManagerUnloadPlugin(AID_PLUGIN_INVALID);
136 }