16 #ifndef TENSORFLOW_SERVING_TEST_UTIL_TEST_UTIL_H_
17 #define TENSORFLOW_SERVING_TEST_UTIL_TEST_UTIL_H_
21 #include "google/protobuf/message.h"
22 #include "google/protobuf/text_format.h"
23 #include <gmock/gmock.h>
24 #include "tensorflow/core/platform/env.h"
25 #include "tensorflow/core/platform/logging.h"
26 #include "tensorflow/core/platform/protobuf.h"
27 #include "tensorflow/core/platform/thread_annotations.h"
28 #include "tensorflow/core/platform/threadpool.h"
29 #include "tensorflow/core/platform/types.h"
30 #include "tensorflow/core/public/session_options.h"
32 namespace tensorflow {
38 T CreateProto(
const string& textual_proto);
42 string TensorflowTestSrcDirPath(
const string& relative_path);
46 string ContribTestSrcDirPath(
const string& relative_path);
50 string TestSrcDirPath(
const string& relative_path);
61 template <
typename Message>
62 bool MatchAndExplain(
const Message& p,
63 ::testing::MatchResultListener* )
const;
65 void DescribeTo(::std::ostream* os)
const { *os << expected_; }
66 void DescribeNegationTo(::std::ostream* os)
const {
67 *os <<
"not equal to expected message: " << expected_;
71 const string expected_;
75 inline ::testing::PolymorphicMatcher<ProtoStringMatcher> EqualsProto(
81 inline ::testing::PolymorphicMatcher<ProtoStringMatcher> EqualsProto(
82 const google::protobuf::Message& x) {
83 return ::testing::MakePolymorphicMatcher(ProtoStringMatcher(x));
90 T CreateProto(
const string& textual_proto) {
92 CHECK(protobuf::TextFormat::ParseFromString(textual_proto, &proto));
96 template <
typename Message>
97 bool ProtoStringMatcher::MatchAndExplain(
98 const Message& p, ::testing::MatchResultListener* )
const {
101 return p.SerializeAsString() ==
102 CreateProto<Message>(expected_).SerializeAsString();
110 : thread_pool_(env, name, num_threads), num_scheduled_(0) {}
113 void Schedule(std::function<
void()> fn)
override {
118 thread_pool_.Schedule(fn);
121 int NumThreads()
const override {
return thread_pool_.NumThreads(); }
123 int CurrentThreadId()
const override {
124 return thread_pool_.CurrentThreadId();
127 int NumScheduled()
const {
130 return num_scheduled_;
135 thread::ThreadPool thread_pool_;
137 int32 num_scheduled_ TF_GUARDED_BY(mu_);