diff --git a/parser/common/acl_graph_parser_util.cc b/parser/common/acl_graph_parser_util.cc index 8a4b261..2af798c 100644 --- a/parser/common/acl_graph_parser_util.cc +++ b/parser/common/acl_graph_parser_util.cc @@ -87,28 +87,6 @@ static string GetSoPath() { } } -static void GetOpsProtoPath(string &opsproto_path) { - GELOGD("Start to get ops proto path schedule."); - const char *path_env = std::getenv("ASCEND_OPP_PATH"); - if (path_env != nullptr) { - string path = path_env; - string file_path = ge::parser::RealPath(path.c_str()); - if (file_path.empty()) { - REPORT_INNER_ERROR("E19999", "File path %s is invalid.", path.c_str()); - GELOGE(ge::FAILED, "[Get][Path] File path %s is invalid.", path.c_str()); - return; - } - opsproto_path = (path + "/op_proto/custom/" + ":") + (path + "/op_proto/built-in/"); - GELOGI("Get opsproto so path from env : %s", path.c_str()); - return; - } - string path_base = GetSoPath(); - GELOGI("path_base is %s", path_base.c_str()); - path_base = path_base.substr(0, path_base.rfind('/')); - path_base = path_base.substr(0, path_base.rfind('/') + 1); - opsproto_path = (path_base + "ops/op_proto/custom/" + ":") + (path_base + "ops/op_proto/built-in/"); -} - static void GetAclParams(const std::map &parser_params, const string &key, string &value) { for (auto &ele : parser_params) { @@ -173,7 +151,10 @@ static Status CheckOutNode(ge::OpDescPtr op_desc, int32_t index) { domi::Status AclGrphParseUtil::LoadOpsProtoLib() { string opsproto_path; - GetOpsProtoPath(opsproto_path); + ge::Status ret = ge::TBEPluginLoader::GetOpsProtoPath(opsproto_path); + if (ret != ge::SUCCESS) { + GELOGW("Failed to get ops proto path!"); + } GELOGI("Get opsproto path is %s", opsproto_path.c_str()); OpsProtoManager *manager = OpsProtoManager::Instance(); map option_tmp; @@ -196,18 +177,17 @@ void AclGrphParseUtil::SaveCustomCaffeProtoPath() { path_base = path_base.substr(0, path_base.rfind('/') + 1); ge::GetParserContext().caffe_proto_path = path_base + "include/proto/"; - string custom_op_path; + std::string path = path_base + "ops"; const char *path_env = std::getenv("ASCEND_OPP_PATH"); if (path_env != nullptr) { - std::string path = path_env; - custom_op_path = path + "/framework/custom/caffe/"; + path = path_env; GELOGI("Get custom proto path from env : %s", path_env); - GetParserContext().custom_proto_path = custom_op_path; - return; } - custom_op_path = path_base + "ops/framework/custom/caffe/"; - ge::GetParserContext().custom_proto_path = custom_op_path; - return; + if (mmIsDir((path + "/vendors").c_str()) != EN_OK) { + ge::GetParserContext().custom_proto_path = path + "framework/custom/caffe/"; + } else { + ge::GetParserContext().custom_proto_path = path + "vendors/customize/framework/caffe/"; + } } // Initialize PARSER, load custom op plugin diff --git a/parser/common/tbe_plugin_loader.cc b/parser/common/tbe_plugin_loader.cc index 2389852..906b7ce 100644 --- a/parser/common/tbe_plugin_loader.cc +++ b/parser/common/tbe_plugin_loader.cc @@ -29,16 +29,26 @@ #include #include #include +#include #include "external/ge/ge_api_types.h" #include "common/util/error_manager/error_manager.h" #include "framework/common/debug/ge_log.h" #include "framework/common/string_util.h" +#include "framework/common/util.h" #include "framework/omg/parser/parser_inner_ctx.h" #include "graph/utils/type_utils.h" #include "parser/common/acl_graph_parser_util.h" +#include "mmpa/mmpa_api.h" +#include "common/checker.h" namespace ge { +namespace { +const char_t *const kOppEnvName = "ASCEND_OPP_PATH"; +const char_t *const kVendors = "vendors"; // opp vendors directory name +const char_t *const kConfig = "config.ini"; // opp vendors config file name +const size_t kVendorConfigPartsCount = 2U; +} // namespace std::map TBEPluginLoader::options_ = {}; // Get Singleton Instance @@ -101,6 +111,93 @@ FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY void TBEPluginLoader::LoadPlugi } } +Status TBEPluginLoader::GetOppPath(std::string &opp_path) { + GELOGI("Enter get opp path schedule"); + const char *path_env = std::getenv(kOppEnvName); + if (path_env != nullptr) { + opp_path = path_env; + std::string file_path = parser::RealPath(opp_path.c_str()); + if (file_path.empty()) { + GELOGW("[Call][RealPath] File path %s is invalid.", opp_path.c_str()); + } else { + GELOGI("Get opp path from env: %s", opp_path.c_str()); + } + if (opp_path.back() != '/') { + opp_path += '/'; + } + } + if (opp_path.empty()) { + opp_path = GetPath(); + GELOGI("Get opp path from so path, value is %s", opp_path.c_str()); + opp_path = opp_path.substr(0, opp_path.rfind('/')); + opp_path = opp_path.substr(0, opp_path.rfind('/') + 1); + opp_path += "ops/"; + } + return SUCCESS; +} + +bool TBEPluginLoader::IsNewOppPathStruct(const std::string &opp_path) { + return mmIsDir((opp_path + kVendors).c_str()) == EN_OK; +} + +Status TBEPluginLoader::GetOppPluginVendors(const std::string &vendors_config, std::vector &vendors) { + GELOGI("Enter get opp plugin config file schedule"); + GE_ASSERT_TRUE(!vendors_config.empty(), "[Check]Value of vendors_config should not be empty!"); + std::ifstream config(vendors_config); + GE_ASSERT_TRUE(config.good(), "File '%s' open failed!", vendors_config.c_str()); + std::string content; + std::getline(config, content); + config.close(); + GE_ASSERT_TRUE(!content.empty(), "Content of file '%s' is empty!", vendors_config.c_str()); + std::vector v_parts = StringUtils::Split(content, '='); + GE_ASSERT_TRUE(v_parts.size() == kVendorConfigPartsCount, "Format of file content is invalid!"); + vendors = StringUtils::Split(v_parts[1], ','); + GE_ASSERT_TRUE(!vendors.empty(), "Format of file content is invalid!"); + return SUCCESS; +} + +Status TBEPluginLoader::GetOppPluginPathOld(const std::string &opp_path, + const std::string &path_fmt, + std::string &plugin_path, + const std::string &path_fmt_custom) { + GELOGI("Enter get opp plugin path old schedule"); + const std::string &fmt_builtin = path_fmt; + const std::string &fmt_custom = path_fmt_custom.empty() ? path_fmt : path_fmt_custom; + plugin_path = (opp_path + std::regex_replace(fmt_custom, std::regex("%s"), "custom") + ":") + + (opp_path + std::regex_replace(fmt_builtin, std::regex("%s"), "built-in")); + return SUCCESS; +} + +Status TBEPluginLoader::GetOppPluginPathNew(const std::string &opp_path, + const std::string &path_fmt, + std::string &plugin_path, + const std::string &path_fmt_custom) { + GELOGI("Enter get opp plugin path new schedule"); + const std::string vendors_config = opp_path + kVendors + "/" + kConfig; + std::vector vendors; + GE_ASSERT_TRUE(GetOppPluginVendors(vendors_config, vendors) == SUCCESS, "Failed to get opp plugin vendors!"); + const std::string &fmt_builtin = path_fmt; + const std::string &fmt_custom = path_fmt_custom.empty() ? path_fmt : path_fmt_custom; + for (const auto &vendor : vendors) { + plugin_path += opp_path + kVendors + "/" + std::regex_replace(fmt_custom, std::regex("%s"), vendor) + ":"; + } + plugin_path += opp_path + std::regex_replace(fmt_builtin, std::regex("%s"), "built-in"); + return SUCCESS; +} + +Status TBEPluginLoader::GetOpsProtoPath(std::string &opsproto_path) { + GELOGI("Enter GetOpsProtoPath schedule"); + std::string opp_path; + GE_ASSERT_TRUE(GetOppPath(opp_path) == SUCCESS, "Failed to get opp path!"); + if (!IsNewOppPathStruct(opp_path)) { + GELOGI("Opp plugin path structure is old version!"); + return GetOppPluginPathOld(opp_path, "op_proto/%s/", opsproto_path); + } else { + GELOGI("Opp plugin path structure is new version!"); + return GetOppPluginPathNew(opp_path, "%s/op_proto/", opsproto_path); + } +} + void TBEPluginLoader::GetCustomOpPath(std::string &customop_path) { GELOGI("Enter get custom op path schedule"); std::string fmk_type; @@ -112,18 +209,22 @@ void TBEPluginLoader::GetCustomOpPath(std::string &customop_path) { fmk_type = ge::TypeUtils::FmkTypeToSerialString(type); GELOGI("Framework type is %s.", fmk_type.c_str()); - const char *path_env = std::getenv("ASCEND_OPP_PATH"); - if (path_env != nullptr) { - std::string path = path_env; - customop_path = (path + "/framework/custom" + "/:") + (path + "/framework/built-in/" + fmk_type); - GELOGI("Get custom so path from env : %s", path_env); + std::string opp_path; + Status ret = GetOppPath(opp_path); + if (ret != SUCCESS) { + GELOGW("Failed to get opp path."); return; } - std::string path_base = GetPath(); - GELOGI("path_base is %s", path_base.c_str()); - path_base = path_base.substr(0, path_base.rfind('/')); - path_base = path_base.substr(0, path_base.rfind('/') + 1); - customop_path = (path_base + "ops/framework/custom" + "/:") + (path_base + "ops/framework/built-in/" + fmk_type); + if (!IsNewOppPathStruct(opp_path)) { + GELOGI("Opp plugin path structure is old version!"); + ret = GetOppPluginPathOld(opp_path, "framework/%s/" + fmk_type + "/", customop_path, "framework/%s/"); + } else { + GELOGI("Opp plugin path structure is new version!"); + ret = GetOppPluginPathNew(opp_path, "%s/framework/" + fmk_type + "/", customop_path, "%s/framework/"); + } + if (ret != SUCCESS) { + GELOGW("Failed to get custom op path!"); + } } string TBEPluginLoader::GetPath() { diff --git a/parser/common/tbe_plugin_loader.h b/parser/common/tbe_plugin_loader.h index b5adfb5..149f925 100644 --- a/parser/common/tbe_plugin_loader.h +++ b/parser/common/tbe_plugin_loader.h @@ -40,12 +40,25 @@ public: static string GetPath(); + static Status GetOpsProtoPath(std::string &opsproto_path); + private: TBEPluginLoader() = default; ~TBEPluginLoader() = default; Status ClearHandles_(); static void ProcessSoFullName(vector &file_list, string &caffe_parser_path, string &full_name, const string &caffe_parser_so_suff); + static Status GetOppPath(std::string &opp_path); + static bool IsNewOppPathStruct(const std::string &opp_path); + static Status GetOppPluginVendors(const std::string &vendors_config, std::vector &vendors); + static Status GetOppPluginPathOld(const std::string &opp_path, + const std::string &path_fmt, + std::string &plugin_path, + const std::string &path_fmt_custom = ""); + static Status GetOppPluginPathNew(const std::string &opp_path, + const std::string &path_fmt, + std::string &plugin_path, + const std::string &path_fmt_custom = ""); static void GetCustomOpPath(std::string &customop_path); static void GetPluginSoFileList(const string &path, vector &file_list, string &caffe_parser_path); static void FindParserSo(const string &path, vector &file_list, string &caffe_parser_path); diff --git a/tests/depends/mmpa/src/mmpa_stub.cc b/tests/depends/mmpa/src/mmpa_stub.cc index ca54c4f..070964d 100644 --- a/tests/depends/mmpa/src/mmpa_stub.cc +++ b/tests/depends/mmpa/src/mmpa_stub.cc @@ -249,6 +249,15 @@ INT32 mmGetErrorCode() INT32 mmIsDir(const CHAR *fileName) { + struct stat fileStat; + memset(&fileStat, sizeof(fileStat), 0); + int32_t ret = lstat(fileName, &fileStat); + if (ret < 0) { + return -1; + } + if (S_ISDIR(fileStat.st_mode) == 0) { + return -1; + } return 0; } @@ -320,4 +329,4 @@ CHAR *mmDirName(CHAR *path) { path[last_sep_pos] = '\0'; return path; -} \ No newline at end of file +} diff --git a/tests/st/testcase/test_tensorflow_parser.cc b/tests/st/testcase/test_tensorflow_parser.cc index b5f1908..ac6c275 100644 --- a/tests/st/testcase/test_tensorflow_parser.cc +++ b/tests/st/testcase/test_tensorflow_parser.cc @@ -1144,18 +1144,16 @@ TEST_F(STestTensorflowParser, tensorflow_parserfrommemory_failed) std::size_t idx = caseDir.find_last_of("/"); caseDir = caseDir.substr(0, idx); std::string modelFile = caseDir + "/origin_models/tf_add.pb"; - const char *data = modelFile.c_str(); uint32_t size = 1; ge::Graph graph; std::map parser_params; Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); ASSERT_EQ(ret, SUCCESS); - modelFile = caseDir + "/origin_models/tf_add.pb"; parser_params = {{AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}}; ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph); - ret = modelParser.ParseFromMemory(data, size, compute_graph); + ret = modelParser.ParseFromMemory(modelFile.c_str(), size, compute_graph); EXPECT_NE(ret, SUCCESS); } @@ -3709,7 +3707,7 @@ TEST_F(STestTensorflowParser, tensorflow_tbe_tfplugin_loader_test) setenv("ASCEND_OPP_PATH", "aaa", 1); std::string customop_path = ""; pluginLoad.GetCustomOpPath(customop_path); - ASSERT_EQ(customop_path, "aaa/framework/custom/:aaa/framework/built-in/tensorflow"); + ASSERT_EQ(customop_path, "aaa/framework/custom/:aaa/framework/built-in/tensorflow/"); Status ret = pluginLoad.Finalize(); EXPECT_EQ(ret, SUCCESS); @@ -4348,4 +4346,120 @@ TEST_F(STestTensorflowParser, AddDumpOriginName_test) EXPECT_EQ(original_names[1], "abc"); } +TEST_F(STestTensorflowParser, test_plugin_manager_getopp_plugin_vendors_01) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority=customize,mdc,lhisi' > " + path_config).c_str()); + + std::vector vendors; + Status ret = TBEPluginLoader::GetOppPluginVendors(path_config, vendors); + EXPECT_EQ(ret, SUCCESS); + EXPECT_EQ(vendors[0], "customize"); + EXPECT_EQ(vendors[1], "mdc"); + EXPECT_EQ(vendors[2], "lhisi"); +} + +TEST_F(STestTensorflowParser, test_plugin_manager_getopp_plugin_vendors_02) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo '' > " + path_config).c_str()); + + std::vector vendors; + Status ret = TBEPluginLoader::GetOppPluginVendors(path_config, vendors); + EXPECT_NE(ret, SUCCESS); +} + +TEST_F(STestTensorflowParser, test_plugin_manager_getopp_plugin_vendors_03) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority' > " + path_config).c_str()); + + std::vector vendors; + Status ret = TBEPluginLoader::GetOppPluginVendors(path_config, vendors); + EXPECT_NE(ret, SUCCESS); +} + +TEST_F(STestTensorflowParser, test_plugin_manager_GetOpsProtoPath_01) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + system(("rm -rf " + path_vendors).c_str()); + + std::string opsproto_path; + Status ret = TBEPluginLoader::GetOpsProtoPath(opsproto_path); + EXPECT_EQ(ret, SUCCESS); + EXPECT_EQ(opsproto_path, + opp_path + "op_proto/custom/:" + opp_path + "op_proto/built-in/" + ); +} + +TEST_F(STestTensorflowParser, test_plugin_manager_GetOpsProtoPath_02) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority=customize,mdc,lhisi' > " + path_config).c_str()); + + std::string opsproto_path; + Status ret = TBEPluginLoader::GetOpsProtoPath(opsproto_path); + EXPECT_EQ(ret, SUCCESS); + EXPECT_EQ(opsproto_path, + path_vendors + "/customize/op_proto/:" + + path_vendors + "/mdc/op_proto/:" + + path_vendors + "/lhisi/op_proto/:" + + opp_path + "built-in/op_proto/" + ); +} + +TEST_F(STestTensorflowParser, test_plugin_manager_GetCustomOpPath_01) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + system(("rm -rf " + path_vendors).c_str()); + + std::string customop_path; + TBEPluginLoader::GetCustomOpPath(customop_path); + EXPECT_EQ(customop_path.find(opp_path + "framework/custom/:" + opp_path + "framework/built-in/"), 0); +} + +TEST_F(STestTensorflowParser, test_plugin_manager_GetCustomOpPath_02) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority=customize,mdc,lhisi' > " + path_config).c_str()); + + std::string customop_path; + TBEPluginLoader::GetCustomOpPath(customop_path); + EXPECT_EQ(customop_path.find( + path_vendors + "/customize/framework/:" + + path_vendors + "/mdc/framework/:" + + path_vendors + "/lhisi/framework/:" + + opp_path + "built-in/framework/"), 0); +} } // namespace ge diff --git a/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc b/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc index c852aad..549ea61 100644 --- a/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc +++ b/tests/ut/parser/testcase/tensorflow_parser_testcase/tensorflow_parser_unittest.cc @@ -1295,18 +1295,16 @@ TEST_F(UtestTensorflowParser, tensorflow_parserfrommemory_failed) std::size_t idx = caseDir.find_last_of("/"); caseDir = caseDir.substr(0, idx); std::string modelFile = caseDir + "/tensorflow_model/tf_add.pb"; - const char *data = modelFile.c_str(); uint32_t size = 1; ge::Graph graph; std::map parser_params; Status ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); ASSERT_EQ(ret, SUCCESS); - modelFile = caseDir + "/tensorflow_model/tf_add.pb"; parser_params = {{AscendString(ge::ir_option::OUT_NODES), AscendString("Placeholder:0;Placeholder_1:0")}}; ret = ge::aclgrphParseTensorFlow(modelFile.c_str(), parser_params, graph); ge::ComputeGraphPtr compute_graph = ge::GraphUtils::GetComputeGraph(graph); - ret = modelParser.ParseFromMemory(data, size, compute_graph); + ret = modelParser.ParseFromMemory(modelFile.c_str(), size, compute_graph); EXPECT_NE(ret, SUCCESS); } @@ -3813,7 +3811,7 @@ TEST_F(UtestTensorflowParser, tensorflow_tbe_tfplugin_loader_test) setenv("ASCEND_OPP_PATH", "aaa", 1); std::string customop_path = ""; pluginLoad.GetCustomOpPath(customop_path); - ASSERT_EQ(customop_path, "aaa/framework/custom/:aaa/framework/built-in/tensorflow"); + ASSERT_EQ(customop_path, "aaa/framework/custom/:aaa/framework/built-in/tensorflow/"); Status ret = pluginLoad.Finalize(); EXPECT_EQ(ret, SUCCESS); @@ -4835,4 +4833,120 @@ TEST_F(UtestTensorflowParser, AddDumpOriginName_test) EXPECT_EQ(original_names[1], "abc"); } +TEST_F(UtestTensorflowParser, test_plugin_manager_getopp_plugin_vendors_01) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority=customize,mdc,lhisi' > " + path_config).c_str()); + + std::vector vendors; + Status ret = TBEPluginLoader::GetOppPluginVendors(path_config, vendors); + EXPECT_EQ(ret, SUCCESS); + EXPECT_EQ(vendors[0], "customize"); + EXPECT_EQ(vendors[1], "mdc"); + EXPECT_EQ(vendors[2], "lhisi"); +} + +TEST_F(UtestTensorflowParser, test_plugin_manager_getopp_plugin_vendors_02) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo '' > " + path_config).c_str()); + + std::vector vendors; + Status ret = TBEPluginLoader::GetOppPluginVendors(path_config, vendors); + EXPECT_NE(ret, SUCCESS); +} + +TEST_F(UtestTensorflowParser, test_plugin_manager_getopp_plugin_vendors_03) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority' > " + path_config).c_str()); + + std::vector vendors; + Status ret = TBEPluginLoader::GetOppPluginVendors(path_config, vendors); + EXPECT_NE(ret, SUCCESS); +} + +TEST_F(UtestTensorflowParser, test_plugin_manager_GetOpsProtoPath_01) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + system(("rm -rf " + path_vendors).c_str()); + + std::string opsproto_path; + Status ret = TBEPluginLoader::GetOpsProtoPath(opsproto_path); + EXPECT_EQ(ret, SUCCESS); + EXPECT_EQ(opsproto_path, + opp_path + "op_proto/custom/:" + opp_path + "op_proto/built-in/" + ); +} + +TEST_F(UtestTensorflowParser, test_plugin_manager_GetOpsProtoPath_02) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority=customize,mdc,lhisi' > " + path_config).c_str()); + + std::string opsproto_path; + Status ret = TBEPluginLoader::GetOpsProtoPath(opsproto_path); + EXPECT_EQ(ret, SUCCESS); + EXPECT_EQ(opsproto_path, + path_vendors + "/customize/op_proto/:" + + path_vendors + "/mdc/op_proto/:" + + path_vendors + "/lhisi/op_proto/:" + + opp_path + "built-in/op_proto/" + ); +} + +TEST_F(UtestTensorflowParser, test_plugin_manager_GetCustomOpPath_01) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + system(("rm -rf " + path_vendors).c_str()); + + std::string customop_path; + TBEPluginLoader::GetCustomOpPath(customop_path); + EXPECT_EQ(customop_path.find(opp_path + "framework/custom/:" + opp_path + "framework/built-in/"), 0); +} + +TEST_F(UtestTensorflowParser, test_plugin_manager_GetCustomOpPath_02) { + std::string opp_path = __FILE__; + opp_path = opp_path.substr(0, opp_path.rfind("/") + 1); + setenv("ASCEND_OPP_PATH", opp_path.c_str(), 1); + + std::string path_vendors = opp_path + "vendors"; + std::string path_config = path_vendors + "/config.ini"; + system(("mkdir -p " + path_vendors).c_str()); + system(("echo 'load_priority=customize,mdc,lhisi' > " + path_config).c_str()); + + std::string customop_path; + TBEPluginLoader::GetCustomOpPath(customop_path); + EXPECT_EQ(customop_path.find( + path_vendors + "/customize/framework/:" + + path_vendors + "/mdc/framework/:" + + path_vendors + "/lhisi/framework/:" + + opp_path + "built-in/framework/"), 0); +} } // namespace ge