| 152 | public ::testing::WithParamInterface<TestCase> {}; |
| 153 | |
| 154 | TEST_P(ParameterizedCacheDatasetOpTest, GetNext) { |
| 155 | int thread_num = 2, cpu_num = 2; |
| 156 | TestCase test_case = GetParam(); |
| 157 | TF_ASSERT_OK(InitThreadPool(thread_num)); |
| 158 | TF_ASSERT_OK(InitFunctionLibraryRuntime({}, cpu_num)); |
| 159 | |
| 160 | std::unique_ptr<OpKernel> cache_dataset_kernel; |
| 161 | TF_ASSERT_OK(CreateCacheDatasetOpKernel(test_case.expected_output_dtypes, |
| 162 | test_case.expected_output_shapes, |
| 163 | &cache_dataset_kernel)); |
| 164 | Tensor tensor_slice_dataset_tensor(DT_VARIANT, TensorShape({})); |
| 165 | std::vector<Tensor> inputs_for_tensor_slice_dataset = test_case.input_tensors; |
| 166 | TF_ASSERT_OK(CreateTensorSliceDatasetTensor(&inputs_for_tensor_slice_dataset, |
| 167 | &tensor_slice_dataset_tensor)); |
| 168 | Tensor file_name = |
| 169 | CreateTensor<tstring>(TensorShape{}, {test_case.file_name}); |
| 170 | gtl::InlinedVector<TensorValue, 4> inputs( |
| 171 | {TensorValue(&tensor_slice_dataset_tensor), TensorValue(&file_name)}); |
| 172 | std::unique_ptr<OpKernelContext> cache_dataset_context; |
| 173 | TF_ASSERT_OK(CreateCacheDatasetContext(cache_dataset_kernel.get(), &inputs, |
| 174 | &cache_dataset_context)); |
| 175 | DatasetBase* cache_dataset; |
| 176 | TF_ASSERT_OK(CreateDataset(cache_dataset_kernel.get(), |
| 177 | cache_dataset_context.get(), &cache_dataset)); |
| 178 | core::ScopedUnref scoped_unref(cache_dataset); |
| 179 | |
| 180 | std::unique_ptr<IteratorContext> iterator_ctx; |
| 181 | TF_ASSERT_OK( |
| 182 | CreateIteratorContext(cache_dataset_context.get(), &iterator_ctx)); |
| 183 | std::unique_ptr<IteratorBase> iterator; |
| 184 | TF_ASSERT_OK(cache_dataset->MakeIterator(iterator_ctx.get(), kIteratorPrefix, |
| 185 | &iterator)); |
| 186 | |
| 187 | // Test the write mode. |
| 188 | bool end_of_sequence = false; |
| 189 | std::vector<Tensor> out_tensors; |
| 190 | while (!end_of_sequence) { |
| 191 | std::vector<Tensor> next; |
| 192 | TF_EXPECT_OK( |
| 193 | iterator->GetNext(iterator_ctx.get(), &next, &end_of_sequence)); |
| 194 | out_tensors.insert(out_tensors.end(), next.begin(), next.end()); |
| 195 | } |
| 196 | TF_EXPECT_OK(ExpectEqual(out_tensors, test_case.expected_outputs, |
| 197 | /*compare_order*/ true)); |
| 198 | |
| 199 | // Test the read mode. |
| 200 | TF_ASSERT_OK(cache_dataset->MakeIterator(iterator_ctx.get(), kIteratorPrefix, |
| 201 | &iterator)); |
| 202 | end_of_sequence = false; |
| 203 | out_tensors.clear(); |
| 204 | while (!end_of_sequence) { |
| 205 | std::vector<Tensor> next; |
| 206 | TF_EXPECT_OK( |
| 207 | iterator->GetNext(iterator_ctx.get(), &next, &end_of_sequence)); |
| 208 | out_tensors.insert(out_tensors.end(), next.begin(), next.end()); |
| 209 | } |
| 210 | TF_EXPECT_OK(ExpectEqual(out_tensors, test_case.expected_outputs, |
| 211 | /*compare_order*/ true)); |
nothing calls this directly
no test coverage detected