diff options
Diffstat (limited to 'test/cpp/qps/server.h')
-rw-r--r-- | test/cpp/qps/server.h | 52 |
1 files changed, 42 insertions, 10 deletions
diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index e48e873dc3..6e81edc8ff 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -34,22 +34,38 @@ #ifndef TEST_QPS_SERVER_H #define TEST_QPS_SERVER_H +#include <grpc/support/cpu.h> +#include <grpc++/security/server_credentials.h> + +#include "test/core/end2end/data/ssl_test_data.h" +#include "test/core/util/port.h" #include "test/cpp/qps/timer.h" -#include "test/proto/qpstest.grpc.pb.h" +#include "test/proto/messages.grpc.pb.h" +#include "test/proto/benchmarks/control.grpc.pb.h" namespace grpc { namespace testing { class Server { public: - Server() : timer_(new Timer) {} + explicit Server(const ServerConfig& config) : timer_(new Timer) { + if (config.port()) { + port_ = config.port(); + } else { + port_ = grpc_pick_unused_port_or_die(); + } + } virtual ~Server() {} - ServerStats Mark() { - std::unique_ptr<Timer> timer(new Timer); - timer.swap(timer_); - - auto timer_result = timer->Mark(); + ServerStats Mark(bool reset) { + Timer::Result timer_result; + if (reset) { + std::unique_ptr<Timer> timer(new Timer); + timer.swap(timer_); + timer_result = timer->Mark(); + } else { + timer_result = timer_->Mark(); + } ServerStats stats; stats.set_time_elapsed(timer_result.wall); @@ -70,13 +86,29 @@ class Server { return true; } + int port() const { return port_; } + int cores() const { return gpr_cpu_num_cores(); } + static std::shared_ptr<ServerCredentials> CreateServerCredentials( + const ServerConfig& config) { + if (config.has_security_params()) { + SslServerCredentialsOptions::PemKeyCertPair pkcp = {test_server1_key, + test_server1_cert}; + SslServerCredentialsOptions ssl_opts; + ssl_opts.pem_root_certs = ""; + ssl_opts.pem_key_cert_pairs.push_back(pkcp); + return SslServerCredentials(ssl_opts); + } else { + return InsecureServerCredentials(); + } + } + private: + int port_; std::unique_ptr<Timer> timer_; }; -std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config, - int port); -std::unique_ptr<Server> CreateAsyncServer(const ServerConfig& config, int port); +std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config); +std::unique_ptr<Server> CreateAsyncServer(const ServerConfig& config); } // namespace testing } // namespace grpc |