| 260 | public ::testing::WithParamInterface<TestCase> {}; |
| 261 | |
| 262 | TEST_P(ParameterizedShardDatasetOpTest, GetNext) { |
| 263 | int thread_num = 2, cpu_num = 2; |
| 264 | TestCase test_case = GetParam(); |
| 265 | TF_ASSERT_OK(InitThreadPool(thread_num)); |
| 266 | TF_ASSERT_OK(InitFunctionLibraryRuntime({}, cpu_num)); |
| 267 | |
| 268 | std::unique_ptr<OpKernel> shard_dataset_kernel; |
| 269 | TF_ASSERT_OK(CreateShardDatasetOpKernel( |
| 270 | test_case.require_non_empty, test_case.expected_output_dtypes, |
| 271 | test_case.expected_output_shapes, &shard_dataset_kernel)); |
| 272 | |
| 273 | DatasetBase* range_dataset; |
| 274 | TF_ASSERT_OK(CreateRangeDataset<int64>( |
| 275 | test_case.range_dataset_param.start, test_case.range_dataset_param.end, |
| 276 | test_case.range_dataset_param.step, "range", &range_dataset)); |
| 277 | Tensor range_dataset_tensor(DT_VARIANT, TensorShape({})); |
| 278 | TF_ASSERT_OK( |
| 279 | StoreDatasetInVariantTensor(range_dataset, &range_dataset_tensor)); |
| 280 | |
| 281 | Tensor num_shards = test_case.num_shards; |
| 282 | Tensor index = test_case.index; |
| 283 | gtl::InlinedVector<TensorValue, 4> inputs({TensorValue(&range_dataset_tensor), |
| 284 | TensorValue(&num_shards), |
| 285 | TensorValue(&index)}); |
| 286 | std::unique_ptr<OpKernelContext> shard_dataset_context; |
| 287 | TF_ASSERT_OK(CreateShardDatasetContext(shard_dataset_kernel.get(), &inputs, |
| 288 | &shard_dataset_context)); |
| 289 | |
| 290 | DatasetBase* shard_dataset; |
| 291 | TF_ASSERT_OK(CreateDataset(shard_dataset_kernel.get(), |
| 292 | shard_dataset_context.get(), &shard_dataset)); |
| 293 | core::ScopedUnref scoped_unref_batch_dataset(shard_dataset); |
| 294 | |
| 295 | std::unique_ptr<IteratorContext> iterator_ctx; |
| 296 | TF_ASSERT_OK( |
| 297 | CreateIteratorContext(shard_dataset_context.get(), &iterator_ctx)); |
| 298 | std::unique_ptr<IteratorBase> iterator; |
| 299 | TF_ASSERT_OK( |
| 300 | shard_dataset->MakeIterator(iterator_ctx.get(), "Iterator", &iterator)); |
| 301 | |
| 302 | bool end_of_sequence = false; |
| 303 | auto expected_outputs_it = test_case.expected_outputs.begin(); |
| 304 | std::vector<Tensor> out_tensors; |
| 305 | while (!end_of_sequence) { |
| 306 | TF_EXPECT_OK( |
| 307 | iterator->GetNext(iterator_ctx.get(), &out_tensors, &end_of_sequence)); |
| 308 | if (!end_of_sequence) { |
| 309 | EXPECT_LT(expected_outputs_it, test_case.expected_outputs.end()); |
| 310 | TF_EXPECT_OK(ExpectEqual(out_tensors.back(), *expected_outputs_it)); |
| 311 | expected_outputs_it++; |
| 312 | } |
| 313 | } |
| 314 | EXPECT_EQ(expected_outputs_it, test_case.expected_outputs.end()); |
| 315 | } |
| 316 | |
| 317 | TEST_F(ShardDatasetOpTest, DatasetNodeName) { |
| 318 | int thread_num = 2, cpu_num = 2; |
nothing calls this directly
no test coverage detected