TensorFlow Serving C++ API Documentation
bundle_factory_test_util.h
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 #ifndef TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_BUNDLE_FACTORY_TEST_UTIL_H_
17 #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_BUNDLE_FACTORY_TEST_UTIL_H_
18 
19 #include <gtest/gtest.h>
20 #include "tensorflow/core/protobuf/meta_graph.pb.h"
21 #include "tensorflow/core/public/session.h"
22 #include "tensorflow_serving/resources/resources.pb.h"
23 
24 namespace tensorflow {
25 namespace serving {
26 namespace test_util {
27 
28 // Returns the path of the Saved Model (the pb version) for the half plus two
29 // model.
30 string GetTestSavedModelPath();
31 string GetTestMLMetadataSavedModelPath();
32 
33 // Returns the Session Bundle export path for the half plus two model.
34 string GetTestSessionBundleExportPath();
35 
36 // Returns the path of TensorFlow Lite model for the half plus two model.
37 string GetTestTfLiteModelPath();
38 
39 // Returns the paths of the files of the Session Bundle export for the half plus
40 // two model.
41 std::vector<string> GetTestSessionBundleExportFiles();
42 
43 // Returns the paths of the files of the SavedModel Bundle export for the half
44 // plus two model.
45 std::vector<string> GetTestSavedModelBundleExportFiles();
46 
47 // Returns the total size of the given files. Requires the files to exist.
48 uint64_t GetTotalFileSize(const std::vector<string>& files);
49 
50 // Returns a signature for the half plus two model.
51 SignatureDef GetTestSessionSignature();
52 
53 // Test that a Session handles a single request for the half plus two
54 // model properly. Each request contains `input_batch_size` sized input.
55 void TestSingleRequest(Session* session, int input_batch_size = 2);
56 
57 // Test that a Session handles multiple concurrent requests for the half plus
58 // two model properly. Send `num_requests` request, with each request containing
59 // `input_batch_size` sized input.
60 void TestMultipleRequests(Session* session, int num_requests,
61  int input_batch_size);
62 
63 // Returns the expected resource estimate for the given total file size.
64 ResourceAllocation GetExpectedResourceEstimate(double total_file_size);
65 
66 // Copy (recursively) directory from `src` to `dst`. If `dst` directory exists
67 // it will be removed before copying. CHECK-fail on errors.
68 void CopyDirOrDie(const string& src_dir, const string& dst_dir);
69 
70 } // namespace test_util
71 } // namespace serving
72 } // namespace tensorflow
73 
74 #endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_BUNDLE_FACTORY_TEST_UTIL_H_