TensorFlow Serving C++ API Documentation
mock_tfrt_saved_model.h
1 /* Copyright 2020 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 #ifndef TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_TEST_UTIL_MOCK_TFRT_SAVED_MODEL
17 #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_TEST_UTIL_MOCK_TFRT_SAVED_MODEL
18 
19 #include <gmock/gmock.h>
20 #include "tensorflow/core/tfrt/runtime/runtime.h"
21 #include "tensorflow/core/tfrt/saved_model/saved_model.h"
22 
23 namespace tensorflow {
24 namespace serving {
25 namespace test_util {
26 
27 inline tfrt_stub::Runtime* GetTestTfrtRuntime() {
28  static auto* const runtime =
29  tfrt_stub::Runtime::Create(/*num_inter_op_threads=*/4).release();
30  return runtime;
31 }
32 
33 // A mock of tfrt::SavedModel.
34 class MockSavedModel : public tfrt::SavedModel {
35  public:
36  MockSavedModel() : SavedModel(GetTestTfrtRuntime()) {}
37 
38  MOCK_METHOD(const tensorflow::MetaGraphDef&, GetMetaGraphDef, (),
39  (const, override));
40 
41  MOCK_METHOD(absl::optional<tfrt::FunctionMetadata>, GetFunctionMetadata,
42  (absl::string_view func_name), (const, override));
43 
44  MOCK_METHOD(::tensorflow::Status, Run,
45  (const tfrt::SavedModel::RunOptions& run_options,
46  absl::string_view func_name, absl::Span<const Tensor> inputs,
47  std::vector<Tensor>* outputs),
48  (override));
49 
50  MOCK_METHOD(std::vector<std::string>, GetFunctionNames, (),
51  (const, override));
52 
53  MOCK_METHOD(::tensorflow::Status, RunMultipleSignatures,
54  (const tfrt::SavedModel::RunOptions& run_options,
55  absl::Span<const std::string> names,
56  absl::Span<const std::vector<tensorflow::Tensor>> multi_inputs,
57  std::vector<std::vector<tensorflow::Tensor>>* multi_outputs),
58  (override));
59 
60  MOCK_METHOD(
61  ::tensorflow::Status, RunByTensorNames,
62  (const tfrt::SavedModel::RunOptions& run_options,
63  (absl::Span<const std::pair<std::string, tensorflow::Tensor>> inputs),
64  absl::Span<const std::string> output_tensor_names,
65  absl::Span<const std::string> target_node_names,
66  std::vector<tensorflow::Tensor>* outputs),
67  (override));
68 };
69 
70 } // namespace test_util
71 } // namespace serving
72 } // namespace tensorflow
73 
74 #endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_TEST_UTIL_MOCK_TFRT_SAVED_MODEL