| 107 | |
| 108 | struct NodeMatcher : public ::testing::MatcherInterface<const Node*> { |
| 109 | bool MatchAndExplain( |
| 110 | const Node* node, |
| 111 | ::testing::MatchResultListener* listener) const override { |
| 112 | if (op && node->type_string() != *op) { |
| 113 | if (listener->IsInterested()) { |
| 114 | *listener << "\nexpected op " << *op << " but found " |
| 115 | << node->type_string(); |
| 116 | } |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | if (assigned_device && node->assigned_device_name() != *assigned_device) { |
| 121 | if (listener->IsInterested()) { |
| 122 | *listener << "\nexpected assigned_device " << *assigned_device |
| 123 | << " but found \"" << node->assigned_device_name() << "\""; |
| 124 | } |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | if (name && node->name() != *name) { |
| 129 | if (listener->IsInterested()) { |
| 130 | *listener << "\nexpected name " << *name << " but found " |
| 131 | << node->name(); |
| 132 | } |
| 133 | return false; |
| 134 | } |
| 135 | |
| 136 | if (constant_value) { |
| 137 | const TensorProto* proto = nullptr; |
| 138 | if (!TryGetNodeAttr(node->def(), "value", &proto)) { |
| 139 | if (listener->IsInterested()) { |
| 140 | *listener << "\ncould not find \"value\" attribute in node"; |
| 141 | } |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | Tensor tensor(proto->dtype()); |
| 146 | if (!tensor.FromProto(*proto)) { |
| 147 | if (listener->IsInterested()) { |
| 148 | *listener << "\ncould not convert TensorProto in \"value\" attribute " |
| 149 | "to Tensor"; |
| 150 | } |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | if (!MatchAndExplainTensor(/*tensor=*/tensor, |
| 155 | /*expected_tensor=*/*constant_value, |
| 156 | listener)) { |
| 157 | return false; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if (input_matchers) { |
| 162 | if (input_matchers->size() != node->num_inputs()) { |
| 163 | if (listener->IsInterested()) { |
| 164 | *listener << "\nexpected " << input_matchers->size() |
| 165 | << " inputs but node has " << node->num_inputs(); |
| 166 | } |