1 /* Copyright 2019 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 <string>
16 #include <vector>
17
18 #include <gtest/gtest.h>
19 #include "benchmark/benchmark.h" // from @com_google_benchmark
20 #include "tensorflow/lite/kernels/test_delegate_providers.h"
21 #include "tensorflow/lite/kernels/test_util.h"
22 #include "tensorflow/lite/testing/util.h"
23 #include "tensorflow/lite/tools/command_line_flags.h"
24
25 namespace {
26
InitKernelTest(int * argc,char ** argv)27 bool InitKernelTest(int* argc, char** argv) {
28 tflite::KernelTestDelegateProviders* const delegate_providers =
29 tflite::KernelTestDelegateProviders::Get();
30 if (!delegate_providers->InitFromCmdlineArgs(
31 argc, const_cast<const char**>(argv))) {
32 return false;
33 }
34
35 if (delegate_providers->ConstParams().Get<bool>("use_nnapi")) {
36 // In Android Q, the NNAPI delegate avoids delegation if the only device
37 // is the reference CPU. However, for testing purposes, we still want
38 // delegation coverage, so force use of this reference path.
39 auto* params = delegate_providers->MutableParams();
40 if (!params->HasValueSet<std::string>("nnapi_accelerator_name")) {
41 params->Set<std::string>("nnapi_accelerator_name", "nnapi-reference");
42 params->Set("disable_nnapi_cpu", false);
43 }
44 }
45 return true;
46 }
47
48 } // namespace
49
main(int argc,char ** argv)50 int main(int argc, char** argv) {
51 ::tflite::LogToStderr();
52 if (InitKernelTest(&argc, argv)) {
53 ::testing::InitGoogleTest(&argc, argv);
54 benchmark::RunSpecifiedBenchmarks();
55 return RUN_ALL_TESTS();
56 } else {
57 return EXIT_FAILURE;
58 }
59 }
60