test_main.cc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /* Copyright 2016 Google Inc. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. // A program with a main that is suitable for unittests, including those
  13. // that also define microbenchmarks. Based on whether the user specified
  14. // the --benchmark_filter flag which specifies which benchmarks to run,
  15. // we will either run benchmarks or run the gtest tests in the program.
  16. #include "tensorflow/core/platform/platform.h"
  17. #include "tensorflow/core/platform/types.h"
  18. #if defined(PLATFORM_GOOGLE) || defined(__ANDROID__)
  19. // main() is supplied by gunit_main
  20. #else
  21. #include "gtest/gtest.h"
  22. #include "tensorflow/core/lib/core/stringpiece.h"
  23. #include "tensorflow/core/platform/test_benchmark.h"
  24. GTEST_API_ int main(int argc, char **argv) {
  25. std::cout << "Running main() from test_main.cc\n";
  26. testing::InitGoogleTest(&argc, argv);
  27. for (int i = 1; i < argc; i++) {
  28. if (tensorflow::StringPiece(argv[i]).starts_with("--benchmarks=")) {
  29. const char *pattern = argv[i] + strlen("--benchmarks=");
  30. tensorflow::testing::Benchmark::Run(pattern);
  31. return 0;
  32. }
  33. }
  34. return RUN_ALL_TESTS();
  35. }
  36. #endif