aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/c/c_api_test.cc
diff options
context:
space:
mode:
authorGravatar Asim Shankar <ashankar@google.com>2018-02-08 13:17:53 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-02-08 13:22:08 -0800
commitcaced55cbc205a9423a480cae0bb9e7a9a10f3a1 (patch)
tree392754e09b8e28225707da44d38a5ffc006c72c2 /tensorflow/c/c_api_test.cc
parent785ac4418d60e3f69115c2a05ee989d620635a71 (diff)
C API: Fixes #7394
Ideally, when TF_NewTensor is provided with invalid arguments it would provide a detailed error message. However, for now, to keep the existing API, signal failure by returning nullptr. PiperOrigin-RevId: 185040858
Diffstat (limited to 'tensorflow/c/c_api_test.cc')
-rw-r--r--tensorflow/c/c_api_test.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/tensorflow/c/c_api_test.cc b/tensorflow/c/c_api_test.cc
index 01954eb235..0f71bd8f32 100644
--- a/tensorflow/c/c_api_test.cc
+++ b/tensorflow/c/c_api_test.cc
@@ -94,6 +94,17 @@ TEST(CAPI, Tensor) {
EXPECT_TRUE(deallocator_called);
}
+void NoOpDeallocator(void* data, size_t, void*) {}
+
+TEST(CAPI, MalformedTensor) {
+ // See https://github.com/tensorflow/tensorflow/issues/7394
+ // num_dims = 0 implies a scalar, so should be backed by at least 4 bytes of
+ // data.
+ TF_Tensor* t =
+ TF_NewTensor(TF_FLOAT, nullptr, 0, nullptr, 0, &NoOpDeallocator, nullptr);
+ ASSERT_TRUE(t == nullptr);
+}
+
TEST(CAPI, AllocateTensor) {
const int num_bytes = 6 * sizeof(float);
int64_t dims[] = {2, 3};