onnxruntime/test/ir/graph_test.cc
TEST(NameResolutionTest, DuplicateName) {
  Model model("graph_1");
  auto& graph = model.MainGraph();

  ONNX_NAMESPACE::TensorProto weight;
  weight.set_data_type(TensorProto_DataType_FLOAT);
  weight.add_dims(1);
  weight.add_float_data(1.0f);
  weight.set_name("W");
  graph.AddInitializedTensor(weight);

  std::vector<NodeArg*> inputs;
  std::vector<NodeArg*> outputs;
  TypeProto tensor_type;
  tensor_type.mutable_tensor_type()->set_elem_type(TensorProto_DataType_FLOAT);
  tensor_type.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(2);
  auto& X = graph.GetOrCreateNodeArg("X", &tensor_type);
  inputs.push_back(&X);
  auto& Y = graph.GetOrCreateNodeArg("Y", nullptr);
  outputs.push_back(&Y);
  auto& W = graph.GetOrCreateNodeArg("W", nullptr);
  outputs.push_back(&W);
  graph.AddNode("node_1", "Split", "node 1.", inputs, outputs);

  auto status = graph.Resolve();
  EXPECT_FALSE(status.IsOK());
  bool duplicate_error_found = status.ErrorMessage().find("Duplicate") != std::string::npos;
  EXPECT_TRUE(duplicate_error_found);
}
// Test that Graph::Resolve identifies name-duplication across initializer and node-output-arg
Test that Graph::Resolve identifies name-duplication across initializer and node-output-arg
Test that Graph :: Resolve identifies name - duplication across initializer and node - output - arg
TEST(NameResolutionTest, DuplicateName) {
  Model model("graph_1");
  auto& graph = model.MainGraph();
  ONNX_NAMESPACE::TensorProto weight;
  weight.set_data_type(TensorProto_DataType_FLOAT);
  weight.add_dims(1);
  weight.add_float_data(1.0f);
  weight.set_name("W");
  graph.AddInitializedTensor(weight);
  std::vector<NodeArg*> inputs;
  std::vector<NodeArg*> outputs;
  TypeProto tensor_type;
  tensor_type.mutable_tensor_type()->set_elem_type(TensorProto_DataType_FLOAT);
  tensor_type.mutable_tensor_type()->mutable_shape()->add_dim()->set_dim_value(2);
  auto& X = graph.GetOrCreateNodeArg("X", &tensor_type);
  inputs.push_back(&X);
  auto& Y = graph.GetOrCreateNodeArg("Y", nullptr);
  outputs.push_back(&Y);
  auto& W = graph.GetOrCreateNodeArg("W", nullptr);
  outputs.push_back(&W);
  graph.AddNode("node_1", "Split", "node 1.", inputs, outputs);
  auto status = graph.Resolve();
  EXPECT_FALSE(status.IsOK());
  bool duplicate_error_found = status.ErrorMessage().find("Duplicate") != std::string::npos;
  EXPECT_TRUE(duplicate_error_found);
}
TEST ( NameResolutionTest , DuplicateName ) { Model model ( " " ) ; auto & graph = model . MainGraph ( ) ; ONNX_NAMESPACE :: TensorProto weight ; weight . set_data_type ( TensorProto_DataType_FLOAT ) ; weight . add_dims ( 1 ) ; weight . add_float_data ( 1.0f ) ; weight . set_name ( " " ) ; graph . AddInitializedTensor ( weight ) ; std :: vector < NodeArg * > inputs ; std :: vector < NodeArg * > outputs ; TypeProto tensor_type ; tensor_type . mutable_tensor_type ( ) -> set_elem_type ( TensorProto_DataType_FLOAT ) ; tensor_type . mutable_tensor_type ( ) -> mutable_shape ( ) -> add_dim ( ) -> set_dim_value ( 2 ) ; auto & X = graph . GetOrCreateNodeArg ( " " , & tensor_type ) ; inputs . push_back ( & X ) ; auto & Y = graph . GetOrCreateNodeArg ( " " , nullptr ) ; outputs . push_back ( & Y ) ; auto & W = graph . GetOrCreateNodeArg ( " " , nullptr ) ; outputs . push_back ( & W ) ; graph . AddNode ( " " , " " , " " , inputs , outputs ) ; auto status = graph . Resolve ( ) ; EXPECT_FALSE ( status . IsOK ( ) ) ; bool duplicate_error_found = status . ErrorMessage ( ) . find ( " " ) != std :: string :: npos ; EXPECT_TRUE ( duplicate_error_found ) ; }
Test that Graph::Resolve identifies name-duplication across initializer and node-output-arg
Test that Graph :: Resolve identifies name - duplication across initializer and node - output - arg