aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite/interpreter_test.cc
diff options
context:
space:
mode:
authorGravatar Yu-Cheng Ling <ycling@google.com>2018-02-26 11:22:43 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-02-26 11:30:09 -0800
commite5b73fc9a8df0d87cb964ed49e946d2477c73e19 (patch)
tree3a96fabfb15e73003e6e01216b3a6761cc95adf2 /tensorflow/contrib/lite/interpreter_test.cc
parentb7b4fe66ee8adf936b1c2508a298c1e26a858af1 (diff)
TFLite: Ensures pointers to tensors won't be invalidated unless 16+ tensors are added.
PiperOrigin-RevId: 187052100
Diffstat (limited to 'tensorflow/contrib/lite/interpreter_test.cc')
-rw-r--r--tensorflow/contrib/lite/interpreter_test.cc40
1 files changed, 40 insertions, 0 deletions
diff --git a/tensorflow/contrib/lite/interpreter_test.cc b/tensorflow/contrib/lite/interpreter_test.cc
index 28c96e5dde..2e6727b323 100644
--- a/tensorflow/contrib/lite/interpreter_test.cc
+++ b/tensorflow/contrib/lite/interpreter_test.cc
@@ -561,6 +561,46 @@ TEST(BasicInterpreter, TestCustomErrorReporter) {
ASSERT_EQ(reporter.calls, 1);
}
+TEST(InterpreterTensorsCapacityTest, TestWithinHeadroom) {
+ Interpreter interpreter;
+ ASSERT_EQ(interpreter.AddTensors(Interpreter::kTensorsReservedCapacity),
+ kTfLiteOk);
+ TfLiteRegistration registration = {nullptr, nullptr, nullptr, nullptr};
+ registration.prepare = [](TfLiteContext* context, TfLiteNode* node) {
+ TfLiteTensor* first_tensor = context->tensors;
+
+ int new_tensor_index;
+ context->AddTensors(context, Interpreter::kTensorsCapacityHeadroom,
+ &new_tensor_index);
+ EXPECT_EQ(first_tensor, context->tensors);
+ return kTfLiteOk;
+ };
+ ASSERT_EQ(interpreter.AddNodeWithParameters({0}, {1}, nullptr, 0, nullptr,
+ &registration),
+ kTfLiteOk);
+ ASSERT_EQ(interpreter.AllocateTensors(), kTfLiteOk);
+}
+
+TEST(InterpreterTensorsCapacityTest, TestExceedHeadroom) {
+ Interpreter interpreter;
+ ASSERT_EQ(interpreter.AddTensors(Interpreter::kTensorsReservedCapacity),
+ kTfLiteOk);
+ TfLiteRegistration registration = {nullptr, nullptr, nullptr, nullptr};
+ registration.prepare = [](TfLiteContext* context, TfLiteNode* node) {
+ TfLiteTensor* first_tensor = context->tensors;
+
+ int new_tensor_index;
+ context->AddTensors(context, Interpreter::kTensorsCapacityHeadroom + 1,
+ &new_tensor_index);
+ EXPECT_NE(first_tensor, context->tensors);
+ return kTfLiteOk;
+ };
+ ASSERT_EQ(interpreter.AddNodeWithParameters({0}, {1}, nullptr, 0, nullptr,
+ &registration),
+ kTfLiteOk);
+ ASSERT_EQ(interpreter.AllocateTensors(), kTfLiteOk);
+}
+
// Test fixture that allows playing with execution plans. It creates a two
// node graph that can be executed in either [0,1] order or [1,0] order.
// The CopyOp records when it is invoked in the class member run_order_