| 296 | public ::testing::WithParamInterface<TestCase> {}; |
| 297 | |
| 298 | TEST_P(ParameterizedInterleaveDatasetOpTest, GetNext) { |
| 299 | int thread_num = 2, cpu_num = 2; |
| 300 | const TestCase &test_case = GetParam(); |
| 301 | TF_ASSERT_OK(InitThreadPool(thread_num)); |
| 302 | TF_ASSERT_OK(InitFunctionLibraryRuntime(test_case.func_lib, cpu_num)); |
| 303 | |
| 304 | std::unique_ptr<OpKernel> interleave_dataset_kernel; |
| 305 | TF_ASSERT_OK(CreateInterleaveDatasetKernel( |
| 306 | test_case.func, test_case.expected_output_dtypes, |
| 307 | test_case.expected_output_shapes, &interleave_dataset_kernel)); |
| 308 | |
| 309 | Tensor tensor_slice_dataset_tensor(DT_VARIANT, TensorShape({})); |
| 310 | std::vector<Tensor> inputs_for_tensor_slice_dataset = test_case.input_tensors; |
| 311 | TF_ASSERT_OK(CreateTensorSliceDatasetTensor(&inputs_for_tensor_slice_dataset, |
| 312 | &tensor_slice_dataset_tensor)); |
| 313 | Tensor cycle_length = test_case.cycle_length; |
| 314 | Tensor block_length = test_case.block_length; |
| 315 | gtl::InlinedVector<TensorValue, 4> inputs( |
| 316 | {TensorValue(&tensor_slice_dataset_tensor), TensorValue(&cycle_length), |
| 317 | TensorValue(&block_length)}); |
| 318 | std::unique_ptr<OpKernelContext> interleave_dataset_context; |
| 319 | TF_ASSERT_OK(CreateInterleaveDatasetContext( |
| 320 | interleave_dataset_kernel.get(), &inputs, &interleave_dataset_context)); |
| 321 | DatasetBase *interleave_dataset; |
| 322 | TF_ASSERT_OK(CreateDataset(interleave_dataset_kernel.get(), |
| 323 | interleave_dataset_context.get(), |
| 324 | &interleave_dataset)); |
| 325 | core::ScopedUnref scoped_unref(interleave_dataset); |
| 326 | |
| 327 | std::unique_ptr<IteratorContext> iterator_ctx; |
| 328 | TF_ASSERT_OK( |
| 329 | CreateIteratorContext(interleave_dataset_context.get(), &iterator_ctx)); |
| 330 | std::unique_ptr<IteratorBase> iterator; |
| 331 | TF_ASSERT_OK(interleave_dataset->MakeIterator(iterator_ctx.get(), "Iterator", |
| 332 | &iterator)); |
| 333 | auto expected_outputs_it = test_case.expected_outputs.begin(); |
| 334 | bool end_of_sequence = false; |
| 335 | std::vector<Tensor> out_tensors; |
| 336 | while (!end_of_sequence) { |
| 337 | TF_EXPECT_OK( |
| 338 | iterator->GetNext(iterator_ctx.get(), &out_tensors, &end_of_sequence)); |
| 339 | if (!end_of_sequence) { |
| 340 | for (const auto &tensor : out_tensors) { |
| 341 | EXPECT_NE(expected_outputs_it, test_case.expected_outputs.end()); |
| 342 | TF_EXPECT_OK(ExpectEqual(tensor, *expected_outputs_it)); |
| 343 | expected_outputs_it++; |
| 344 | } |
| 345 | } |
| 346 | } |
| 347 | EXPECT_EQ(expected_outputs_it, test_case.expected_outputs.end()); |
| 348 | } |
| 349 | |
| 350 | TEST_F(InterleaveDatasetOpTest, InvalidCycleLength) { |
| 351 | int thread_num = 2, cpu_num = 2; |
nothing calls this directly
no test coverage detected