aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/lite/interpreter_test.cc
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2018-07-03 13:17:19 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-07-03 13:20:38 -0700
commit3340c2da43f8b2313692aaad1a94da6c4a4e4106 (patch)
tree24f1f45d83c771c2324dec4f98b022faaca29849 /tensorflow/contrib/lite/interpreter_test.cc
parent02ed358a986496e387d5f2e52865b10606e52c0a (diff)
Remove framework's dependency on eigen and gemmlowp.
PiperOrigin-RevId: 203172717
Diffstat (limited to 'tensorflow/contrib/lite/interpreter_test.cc')
-rw-r--r--tensorflow/contrib/lite/interpreter_test.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/tensorflow/contrib/lite/interpreter_test.cc b/tensorflow/contrib/lite/interpreter_test.cc
index 4f7fb36696..4fa97512fc 100644
--- a/tensorflow/contrib/lite/interpreter_test.cc
+++ b/tensorflow/contrib/lite/interpreter_test.cc
@@ -23,6 +23,15 @@ limitations under the License.
#include "tensorflow/contrib/lite/testing/util.h"
namespace tflite {
+
+// InterpreterTest is a friend of Interpreter, so it can access context_.
+class InterpreterTest : public ::testing::Test {
+ protected:
+ TfLiteContext* GetInterpreterContext() { return &interpreter_.context_; }
+
+ Interpreter interpreter_;
+};
+
namespace ops {
namespace builtin {
TfLiteRegistration* Register_PADV2();
@@ -780,6 +789,47 @@ TEST(InterpreterTensorsCapacityTest, TestExceedHeadroom) {
ASSERT_EQ(interpreter.AllocateTensors(), kTfLiteOk);
}
+struct TestExternalContext : public TfLiteExternalContext {
+ static const TfLiteExternalContextType kType = kTfLiteGemmLowpContext;
+
+ static TestExternalContext* Get(TfLiteContext* context) {
+ return reinterpret_cast<TestExternalContext*>(
+ context->GetExternalContext(context, kType));
+ }
+
+ static void Set(TfLiteContext* context, TestExternalContext* value) {
+ context->SetExternalContext(context, kType, value);
+ }
+
+ int num_refreshes = 0;
+};
+
+TEST_F(InterpreterTest, GetSetResetExternalContexts) {
+ auto* context = GetInterpreterContext();
+
+ TestExternalContext external_context;
+ external_context.Refresh = [](TfLiteContext* context) {
+ auto* ptr = TestExternalContext::Get(context);
+ if (ptr != nullptr) {
+ ++ptr->num_refreshes;
+ }
+ return kTfLiteOk;
+ };
+
+ EXPECT_EQ(TestExternalContext::Get(context), nullptr);
+ interpreter_.SetNumThreads(4);
+
+ TestExternalContext::Set(context, &external_context);
+ EXPECT_EQ(TestExternalContext::Get(context), &external_context);
+ interpreter_.SetNumThreads(4);
+ interpreter_.SetNumThreads(5);
+ EXPECT_EQ(external_context.num_refreshes, 2);
+
+ TestExternalContext::Set(context, nullptr);
+ EXPECT_EQ(TestExternalContext::Get(context), nullptr);
+ interpreter_.SetNumThreads(4);
+}
+
// 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_