diff options
author | 2018-03-22 20:51:51 -0700 | |
---|---|---|
committer | 2018-03-22 20:54:37 -0700 | |
commit | 0191d264a6e3da12ff7db5ba8002fed6356f071b (patch) | |
tree | 1e974458c633f2f64e3a6d6165e66905c7605083 /tensorflow/c/c_api_experimental_test.cc | |
parent | 72f48771ea4fce68af893bcda862ca390a0e6b70 (diff) |
Added experimental C APIs to build a hard-coded stack of dataset + iterator.
PiperOrigin-RevId: 190170332
Diffstat (limited to 'tensorflow/c/c_api_experimental_test.cc')
-rw-r--r-- | tensorflow/c/c_api_experimental_test.cc | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tensorflow/c/c_api_experimental_test.cc b/tensorflow/c/c_api_experimental_test.cc new file mode 100644 index 0000000000..9ddd65f0c5 --- /dev/null +++ b/tensorflow/c/c_api_experimental_test.cc @@ -0,0 +1,66 @@ +/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "tensorflow/c/c_api_experimental.h" +#include "tensorflow/c/c_test_util.h" + +namespace tensorflow { +namespace { + +void TestIteratorStack() { + TF_Status* s = TF_NewStatus(); + TF_Graph* graph = TF_NewGraph(); + + TF_Function* dataset_func = nullptr; + + TF_Operation* get_next = + TF_MakeIteratorGetNextWithDatasets(graph, "dummy_path", &dataset_func, s); + ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); + + ASSERT_NE(dataset_func, nullptr); + TF_DeleteFunction(dataset_func); + + CSession csession(graph, s); + ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); + + // Run the graph. + for (int i = 0; i < 1; ++i) { + csession.SetOutputs({get_next}); + csession.Run(s); + ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); + TF_Tensor* out = csession.output_tensor(0); + ASSERT_TRUE(out != nullptr); + EXPECT_EQ(TF_INT32, TF_TensorType(out)); + EXPECT_EQ(0, TF_NumDims(out)); // scalar + ASSERT_EQ(sizeof(int32), TF_TensorByteSize(out)); + int32* output_contents = static_cast<int32*>(TF_TensorData(out)); + EXPECT_EQ(1, *output_contents); + } + + // This should error out since we've exhausted the iterator. + csession.Run(s); + ASSERT_EQ(TF_OUT_OF_RANGE, TF_GetCode(s)) << TF_Message(s); + + // Clean up + csession.CloseAndDelete(s); + ASSERT_EQ(TF_OK, TF_GetCode(s)) << TF_Message(s); + TF_DeleteGraph(graph); + TF_DeleteStatus(s); +} + +TEST(CAPI_EXPERIMENTAL, IteratorGetNext) { TestIteratorStack(); } + +} // namespace +} // namespace tensorflow |