1 /* Copyright 2016 The TensorFlow Authors. 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_CORE_DISTRIBUTED_RUNTIME_RPC_GRPC_TESTLIB_H_ 17 #define TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_RPC_GRPC_TESTLIB_H_ 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "tensorflow/core/framework/device_attributes.pb.h" 24 #include "tensorflow/core/lib/core/status.h" 25 #include "tensorflow/core/platform/macros.h" 26 #include "tensorflow/core/platform/subprocess.h" 27 #include "tensorflow/core/platform/test.h" 28 #include "tensorflow/core/platform/types.h" 29 #include "tensorflow/core/public/session_options.h" 30 31 namespace tensorflow { 32 33 class Device; 34 35 namespace test { 36 37 // Provides a handle to a set of TensorFlow servers (masters and 38 // workers) for testing purposes. 39 // 40 // This class currently runs the servers in separate processes; the 41 // lifetime of this object is coterminous with the lifetimes of those 42 // processes. 43 class TestCluster { 44 public: 45 // Creates a new test cluster based on the given `options` (which 46 // configure the number of devices of each type) and a count of 47 // processes `n`. On success, the test cluster is stored in 48 // *out_cluster, and this function returns OK. Otherwise an error is 49 // returned. 50 static Status MakeTestCluster(const SessionOptions& options, int n, 51 std::unique_ptr<TestCluster>* out_cluster); 52 ~TestCluster(); 53 54 // Returns a vector of string "<hostname>:<port>" pairs that may be 55 // used as targets to construct a GrpcSession. targets()56 const std::vector<string>& targets() const { return targets_; } 57 58 // Returns a vector of devices available in this test cluster. devices()59 const std::vector<DeviceAttributes>& devices() const { return devices_; } 60 61 private: 62 TestCluster() = default; 63 64 std::vector<std::unique_ptr<SubProcess>> subprocesses_; 65 std::vector<string> targets_; 66 std::vector<DeviceAttributes> devices_; 67 68 TF_DISALLOW_COPY_AND_ASSIGN(TestCluster); 69 }; 70 71 } // end namespace test 72 } // end namespace tensorflow 73 74 #endif // TENSORFLOW_CORE_DISTRIBUTED_RUNTIME_RPC_GRPC_TESTLIB_H_ 75