!47717 fix issue of dynamic obfuscation ut

Merge pull request !47717 from jxl/master
This commit is contained in:
i-robot 2023-02-06 06:53:39 +00:00 committed by Gitee
commit 8f1be531c7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 18 additions and 4 deletions

View File

@ -1768,9 +1768,22 @@ FuncGraphPtr DynamicObfuscateMindIR(const std::string &file_name, float obf_rati
mindspore::DynamicObfuscator dynamic_obfuscator(obf_ratio, obf_password, append_password);
MindIRLoader mindir_loader(false, reinterpret_cast<unsigned char *>(dec_key), key_len, dec_mode, false);
FuncGraphPtr func_graph = mindir_loader.LoadMindIR(file_name);
if (func_graph == nullptr) {
MS_LOG(ERROR) << "[DynamicObfuscateMindIR] load mindir failed, please check the mindir file.";
return nullptr;
int repeat_max_count = 10;
int repeat_count = 0;
while (func_graph == nullptr) {
#if defined(__linux__) && defined(WITH_BACKEND)
(void)sleep(1);
#endif
try {
func_graph = mindir_loader.LoadMindIR(file_name);
} catch (const std::exception &e) {
MS_LOG(ERROR) << "Load MindIR file failed, error msg is: " << e.what();
}
repeat_count += 1;
if (repeat_count >= repeat_max_count) {
MS_LOG(ERROR) << "[DynamicObfuscateMindIR] load mindir failed, please check the mindir file.";
return nullptr;
}
}
mindspore::FuncGraphPtr obfuscated_graph = dynamic_obfuscator.ObfuscateMindIR(func_graph);
if (obfuscated_graph == nullptr) {

View File

@ -27,6 +27,7 @@
#include "load_mindir/load_model.h"
#include "utils/crypto.h"
#include "utils/os.h"
#include "include/common/debug/common.h"
using std::string;
using std::vector;
@ -234,7 +235,7 @@ FuncGraphPtr MindIRLoader::LoadMindIR(const std::string &file_name) {
_fullpath(abs_path_buff, file_name.c_str(), PATH_MAX);
#else
if (!realpath(file_name.c_str(), abs_path_buff)) {
MS_LOG(ERROR) << "Load MindIR get absolute path of " << file_name << " failed";
MS_LOG(ERROR) << "Load MindIR get absolute path of " << file_name << " failed, errno is: " << ErrnoToString(errno);
}
#endif
// Read graph