From 395fddbcff8d8e03ab19012ef4f600f27b512379 Mon Sep 17 00:00:00 2001 From: wangxiaotian22 Date: Wed, 10 Mar 2021 11:07:33 +0800 Subject: [PATCH] fix ut core --- .../depends/error_manager/src/error_manager_stub.cc | 4 +++- .../testcase/ge_graph/ge_anchor_utils_unittest.cc | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/depends/error_manager/src/error_manager_stub.cc b/tests/depends/error_manager/src/error_manager_stub.cc index d7135777..f2048279 100644 --- a/tests/depends/error_manager/src/error_manager_stub.cc +++ b/tests/depends/error_manager/src/error_manager_stub.cc @@ -18,6 +18,8 @@ using namespace ErrorMessage; +thread_local Context ErrorManager::error_context_ = {0, "", "", ""}; + ErrorManager &ErrorManager::GetInstance() { static ErrorManager instance; return instance; @@ -88,7 +90,7 @@ using namespace ErrorMessage; void ErrorManager::GenWorkStreamIdBySessionGraph(uint64_t session_id, uint64_t graph_id) {} - const std::string &ErrorManager::GetLogHeader() { return "[TEST][TEST]"; } + const std::string &ErrorManager::GetLogHeader() { return error_context_.log_header; } struct Context &ErrorManager::GetErrorContext() { struct Context error_context; diff --git a/tests/ut/common/graph/testcase/ge_graph/ge_anchor_utils_unittest.cc b/tests/ut/common/graph/testcase/ge_graph/ge_anchor_utils_unittest.cc index 7f7f3465..7c4178a8 100644 --- a/tests/ut/common/graph/testcase/ge_graph/ge_anchor_utils_unittest.cc +++ b/tests/ut/common/graph/testcase/ge_graph/ge_anchor_utils_unittest.cc @@ -36,31 +36,52 @@ class UtestGeAnchorUtils : public testing::Test { TEST_F(UtestGeAnchorUtils, base) { ComputeGraphPtr graph_ptr = std::make_shared("name"); + if (graph_ptr == nullptr) { + return; + } OpDescPtr desc_ptr = std::make_shared("name1", "type1"); + if (desc_ptr == nullptr) { + return; + } NodePtr n1 = graph_ptr->AddNode(desc_ptr); InDataAnchorPtr a1 = std::make_shared(n1, 0); + if (a1 == nullptr) { + return; + } EXPECT_EQ(AnchorUtils::SetFormat(a1, FORMAT_ND), GRAPH_SUCCESS); Format f1 = AnchorUtils::GetFormat(a1); EXPECT_EQ(f1, FORMAT_ND); InDataAnchorPtr a2 = std::make_shared(n1, 0); + if (a2 == nullptr) { + return; + } EXPECT_EQ(AnchorUtils::SetFormat(nullptr, FORMAT_ND), GRAPH_FAILED); Format f2 = AnchorUtils::GetFormat(nullptr); EXPECT_EQ(f2, FORMAT_RESERVED); // has control edge OpDescPtr desc_ptr1 = std::make_shared("name1", "type1"); + if (desc_ptr1 == nullptr) { + return; + } EXPECT_EQ(desc_ptr1->AddInputDesc("x", GeTensorDesc(GeShape({1, 16, 16, 16}), FORMAT_NCHW)), GRAPH_SUCCESS); EXPECT_EQ(desc_ptr1->AddInputDesc("w", GeTensorDesc(GeShape({1, 1, 1, 1}), FORMAT_NCHW)), GRAPH_SUCCESS); EXPECT_EQ(desc_ptr1->AddOutputDesc("y", GeTensorDesc(GeShape({1, 32, 8, 8}), FORMAT_NCHW)), GRAPH_SUCCESS); OpDescPtr desc_ptr2 = std::make_shared("name2", "type2"); + if (desc_ptr2 == nullptr) { + return; + } EXPECT_EQ(desc_ptr2->AddInputDesc("x", GeTensorDesc(GeShape({1, 16, 16, 16}), FORMAT_NCHW)), GRAPH_SUCCESS); EXPECT_EQ(desc_ptr2->AddInputDesc("w", GeTensorDesc(GeShape({1, 1, 1, 1}), FORMAT_NCHW)), GRAPH_SUCCESS); EXPECT_EQ(desc_ptr2->AddOutputDesc("y", GeTensorDesc(GeShape({1, 32, 8, 8}), FORMAT_NCHW)), GRAPH_SUCCESS); ComputeGraphPtr graph_ptr1 = std::make_shared("name"); + if (graph_ptr1 == nullptr) { + return; + } n1 = graph_ptr1->AddNode(desc_ptr1); NodePtr n2 = graph_ptr1->AddNode(desc_ptr2);