aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/cpp')
-rw-r--r--test/cpp/interop/server_main.cc (renamed from test/cpp/interop/server.cc)0
-rw-r--r--test/cpp/qps/client.h12
-rw-r--r--test/cpp/qps/client_async.cc20
-rw-r--r--test/cpp/qps/client_sync.cc10
-rwxr-xr-xtest/cpp/qps/qps-sweep.sh2
-rw-r--r--test/cpp/qps/server.h10
-rw-r--r--test/cpp/qps/server_sync.cc12
-rw-r--r--test/cpp/qps/usage_timer.cc (renamed from test/cpp/qps/timer.cc)16
-rw-r--r--test/cpp/qps/usage_timer.h (renamed from test/cpp/qps/timer.h)10
-rw-r--r--test/cpp/util/test_credentials_provider.cc116
-rw-r--r--test/cpp/util/test_credentials_provider.h16
11 files changed, 150 insertions, 74 deletions
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server_main.cc
index 18ac35d551..18ac35d551 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server_main.cc
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index c94a523fa1..2dc83f0f29 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -46,10 +46,10 @@
#include "src/proto/grpc/testing/payloads.grpc.pb.h"
#include "src/proto/grpc/testing/services.grpc.pb.h"
-#include "test/cpp/qps/limit_cores.h"
#include "test/cpp/qps/histogram.h"
#include "test/cpp/qps/interarrival.h"
-#include "test/cpp/qps/timer.h"
+#include "test/cpp/qps/limit_cores.h"
+#include "test/cpp/qps/usage_timer.h"
#include "test/cpp/util/create_test_channel.h"
namespace grpc {
@@ -112,12 +112,12 @@ class ClientRequestCreator<ByteBuffer> {
class Client {
public:
- Client() : timer_(new Timer), interarrival_timer_() {}
+ Client() : timer_(new UsageTimer), interarrival_timer_() {}
virtual ~Client() {}
ClientStats Mark(bool reset) {
Histogram latencies;
- Timer::Result timer_result;
+ UsageTimer::Result timer_result;
// avoid std::vector for old compilers that expect a copy constructor
if (reset) {
@@ -125,7 +125,7 @@ class Client {
for (size_t i = 0; i < threads_.size(); i++) {
threads_[i]->BeginSwap(&to_merge[i]);
}
- std::unique_ptr<Timer> timer(new Timer);
+ std::unique_ptr<UsageTimer> timer(new UsageTimer);
timer_.swap(timer);
for (size_t i = 0; i < threads_.size(); i++) {
threads_[i]->EndSwap();
@@ -294,7 +294,7 @@ class Client {
};
std::vector<std::unique_ptr<Thread>> threads_;
- std::unique_ptr<Timer> timer_;
+ std::unique_ptr<UsageTimer> timer_;
InterarrivalTimer interarrival_timer_;
std::vector<gpr_timespec> next_time_;
diff --git a/test/cpp/qps/client_async.cc b/test/cpp/qps/client_async.cc
index 9e8767d103..9e9da9909a 100644
--- a/test/cpp/qps/client_async.cc
+++ b/test/cpp/qps/client_async.cc
@@ -54,7 +54,7 @@
#include "src/proto/grpc/testing/services.grpc.pb.h"
#include "test/cpp/qps/client.h"
-#include "test/cpp/qps/timer.h"
+#include "test/cpp/qps/usage_timer.h"
#include "test/cpp/util/create_test_channel.h"
namespace grpc {
@@ -107,14 +107,14 @@ class ClientRpcContextUnaryImpl : public ClientRpcContext {
bool RunNextState(bool ok, Histogram* hist) GRPC_OVERRIDE {
switch (next_state_) {
case State::READY:
- start_ = Timer::Now();
+ start_ = UsageTimer::Now();
response_reader_ = start_req_(stub_, &context_, req_, cq_);
response_reader_->Finish(&response_, &status_,
ClientRpcContext::tag(this));
next_state_ = State::RESP_DONE;
return true;
case State::RESP_DONE:
- hist->Add((Timer::Now() - start_) * 1e9);
+ hist->Add((UsageTimer::Now() - start_) * 1e9);
callback_(status_, &response_);
next_state_ = State::INVALID;
return false;
@@ -287,8 +287,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
next_state_(State::INVALID),
callback_(on_done),
next_issue_(next_issue),
- start_req_(start_req),
- start_(Timer::Now()) {}
+ start_req_(start_req) {}
~ClientRpcContextStreamingImpl() GRPC_OVERRIDE {}
void Start(CompletionQueue* cq) GRPC_OVERRIDE {
cq_ = cq;
@@ -314,7 +313,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
if (!ok) {
return false;
}
- start_ = Timer::Now();
+ start_ = UsageTimer::Now();
next_state_ = State::WRITE_DONE;
stream_->Write(req_, ClientRpcContext::tag(this));
return true;
@@ -327,7 +326,7 @@ class ClientRpcContextStreamingImpl : public ClientRpcContext {
return true;
break;
case State::READ_DONE:
- hist->Add((Timer::Now() - start_) * 1e9);
+ hist->Add((UsageTimer::Now() - start_) * 1e9);
callback_(status_, &response_);
next_state_ = State::STREAM_IDLE;
break; // loop around
@@ -415,8 +414,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
next_state_(State::INVALID),
callback_(on_done),
next_issue_(next_issue),
- start_req_(start_req),
- start_(Timer::Now()) {}
+ start_req_(start_req) {}
~ClientRpcContextGenericStreamingImpl() GRPC_OVERRIDE {}
void Start(CompletionQueue* cq) GRPC_OVERRIDE {
cq_ = cq;
@@ -445,7 +443,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
if (!ok) {
return false;
}
- start_ = Timer::Now();
+ start_ = UsageTimer::Now();
next_state_ = State::WRITE_DONE;
stream_->Write(req_, ClientRpcContext::tag(this));
return true;
@@ -458,7 +456,7 @@ class ClientRpcContextGenericStreamingImpl : public ClientRpcContext {
return true;
break;
case State::READ_DONE:
- hist->Add((Timer::Now() - start_) * 1e9);
+ hist->Add((UsageTimer::Now() - start_) * 1e9);
callback_(status_, &response_);
next_state_ = State::STREAM_IDLE;
break; // loop around
diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc
index edfc246a25..4284e07bd4 100644
--- a/test/cpp/qps/client_sync.cc
+++ b/test/cpp/qps/client_sync.cc
@@ -58,7 +58,7 @@
#include "test/cpp/qps/client.h"
#include "test/cpp/qps/histogram.h"
#include "test/cpp/qps/interarrival.h"
-#include "test/cpp/qps/timer.h"
+#include "test/cpp/qps/usage_timer.h"
namespace grpc {
namespace testing {
@@ -104,12 +104,12 @@ class SynchronousUnaryClient GRPC_FINAL : public SynchronousClient {
bool ThreadFunc(Histogram* histogram, size_t thread_idx) GRPC_OVERRIDE {
WaitToIssue(thread_idx);
auto* stub = channels_[thread_idx % channels_.size()].get_stub();
- double start = Timer::Now();
+ double start = UsageTimer::Now();
GPR_TIMER_SCOPE("SynchronousUnaryClient::ThreadFunc", 0);
grpc::ClientContext context;
grpc::Status s =
stub->UnaryCall(&context, request_, &responses_[thread_idx]);
- histogram->Add((Timer::Now() - start) * 1e9);
+ histogram->Add((UsageTimer::Now() - start) * 1e9);
return s.ok();
}
};
@@ -143,10 +143,10 @@ class SynchronousStreamingClient GRPC_FINAL : public SynchronousClient {
bool ThreadFunc(Histogram* histogram, size_t thread_idx) GRPC_OVERRIDE {
WaitToIssue(thread_idx);
GPR_TIMER_SCOPE("SynchronousStreamingClient::ThreadFunc", 0);
- double start = Timer::Now();
+ double start = UsageTimer::Now();
if (stream_[thread_idx]->Write(request_) &&
stream_[thread_idx]->Read(&responses_[thread_idx])) {
- histogram->Add((Timer::Now() - start) * 1e9);
+ histogram->Add((UsageTimer::Now() - start) * 1e9);
return true;
}
return false;
diff --git a/test/cpp/qps/qps-sweep.sh b/test/cpp/qps/qps-sweep.sh
index 7a35788849..9d3f053a7b 100755
--- a/test/cpp/qps/qps-sweep.sh
+++ b/test/cpp/qps/qps-sweep.sh
@@ -72,7 +72,7 @@ for secure in true false; do
--server_type=ASYNC_GENERIC_SERVER --outstanding_rpcs_per_channel=$deep \
--client_channels=$wide --bbuf_req_size=0 --bbuf_resp_size=0 \
--async_client_threads=0 --async_server_threads=0 --secure_test=$secure \
- --num_servers=1 --num_clients=0 |& tee /tmp/qps-test.$$
+ --num_servers=1 --num_clients=0 2>&1 | tee /tmp/qps-test.$$
# Scenario 2b: QPS with a single server core
"$bins"/opt/qps_driver --rpc_type=STREAMING --client_type=ASYNC_CLIENT \
diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h
index 94a6f8acfa..de46452c3d 100644
--- a/test/cpp/qps/server.h
+++ b/test/cpp/qps/server.h
@@ -43,14 +43,14 @@
#include "test/core/end2end/data/ssl_test_data.h"
#include "test/core/util/port.h"
#include "test/cpp/qps/limit_cores.h"
-#include "test/cpp/qps/timer.h"
+#include "test/cpp/qps/usage_timer.h"
namespace grpc {
namespace testing {
class Server {
public:
- explicit Server(const ServerConfig& config) : timer_(new Timer) {
+ explicit Server(const ServerConfig& config) : timer_(new UsageTimer) {
cores_ = LimitCores(config.core_list().data(), config.core_list_size());
if (config.port()) {
port_ = config.port();
@@ -62,9 +62,9 @@ class Server {
virtual ~Server() {}
ServerStats Mark(bool reset) {
- Timer::Result timer_result;
+ UsageTimer::Result timer_result;
if (reset) {
- std::unique_ptr<Timer> timer(new Timer);
+ std::unique_ptr<UsageTimer> timer(new UsageTimer);
timer.swap(timer_);
timer_result = timer->Mark();
} else {
@@ -108,7 +108,7 @@ class Server {
private:
int port_;
int cores_;
- std::unique_ptr<Timer> timer_;
+ std::unique_ptr<UsageTimer> timer_;
};
std::unique_ptr<Server> CreateSynchronousServer(const ServerConfig& config);
diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc
index 4b778820d0..b7682f5763 100644
--- a/test/cpp/qps/server_sync.cc
+++ b/test/cpp/qps/server_sync.cc
@@ -34,18 +34,18 @@
#include <thread>
#include <gflags/gflags.h>
+#include <grpc++/security/server_credentials.h>
+#include <grpc++/server.h>
+#include <grpc++/server_builder.h>
+#include <grpc++/server_context.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
#include <grpc/support/log.h>
-#include <grpc++/server.h>
-#include <grpc++/server_builder.h>
-#include <grpc++/server_context.h>
-#include <grpc++/security/server_credentials.h>
-#include "test/cpp/qps/server.h"
-#include "test/cpp/qps/timer.h"
#include "src/proto/grpc/testing/services.grpc.pb.h"
+#include "test/cpp/qps/server.h"
+#include "test/cpp/qps/usage_timer.h"
namespace grpc {
namespace testing {
diff --git a/test/cpp/qps/timer.cc b/test/cpp/qps/usage_timer.cc
index 3ec7f49f83..6663a9ac10 100644
--- a/test/cpp/qps/timer.cc
+++ b/test/cpp/qps/usage_timer.cc
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,15 +31,15 @@
*
*/
-#include "test/cpp/qps/timer.h"
+#include "test/cpp/qps/usage_timer.h"
-#include <sys/time.h>
-#include <sys/resource.h>
#include <grpc/support/time.h>
+#include <sys/resource.h>
+#include <sys/time.h>
-Timer::Timer() : start_(Sample()) {}
+UsageTimer::UsageTimer() : start_(Sample()) {}
-double Timer::Now() {
+double UsageTimer::Now() {
auto ts = gpr_now(GPR_CLOCK_REALTIME);
return ts.tv_sec + 1e-9 * ts.tv_nsec;
}
@@ -48,7 +48,7 @@ static double time_double(struct timeval* tv) {
return tv->tv_sec + 1e-6 * tv->tv_usec;
}
-Timer::Result Timer::Sample() {
+UsageTimer::Result UsageTimer::Sample() {
struct rusage usage;
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -61,7 +61,7 @@ Timer::Result Timer::Sample() {
return r;
}
-Timer::Result Timer::Mark() const {
+UsageTimer::Result UsageTimer::Mark() const {
Result s = Sample();
Result r;
r.wall = s.wall - start_.wall;
diff --git a/test/cpp/qps/timer.h b/test/cpp/qps/usage_timer.h
index d1aee1a9d1..d19f820564 100644
--- a/test/cpp/qps/timer.h
+++ b/test/cpp/qps/usage_timer.h
@@ -1,6 +1,6 @@
/*
*
- * Copyright 2015, Google Inc.
+ * Copyright 2015-2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -31,12 +31,12 @@
*
*/
-#ifndef TEST_QPS_TIMER_H
-#define TEST_QPS_TIMER_H
+#ifndef TEST_QPS_USAGE_TIMER_H
+#define TEST_QPS_USAGE_TIMER_H
-class Timer {
+class UsageTimer {
public:
- Timer();
+ UsageTimer();
struct Result {
double wall;
diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc
index 1086e14258..7e1eb0d501 100644
--- a/test/cpp/util/test_credentials_provider.cc
+++ b/test/cpp/util/test_credentials_provider.cc
@@ -34,48 +34,110 @@
#include "test/cpp/util/test_credentials_provider.h"
+#include <grpc/support/sync.h>
+#include <grpc++/impl/sync.h>
+
#include "test/core/end2end/data/ssl_test_data.h"
+namespace {
+
+using grpc::ChannelArguments;
+using grpc::ChannelCredentials;
+using grpc::InsecureChannelCredentials;
+using grpc::InsecureServerCredentials;
+using grpc::ServerCredentials;
+using grpc::SslCredentialsOptions;
+using grpc::SslServerCredentialsOptions;
+using grpc::testing::CredentialsProvider;
+
+class DefaultCredentialsProvider : public CredentialsProvider {
+ public:
+ ~DefaultCredentialsProvider() override {}
+
+ std::shared_ptr<ChannelCredentials> GetChannelCredentials(
+ const grpc::string& type, ChannelArguments* args) override {
+ if (type == grpc::testing::kInsecureCredentialsType) {
+ return InsecureChannelCredentials();
+ } else if (type == grpc::testing::kTlsCredentialsType) {
+ SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
+ args->SetSslTargetNameOverride("foo.test.google.fr");
+ return SslCredentials(ssl_opts);
+ } else {
+ gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
+ }
+ return nullptr;
+ }
+
+ std::shared_ptr<ServerCredentials> GetServerCredentials(
+ const grpc::string& type) override {
+ if (type == grpc::testing::kInsecureCredentialsType) {
+ return InsecureServerCredentials();
+ } else if (type == grpc::testing::kTlsCredentialsType) {
+ 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 {
+ gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
+ }
+ return nullptr;
+ }
+ std::vector<grpc::string> GetSecureCredentialsTypeList() override {
+ std::vector<grpc::string> types;
+ types.push_back(grpc::testing::kTlsCredentialsType);
+ return types;
+ }
+};
+
+gpr_once g_once_init_provider_mu = GPR_ONCE_INIT;
+grpc::mutex* g_provider_mu = nullptr;
+CredentialsProvider* g_provider = nullptr;
+
+void InitProviderMu() { g_provider_mu = new grpc::mutex; }
+
+grpc::mutex& GetMu() {
+ gpr_once_init(&g_once_init_provider_mu, &InitProviderMu);
+ return *g_provider_mu;
+}
+
+CredentialsProvider* GetProvider() {
+ grpc::unique_lock<grpc::mutex> lock(GetMu());
+ if (g_provider == nullptr) {
+ g_provider = new DefaultCredentialsProvider;
+ }
+ return g_provider;
+}
+
+} // namespace
+
namespace grpc {
namespace testing {
-const char kTlsCredentialsType[] = "TLS_CREDENTIALS";
+// Note that it is not thread-safe to set a provider while concurrently using
+// the previously set provider, as this deletes and replaces it. nullptr may be
+// given to reset to the default.
+void SetTestCredentialsProvider(std::unique_ptr<CredentialsProvider> provider) {
+ grpc::unique_lock<grpc::mutex> lock(GetMu());
+ if (g_provider != nullptr) {
+ delete g_provider;
+ }
+ g_provider = provider.release();
+}
std::shared_ptr<ChannelCredentials> GetChannelCredentials(
const grpc::string& type, ChannelArguments* args) {
- if (type == kInsecureCredentialsType) {
- return InsecureChannelCredentials();
- } else if (type == kTlsCredentialsType) {
- SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
- args->SetSslTargetNameOverride("foo.test.google.fr");
- return SslCredentials(ssl_opts);
- } else {
- gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
- }
- return nullptr;
+ return GetProvider()->GetChannelCredentials(type, args);
}
std::shared_ptr<ServerCredentials> GetServerCredentials(
const grpc::string& type) {
- if (type == kInsecureCredentialsType) {
- return InsecureServerCredentials();
- } else if (type == kTlsCredentialsType) {
- 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 {
- gpr_log(GPR_ERROR, "Unsupported credentials type %s.", type.c_str());
- }
- return nullptr;
+ return GetProvider()->GetServerCredentials(type);
}
std::vector<grpc::string> GetSecureCredentialsTypeList() {
- std::vector<grpc::string> types;
- types.push_back(kTlsCredentialsType);
- return types;
+ return GetProvider()->GetSecureCredentialsTypeList();
}
} // namespace testing
diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h
index f7253051a9..a6b547cb07 100644
--- a/test/cpp/util/test_credentials_provider.h
+++ b/test/cpp/util/test_credentials_provider.h
@@ -44,6 +44,22 @@ namespace grpc {
namespace testing {
const char kInsecureCredentialsType[] = "INSECURE_CREDENTIALS";
+const char kTlsCredentialsType[] = "TLS_CREDENTIALS";
+
+class CredentialsProvider {
+ public:
+ virtual ~CredentialsProvider() {}
+
+ virtual std::shared_ptr<ChannelCredentials> GetChannelCredentials(
+ const grpc::string& type, ChannelArguments* args) = 0;
+ virtual std::shared_ptr<ServerCredentials> GetServerCredentials(
+ const grpc::string& type) = 0;
+ virtual std::vector<grpc::string> GetSecureCredentialsTypeList() = 0;
+};
+
+// Set the CredentialsProvider used by the other functions in this file. If this
+// is not set, a default provider will be used.
+void SetTestCredentialsProvider(std::unique_ptr<CredentialsProvider> provider);
// Provide channel credentials according to the given type. Alter the channel
// arguments if needed.