| 1535 | } |
| 1536 | |
| 1537 | void TestUpdateFanin(absl::string_view node_name, bool node_exists, |
| 1538 | const TensorId& from_fanin, const TensorId& to_fanin, |
| 1539 | bool success, const string& error_msg, |
| 1540 | absl::Span<const string> expected_fanins) { |
| 1541 | GraphDef graph_def = SimpleMutateFaninGraph(); |
| 1542 | |
| 1543 | MutableGraphView graph(&graph_def); |
| 1544 | |
| 1545 | NodeDef* node = graph.GetNode(node_name); |
| 1546 | if (node_exists) { |
| 1547 | EXPECT_NE(node, nullptr); |
| 1548 | } else { |
| 1549 | EXPECT_EQ(node, nullptr); |
| 1550 | } |
| 1551 | |
| 1552 | absl::flat_hash_map<string, std::vector<string>> unmodified_node_inputs = |
| 1553 | GetNodeInputsFromGraph(graph_def, node_name); |
| 1554 | |
| 1555 | Status s = graph.UpdateFanin(node_name, from_fanin, to_fanin); |
| 1556 | EXPECT_EQ(s.ok(), success); |
| 1557 | if (!success) { |
| 1558 | EXPECT_EQ(s.error_message(), error_msg); |
| 1559 | } |
| 1560 | if (node_exists) { |
| 1561 | CompareNodeFanins(graph, node, expected_fanins); |
| 1562 | if (success) { |
| 1563 | CheckFanoutRemoved(graph, from_fanin, node_name); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | CheckUnmodifiedNodeFanins(graph_def, node_name, unmodified_node_inputs); |
| 1568 | |
| 1569 | CheckGraph(graph); |
| 1570 | } |
| 1571 | |
| 1572 | TEST(MutableGraphViewTest, UpdateFanin) { |
| 1573 | string error_msg; |
no test coverage detected