aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite/interpreter_test.cc
diff options
context:
space:
mode:
authorGravatar Yu-Cheng Ling <ycling@google.com>2018-03-08 16:16:47 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-03-08 16:21:23 -0800
commit7c3c5801d67a2d56d4015c3f505f3d89386cb394 (patch)
treea43fd3eaf15e0efdc6f22221ff9f65e27c907624 /tensorflow/contrib/lite/interpreter_test.cc
parente8f6485d88dbf4027917e3559519b2f363325479 (diff)
Return kTfLiteError if calling delegate-specific functions from non-delegate code.
PiperOrigin-RevId: 188407931
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 2586c15287..17eb2f4b07 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(BasicInterpreter, TestUnsupportedDelegateFunctions) {
+ Interpreter interpreter;
+ ASSERT_EQ(interpreter.AddTensors(2), kTfLiteOk);
+ TfLiteRegistration registration = {
+ .init = nullptr, .free = nullptr, .prepare = nullptr, .invoke = nullptr};
+ // These functions are only supported inside Delegate's Prepare function.
+ // The test verifies that these functions returns `kTfLiteError`, but not
+ // `kTfLiteOk` or just crashes.
+ registration.prepare = [](TfLiteContext* context, TfLiteNode* node) {
+ {
+ TfLiteIntArray* execution_plan;
+ EXPECT_EQ(context->GetExecutionPlan(context, &execution_plan),
+ kTfLiteError);
+ }
+ {
+ TfLiteNode* node;
+ TfLiteRegistration* registration;
+ EXPECT_EQ(
+ context->GetNodeAndRegistration(context, 0, &node, &registration),
+ kTfLiteError);
+ }
+ {
+ TfLiteRegistration delegate_registration = {nullptr, nullptr, nullptr,
+ nullptr};
+ TfLiteIntArray nodes_to_replace;
+ nodes_to_replace.size = 0;
+ EXPECT_EQ(context->ReplaceSubgraphsWithDelegateKernels(
+ context, delegate_registration, &nodes_to_replace, nullptr),
+ kTfLiteError);
+ }
+ return kTfLiteError;
+ };
+ ASSERT_EQ(interpreter.SetInputs({0}), kTfLiteOk);
+ ASSERT_EQ(interpreter.SetOutputs({0}), kTfLiteOk);
+ ASSERT_EQ(interpreter.AddNodeWithParameters({0}, {1}, nullptr, 0, nullptr,
+ &registration),
+ kTfLiteOk);
+ EXPECT_EQ(interpreter.AllocateTensors(), kTfLiteError);
+}
+
TEST(InterpreterTensorsCapacityTest, TestWithinHeadroom) {
Interpreter interpreter;
ASSERT_EQ(interpreter.AddTensors(Interpreter::kTensorsReservedCapacity),