TensorFlow Serving C++ API Documentation
test_main.cc
1 /* Copyright 2016 Google Inc. 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 #include "tensorflow/core/platform/types.h"
23 
24 #if defined(PLATFORM_GOOGLE) || defined(__ANDROID__)
25 // main() is supplied by gunit_main
26 #else
27 #include <iostream>
28 #include <string>
29 
30 #include "gtest/gtest.h"
31 #include "absl/strings/match.h"
32 #include "tensorflow/core/lib/strings/str_util.h"
33 #include "tensorflow/core/platform/stacktrace_handler.h"
34 #include "tensorflow/core/platform/test.h"
35 #include "tensorflow/core/platform/test_benchmark.h"
36 
37 GTEST_API_ int main(int argc, char** argv) {
38  std::cout << "Running main() from test_main.cc\n";
39 
40  tensorflow::testing::InstallStacktraceHandler();
41 
42  for (int i = 1; i < argc; i++) {
43  if (absl::StartsWith(argv[i], "--benchmark_filter=")) {
44  tensorflow::testing::InitializeBenchmarks(&argc, argv);
45 
46  // XXX: Must be called after benchmark's init because
47  // InitGoogleTest eventually calls absl::ParseCommandLine() which would
48  // complain that benchmark_filter flag is not known because that flag is
49  // defined by the benchmark library via its own command-line flag
50  // facility, which is not known to absl flags.
51  // FIXME(b/195442215): Fix this mess once we make benchmark use absl flags
52  testing::InitGoogleTest(&argc, argv);
53  tensorflow::testing::RunBenchmarks();
54  return 0;
55  }
56  }
57 
58  testing::InitGoogleTest(&argc, argv);
59  return RUN_ALL_TESTS();
60 }
61 
62 #endif