tensorflow/core/framework/graph_to_functiondef_test.cc
// Regression test for a crash if there was a control edge to a _Retval node.
Regression test for a crash if there was a control edge to a _Retval node.
Regression test for a crash if there was a control edge to a _Retval node .
TEST(GraphToFunctionDefTest, ControlDependencies) {
  Scope root = Scope::NewRootScope().ExitOnError();
  auto a = ops::_Arg(root.WithOpName("a"), DT_FLOAT, 0);
  auto b = ops::Neg(root.WithOpName("b").WithControlDependencies(a), a);
  auto c = ops::_Retval(root.WithOpName("c").WithControlDependencies(b), b, 0);
  GraphDef graph_def;
  TF_EXPECT_OK(root.ToGraphDef(&graph_def));
  std::unique_ptr<Graph> graph(new Graph(OpRegistry::Global()));
  GraphConstructorOptions options;
  TF_EXPECT_OK(ConvertGraphDefToGraph(options, graph_def, graph.get()));
  FunctionDef fdef;
  TF_EXPECT_OK(GraphToFunctionDef(*graph, "test_fn", &fdef));
  FunctionDef fdef_expected = FunctionDefHelper::Create(
      "test_fn",     
      {"a: float"},  
      {"c: float"},  
      {},            
      {
          {{"b"}, "Neg", {"a", "^a"}, {{"T", DT_FLOAT}}},
      },
      {{"c", "b:y:0"}});  
  string diff;
  bool fdefs_equal =
      EqualFunctionDef(fdef_expected, RemoveDebugInfo(fdef), &diff);
  EXPECT_TRUE(fdefs_equal) << diff;
}
TEST ( GraphToFunctionDefTest , ControlDependencies ) { Scope root = Scope :: NewRootScope ( ) . ExitOnError ( ) ; auto a = ops :: _Arg ( root . WithOpName ( " " ) , DT_FLOAT , 0 ) ; auto b = ops :: Neg ( root . WithOpName ( " " ) . WithControlDependencies ( a ) , a ) ; auto c = ops :: _Retval ( root . WithOpName ( " " ) . WithControlDependencies ( b ) , b , 0 ) ; GraphDef graph_def ; TF_EXPECT_OK ( root . ToGraphDef ( & graph_def ) ) ; std :: unique_ptr < Graph > graph ( new Graph ( OpRegistry :: Global ( ) ) ) ; GraphConstructorOptions options ; TF_EXPECT_OK ( ConvertGraphDefToGraph ( options , graph_def , graph . get ( ) ) ) ; FunctionDef fdef ; TF_EXPECT_OK ( GraphToFunctionDef ( * graph , " " , & fdef ) ) ; FunctionDef fdef_expected = FunctionDefHelper :: Create ( " " , { " " } , { " " } , { } , { { { " " } , " " , { " " , " " } , { { " " , DT_FLOAT } } } , } , { { " " , " " } } ) ; string diff ; bool fdefs_equal = EqualFunctionDef ( fdef_expected , RemoveDebugInfo ( fdef ) , & diff ) ; EXPECT_TRUE ( fdefs_equal ) << diff ; }
Regression test for a crash if there was a control edge to a _Retval node.
Regression test for a crash if there was a control edge to a _Retval node .
// function name // inputs // outputs // attrs // nodes in the function body // return values