Home | History | Annotate | Download | only in testing
      1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 #include "tensorflow/contrib/lite/testing/tf_driver.h"
     16 
     17 #include <gmock/gmock.h>
     18 #include <gtest/gtest.h>
     19 
     20 namespace tflite {
     21 namespace testing {
     22 namespace {
     23 
     24 using ::testing::ElementsAre;
     25 
     26 TEST(TfDriverTest, SimpleTest) {
     27   std::unique_ptr<TfDriver> runner(
     28       new TfDriver({"a", "b", "c", "d"}, {"float", "float", "float", "float"},
     29                    {"1,8,8,3", "1,8,8,3", "1,8,8,3", "1,8,8,3"}, {"x", "y"}));
     30 
     31   runner->LoadModel(
     32       "third_party/tensorflow/contrib/lite/testdata/multi_add.pb");
     33   EXPECT_TRUE(runner->IsValid()) << runner->GetErrorMessage();
     34 
     35   ASSERT_THAT(runner->GetInputs(), ElementsAre(0, 1, 2, 3));
     36   ASSERT_THAT(runner->GetOutputs(), ElementsAre(0, 1));
     37 
     38   for (int i : {0, 1, 2, 3}) {
     39     runner->ReshapeTensor(i, "1,2,2,1");
     40   }
     41   ASSERT_TRUE(runner->IsValid());
     42 
     43   runner->SetInput(0, "0.1,0.2,0.3,0.4");
     44   runner->SetInput(1, "0.001,0.002,0.003,0.004");
     45   runner->SetInput(2, "0.001,0.002,0.003,0.004");
     46   runner->SetInput(3, "0.01,0.02,0.03,0.04");
     47   runner->ResetTensor(2);
     48   runner->Invoke();
     49 
     50   ASSERT_EQ(runner->ReadOutput(0), "0.101,0.202,0.303,0.404");
     51   ASSERT_EQ(runner->ReadOutput(1), "0.011,0.022,0.033,0.044");
     52 }
     53 
     54 }  // namespace
     55 }  // namespace testing
     56 }  // namespace tflite
     57