Home | History | Annotate | Download | only in platform
      1 /* Copyright 2015 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 
     16 // A program with a main that is suitable for unittests, including those
     17 // that also define microbenchmarks.  Based on whether the user specified
     18 // the --benchmark_filter flag which specifies which benchmarks to run,
     19 // we will either run benchmarks or run the gtest tests in the program.
     20 
     21 #include "tensorflow/core/platform/platform.h"
     22 
     23 #if defined(PLATFORM_GOOGLE) || defined(__ANDROID__)
     24 // main() is supplied by gunit_main
     25 #else
     26 
     27 #include <iostream>
     28 
     29 #include "tensorflow/core/lib/core/stringpiece.h"
     30 #include "tensorflow/core/platform/stacktrace_handler.h"
     31 #include "tensorflow/core/platform/test.h"
     32 #include "tensorflow/core/platform/test_benchmark.h"
     33 
     34 GTEST_API_ int main(int argc, char** argv) {
     35   std::cout << "Running main() from test_main.cc\n";
     36 
     37   tensorflow::testing::InstallStacktraceHandler();
     38   testing::InitGoogleTest(&argc, argv);
     39   for (int i = 1; i < argc; i++) {
     40     if (tensorflow::StringPiece(argv[i]).starts_with("--benchmarks=")) {
     41       const char* pattern = argv[i] + strlen("--benchmarks=");
     42       tensorflow::testing::Benchmark::Run(pattern);
     43       return 0;
     44     }
     45   }
     46   return RUN_ALL_TESTS();
     47 }
     48 #endif
     49