Add unit test for generator

pull/1134/head
zhangxiaokun 4 years ago
parent bab5b2c61b
commit 9d4b0ab4dc

@ -53,6 +53,7 @@ string PluginManager::GetPath() {
GELOGW("Failed to read the shared library file path!"); GELOGW("Failed to read the shared library file path!");
return string(); return string();
} else { } else {
GE_IF_BOOL_EXEC(dl_info.dli_fname == nullptr, return string());
std::string so_path = dl_info.dli_fname; std::string so_path = dl_info.dli_fname;
char path[MMPA_MAX_PATH] = {0}; char path[MMPA_MAX_PATH] = {0};
if (so_path.length() >= MMPA_MAX_PATH) { if (so_path.length() >= MMPA_MAX_PATH) {

@ -671,6 +671,8 @@ Status GeGenerator::CheckForSingleOp(OpDescPtr &op_desc, const vector<GeTensor>
Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs, Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &inputs, const vector<GeTensor> &outputs,
const string &model_file_name, OpEngineType engine_type, ModelBufferData &model_buff, const string &model_file_name, OpEngineType engine_type, ModelBufferData &model_buff,
bool is_offline) { bool is_offline) {
GE_CHECK_NOTNULL_EXEC(impl_, return PARAM_INVALID);
impl_->is_offline_ = is_offline;
if (!is_offline) { if (!is_offline) {
(void)AttrUtils::SetBool(op_desc, ATTR_SINGLE_OP_SCENE, true); (void)AttrUtils::SetBool(op_desc, ATTR_SINGLE_OP_SCENE, true);
} }
@ -709,8 +711,6 @@ Status GeGenerator::BuildSingleOp(OpDescPtr &op_desc, const vector<GeTensor> &in
GELOGI("ATC parser success in single op build."); GELOGI("ATC parser success in single op build.");
GeRootModelPtr ge_root_model = nullptr; GeRootModelPtr ge_root_model = nullptr;
GE_CHECK_NOTNULL_EXEC(impl_, return PARAM_INVALID);
impl_->is_offline_ = is_offline;
GE_CHK_STATUS_RET_NOLOG(impl_->BuildModel(graph, inputs, ge_root_model)); GE_CHK_STATUS_RET_NOLOG(impl_->BuildModel(graph, inputs, ge_root_model));
map<string, GeAttrValue> op_attrs = op_desc_tmp->GetAllAttrs(); map<string, GeAttrValue> op_attrs = op_desc_tmp->GetAllAttrs();
GE_CHECK_NOTNULL(ge_root_model); GE_CHECK_NOTNULL(ge_root_model);
@ -758,7 +758,7 @@ Status GeGenerator::BuildSingleOpModel(OpDescPtr &op_desc, const vector<GeTensor
ModelBufferData model_buff; ModelBufferData model_buff;
OpEngineType engine_type = ENGINE_SYS; OpEngineType engine_type = ENGINE_SYS;
Status status = BuildSingleOp(op_desc, inputs, outputs, model_file_name, engine_type, model_buff, true); Status status = BuildSingleOp(op_desc, inputs, outputs, model_file_name, engine_type, model_buff, true);
GELOGI("Finish build single offline model"); GELOGI("Finish build single offline model, status: %u", status);
return status; return status;
} }
@ -777,7 +777,7 @@ Status GeGenerator::BuildSingleOpModel(OpDescPtr &op_desc, const vector<GeTensor
ModelBufferData &model_buff) { ModelBufferData &model_buff) {
GELOGI("Start to build single op online, input size: %zu, output size: %zu", inputs.size(), outputs.size()); GELOGI("Start to build single op online, input size: %zu, output size: %zu", inputs.size(), outputs.size());
Status status = BuildSingleOp(op_desc, inputs, outputs, kFileNameSuffix, engine_type, model_buff, false); Status status = BuildSingleOp(op_desc, inputs, outputs, kFileNameSuffix, engine_type, model_buff, false);
GELOGI("Finish build single online model"); GELOGI("Finish build single online model, status: %u", status);
return status; return status;
} }

@ -755,6 +755,10 @@ set(MULTI_PARTS_TEST_FILES
"session/omg_omg_unittest.cc" "session/omg_omg_unittest.cc"
) )
set(GENERATOR_TEST_FILES
"generator/ge_generator_unittest.cc"
)
set(SINGLE_OP_TEST_FILES set(SINGLE_OP_TEST_FILES
#"single_op/single_op_model_unittest.cc" #"single_op/single_op_model_unittest.cc"
"single_op/single_op_manager_unittest.cc" "single_op/single_op_manager_unittest.cc"
@ -1055,6 +1059,7 @@ target_link_libraries(ut_libge_kernel_utest
# libge_distinct_load_utest # libge_distinct_load_utest
add_executable(ut_libge_distinct_load_utest add_executable(ut_libge_distinct_load_utest
${COMMON_TEST_FILES} ${COMMON_TEST_FILES}
${GENERATOR_TEST_FILES}
${DISTINCT_GRAPH_LOAD_TEST_FILES} ${DISTINCT_GRAPH_LOAD_TEST_FILES}
${DISTINCT_GRAPH_LOAD_SRC_FILES} ${DISTINCT_GRAPH_LOAD_SRC_FILES}
${SINGLE_OP_TEST_FILES} ${SINGLE_OP_TEST_FILES}

@ -0,0 +1,76 @@
/**
* Copyright 2019-2020 Huawei Technologies 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>
#define private public
#define protected public
#include "generator/ge_generator.h"
#include "graph/utils/tensor_utils.h"
using namespace std;
namespace ge {
class UtestGeGenerator : public testing::Test {
protected:
void SetUp() {}
void TearDown() {}
};
TEST_F(UtestGeGenerator, test_build_single_op_offline) {
GeTensorDesc tensor_desc(GeShape(), FORMAT_NCHW, DT_FLOAT);
TensorUtils::SetSize(tensor_desc, 512);
shared_ptr<OpDesc> op_desc = make_shared<OpDesc>("Add", "add");
EXPECT_EQ(op_desc->AddInputDesc(tensor_desc), GRAPH_SUCCESS);
EXPECT_EQ(op_desc->AddInputDesc(tensor_desc), GRAPH_SUCCESS);
EXPECT_EQ(op_desc->AddOutputDesc(tensor_desc), GRAPH_SUCCESS);
GeTensor tensor(tensor_desc);
const vector<GeTensor> inputs = { tensor, tensor };
const vector<GeTensor> outputs = { tensor };
// not Initialize, impl is null.
GeGenerator generator;
EXPECT_EQ(generator.BuildSingleOpModel(op_desc, inputs, outputs, "offline_"), PARAM_INVALID);
// const map<string, string> &options
generator.Initialize({});
EXPECT_EQ(generator.BuildSingleOpModel(op_desc, inputs, outputs, "offline_"), GE_GENERATOR_GRAPH_MANAGER_BUILD_GRAPH_FAILED);
}
TEST_F(UtestGeGenerator, test_build_single_op_online) {
GeTensorDesc tensor_desc(GeShape(), FORMAT_NCHW, DT_FLOAT);
TensorUtils::SetSize(tensor_desc, 512);
shared_ptr<OpDesc> op_desc = make_shared<OpDesc>("Add", "add");
EXPECT_EQ(op_desc->AddInputDesc(tensor_desc), GRAPH_SUCCESS);
EXPECT_EQ(op_desc->AddInputDesc(tensor_desc), GRAPH_SUCCESS);
EXPECT_EQ(op_desc->AddOutputDesc(tensor_desc), GRAPH_SUCCESS);
GeTensor tensor(tensor_desc);
const vector<GeTensor> inputs = { tensor, tensor };
const vector<GeTensor> outputs = { tensor };
// not Initialize, impl is null.
GeGenerator generator;
generator.Initialize({});
ModelBufferData model_buffer;
EXPECT_EQ(generator.BuildSingleOpModel(op_desc, inputs, outputs, ENGINE_SYS, model_buffer), GE_GENERATOR_GRAPH_MANAGER_BUILD_GRAPH_FAILED);
}
} // namespace ge
Loading…
Cancel
Save