Process an 'invoke' message, triggering execution of the test runner, as well as verification of outputs. An 'invoke' message looks like: invoke { id: xyz input: 1,2,1,1,1,2,3,4 output: 4,5,6 }
| 253 | // output: 4,5,6 |
| 254 | // } |
| 255 | class Invoke : public Message { |
| 256 | public: |
| 257 | explicit Invoke(TestRunner* test_runner) : test_runner_(test_runner) { |
| 258 | expected_inputs_ = test_runner->GetInputs(); |
| 259 | expected_outputs_ = test_runner->GetOutputs(); |
| 260 | } |
| 261 | |
| 262 | void SetField(const std::string& name, const std::string& value) override { |
| 263 | if (name == "id") { |
| 264 | test_runner_->SetInvocationId(value); |
| 265 | } else if (name == "input") { |
| 266 | if (parsed_input_count_ >= expected_inputs_.size()) { |
| 267 | return test_runner_->Invalidate("Too many inputs"); |
| 268 | } |
| 269 | test_runner_->SetInput(expected_inputs_[parsed_input_count_], value); |
| 270 | ++parsed_input_count_; |
| 271 | } else if (name == "output") { |
| 272 | if (parsed_output_count_ >= expected_outputs_.size()) { |
| 273 | return test_runner_->Invalidate("Too many outputs"); |
| 274 | } |
| 275 | test_runner_->SetExpectation(expected_outputs_[parsed_output_count_], |
| 276 | value); |
| 277 | ++parsed_output_count_; |
| 278 | } else if (name == "output_shape") { |
| 279 | if (parsed_output_shape_count_ >= expected_outputs_.size()) { |
| 280 | return test_runner_->Invalidate("Too many output shapes"); |
| 281 | } |
| 282 | test_runner_->SetShapeExpectation( |
| 283 | expected_outputs_[parsed_output_shape_count_], value); |
| 284 | ++parsed_output_shape_count_; |
| 285 | } |
| 286 | } |
| 287 | void Finish() override { |
| 288 | test_runner_->Invoke(); |
| 289 | test_runner_->CheckResults(); |
| 290 | } |
| 291 | |
| 292 | private: |
| 293 | std::vector<int> expected_inputs_; |
| 294 | std::vector<int> expected_outputs_; |
| 295 | |
| 296 | int parsed_input_count_ = 0; |
| 297 | int parsed_output_count_ = 0; |
| 298 | int parsed_output_shape_count_ = 0; |
| 299 | |
| 300 | TestRunner* test_runner_; |
| 301 | }; |
| 302 | |
| 303 | // Process an 'reshape' message, triggering resizing of the input tensors via |
| 304 | // the test runner. A 'reshape' message looks like: |