diff options
Diffstat (limited to 'tensorflow/core/platform/test_main.cc')
-rw-r--r-- | tensorflow/core/platform/test_main.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tensorflow/core/platform/test_main.cc b/tensorflow/core/platform/test_main.cc new file mode 100644 index 0000000000..11230c3f7b --- /dev/null +++ b/tensorflow/core/platform/test_main.cc @@ -0,0 +1,31 @@ +// A program with a main that is suitable for unittests, including those +// that also define microbenchmarks. Based on whether the user specified +// the --benchmark_filter flag which specifies which benchmarks to run, +// we will either run benchmarks or run the gtest tests in the program. + +#include <iostream> + +#include "tensorflow/core/platform/port.h" + +#if defined(PLATFORM_GOOGLE) || defined(PLATFORM_POSIX_ANDROID) || \ + defined(PLATFORM_GOOGLE_ANDROID) +// main() is supplied by gunit_main +#else +#include "gtest/gtest.h" +#include "tensorflow/core/lib/core/stringpiece.h" +#include "tensorflow/core/platform/test_benchmark.h" + +GTEST_API_ int main(int argc, char** argv) { + std::cout << "Running main() from test_main.cc\n"; + + testing::InitGoogleTest(&argc, argv); + for (int i = 1; i < argc; i++) { + if (tensorflow::StringPiece(argv[i]).starts_with("--benchmarks=")) { + const char* pattern = argv[i] + strlen("--benchmarks="); + tensorflow::testing::Benchmark::Run(pattern); + return 0; + } + } + return RUN_ALL_TESTS(); +} +#endif |