aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/bad_client/BUILD2
-rw-r--r--test/core/bad_ssl/BUILD2
-rw-r--r--test/core/end2end/BUILD2
-rw-r--r--test/core/end2end/end2end_nosec_tests.c16
-rw-r--r--test/core/end2end/end2end_tests.c16
-rw-r--r--test/core/end2end/fuzzers/BUILD2
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/08455b3ef9d516deb8155d8db7d51c43ce0ff07abin0 -> 426 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4bin0 -> 167 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/14064ac4844c709b247a4345a92d8be9766785c4bin0 -> 316 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/1901234bd7c9cb6ee19ff8b17179c481bdc7c5f2bin0 -> 345 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/20ff1f8d5d34cb01d58aa334dc46a6644e6e1d12bin0 -> 199 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/2378c3f1206f20711468391ce739116ffe58374bbin0 -> 216 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/40640a91fda4e4e42d3063a28b9ffbba1b8c3701bin0 -> 226 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/49f564289c79de9e0342f8b0821a167bc8c5ec00bin0 -> 183 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/507865c4a5ce880b80400d93fa85def2682581cbbin0 -> 314 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/5f2fdb01d8ff632803ca2b732a7c088c6843d7d3bin0 -> 349 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/61de97a9d6c4b082602c02277d8d763921f5f95bbin0 -> 175 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/62b039b8a318cc08471f13629da08c68c414d8e7bin0 -> 176 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/641739453f7d4d3b55a1c7b79bed7da6dfd62ae0bin0 -> 175 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/6589505362ffb5164a3c7cb1b9feadcddfba44e9bin0 -> 33 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/724f5400f19e5a0be97022341c39eeaaaffeb390bin0 -> 336 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/7254b9ff59ab3fcf345effdabbc25ebd2e907b23bin0 -> 167 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/784d6f5c093ab5360670173ce001e1a446f95822bin0 -> 202 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/79328fdc89d0af0e38da089dab062fd3ea5aae59bin0 -> 474 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/7a2569f4daf4480ad142cb4ee7c675bed82db74cbin0 -> 547 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/87a300cd25d2e57745bd00499d4d2352a10a2fa1bin0 -> 35 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/8a1c629910280f8beebb88687696de98da988eccbin0 -> 41 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/8ff7b1568d2da2e4196c2e28617e1911d62021e6bin0 -> 371 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/982f375b183d984958667461c7767206062eb4cbbin0 -> 429 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/98739af631223fa05ad88f1e63a52052a9bb4b1cbin0 -> 178 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/a78bca1ef8829d720dd5dedac3a9d4d12684da34bin0 -> 373 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/ac763d89466ebfad676e75be0076831c03fe2a5dbin0 -> 473 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/b165523f699e6ae9b2ad15873b9d56465d1af546bin0 -> 224 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/b2a5ec3ef40c68d594638218e3c943a479f82215bin0 -> 474 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/b92b1c5e0dba009a9516e7185f5df019c62c5cc9bin0 -> 414 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533bin0 -> 425 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/crash-da39a3ee5e6b4b0d3255bfef95601890afd807090
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/e28ffd8c2816f12f6395805199c792d1718191dfbin0 -> 371 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/ec823f4018389e64a99f6580277fba28df6bd136bin0 -> 226 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/ee2c1ac1e668f22836cf25a59495e778b0e2c7a8bin0 -> 338 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/ee6855178435d2046d8763ecae46e1e0a71a95f4bin0 -> 178 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/eeb310d91038cb02862e187e68c5d6578233485bbin0 -> 46 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/f07bc2907c95f2aeb79ca60e2ad826e13b848f45bin0 -> 351 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/fb655905396b768cf3ff015afdb0b564dae2cdfdbin0 -> 349 bytes
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/fdb038087233cd176746558875932029f779221dbin0 -> 371 bytes
-rwxr-xr-xtest/core/end2end/gen_build_yaml.py2
-rwxr-xr-xtest/core/end2end/generate_tests.bzl2
-rw-r--r--test/core/end2end/tests/write_buffering.c291
-rw-r--r--test/core/end2end/tests/write_buffering_at_end.c280
-rw-r--r--test/core/http/BUILD2
-rw-r--r--test/core/json/BUILD2
-rw-r--r--test/core/memory_usage/client.c316
-rw-r--r--test/core/memory_usage/memory_usage_test.c93
-rw-r--r--test/core/memory_usage/server.c321
-rw-r--r--test/core/nanopb/BUILD2
-rw-r--r--test/core/support/BUILD2
-rw-r--r--test/core/surface/public_headers_must_be_c89.c1
-rw-r--r--test/core/transport/chttp2/BUILD2
-rw-r--r--test/core/util/BUILD29
-rw-r--r--test/core/util/memory_counters.h2
-rw-r--r--test/cpp/end2end/async_end2end_test.cc19
-rw-r--r--test/cpp/end2end/end2end_test.cc20
-rw-r--r--test/cpp/interop/client.cc1
-rw-r--r--test/cpp/interop/client_helper.cc10
-rw-r--r--test/cpp/interop/http2_client.cc272
-rw-r--r--test/cpp/interop/http2_client.h (renamed from test/cpp/qps/limit_cores.h)51
-rw-r--r--test/cpp/interop/interop_server.cc1
-rw-r--r--test/cpp/interop/server_helper.cc18
-rw-r--r--test/cpp/interop/stress_test.cc1
-rw-r--r--test/cpp/qps/client.h16
-rw-r--r--test/cpp/qps/driver.cc92
-rw-r--r--test/cpp/qps/driver.h3
-rw-r--r--test/cpp/qps/limit_cores.cc87
-rw-r--r--test/cpp/qps/qps_json_driver.cc16
-rw-r--r--test/cpp/qps/server.h3
-rw-r--r--test/cpp/util/create_test_channel.cc64
-rw-r--r--test/cpp/util/create_test_channel.h4
-rw-r--r--test/cpp/util/test_credentials_provider.cc52
-rw-r--r--test/cpp/util/test_credentials_provider.h50
79 files changed, 1875 insertions, 292 deletions
diff --git a/test/core/bad_client/BUILD b/test/core/bad_client/BUILD
index 5406eb9a4b..6b06955efe 100644
--- a/test/core/bad_client/BUILD
+++ b/test/core/bad_client/BUILD
@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
+
load(":generate_tests.bzl", "grpc_bad_client_tests")
grpc_bad_client_tests()
diff --git a/test/core/bad_ssl/BUILD b/test/core/bad_ssl/BUILD
index 630733dd4d..288788a52d 100644
--- a/test/core/bad_ssl/BUILD
+++ b/test/core/bad_ssl/BUILD
@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
+
load(":generate_tests.bzl", "grpc_bad_ssl_tests")
grpc_bad_ssl_tests()
diff --git a/test/core/end2end/BUILD b/test/core/end2end/BUILD
index 681cea1de7..a40fb8e083 100644
--- a/test/core/end2end/BUILD
+++ b/test/core/end2end/BUILD
@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
+
load(":generate_tests.bzl", "grpc_end2end_tests")
cc_library(
diff --git a/test/core/end2end/end2end_nosec_tests.c b/test/core/end2end/end2end_nosec_tests.c
index 663489082f..b162bf2f40 100644
--- a/test/core/end2end/end2end_nosec_tests.c
+++ b/test/core/end2end/end2end_nosec_tests.c
@@ -135,6 +135,10 @@ extern void streaming_error_response(grpc_end2end_test_config config);
extern void streaming_error_response_pre_init(void);
extern void trailing_metadata(grpc_end2end_test_config config);
extern void trailing_metadata_pre_init(void);
+extern void write_buffering(grpc_end2end_test_config config);
+extern void write_buffering_pre_init(void);
+extern void write_buffering_at_end(grpc_end2end_test_config config);
+extern void write_buffering_at_end_pre_init(void);
void grpc_end2end_tests_pre_init(void) {
GPR_ASSERT(!g_pre_init_called);
@@ -185,6 +189,8 @@ void grpc_end2end_tests_pre_init(void) {
simple_request_pre_init();
streaming_error_response_pre_init();
trailing_metadata_pre_init();
+ write_buffering_pre_init();
+ write_buffering_at_end_pre_init();
}
void grpc_end2end_tests(int argc, char **argv,
@@ -240,6 +246,8 @@ void grpc_end2end_tests(int argc, char **argv,
simple_request(config);
streaming_error_response(config);
trailing_metadata(config);
+ write_buffering(config);
+ write_buffering_at_end(config);
return;
}
@@ -428,6 +436,14 @@ void grpc_end2end_tests(int argc, char **argv,
trailing_metadata(config);
continue;
}
+ if (0 == strcmp("write_buffering", argv[i])) {
+ write_buffering(config);
+ continue;
+ }
+ if (0 == strcmp("write_buffering_at_end", argv[i])) {
+ write_buffering_at_end(config);
+ continue;
+ }
gpr_log(GPR_DEBUG, "not a test: '%s'", argv[i]);
abort();
}
diff --git a/test/core/end2end/end2end_tests.c b/test/core/end2end/end2end_tests.c
index 25c7c62fde..9bca0c81f6 100644
--- a/test/core/end2end/end2end_tests.c
+++ b/test/core/end2end/end2end_tests.c
@@ -137,6 +137,10 @@ extern void streaming_error_response(grpc_end2end_test_config config);
extern void streaming_error_response_pre_init(void);
extern void trailing_metadata(grpc_end2end_test_config config);
extern void trailing_metadata_pre_init(void);
+extern void write_buffering(grpc_end2end_test_config config);
+extern void write_buffering_pre_init(void);
+extern void write_buffering_at_end(grpc_end2end_test_config config);
+extern void write_buffering_at_end_pre_init(void);
void grpc_end2end_tests_pre_init(void) {
GPR_ASSERT(!g_pre_init_called);
@@ -188,6 +192,8 @@ void grpc_end2end_tests_pre_init(void) {
simple_request_pre_init();
streaming_error_response_pre_init();
trailing_metadata_pre_init();
+ write_buffering_pre_init();
+ write_buffering_at_end_pre_init();
}
void grpc_end2end_tests(int argc, char **argv,
@@ -244,6 +250,8 @@ void grpc_end2end_tests(int argc, char **argv,
simple_request(config);
streaming_error_response(config);
trailing_metadata(config);
+ write_buffering(config);
+ write_buffering_at_end(config);
return;
}
@@ -436,6 +444,14 @@ void grpc_end2end_tests(int argc, char **argv,
trailing_metadata(config);
continue;
}
+ if (0 == strcmp("write_buffering", argv[i])) {
+ write_buffering(config);
+ continue;
+ }
+ if (0 == strcmp("write_buffering_at_end", argv[i])) {
+ write_buffering_at_end(config);
+ continue;
+ }
gpr_log(GPR_DEBUG, "not a test: '%s'", argv[i]);
abort();
}
diff --git a/test/core/end2end/fuzzers/BUILD b/test/core/end2end/fuzzers/BUILD
index 2adda560b4..4d98aa0725 100644
--- a/test/core/end2end/fuzzers/BUILD
+++ b/test/core/end2end/fuzzers/BUILD
@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
+
load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_fuzzer(
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/08455b3ef9d516deb8155d8db7d51c43ce0ff07a b/test/core/end2end/fuzzers/api_fuzzer_corpus/08455b3ef9d516deb8155d8db7d51c43ce0ff07a
new file mode 100644
index 0000000000..4b698ba9ee
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/08455b3ef9d516deb8155d8db7d51c43ce0ff07a
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4 b/test/core/end2end/fuzzers/api_fuzzer_corpus/0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4
new file mode 100644
index 0000000000..2889e7040e
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/14064ac4844c709b247a4345a92d8be9766785c4 b/test/core/end2end/fuzzers/api_fuzzer_corpus/14064ac4844c709b247a4345a92d8be9766785c4
new file mode 100644
index 0000000000..fa731d4a05
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/14064ac4844c709b247a4345a92d8be9766785c4
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/1901234bd7c9cb6ee19ff8b17179c481bdc7c5f2 b/test/core/end2end/fuzzers/api_fuzzer_corpus/1901234bd7c9cb6ee19ff8b17179c481bdc7c5f2
new file mode 100644
index 0000000000..ef09a0eaf5
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/1901234bd7c9cb6ee19ff8b17179c481bdc7c5f2
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/20ff1f8d5d34cb01d58aa334dc46a6644e6e1d12 b/test/core/end2end/fuzzers/api_fuzzer_corpus/20ff1f8d5d34cb01d58aa334dc46a6644e6e1d12
new file mode 100644
index 0000000000..fc747d4a72
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/20ff1f8d5d34cb01d58aa334dc46a6644e6e1d12
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/2378c3f1206f20711468391ce739116ffe58374b b/test/core/end2end/fuzzers/api_fuzzer_corpus/2378c3f1206f20711468391ce739116ffe58374b
new file mode 100644
index 0000000000..ca3ce31cbe
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/2378c3f1206f20711468391ce739116ffe58374b
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/40640a91fda4e4e42d3063a28b9ffbba1b8c3701 b/test/core/end2end/fuzzers/api_fuzzer_corpus/40640a91fda4e4e42d3063a28b9ffbba1b8c3701
new file mode 100644
index 0000000000..f11821acc9
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/40640a91fda4e4e42d3063a28b9ffbba1b8c3701
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/49f564289c79de9e0342f8b0821a167bc8c5ec00 b/test/core/end2end/fuzzers/api_fuzzer_corpus/49f564289c79de9e0342f8b0821a167bc8c5ec00
new file mode 100644
index 0000000000..c846377f0a
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/49f564289c79de9e0342f8b0821a167bc8c5ec00
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/507865c4a5ce880b80400d93fa85def2682581cb b/test/core/end2end/fuzzers/api_fuzzer_corpus/507865c4a5ce880b80400d93fa85def2682581cb
new file mode 100644
index 0000000000..c4473eacbb
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/507865c4a5ce880b80400d93fa85def2682581cb
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/5f2fdb01d8ff632803ca2b732a7c088c6843d7d3 b/test/core/end2end/fuzzers/api_fuzzer_corpus/5f2fdb01d8ff632803ca2b732a7c088c6843d7d3
new file mode 100644
index 0000000000..b91a052534
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/5f2fdb01d8ff632803ca2b732a7c088c6843d7d3
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/61de97a9d6c4b082602c02277d8d763921f5f95b b/test/core/end2end/fuzzers/api_fuzzer_corpus/61de97a9d6c4b082602c02277d8d763921f5f95b
new file mode 100644
index 0000000000..a24008b1d4
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/61de97a9d6c4b082602c02277d8d763921f5f95b
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/62b039b8a318cc08471f13629da08c68c414d8e7 b/test/core/end2end/fuzzers/api_fuzzer_corpus/62b039b8a318cc08471f13629da08c68c414d8e7
new file mode 100644
index 0000000000..e5e218acc3
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/62b039b8a318cc08471f13629da08c68c414d8e7
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/641739453f7d4d3b55a1c7b79bed7da6dfd62ae0 b/test/core/end2end/fuzzers/api_fuzzer_corpus/641739453f7d4d3b55a1c7b79bed7da6dfd62ae0
new file mode 100644
index 0000000000..9dcc5c578c
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/641739453f7d4d3b55a1c7b79bed7da6dfd62ae0
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/6589505362ffb5164a3c7cb1b9feadcddfba44e9 b/test/core/end2end/fuzzers/api_fuzzer_corpus/6589505362ffb5164a3c7cb1b9feadcddfba44e9
new file mode 100644
index 0000000000..10625da2ff
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/6589505362ffb5164a3c7cb1b9feadcddfba44e9
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/724f5400f19e5a0be97022341c39eeaaaffeb390 b/test/core/end2end/fuzzers/api_fuzzer_corpus/724f5400f19e5a0be97022341c39eeaaaffeb390
new file mode 100644
index 0000000000..1dbc538192
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/724f5400f19e5a0be97022341c39eeaaaffeb390
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/7254b9ff59ab3fcf345effdabbc25ebd2e907b23 b/test/core/end2end/fuzzers/api_fuzzer_corpus/7254b9ff59ab3fcf345effdabbc25ebd2e907b23
new file mode 100644
index 0000000000..92371e031f
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/7254b9ff59ab3fcf345effdabbc25ebd2e907b23
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/784d6f5c093ab5360670173ce001e1a446f95822 b/test/core/end2end/fuzzers/api_fuzzer_corpus/784d6f5c093ab5360670173ce001e1a446f95822
new file mode 100644
index 0000000000..79885b7f2a
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/784d6f5c093ab5360670173ce001e1a446f95822
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/79328fdc89d0af0e38da089dab062fd3ea5aae59 b/test/core/end2end/fuzzers/api_fuzzer_corpus/79328fdc89d0af0e38da089dab062fd3ea5aae59
new file mode 100644
index 0000000000..4a5cbfd654
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/79328fdc89d0af0e38da089dab062fd3ea5aae59
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/7a2569f4daf4480ad142cb4ee7c675bed82db74c b/test/core/end2end/fuzzers/api_fuzzer_corpus/7a2569f4daf4480ad142cb4ee7c675bed82db74c
new file mode 100644
index 0000000000..75b55e7e10
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/7a2569f4daf4480ad142cb4ee7c675bed82db74c
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/87a300cd25d2e57745bd00499d4d2352a10a2fa1 b/test/core/end2end/fuzzers/api_fuzzer_corpus/87a300cd25d2e57745bd00499d4d2352a10a2fa1
new file mode 100644
index 0000000000..c8f79862bc
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/87a300cd25d2e57745bd00499d4d2352a10a2fa1
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/8a1c629910280f8beebb88687696de98da988ecc b/test/core/end2end/fuzzers/api_fuzzer_corpus/8a1c629910280f8beebb88687696de98da988ecc
new file mode 100644
index 0000000000..ce3377fdc1
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/8a1c629910280f8beebb88687696de98da988ecc
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/8ff7b1568d2da2e4196c2e28617e1911d62021e6 b/test/core/end2end/fuzzers/api_fuzzer_corpus/8ff7b1568d2da2e4196c2e28617e1911d62021e6
new file mode 100644
index 0000000000..321520b870
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/8ff7b1568d2da2e4196c2e28617e1911d62021e6
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/982f375b183d984958667461c7767206062eb4cb b/test/core/end2end/fuzzers/api_fuzzer_corpus/982f375b183d984958667461c7767206062eb4cb
new file mode 100644
index 0000000000..01d07d6408
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/982f375b183d984958667461c7767206062eb4cb
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/98739af631223fa05ad88f1e63a52052a9bb4b1c b/test/core/end2end/fuzzers/api_fuzzer_corpus/98739af631223fa05ad88f1e63a52052a9bb4b1c
new file mode 100644
index 0000000000..a4adb7aee6
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/98739af631223fa05ad88f1e63a52052a9bb4b1c
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/a78bca1ef8829d720dd5dedac3a9d4d12684da34 b/test/core/end2end/fuzzers/api_fuzzer_corpus/a78bca1ef8829d720dd5dedac3a9d4d12684da34
new file mode 100644
index 0000000000..322d4ae019
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/a78bca1ef8829d720dd5dedac3a9d4d12684da34
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/ac763d89466ebfad676e75be0076831c03fe2a5d b/test/core/end2end/fuzzers/api_fuzzer_corpus/ac763d89466ebfad676e75be0076831c03fe2a5d
new file mode 100644
index 0000000000..64c9720c9b
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/ac763d89466ebfad676e75be0076831c03fe2a5d
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/b165523f699e6ae9b2ad15873b9d56465d1af546 b/test/core/end2end/fuzzers/api_fuzzer_corpus/b165523f699e6ae9b2ad15873b9d56465d1af546
new file mode 100644
index 0000000000..b0b7452924
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/b165523f699e6ae9b2ad15873b9d56465d1af546
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/b2a5ec3ef40c68d594638218e3c943a479f82215 b/test/core/end2end/fuzzers/api_fuzzer_corpus/b2a5ec3ef40c68d594638218e3c943a479f82215
new file mode 100644
index 0000000000..ac2b154407
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/b2a5ec3ef40c68d594638218e3c943a479f82215
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/b92b1c5e0dba009a9516e7185f5df019c62c5cc9 b/test/core/end2end/fuzzers/api_fuzzer_corpus/b92b1c5e0dba009a9516e7185f5df019c62c5cc9
new file mode 100644
index 0000000000..3d542f38ec
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/b92b1c5e0dba009a9516e7185f5df019c62c5cc9
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533 b/test/core/end2end/fuzzers/api_fuzzer_corpus/c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533
new file mode 100644
index 0000000000..c8fca17ad3
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/crash-da39a3ee5e6b4b0d3255bfef95601890afd80709 b/test/core/end2end/fuzzers/api_fuzzer_corpus/crash-da39a3ee5e6b4b0d3255bfef95601890afd80709
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/crash-da39a3ee5e6b4b0d3255bfef95601890afd80709
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/e28ffd8c2816f12f6395805199c792d1718191df b/test/core/end2end/fuzzers/api_fuzzer_corpus/e28ffd8c2816f12f6395805199c792d1718191df
new file mode 100644
index 0000000000..a867a8b0be
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/e28ffd8c2816f12f6395805199c792d1718191df
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/ec823f4018389e64a99f6580277fba28df6bd136 b/test/core/end2end/fuzzers/api_fuzzer_corpus/ec823f4018389e64a99f6580277fba28df6bd136
new file mode 100644
index 0000000000..2e6d409d39
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/ec823f4018389e64a99f6580277fba28df6bd136
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/ee2c1ac1e668f22836cf25a59495e778b0e2c7a8 b/test/core/end2end/fuzzers/api_fuzzer_corpus/ee2c1ac1e668f22836cf25a59495e778b0e2c7a8
new file mode 100644
index 0000000000..f1990ac231
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/ee2c1ac1e668f22836cf25a59495e778b0e2c7a8
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/ee6855178435d2046d8763ecae46e1e0a71a95f4 b/test/core/end2end/fuzzers/api_fuzzer_corpus/ee6855178435d2046d8763ecae46e1e0a71a95f4
new file mode 100644
index 0000000000..6badaf36dc
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/ee6855178435d2046d8763ecae46e1e0a71a95f4
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/eeb310d91038cb02862e187e68c5d6578233485b b/test/core/end2end/fuzzers/api_fuzzer_corpus/eeb310d91038cb02862e187e68c5d6578233485b
new file mode 100644
index 0000000000..1b05cfb036
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/eeb310d91038cb02862e187e68c5d6578233485b
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/f07bc2907c95f2aeb79ca60e2ad826e13b848f45 b/test/core/end2end/fuzzers/api_fuzzer_corpus/f07bc2907c95f2aeb79ca60e2ad826e13b848f45
new file mode 100644
index 0000000000..313d456262
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/f07bc2907c95f2aeb79ca60e2ad826e13b848f45
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/fb655905396b768cf3ff015afdb0b564dae2cdfd b/test/core/end2end/fuzzers/api_fuzzer_corpus/fb655905396b768cf3ff015afdb0b564dae2cdfd
new file mode 100644
index 0000000000..b02dabe03a
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/fb655905396b768cf3ff015afdb0b564dae2cdfd
Binary files differ
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/fdb038087233cd176746558875932029f779221d b/test/core/end2end/fuzzers/api_fuzzer_corpus/fdb038087233cd176746558875932029f779221d
new file mode 100644
index 0000000000..017fdbf661
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/fdb038087233cd176746558875932029f779221d
Binary files differ
diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py
index 201a92a1fd..bcb7136eaa 100755
--- a/test/core/end2end/gen_build_yaml.py
+++ b/test/core/end2end/gen_build_yaml.py
@@ -143,6 +143,8 @@ END2END_TESTS = {
'streaming_error_response': default_test_options,
'trailing_metadata': default_test_options,
'authority_not_supported': default_test_options,
+ 'write_buffering': default_test_options,
+ 'write_buffering_at_end': default_test_options,
}
diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl
index ed1ba3eea9..95c06de73f 100755
--- a/test/core/end2end/generate_tests.bzl
+++ b/test/core/end2end/generate_tests.bzl
@@ -131,6 +131,8 @@ END2END_TESTS = {
'trailing_metadata': test_options(),
'authority_not_supported': test_options(),
'filter_latency': test_options(),
+ 'write_buffering': test_options(),
+ 'write_buffering_at_end': test_options(),
}
diff --git a/test/core/end2end/tests/write_buffering.c b/test/core/end2end/tests/write_buffering.c
new file mode 100644
index 0000000000..856e9f0306
--- /dev/null
+++ b/test/core/end2end/tests/write_buffering.c
@@ -0,0 +1,291 @@
+/*
+ *
+ * Copyright 2017, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+static void *tag(intptr_t t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_server(&f, server_args);
+ config.init_client(&f, client_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event ev;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL);
+ } while (ev.type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
+ GPR_ASSERT(grpc_completion_queue_pluck(
+ f->cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL)
+ .type == GRPC_OP_COMPLETE);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->cq);
+ drain_cq(f->cq);
+ grpc_completion_queue_destroy(f->cq);
+}
+
+/* Client sends a request with payload, server reads then returns status. */
+static void test_invoke_request_with_payload(grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ grpc_slice request_payload_slice1 =
+ grpc_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload1 =
+ grpc_raw_byte_buffer_create(&request_payload_slice1, 1);
+ grpc_slice request_payload_slice2 = grpc_slice_from_copied_string("abc123");
+ grpc_byte_buffer *request_payload2 =
+ grpc_raw_byte_buffer_create(&request_payload_slice2, 1);
+ gpr_timespec deadline = five_seconds_time();
+ grpc_end2end_test_fixture f =
+ begin_test(config, "test_invoke_request_with_payload", NULL, NULL);
+ cq_verifier *cqv = cq_verifier_create(f.cq);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_byte_buffer *request_payload_recv1 = NULL;
+ grpc_byte_buffer *request_payload_recv2 = NULL;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ grpc_call_error error;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(
+ f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo",
+ get_host_override_string("foo.test.google.fr:1234", config), deadline,
+ NULL);
+ GPR_ASSERT(c);
+
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
+ f.server, &s, &call_details,
+ &request_metadata_recv, f.cq, f.cq, tag(101)));
+ CQ_EXPECT_COMPLETION(cqv, tag(1), true); /* send message is buffered */
+ CQ_EXPECT_COMPLETION(cqv, tag(101), true);
+ cq_verify(cqv);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload1;
+ op->flags = GRPC_WRITE_BUFFER_HINT;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ /* recv message should not succeed yet - it's buffered at the client still */
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv1;
+ op++;
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ CQ_EXPECT_COMPLETION(cqv, tag(2), true);
+ CQ_EXPECT_COMPLETION(cqv, tag(3), true);
+ CQ_EXPECT_COMPLETION(cqv, tag(102), true);
+ cq_verify(cqv);
+
+ /* send another message, this time not buffered */
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload2;
+ op->flags = 0;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ /* now the first send should match up with the first recv */
+ CQ_EXPECT_COMPLETION(cqv, tag(103), true);
+ CQ_EXPECT_COMPLETION(cqv, tag(4), true);
+ cq_verify(cqv);
+
+ /* and the next recv should be ready immediately also */
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv2;
+ op++;
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ CQ_EXPECT_COMPLETION(cqv, tag(104), true);
+ cq_verify(cqv);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), NULL);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_OK;
+ op->data.send_status_from_server.status_details = "xyz";
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(105), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ CQ_EXPECT_COMPLETION(cqv, tag(105), 1);
+ CQ_EXPECT_COMPLETION(cqv, tag(4), 1);
+ cq_verify(cqv);
+
+ GPR_ASSERT(status == GRPC_STATUS_OK);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ validate_host_override_string("foo.test.google.fr:1234", call_details.host,
+ config);
+ GPR_ASSERT(was_cancelled == 0);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv1, "hello world"));
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv2, "abc123"));
+
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(cqv);
+
+ grpc_byte_buffer_destroy(request_payload1);
+ grpc_byte_buffer_destroy(request_payload_recv1);
+ grpc_byte_buffer_destroy(request_payload2);
+ grpc_byte_buffer_destroy(request_payload_recv2);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void write_buffering(grpc_end2end_test_config config) {
+ test_invoke_request_with_payload(config);
+}
+
+void write_buffering_pre_init(void) {}
diff --git a/test/core/end2end/tests/write_buffering_at_end.c b/test/core/end2end/tests/write_buffering_at_end.c
new file mode 100644
index 0000000000..43aefcbdbc
--- /dev/null
+++ b/test/core/end2end/tests/write_buffering_at_end.c
@@ -0,0 +1,280 @@
+/*
+ *
+ * Copyright 2017, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "test/core/end2end/end2end_tests.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "test/core/end2end/cq_verifier.h"
+
+static void *tag(intptr_t t) { return (void *)t; }
+
+static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config,
+ const char *test_name,
+ grpc_channel_args *client_args,
+ grpc_channel_args *server_args) {
+ grpc_end2end_test_fixture f;
+ gpr_log(GPR_INFO, "%s/%s", test_name, config.name);
+ f = config.create_fixture(client_args, server_args);
+ config.init_server(&f, server_args);
+ config.init_client(&f, client_args);
+ return f;
+}
+
+static gpr_timespec n_seconds_time(int n) {
+ return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n);
+}
+
+static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); }
+
+static void drain_cq(grpc_completion_queue *cq) {
+ grpc_event ev;
+ do {
+ ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL);
+ } while (ev.type != GRPC_QUEUE_SHUTDOWN);
+}
+
+static void shutdown_server(grpc_end2end_test_fixture *f) {
+ if (!f->server) return;
+ grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000));
+ GPR_ASSERT(grpc_completion_queue_pluck(
+ f->cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL)
+ .type == GRPC_OP_COMPLETE);
+ grpc_server_destroy(f->server);
+ f->server = NULL;
+}
+
+static void shutdown_client(grpc_end2end_test_fixture *f) {
+ if (!f->client) return;
+ grpc_channel_destroy(f->client);
+ f->client = NULL;
+}
+
+static void end_test(grpc_end2end_test_fixture *f) {
+ shutdown_server(f);
+ shutdown_client(f);
+
+ grpc_completion_queue_shutdown(f->cq);
+ drain_cq(f->cq);
+ grpc_completion_queue_destroy(f->cq);
+}
+
+/* Client sends a request with payload, server reads then returns status. */
+static void test_invoke_request_with_payload(grpc_end2end_test_config config) {
+ grpc_call *c;
+ grpc_call *s;
+ grpc_slice request_payload_slice =
+ grpc_slice_from_copied_string("hello world");
+ grpc_byte_buffer *request_payload =
+ grpc_raw_byte_buffer_create(&request_payload_slice, 1);
+ gpr_timespec deadline = five_seconds_time();
+ grpc_end2end_test_fixture f =
+ begin_test(config, "test_invoke_request_with_payload", NULL, NULL);
+ cq_verifier *cqv = cq_verifier_create(f.cq);
+ grpc_op ops[6];
+ grpc_op *op;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_metadata_array trailing_metadata_recv;
+ grpc_metadata_array request_metadata_recv;
+ grpc_byte_buffer *request_payload_recv1 = NULL;
+ grpc_byte_buffer *request_payload_recv2 = NULL;
+ grpc_call_details call_details;
+ grpc_status_code status;
+ grpc_call_error error;
+ char *details = NULL;
+ size_t details_capacity = 0;
+ int was_cancelled = 2;
+
+ c = grpc_channel_create_call(
+ f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo",
+ get_host_override_string("foo.test.google.fr:1234", config), deadline,
+ NULL);
+ GPR_ASSERT(c);
+
+ grpc_metadata_array_init(&initial_metadata_recv);
+ grpc_metadata_array_init(&trailing_metadata_recv);
+ grpc_metadata_array_init(&request_metadata_recv);
+ grpc_call_details_init(&call_details);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &initial_metadata_recv;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
+ f.server, &s, &call_details,
+ &request_metadata_recv, f.cq, f.cq, tag(101)));
+ CQ_EXPECT_COMPLETION(cqv, tag(1), true); /* send message is buffered */
+ CQ_EXPECT_COMPLETION(cqv, tag(101), true);
+ cq_verify(cqv);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ op->data.send_message = request_payload;
+ op->flags = GRPC_WRITE_BUFFER_HINT;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ /* recv message should not succeed yet - it's buffered at the client still */
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv1;
+ op++;
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ CQ_EXPECT_COMPLETION(cqv, tag(2), true);
+ CQ_EXPECT_COMPLETION(cqv, tag(3), true);
+ CQ_EXPECT_COMPLETION(cqv, tag(102), true);
+ cq_verify(cqv);
+
+ /* send end of stream: should release the buffering */
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ /* now the first send should match up with the first recv */
+ CQ_EXPECT_COMPLETION(cqv, tag(103), true);
+ CQ_EXPECT_COMPLETION(cqv, tag(4), true);
+ cq_verify(cqv);
+
+ /* and the next recv should be ready immediately also (and empty) */
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &request_payload_recv2;
+ op++;
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ CQ_EXPECT_COMPLETION(cqv, tag(104), true);
+ cq_verify(cqv);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &status;
+ op->data.recv_status_on_client.status_details = &details;
+ op->data.recv_status_on_client.status_details_capacity = &details_capacity;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), NULL);
+
+ memset(ops, 0, sizeof(ops));
+ op = ops;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status = GRPC_STATUS_OK;
+ op->data.send_status_from_server.status_details = "xyz";
+ op->flags = 0;
+ op->reserved = NULL;
+ op++;
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(105), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == error);
+
+ CQ_EXPECT_COMPLETION(cqv, tag(105), 1);
+ CQ_EXPECT_COMPLETION(cqv, tag(4), 1);
+ cq_verify(cqv);
+
+ GPR_ASSERT(status == GRPC_STATUS_OK);
+ GPR_ASSERT(0 == strcmp(details, "xyz"));
+ GPR_ASSERT(0 == strcmp(call_details.method, "/foo"));
+ validate_host_override_string("foo.test.google.fr:1234", call_details.host,
+ config);
+ GPR_ASSERT(was_cancelled == 0);
+ GPR_ASSERT(byte_buffer_eq_string(request_payload_recv1, "hello world"));
+ GPR_ASSERT(request_payload_recv2 == NULL);
+
+ gpr_free(details);
+ grpc_metadata_array_destroy(&initial_metadata_recv);
+ grpc_metadata_array_destroy(&trailing_metadata_recv);
+ grpc_metadata_array_destroy(&request_metadata_recv);
+ grpc_call_details_destroy(&call_details);
+
+ grpc_call_destroy(c);
+ grpc_call_destroy(s);
+
+ cq_verifier_destroy(cqv);
+
+ grpc_byte_buffer_destroy(request_payload);
+ grpc_byte_buffer_destroy(request_payload_recv1);
+
+ end_test(&f);
+ config.tear_down_data(&f);
+}
+
+void write_buffering_at_end(grpc_end2end_test_config config) {
+ test_invoke_request_with_payload(config);
+}
+
+void write_buffering_at_end_pre_init(void) {}
diff --git a/test/core/http/BUILD b/test/core/http/BUILD
index 58d265bd8f..037ede3cd1 100644
--- a/test/core/http/BUILD
+++ b/test/core/http/BUILD
@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
+
load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_fuzzer(
diff --git a/test/core/json/BUILD b/test/core/json/BUILD
index 4b3fbd6076..05d4c6e0c5 100644
--- a/test/core/json/BUILD
+++ b/test/core/json/BUILD
@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
+
load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_fuzzer(
diff --git a/test/core/memory_usage/client.c b/test/core/memory_usage/client.c
new file mode 100644
index 0000000000..f4432bf572
--- /dev/null
+++ b/test/core/memory_usage/client.c
@@ -0,0 +1,316 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc/grpc.h>
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/byte_buffer.h>
+#include <grpc/byte_buffer_reader.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/cmdline.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "src/core/lib/support/string.h"
+#include "test/core/util/memory_counters.h"
+#include "test/core/util/test_config.h"
+
+static grpc_channel *channel;
+static grpc_completion_queue *cq;
+static grpc_op metadata_ops[2];
+static grpc_op status_ops[2];
+static grpc_op snapshot_ops[6];
+static grpc_op *op;
+
+typedef struct {
+ grpc_call *call;
+ grpc_metadata_array initial_metadata_recv;
+ grpc_status_code status;
+ char *details;
+ size_t details_capacity;
+ grpc_metadata_array trailing_metadata_recv;
+} fling_call;
+
+// Statically allocate call data structs. Enough to accomodate 10000 ping-pong
+// calls and 1 extra for the snapshot calls.
+static fling_call calls[10001];
+
+static void *tag(intptr_t t) { return (void *)t; }
+
+// A call is intentionally divided into two steps. First step is to initiate a
+// call (i.e send and recv metadata). A call is outstanding after we initated,
+// so we can measure the call memory usage.
+static void init_ping_pong_request(int call_idx) {
+ grpc_metadata_array_init(&calls[call_idx].initial_metadata_recv);
+
+ memset(metadata_ops, 0, sizeof(metadata_ops));
+ op = metadata_ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &calls[call_idx].initial_metadata_recv;
+ op++;
+
+ calls[call_idx].call = grpc_channel_create_call(
+ channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/Reflector/reflectUnary",
+ "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call,
+ metadata_ops,
+ (size_t)(op - metadata_ops),
+ tag(call_idx), NULL));
+ grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+}
+
+// Second step is to finish the call (i.e recv status) and destroy the call.
+static void finish_ping_pong_request(int call_idx) {
+ grpc_metadata_array_init(&calls[call_idx].trailing_metadata_recv);
+
+ memset(status_ops, 0, sizeof(status_ops));
+ op = status_ops;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata =
+ &calls[call_idx].trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &calls[call_idx].status;
+ op->data.recv_status_on_client.status_details = &calls[call_idx].details;
+ op->data.recv_status_on_client.status_details_capacity =
+ &calls[call_idx].details_capacity;
+ op++;
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call,
+ status_ops,
+ (size_t)(op - status_ops),
+ tag(call_idx), NULL));
+ grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+ grpc_metadata_array_destroy(&calls[call_idx].initial_metadata_recv);
+ grpc_metadata_array_destroy(&calls[call_idx].trailing_metadata_recv);
+ gpr_free(calls[call_idx].details);
+ grpc_call_destroy(calls[call_idx].call);
+ calls[call_idx].call = NULL;
+}
+
+static struct grpc_memory_counters send_snapshot_request(
+ int call_idx, const char *call_type) {
+ grpc_metadata_array_init(&calls[call_idx].initial_metadata_recv);
+ grpc_metadata_array_init(&calls[call_idx].trailing_metadata_recv);
+
+ grpc_byte_buffer *response_payload_recv = NULL;
+ memset(snapshot_ops, 0, sizeof(snapshot_ops));
+ op = snapshot_ops;
+
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY;
+ op++;
+ op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ op++;
+ op->op = GRPC_OP_RECV_INITIAL_METADATA;
+ op->data.recv_initial_metadata = &calls[call_idx].initial_metadata_recv;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &response_payload_recv;
+ op++;
+ op->op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ op->data.recv_status_on_client.trailing_metadata =
+ &calls[call_idx].trailing_metadata_recv;
+ op->data.recv_status_on_client.status = &calls[call_idx].status;
+ op->data.recv_status_on_client.status_details = &calls[call_idx].details;
+ op->data.recv_status_on_client.status_details_capacity =
+ &calls[call_idx].details_capacity;
+ op++;
+
+ calls[call_idx].call = grpc_channel_create_call(
+ channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, call_type, "localhost",
+ gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(
+ calls[call_idx].call, snapshot_ops,
+ (size_t)(op - snapshot_ops), (void *)0, NULL));
+ grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
+
+ grpc_byte_buffer_reader reader;
+ grpc_byte_buffer_reader_init(&reader, response_payload_recv);
+ grpc_slice response = grpc_byte_buffer_reader_readall(&reader);
+
+ struct grpc_memory_counters snapshot;
+ snapshot.total_size_absolute =
+ ((struct grpc_memory_counters *)GRPC_SLICE_START_PTR(response))
+ ->total_size_absolute;
+ snapshot.total_allocs_absolute =
+ ((struct grpc_memory_counters *)GRPC_SLICE_START_PTR(response))
+ ->total_allocs_absolute;
+ snapshot.total_size_relative =
+ ((struct grpc_memory_counters *)GRPC_SLICE_START_PTR(response))
+ ->total_size_relative;
+ snapshot.total_allocs_relative =
+ ((struct grpc_memory_counters *)GRPC_SLICE_START_PTR(response))
+ ->total_allocs_relative;
+
+ grpc_metadata_array_destroy(&calls[call_idx].initial_metadata_recv);
+ grpc_metadata_array_destroy(&calls[call_idx].trailing_metadata_recv);
+ grpc_slice_unref(response);
+ grpc_byte_buffer_reader_destroy(&reader);
+ grpc_byte_buffer_destroy(response_payload_recv);
+ gpr_free(calls[call_idx].details);
+ calls[call_idx].details = NULL;
+ calls[call_idx].details_capacity = 0;
+ grpc_call_destroy(calls[call_idx].call);
+ calls[call_idx].call = NULL;
+
+ return snapshot;
+}
+
+int main(int argc, char **argv) {
+ grpc_memory_counters_init();
+ grpc_slice slice = grpc_slice_from_copied_string("x");
+ char *fake_argv[1];
+
+ char *target = "localhost:443";
+ gpr_cmdline *cl;
+ grpc_event event;
+
+ grpc_init();
+
+ GPR_ASSERT(argc >= 1);
+ fake_argv[0] = argv[0];
+ grpc_test_init(1, fake_argv);
+
+ int warmup_iterations = 100;
+ int benchmark_iterations = 1000;
+
+ cl = gpr_cmdline_create("memory profiling client");
+ gpr_cmdline_add_string(cl, "target", "Target host:port", &target);
+ gpr_cmdline_add_int(cl, "warmup", "Warmup iterations", &warmup_iterations);
+ gpr_cmdline_add_int(cl, "benchmark", "Benchmark iterations",
+ &benchmark_iterations);
+ gpr_cmdline_parse(cl, argc, argv);
+ gpr_cmdline_destroy(cl);
+
+ for (int k = 0; k < (int)(sizeof(calls) / sizeof(fling_call)); k++) {
+ calls[k].details = NULL;
+ calls[k].details_capacity = 0;
+ }
+
+ cq = grpc_completion_queue_create(NULL);
+
+ struct grpc_memory_counters client_channel_start =
+ grpc_memory_counters_snapshot();
+ channel = grpc_insecure_channel_create(target, NULL, NULL);
+
+ int call_idx = 0;
+
+ struct grpc_memory_counters before_server_create =
+ send_snapshot_request(0, "Reflector/GetBeforeSvrCreation");
+ struct grpc_memory_counters after_server_create =
+ send_snapshot_request(0, "Reflector/GetAfterSvrCreation");
+
+ // warmup period
+ for (call_idx = 0; call_idx < warmup_iterations; ++call_idx) {
+ init_ping_pong_request(call_idx + 1);
+ }
+
+ struct grpc_memory_counters server_benchmark_calls_start =
+ send_snapshot_request(0, "Reflector/SimpleSnapshot");
+
+ struct grpc_memory_counters client_benchmark_calls_start =
+ grpc_memory_counters_snapshot();
+
+ // benchmark period
+ for (; call_idx < warmup_iterations + benchmark_iterations; ++call_idx) {
+ init_ping_pong_request(call_idx + 1);
+ }
+
+ struct grpc_memory_counters client_calls_inflight =
+ grpc_memory_counters_snapshot();
+
+ struct grpc_memory_counters server_calls_inflight =
+ send_snapshot_request(0, "Reflector/DestroyCalls");
+
+ do {
+ event = grpc_completion_queue_next(
+ cq, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_micros(10000, GPR_TIMESPAN)),
+ NULL);
+ } while (event.type != GRPC_QUEUE_TIMEOUT);
+
+ // second step - recv status and destroy call
+ for (call_idx = 0; call_idx < warmup_iterations + benchmark_iterations;
+ ++call_idx) {
+ finish_ping_pong_request(call_idx + 1);
+ }
+
+ struct grpc_memory_counters server_calls_end =
+ send_snapshot_request(0, "Reflector/SimpleSnapshot");
+
+ struct grpc_memory_counters client_channel_end =
+ grpc_memory_counters_snapshot();
+
+ grpc_channel_destroy(channel);
+ grpc_completion_queue_shutdown(cq);
+
+ do {
+ event = grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME),
+ NULL);
+ } while (event.type != GRPC_QUEUE_SHUTDOWN);
+ grpc_slice_unref(slice);
+
+ grpc_completion_queue_destroy(cq);
+ grpc_shutdown();
+
+ gpr_log(GPR_INFO, "---------client stats--------");
+ gpr_log(GPR_INFO, "client call memory usage: %f bytes per call",
+ (double)(client_calls_inflight.total_size_relative -
+ client_benchmark_calls_start.total_size_relative) /
+ benchmark_iterations);
+ gpr_log(GPR_INFO, "client channel memory usage %zi bytes",
+ client_channel_end.total_size_relative -
+ client_channel_start.total_size_relative);
+
+ gpr_log(GPR_INFO, "---------server stats--------");
+ gpr_log(GPR_INFO, "server create: %zi bytes",
+ after_server_create.total_size_relative -
+ before_server_create.total_size_relative);
+ gpr_log(GPR_INFO, "server call memory usage: %f bytes per call",
+ (double)(server_calls_inflight.total_size_relative -
+ server_benchmark_calls_start.total_size_relative) /
+ benchmark_iterations);
+ gpr_log(GPR_INFO, "server channel memory usage %zi bytes",
+ server_calls_end.total_size_relative -
+ after_server_create.total_size_relative);
+
+ grpc_memory_counters_destroy();
+ return 0;
+}
diff --git a/test/core/memory_usage/memory_usage_test.c b/test/core/memory_usage/memory_usage_test.c
new file mode 100644
index 0000000000..7e7a9d050d
--- /dev/null
+++ b/test/core/memory_usage/memory_usage_test.c
@@ -0,0 +1,93 @@
+/*
+ *
+ * Copyright 2015, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/host_port.h>
+#include <grpc/support/string_util.h>
+#include <grpc/support/subprocess.h>
+#include "src/core/lib/support/string.h"
+#include "test/core/util/port.h"
+
+int main(int argc, char **argv) {
+ char *me = argv[0];
+ char *lslash = strrchr(me, '/');
+ char root[1024];
+ int port = grpc_pick_unused_port_or_die();
+ char *args[10];
+ int status;
+ gpr_subprocess *svr, *cli;
+ /* figure out where we are */
+ if (lslash) {
+ memcpy(root, me, (size_t)(lslash - me));
+ root[lslash - me] = 0;
+ } else {
+ strcpy(root, ".");
+ }
+ /* start the server */
+ gpr_asprintf(&args[0], "%s/memory_profile_server%s", root,
+ gpr_subprocess_binary_extension());
+ args[1] = "--bind";
+ gpr_join_host_port(&args[2], "::", port);
+ args[3] = "--no-secure";
+ svr = gpr_subprocess_create(4, (const char **)args);
+ gpr_free(args[0]);
+ gpr_free(args[2]);
+
+ /* start the client */
+ gpr_asprintf(&args[0], "%s/memory_profile_client%s", root,
+ gpr_subprocess_binary_extension());
+ args[1] = "--target";
+ gpr_join_host_port(&args[2], "127.0.0.1", port);
+ args[3] = "--warmup=1000";
+ args[4] = "--benchmark=9000";
+ cli = gpr_subprocess_create(5, (const char **)args);
+ gpr_free(args[0]);
+ gpr_free(args[2]);
+
+ /* wait for completion */
+ printf("waiting for client\n");
+ if ((status = gpr_subprocess_join(cli))) {
+ gpr_subprocess_destroy(cli);
+ gpr_subprocess_destroy(svr);
+ return status;
+ }
+ gpr_subprocess_destroy(cli);
+
+ gpr_subprocess_interrupt(svr);
+ status = gpr_subprocess_join(svr);
+ gpr_subprocess_destroy(svr);
+ return status;
+}
diff --git a/test/core/memory_usage/server.c b/test/core/memory_usage/server.c
new file mode 100644
index 0000000000..c0710930b0
--- /dev/null
+++ b/test/core/memory_usage/server.c
@@ -0,0 +1,321 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <grpc/grpc.h>
+#include <grpc/grpc_security.h>
+
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#ifndef _WIN32
+/* This is for _exit() below, which is temporary. */
+#include <unistd.h>
+#endif
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/cmdline.h>
+#include <grpc/support/host_port.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include "test/core/end2end/data/ssl_test_data.h"
+#include "test/core/util/memory_counters.h"
+#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
+
+static grpc_completion_queue *cq;
+static grpc_server *server;
+static grpc_op metadata_ops[2];
+static grpc_op snapshot_ops[5];
+static grpc_op status_op;
+static int got_sigint = 0;
+static grpc_byte_buffer *payload_buffer = NULL;
+static grpc_byte_buffer *terminal_buffer = NULL;
+static int was_cancelled = 2;
+
+static void *tag(intptr_t t) { return (void *)t; }
+
+typedef enum {
+ FLING_SERVER_NEW_REQUEST = 1,
+ FLING_SERVER_SEND_INIT_METADATA,
+ FLING_SERVER_WAIT_FOR_DESTROY,
+ FLING_SERVER_SEND_STATUS_FLING_CALL,
+ FLING_SERVER_SEND_STATUS_SNAPSHOT,
+ FLING_SERVER_BATCH_SEND_STATUS_FLING_CALL
+} fling_server_tags;
+
+typedef struct {
+ fling_server_tags state;
+ grpc_call *call;
+ grpc_call_details call_details;
+ grpc_metadata_array request_metadata_recv;
+ grpc_metadata_array initial_metadata_send;
+} fling_call;
+
+// hold up to 10000 calls and 6 snaphost calls
+static fling_call calls[100006];
+
+static void request_call_unary(int call_idx) {
+ if (call_idx == (int)(sizeof(calls) / sizeof(fling_call))) {
+ gpr_log(GPR_INFO, "Used all call slots (10000) on server. Server exit.");
+ _exit(0);
+ }
+ grpc_metadata_array_init(&calls[call_idx].request_metadata_recv);
+ grpc_server_request_call(
+ server, &calls[call_idx].call, &calls[call_idx].call_details,
+ &calls[call_idx].request_metadata_recv, cq, cq, &calls[call_idx]);
+}
+
+static void send_initial_metadata_unary(void *tag) {
+ grpc_metadata_array_init(&(*(fling_call *)tag).initial_metadata_send);
+ metadata_ops[0].op = GRPC_OP_SEND_INITIAL_METADATA;
+ metadata_ops[0].data.send_initial_metadata.count = 0;
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call *)tag).call,
+ metadata_ops, 1, tag, NULL));
+}
+
+static void send_status(void *tag) {
+ status_op.op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ status_op.data.send_status_from_server.status = GRPC_STATUS_OK;
+ status_op.data.send_status_from_server.trailing_metadata_count = 0;
+ status_op.data.send_status_from_server.status_details = "";
+
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call *)tag).call,
+ &status_op, 1, tag, NULL));
+}
+
+static void send_snapshot(void *tag, struct grpc_memory_counters *snapshot) {
+ grpc_op *op;
+
+ grpc_slice snapshot_slice =
+ grpc_slice_new(snapshot, sizeof(*snapshot), gpr_free);
+ payload_buffer = grpc_raw_byte_buffer_create(&snapshot_slice, 1);
+ grpc_metadata_array_init(&(*(fling_call *)tag).initial_metadata_send);
+
+ op = snapshot_ops;
+ op->op = GRPC_OP_SEND_INITIAL_METADATA;
+ op->data.send_initial_metadata.count = 0;
+ op++;
+ op->op = GRPC_OP_RECV_MESSAGE;
+ op->data.recv_message = &terminal_buffer;
+ op++;
+ op->op = GRPC_OP_SEND_MESSAGE;
+ if (payload_buffer == NULL) {
+ gpr_log(GPR_INFO, "NULL payload buffer !!!");
+ }
+ op->data.send_message = payload_buffer;
+ op++;
+ op->op = GRPC_OP_SEND_STATUS_FROM_SERVER;
+ op->data.send_status_from_server.status = GRPC_STATUS_OK;
+ op->data.send_status_from_server.trailing_metadata_count = 0;
+ op->data.send_status_from_server.status_details = "";
+ op++;
+ op->op = GRPC_OP_RECV_CLOSE_ON_SERVER;
+ op->data.recv_close_on_server.cancelled = &was_cancelled;
+ op++;
+
+ GPR_ASSERT(GRPC_CALL_OK ==
+ grpc_call_start_batch((*(fling_call *)tag).call, snapshot_ops,
+ (size_t)(op - snapshot_ops), tag, NULL));
+}
+/* We have some sort of deadlock, so let's not exit gracefully for now.
+ When that is resolved, please remove the #include <unistd.h> above. */
+static void sigint_handler(int x) { _exit(0); }
+
+int main(int argc, char **argv) {
+ grpc_memory_counters_init();
+ grpc_event ev;
+ char *addr_buf = NULL;
+ gpr_cmdline *cl;
+ int shutdown_started = 0;
+ int shutdown_finished = 0;
+
+ int secure = 0;
+ char *addr = NULL;
+
+ char *fake_argv[1];
+
+ GPR_ASSERT(argc >= 1);
+ fake_argv[0] = argv[0];
+ grpc_test_init(1, fake_argv);
+
+ grpc_init();
+ srand((unsigned)clock());
+
+ cl = gpr_cmdline_create("fling server");
+ gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr);
+ gpr_cmdline_add_flag(cl, "secure", "Run with security?", &secure);
+ gpr_cmdline_parse(cl, argc, argv);
+ gpr_cmdline_destroy(cl);
+
+ if (addr == NULL) {
+ gpr_join_host_port(&addr_buf, "::", grpc_pick_unused_port_or_die());
+ addr = addr_buf;
+ }
+ gpr_log(GPR_INFO, "creating server on: %s", addr);
+
+ cq = grpc_completion_queue_create(NULL);
+
+ struct grpc_memory_counters before_server_create =
+ grpc_memory_counters_snapshot();
+ if (secure) {
+ grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {test_server1_key,
+ test_server1_cert};
+ grpc_server_credentials *ssl_creds = grpc_ssl_server_credentials_create(
+ NULL, &pem_key_cert_pair, 1, 0, NULL);
+ server = grpc_server_create(NULL, NULL);
+ GPR_ASSERT(grpc_server_add_secure_http2_port(server, addr, ssl_creds));
+ grpc_server_credentials_release(ssl_creds);
+ } else {
+ server = grpc_server_create(NULL, NULL);
+ GPR_ASSERT(grpc_server_add_insecure_http2_port(server, addr));
+ }
+
+ grpc_server_register_completion_queue(server, cq, NULL);
+ grpc_server_start(server);
+
+ struct grpc_memory_counters after_server_create =
+ grpc_memory_counters_snapshot();
+
+ gpr_free(addr_buf);
+ addr = addr_buf = NULL;
+
+ // initialize call instances
+ for (int i = 0; i < (int)(sizeof(calls) / sizeof(fling_call)); i++) {
+ grpc_call_details_init(&calls[i].call_details);
+ calls[i].state = FLING_SERVER_NEW_REQUEST;
+ }
+
+ int next_call_idx = 0;
+ struct grpc_memory_counters current_snapshot;
+
+ request_call_unary(next_call_idx);
+
+ signal(SIGINT, sigint_handler);
+
+ while (!shutdown_finished) {
+ if (got_sigint && !shutdown_started) {
+ gpr_log(GPR_INFO, "Shutting down due to SIGINT");
+ grpc_server_shutdown_and_notify(server, cq, tag(1000));
+ GPR_ASSERT(grpc_completion_queue_pluck(
+ cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL)
+ .type == GRPC_OP_COMPLETE);
+ grpc_completion_queue_shutdown(cq);
+ shutdown_started = 1;
+ }
+ ev = grpc_completion_queue_next(
+ cq, gpr_time_add(gpr_now(GPR_CLOCK_REALTIME),
+ gpr_time_from_micros(1000000, GPR_TIMESPAN)),
+ NULL);
+ fling_call *s = ev.tag;
+ switch (ev.type) {
+ case GRPC_OP_COMPLETE:
+ switch (s->state) {
+ case FLING_SERVER_NEW_REQUEST:
+ request_call_unary(++next_call_idx);
+ if (0 ==
+ strcmp(s->call_details.method, "/Reflector/reflectUnary")) {
+ s->state = FLING_SERVER_SEND_INIT_METADATA;
+ send_initial_metadata_unary(s);
+ } else if (0 == strcmp(s->call_details.method,
+ "Reflector/GetBeforeSvrCreation")) {
+ s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT;
+ send_snapshot(s, &before_server_create);
+ } else if (0 == strcmp(s->call_details.method,
+ "Reflector/GetAfterSvrCreation")) {
+ s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT;
+ send_snapshot(s, &after_server_create);
+ } else if (0 == strcmp(s->call_details.method,
+ "Reflector/SimpleSnapshot")) {
+ s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT;
+ current_snapshot = grpc_memory_counters_snapshot();
+ send_snapshot(s, &current_snapshot);
+ } else if (0 == strcmp(s->call_details.method,
+ "Reflector/DestroyCalls")) {
+ s->state = FLING_SERVER_BATCH_SEND_STATUS_FLING_CALL;
+ current_snapshot = grpc_memory_counters_snapshot();
+ send_snapshot(s, &current_snapshot);
+ } else {
+ gpr_log(GPR_ERROR, "Wrong call method");
+ }
+ break;
+ case FLING_SERVER_SEND_INIT_METADATA:
+ s->state = FLING_SERVER_WAIT_FOR_DESTROY;
+ break;
+ case FLING_SERVER_WAIT_FOR_DESTROY:
+ break;
+ case FLING_SERVER_SEND_STATUS_FLING_CALL:
+ grpc_call_destroy(s->call);
+ grpc_call_details_destroy(&s->call_details);
+ grpc_metadata_array_destroy(&s->initial_metadata_send);
+ grpc_metadata_array_destroy(&s->request_metadata_recv);
+ break;
+ case FLING_SERVER_BATCH_SEND_STATUS_FLING_CALL:
+ for (int k = 0; k < (int)(sizeof(calls) / sizeof(fling_call));
+ ++k) {
+ if (calls[k].state == FLING_SERVER_WAIT_FOR_DESTROY) {
+ calls[k].state = FLING_SERVER_SEND_STATUS_FLING_CALL;
+ send_status(&calls[k]);
+ }
+ }
+ // no break here since we want to continue to case
+ // FLING_SERVER_SEND_STATUS_SNAPSHOT to destroy the snapshot call
+ case FLING_SERVER_SEND_STATUS_SNAPSHOT:
+ grpc_byte_buffer_destroy(payload_buffer);
+ grpc_byte_buffer_destroy(terminal_buffer);
+ grpc_call_destroy(s->call);
+ grpc_call_details_destroy(&s->call_details);
+ grpc_metadata_array_destroy(&s->initial_metadata_send);
+ grpc_metadata_array_destroy(&s->request_metadata_recv);
+ terminal_buffer = NULL;
+ payload_buffer = NULL;
+ break;
+ }
+ break;
+ case GRPC_QUEUE_SHUTDOWN:
+ GPR_ASSERT(shutdown_started);
+ shutdown_finished = 1;
+ break;
+ case GRPC_QUEUE_TIMEOUT:
+ break;
+ }
+ }
+
+ grpc_server_destroy(server);
+ grpc_completion_queue_destroy(cq);
+ grpc_shutdown();
+ grpc_memory_counters_destroy();
+ return 0;
+}
diff --git a/test/core/nanopb/BUILD b/test/core/nanopb/BUILD
index bdf79b7fef..b02d750f32 100644
--- a/test/core/nanopb/BUILD
+++ b/test/core/nanopb/BUILD
@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
+
load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_fuzzer(
diff --git a/test/core/support/BUILD b/test/core/support/BUILD
index 77f0a9a048..dfe952eb37 100644
--- a/test/core/support/BUILD
+++ b/test/core/support/BUILD
@@ -27,8 +27,6 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
-
cc_test(
name = "alloc_test",
srcs = ["alloc_test.c"],
diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c
index 610495377c..e0a2c94216 100644
--- a/test/core/surface/public_headers_must_be_c89.c
+++ b/test/core/surface/public_headers_must_be_c89.c
@@ -43,6 +43,7 @@
#include <grpc/impl/codegen/compression_types.h>
#include <grpc/impl/codegen/connectivity_state.h>
#include <grpc/impl/codegen/exec_ctx_fwd.h>
+#include <grpc/impl/codegen/gpr_slice.h>
#include <grpc/impl/codegen/gpr_types.h>
#include <grpc/impl/codegen/grpc_types.h>
#include <grpc/impl/codegen/port_platform.h>
diff --git a/test/core/transport/chttp2/BUILD b/test/core/transport/chttp2/BUILD
index 5dd205174f..94b4830138 100644
--- a/test/core/transport/chttp2/BUILD
+++ b/test/core/transport/chttp2/BUILD
@@ -27,6 +27,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
+
load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer")
grpc_fuzzer(
diff --git a/test/core/util/BUILD b/test/core/util/BUILD
index e50e595d03..8769683b23 100644
--- a/test/core/util/BUILD
+++ b/test/core/util/BUILD
@@ -1,4 +1,33 @@
+# Copyright 2017, Google Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+licenses(["notice"]) # 3-clause BSD
cc_library(
name = "gpr_test_util",
diff --git a/test/core/util/memory_counters.h b/test/core/util/memory_counters.h
index f332816501..b9b2b3adda 100644
--- a/test/core/util/memory_counters.h
+++ b/test/core/util/memory_counters.h
@@ -34,6 +34,8 @@
#ifndef GRPC_TEST_CORE_UTIL_MEMORY_COUNTERS_H
#define GRPC_TEST_CORE_UTIL_MEMORY_COUNTERS_H
+#include <stddef.h>
+
struct grpc_memory_counters {
size_t total_size_relative;
size_t total_size_absolute;
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 8e385d100c..2ce3f2f7bd 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -254,7 +254,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
// Setup server
ServerBuilder builder;
- auto server_creds = GetServerCredentials(GetParam().credentials_type);
+ auto server_creds = GetCredentialsProvider()->GetServerCredentials(
+ GetParam().credentials_type);
builder.AddListeningPort(server_address_.str(), server_creds);
builder.RegisterService(&service_);
cq_ = builder.AddCompletionQueue();
@@ -283,8 +284,8 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<TestScenario> {
void ResetStub() {
ChannelArguments args;
- auto channel_creds =
- GetChannelCredentials(GetParam().credentials_type, &args);
+ auto channel_creds = GetCredentialsProvider()->GetChannelCredentials(
+ GetParam().credentials_type, &args);
std::shared_ptr<Channel> channel =
CreateCustomChannel(server_address_.str(), channel_creds, args);
stub_ = grpc::testing::EchoTestService::NewStub(channel);
@@ -892,8 +893,8 @@ TEST_P(AsyncEnd2endTest, ServerCheckDone) {
TEST_P(AsyncEnd2endTest, UnimplementedRpc) {
ChannelArguments args;
- auto channel_creds =
- GetChannelCredentials(GetParam().credentials_type, &args);
+ auto channel_creds = GetCredentialsProvider()->GetChannelCredentials(
+ GetParam().credentials_type, &args);
std::shared_ptr<Channel> channel =
CreateCustomChannel(server_address_.str(), channel_creds, args);
std::unique_ptr<grpc::testing::UnimplementedEchoService::Stub> stub;
@@ -1404,11 +1405,15 @@ std::vector<TestScenario> CreateTestScenarios(bool test_disable_blocking,
std::vector<grpc::string> credentials_types;
std::vector<grpc::string> messages;
- credentials_types.push_back(kInsecureCredentialsType);
- auto sec_list = GetSecureCredentialsTypeList();
+ if (GetCredentialsProvider()->GetChannelCredentials(kInsecureCredentialsType,
+ nullptr) != nullptr) {
+ credentials_types.push_back(kInsecureCredentialsType);
+ }
+ auto sec_list = GetCredentialsProvider()->GetSecureCredentialsTypeList();
for (auto sec = sec_list.begin(); sec != sec_list.end(); sec++) {
credentials_types.push_back(*sec);
}
+ GPR_ASSERT(!credentials_types.empty());
messages.push_back("Hello");
for (int sz = 1; sz < test_big_limit; sz *= 2) {
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 9bb892c694..1a1a94e87c 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -242,7 +242,8 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
// Setup server
ServerBuilder builder;
ConfigureServerBuilder(&builder);
- auto server_creds = GetServerCredentials(GetParam().credentials_type);
+ auto server_creds = GetCredentialsProvider()->GetServerCredentials(
+ GetParam().credentials_type);
if (GetParam().credentials_type != kInsecureCredentialsType) {
server_creds->SetAuthMetadataProcessor(processor);
}
@@ -270,8 +271,8 @@ class End2endTest : public ::testing::TestWithParam<TestScenario> {
}
EXPECT_TRUE(is_server_started_);
ChannelArguments args;
- auto channel_creds =
- GetChannelCredentials(GetParam().credentials_type, &args);
+ auto channel_creds = GetCredentialsProvider()->GetChannelCredentials(
+ GetParam().credentials_type, &args);
if (!user_agent_prefix_.empty()) {
args.SetUserAgentPrefix(user_agent_prefix_);
}
@@ -1520,11 +1521,18 @@ std::vector<TestScenario> CreateTestScenarios(bool use_proxy,
std::vector<TestScenario> scenarios;
std::vector<grpc::string> credentials_types;
if (test_secure) {
- credentials_types = GetSecureCredentialsTypeList();
+ credentials_types =
+ GetCredentialsProvider()->GetSecureCredentialsTypeList();
}
if (test_insecure) {
- credentials_types.push_back(kInsecureCredentialsType);
+ // Only add insecure credentials type when it is registered with the
+ // provider. User may create providers that do not have insecure.
+ if (GetCredentialsProvider()->GetChannelCredentials(
+ kInsecureCredentialsType, nullptr) != nullptr) {
+ credentials_types.push_back(kInsecureCredentialsType);
+ }
}
+ GPR_ASSERT(!credentials_types.empty());
for (auto it = credentials_types.begin(); it != credentials_types.end();
++it) {
scenarios.emplace_back(false, *it);
@@ -1541,7 +1549,7 @@ INSTANTIATE_TEST_CASE_P(End2end, End2endTest,
INSTANTIATE_TEST_CASE_P(End2endServerTryCancel, End2endServerTryCancelTest,
::testing::ValuesIn(CreateTestScenarios(false, true,
- false)));
+ true)));
INSTANTIATE_TEST_CASE_P(ProxyEnd2end, ProxyEnd2endTest,
::testing::ValuesIn(CreateTestScenarios(true, true,
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index c58910abc3..3265554444 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -49,6 +49,7 @@
#include "test/cpp/util/test_config.h"
DEFINE_bool(use_tls, false, "Whether to use tls.");
+DEFINE_string(custom_credentials_type, "", "User provided credentials type.");
DEFINE_bool(use_test_ca, false, "False to use SSL roots for google");
DEFINE_int32(server_port, 0, "Server port.");
DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
diff --git a/test/cpp/interop/client_helper.cc b/test/cpp/interop/client_helper.cc
index c171969e14..91564e5dce 100644
--- a/test/cpp/interop/client_helper.cc
+++ b/test/cpp/interop/client_helper.cc
@@ -50,8 +50,10 @@
#include "src/cpp/client/secure_credentials.h"
#include "test/core/security/oauth2_utils.h"
#include "test/cpp/util/create_test_channel.h"
+#include "test/cpp/util/test_credentials_provider.h"
DECLARE_bool(use_tls);
+DECLARE_string(custom_credentials_type);
DECLARE_bool(use_test_ca);
DECLARE_int32(server_port);
DECLARE_string(server_host);
@@ -114,8 +116,12 @@ std::shared_ptr<Channel> CreateChannelForTestCase(
creds = AccessTokenCredentials(raw_token);
GPR_ASSERT(creds);
}
- return CreateTestChannel(host_port, FLAGS_server_host_override, FLAGS_use_tls,
- !FLAGS_use_test_ca, creds);
+ if (FLAGS_custom_credentials_type.empty()) {
+ return CreateTestChannel(host_port, FLAGS_server_host_override,
+ FLAGS_use_tls, !FLAGS_use_test_ca, creds);
+ } else {
+ return CreateTestChannel(host_port, FLAGS_custom_credentials_type, creds);
+ }
}
} // namespace testing
diff --git a/test/cpp/interop/http2_client.cc b/test/cpp/interop/http2_client.cc
new file mode 100644
index 0000000000..38aee43b26
--- /dev/null
+++ b/test/cpp/interop/http2_client.cc
@@ -0,0 +1,272 @@
+/*
+ *
+ * Copyright 2016, Google Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <thread>
+
+#include <gflags/gflags.h>
+#include <grpc++/channel.h>
+#include <grpc++/client_context.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/useful.h>
+
+#include "src/core/lib/transport/byte_stream.h"
+#include "src/proto/grpc/testing/messages.grpc.pb.h"
+#include "src/proto/grpc/testing/test.grpc.pb.h"
+#include "test/cpp/interop/http2_client.h"
+
+#include "src/core/lib/support/string.h"
+#include "test/cpp/util/create_test_channel.h"
+#include "test/cpp/util/test_config.h"
+
+namespace grpc {
+namespace testing {
+
+namespace {
+const int kLargeRequestSize = 271828;
+const int kLargeResponseSize = 314159;
+} // namespace
+
+Http2Client::ServiceStub::ServiceStub(std::shared_ptr<Channel> channel)
+ : channel_(channel) {
+ stub_ = TestService::NewStub(channel);
+}
+
+TestService::Stub* Http2Client::ServiceStub::Get() { return stub_.get(); }
+
+Http2Client::Http2Client(std::shared_ptr<Channel> channel)
+ : serviceStub_(channel), channel_(channel) {}
+
+bool Http2Client::AssertStatusCode(const Status& s, StatusCode expected_code) {
+ if (s.error_code() == expected_code) {
+ return true;
+ }
+
+ gpr_log(GPR_ERROR, "Error status code: %d (expected: %d), message: %s",
+ s.error_code(), expected_code, s.error_message().c_str());
+ abort();
+}
+
+bool Http2Client::DoRstAfterHeader() {
+ gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream after header");
+
+ ClientContext context;
+ SimpleRequest request;
+ SimpleResponse response;
+ request.set_response_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+
+ Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
+ AssertStatusCode(s, grpc::StatusCode::UNKNOWN);
+ GPR_ASSERT(!response.has_payload()); // no data should be received
+
+ gpr_log(GPR_DEBUG, "Done testing reset stream after header");
+ return true;
+}
+
+bool Http2Client::DoRstAfterData() {
+ gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream after data");
+
+ ClientContext context;
+ SimpleRequest request;
+ SimpleResponse response;
+ request.set_response_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+
+ Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
+ AssertStatusCode(s, grpc::StatusCode::UNKNOWN);
+ GPR_ASSERT(response.has_payload()); // data should be received
+
+ gpr_log(GPR_DEBUG, "Done testing reset stream after data");
+ return true;
+}
+
+bool Http2Client::DoRstDuringData() {
+ gpr_log(GPR_DEBUG, "Sending RPC and expecting reset stream during data");
+
+ ClientContext context;
+ SimpleRequest request;
+ SimpleResponse response;
+ request.set_response_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+
+ Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
+ AssertStatusCode(s, grpc::StatusCode::UNKNOWN);
+ GPR_ASSERT(!response.has_payload()); // no data should be received
+
+ gpr_log(GPR_DEBUG, "Done testing reset stream during data");
+ return true;
+}
+
+bool Http2Client::DoGoaway() {
+ gpr_log(GPR_DEBUG, "Sending two RPCs and expecting goaway");
+
+ int numCalls = 2;
+ for (int i = 0; i < numCalls; i++) {
+ ClientContext context;
+ SimpleRequest request;
+ SimpleResponse response;
+ request.set_response_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+
+ Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
+ AssertStatusCode(s, grpc::StatusCode::OK);
+ GPR_ASSERT(response.payload().body() ==
+ grpc::string(kLargeResponseSize, '\0'));
+ }
+
+ gpr_log(GPR_DEBUG, "Done testing goaway");
+ return true;
+}
+
+bool Http2Client::DoPing() {
+ gpr_log(GPR_DEBUG, "Sending RPC and expecting ping");
+
+ ClientContext context;
+ SimpleRequest request;
+ SimpleResponse response;
+ request.set_response_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+
+ Status s = serviceStub_.Get()->UnaryCall(&context, request, &response);
+ AssertStatusCode(s, grpc::StatusCode::OK);
+ GPR_ASSERT(response.payload().body() ==
+ grpc::string(kLargeResponseSize, '\0'));
+
+ gpr_log(GPR_DEBUG, "Done testing ping");
+ return true;
+}
+
+void Http2Client::MaxStreamsWorker(std::shared_ptr<grpc::Channel> channel) {
+ ClientContext context;
+ SimpleRequest request;
+ SimpleResponse response;
+ request.set_response_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+
+ Status s =
+ TestService::NewStub(channel)->UnaryCall(&context, request, &response);
+ AssertStatusCode(s, grpc::StatusCode::OK);
+ GPR_ASSERT(response.payload().body() ==
+ grpc::string(kLargeResponseSize, '\0'));
+}
+
+bool Http2Client::DoMaxStreams() {
+ gpr_log(GPR_DEBUG, "Testing max streams");
+
+ // Make an initial call on the channel to ensure the server's max streams
+ // setting is received
+ ClientContext context;
+ SimpleRequest request;
+ SimpleResponse response;
+ request.set_response_size(kLargeResponseSize);
+ grpc::string payload(kLargeRequestSize, '\0');
+ request.mutable_payload()->set_body(payload.c_str(), kLargeRequestSize);
+ Status s =
+ TestService::NewStub(channel_)->UnaryCall(&context, request, &response);
+ AssertStatusCode(s, grpc::StatusCode::OK);
+ GPR_ASSERT(response.payload().body() ==
+ grpc::string(kLargeResponseSize, '\0'));
+
+ std::vector<std::thread> test_threads;
+
+ for (int i = 0; i < 10; i++) {
+ test_threads.emplace_back(
+ std::thread(&Http2Client::MaxStreamsWorker, this, channel_));
+ }
+
+ for (auto it = test_threads.begin(); it != test_threads.end(); it++) {
+ it->join();
+ }
+
+ gpr_log(GPR_DEBUG, "Done testing max streams");
+ return true;
+}
+
+} // namespace testing
+} // namespace grpc
+
+DEFINE_int32(server_port, 0, "Server port.");
+DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
+DEFINE_string(test_case, "rst_after_header",
+ "Configure different test cases. Valid options are:\n\n"
+ "goaway\n"
+ "max_streams\n"
+ "ping\n"
+ "rst_after_data\n"
+ "rst_after_header\n"
+ "rst_during_data\n");
+
+int main(int argc, char** argv) {
+ grpc::testing::InitTest(&argc, &argv, true);
+ GPR_ASSERT(FLAGS_server_port);
+ const int host_port_buf_size = 1024;
+ char host_port[host_port_buf_size];
+ snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(),
+ FLAGS_server_port);
+ grpc::testing::Http2Client client(grpc::CreateTestChannel(host_port, false));
+ gpr_log(GPR_INFO, "Testing case: %s", FLAGS_test_case.c_str());
+ int ret = 0;
+ if (FLAGS_test_case == "rst_after_header") {
+ client.DoRstAfterHeader();
+ } else if (FLAGS_test_case == "rst_after_data") {
+ client.DoRstAfterData();
+ } else if (FLAGS_test_case == "rst_during_data") {
+ client.DoRstDuringData();
+ } else if (FLAGS_test_case == "goaway") {
+ client.DoGoaway();
+ } else if (FLAGS_test_case == "ping") {
+ client.DoPing();
+ } else if (FLAGS_test_case == "max_streams") {
+ client.DoMaxStreams();
+ } else {
+ const char* testcases[] = {
+ "goaway", "max_streams", "ping",
+ "rst_after_data", "rst_after_header", "rst_during_data"};
+ char* joined_testcases =
+ gpr_strjoin_sep(testcases, GPR_ARRAY_SIZE(testcases), "\n", NULL);
+
+ gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s",
+ FLAGS_test_case.c_str(), joined_testcases);
+ gpr_free(joined_testcases);
+ ret = 1;
+ }
+
+ return ret;
+}
diff --git a/test/cpp/qps/limit_cores.h b/test/cpp/interop/http2_client.h
index 5482904a3c..6a315f5abb 100644
--- a/test/cpp/qps/limit_cores.h
+++ b/test/cpp/interop/http2_client.h
@@ -31,19 +31,50 @@
*
*/
-#ifndef TEST_QPS_LIMIT_CORES_H
-#define TEST_QPS_LIMIT_CORES_H
+#ifndef GRPC_TEST_CPP_INTEROP_HTTP2_CLIENT_H
+#define GRPC_TEST_CPP_INTEROP_HTTP2_CLIENT_H
+
+#include <memory>
+
+#include <grpc++/channel.h>
+#include <grpc/grpc.h>
+#include "src/proto/grpc/testing/messages.grpc.pb.h"
+#include "src/proto/grpc/testing/test.grpc.pb.h"
namespace grpc {
namespace testing {
-/// LimitCores: allow this worker to only run on the cores specified in the
-/// array \a cores, which is of length \a cores_size.
-///
-/// LimitCores takes array and size arguments (instead of vector) for direct
-/// conversion from repeated field of protobuf. Use a cores_size of 0 to remove
-/// existing limits (from an empty repeated field)
-int LimitCores(const int *cores, int cores_size);
+
+class Http2Client {
+ public:
+ explicit Http2Client(std::shared_ptr<Channel> channel);
+ ~Http2Client() {}
+
+ bool DoRstAfterHeader();
+ bool DoRstAfterData();
+ bool DoRstDuringData();
+ bool DoGoaway();
+ bool DoPing();
+ bool DoMaxStreams();
+
+ private:
+ class ServiceStub {
+ public:
+ ServiceStub(std::shared_ptr<Channel> channel);
+
+ TestService::Stub* Get();
+
+ private:
+ std::unique_ptr<TestService::Stub> stub_;
+ std::shared_ptr<Channel> channel_;
+ };
+
+ void MaxStreamsWorker(std::shared_ptr<grpc::Channel> channel);
+ bool AssertStatusCode(const Status& s, StatusCode expected_code);
+ ServiceStub serviceStub_;
+ std::shared_ptr<Channel> channel_;
+};
+
} // namespace testing
} // namespace grpc
-#endif // TEST_QPS_LIMIT_CORES_H
+#endif // GRPC_TEST_CPP_INTEROP_HTTP2_CLIENT_H
diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc
index 67456ce18b..956840ba70 100644
--- a/test/cpp/interop/interop_server.cc
+++ b/test/cpp/interop/interop_server.cc
@@ -56,6 +56,7 @@
#include "test/cpp/util/test_config.h"
DEFINE_bool(use_tls, false, "Whether to use tls.");
+DEFINE_string(custom_credentials_type, "", "User provided credentials type.");
DEFINE_int32(port, 0, "Server port.");
DEFINE_int32(max_send_message_size, -1, "The maximum send message size.");
diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc
index 8b0b511bcb..d395f50fa5 100644
--- a/test/cpp/interop/server_helper.cc
+++ b/test/cpp/interop/server_helper.cc
@@ -39,23 +39,23 @@
#include <grpc++/security/server_credentials.h>
#include "src/core/lib/surface/call_test_only.h"
-#include "test/core/end2end/data/ssl_test_data.h"
+#include "test/cpp/util/test_credentials_provider.h"
DECLARE_bool(use_tls);
+DECLARE_string(custom_credentials_type);
namespace grpc {
namespace testing {
std::shared_ptr<ServerCredentials> CreateInteropServerCredentials() {
- if (FLAGS_use_tls) {
- 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);
+ if (!FLAGS_custom_credentials_type.empty()) {
+ return GetCredentialsProvider()->GetServerCredentials(
+ FLAGS_custom_credentials_type);
+ } else if (FLAGS_use_tls) {
+ return GetCredentialsProvider()->GetServerCredentials(kTlsCredentialsType);
} else {
- return InsecureServerCredentials();
+ return GetCredentialsProvider()->GetServerCredentials(
+ kInsecureCredentialsType);
}
}
diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc
index 97e658869f..562522de77 100644
--- a/test/cpp/interop/stress_test.cc
+++ b/test/cpp/interop/stress_test.cc
@@ -147,6 +147,7 @@ DEFINE_bool(do_not_abort_on_transient_failures, true,
// Options from client.cc (for compatibility with interop test).
// TODO(sreek): Consolidate overlapping options
DEFINE_bool(use_tls, false, "Whether to use tls.");
+DEFINE_string(custom_credentials_type, "", "User provided credentials type.");
DEFINE_bool(use_test_ca, false, "False to use SSL roots for google");
DEFINE_int32(server_port, 0, "Server port.");
DEFINE_string(server_host, "127.0.0.1", "Server host to connect to");
diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h
index fdd78ebb89..baa9304cc2 100644
--- a/test/cpp/qps/client.h
+++ b/test/cpp/qps/client.h
@@ -51,7 +51,6 @@
#include "test/cpp/qps/histogram.h"
#include "test/cpp/qps/interarrival.h"
-#include "test/cpp/qps/limit_cores.h"
#include "test/cpp/qps/usage_timer.h"
#include "test/cpp/util/create_test_channel.h"
@@ -374,7 +373,7 @@ class ClientImpl : public Client {
ClientImpl(const ClientConfig& config,
std::function<std::unique_ptr<StubType>(std::shared_ptr<Channel>)>
create_stub)
- : cores_(LimitCores(config.core_list().data(), config.core_list_size())),
+ : cores_(gpr_cpu_num_cores()),
channels_(config.client_channels()),
create_stub_(create_stub) {
for (int i = 0; i < config.client_channels(); i++) {
@@ -409,6 +408,7 @@ class ClientImpl : public Client {
// old compilers happy with using this in std::vector
ChannelArguments args;
args.SetInt("shard_to_ensure_no_subchannel_merges", shard);
+ set_channel_args(config, &args);
channel_ = CreateTestChannel(
target, config.security_params().server_host_override(),
config.has_security_params(), !config.security_params().use_test_ca(),
@@ -423,6 +423,18 @@ class ClientImpl : public Client {
StubType* get_stub() { return stub_.get(); }
private:
+ void set_channel_args(const ClientConfig& config, ChannelArguments* args) {
+ for (auto channel_arg : config.channel_args()) {
+ if (channel_arg.value_case() == ChannelArg::kStrValue) {
+ args->SetString(channel_arg.name(), channel_arg.str_value());
+ } else if (channel_arg.value_case() == ChannelArg::kIntValue) {
+ args->SetInt(channel_arg.name(), channel_arg.int_value());
+ } else {
+ gpr_log(GPR_ERROR, "Empty channel arg value.");
+ }
+ }
+ }
+
std::shared_ptr<Channel> channel_;
std::unique_ptr<StubType> stub_;
};
diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc
index 93ef32db77..74fe3662c1 100644
--- a/test/cpp/qps/driver.cc
+++ b/test/cpp/qps/driver.cc
@@ -76,30 +76,6 @@ static std::string get_host(const std::string& worker) {
return s;
}
-static std::unordered_map<string, std::deque<int>> get_hosts_and_cores(
- const deque<string>& workers) {
- std::unordered_map<string, std::deque<int>> hosts;
- for (auto it = workers.begin(); it != workers.end(); it++) {
- const string host = get_host(*it);
- if (hosts.find(host) == hosts.end()) {
- auto stub = WorkerService::NewStub(
- CreateChannel(*it, InsecureChannelCredentials()));
- grpc::ClientContext ctx;
- ctx.set_wait_for_ready(true);
- CoreRequest dummy;
- CoreResponse cores;
- grpc::Status s = stub->CoreCount(&ctx, dummy, &cores);
- GPR_ASSERT(s.ok());
- std::deque<int> dq;
- for (int i = 0; i < cores.cores(); i++) {
- dq.push_back(i);
- }
- hosts[host] = dq;
- }
- }
- return hosts;
-}
-
static deque<string> get_workers(const string& env_name) {
char* env = gpr_getenv(env_name.c_str());
if (!env) {
@@ -210,7 +186,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
const ClientConfig& initial_client_config, size_t num_clients,
const ServerConfig& initial_server_config, size_t num_servers,
int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count,
- const char* qps_server_target_override, bool configure_core_lists) {
+ const char* qps_server_target_override) {
// Log everything from the driver
gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG);
@@ -279,9 +255,6 @@ std::unique_ptr<ScenarioResult> RunScenario(
std::vector<ServerData> servers(num_servers);
std::unordered_map<string, std::deque<int>> hosts_cores;
- if (configure_core_lists) {
- hosts_cores = get_hosts_and_cores(workers);
- }
for (size_t i = 0; i < num_servers; i++) {
gpr_log(GPR_INFO, "Starting server on %s (worker #%" PRIuPTR ")",
workers[i].c_str(), i);
@@ -289,37 +262,9 @@ std::unique_ptr<ScenarioResult> RunScenario(
CreateChannel(workers[i], InsecureChannelCredentials()));
ServerConfig server_config = initial_server_config;
- int server_core_limit = initial_server_config.core_limit();
- int client_core_limit = initial_client_config.core_limit();
-
- if (configure_core_lists) {
- string host_str(get_host(workers[i]));
- if (server_core_limit == 0 && client_core_limit > 0) {
- // In this case, limit the server cores if it matches the
- // same host as one or more clients
- const auto& dq = hosts_cores.at(host_str);
- bool match = false;
- int limit = dq.size();
- for (size_t cli = 0; cli < num_clients; cli++) {
- if (host_str == get_host(workers[cli + num_servers])) {
- limit -= client_core_limit;
- match = true;
- }
- }
- if (match) {
- GPR_ASSERT(limit > 0);
- server_core_limit = limit;
- }
- }
- if (server_core_limit > 0) {
- auto& dq = hosts_cores.at(host_str);
- GPR_ASSERT(dq.size() >= static_cast<size_t>(server_core_limit));
- gpr_log(GPR_INFO, "Setting server core_list");
- for (int core = 0; core < server_core_limit; core++) {
- server_config.add_core_list(dq.front());
- dq.pop_front();
- }
- }
+ if (server_config.core_limit() != 0) {
+ gpr_log(GPR_ERROR,
+ "server config core limit is set but ignored by driver");
}
ServerArgs args;
@@ -364,33 +309,8 @@ std::unique_ptr<ScenarioResult> RunScenario(
CreateChannel(worker, InsecureChannelCredentials()));
ClientConfig per_client_config = client_config;
- int server_core_limit = initial_server_config.core_limit();
- int client_core_limit = initial_client_config.core_limit();
- if (configure_core_lists &&
- ((server_core_limit > 0) || (client_core_limit > 0))) {
- auto& dq = hosts_cores.at(get_host(worker));
- if (client_core_limit == 0) {
- // limit client cores if it matches a server host
- bool match = false;
- int limit = dq.size();
- for (size_t srv = 0; srv < num_servers; srv++) {
- if (get_host(worker) == get_host(workers[srv])) {
- match = true;
- }
- }
- if (match) {
- GPR_ASSERT(limit > 0);
- client_core_limit = limit;
- }
- }
- if (client_core_limit > 0) {
- GPR_ASSERT(dq.size() >= static_cast<size_t>(client_core_limit));
- gpr_log(GPR_INFO, "Setting client core_list");
- for (int core = 0; core < client_core_limit; core++) {
- per_client_config.add_core_list(dq.front());
- dq.pop_front();
- }
- }
+ if (initial_client_config.core_limit() != 0) {
+ gpr_log(GPR_ERROR, "client config core limit set but ignored");
}
// Reduce channel count so that total channels specified is held regardless
diff --git a/test/cpp/qps/driver.h b/test/cpp/qps/driver.h
index b5c8152e1b..e72d30a4ef 100644
--- a/test/cpp/qps/driver.h
+++ b/test/cpp/qps/driver.h
@@ -46,8 +46,7 @@ std::unique_ptr<ScenarioResult> RunScenario(
const grpc::testing::ClientConfig& client_config, size_t num_clients,
const grpc::testing::ServerConfig& server_config, size_t num_servers,
int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count,
- const char* qps_server_target_override = "",
- bool configure_core_lists = true);
+ const char* qps_server_target_override = "");
bool RunQuit();
} // namespace testing
diff --git a/test/cpp/qps/limit_cores.cc b/test/cpp/qps/limit_cores.cc
deleted file mode 100644
index b5c222542b..0000000000
--- a/test/cpp/qps/limit_cores.cc
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- *
- * Copyright 2016, Google Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include "test/cpp/qps/limit_cores.h"
-
-#include <grpc/support/cpu.h>
-#include <grpc/support/log.h>
-#include <grpc/support/port_platform.h>
-
-#ifdef GPR_CPU_LINUX
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-#include <sched.h>
-
-namespace grpc {
-namespace testing {
-
-int LimitCores(const int* cores, int cores_size) {
- const int num_cores = gpr_cpu_num_cores();
- int cores_set = 0;
-
- cpu_set_t* cpup = CPU_ALLOC(num_cores);
- GPR_ASSERT(cpup);
- const size_t size = CPU_ALLOC_SIZE(num_cores);
- CPU_ZERO_S(size, cpup);
-
- if (cores_size > 0) {
- for (int i = 0; i < cores_size; i++) {
- if (cores[i] < num_cores) {
- CPU_SET_S(cores[i], size, cpup);
- cores_set++;
- }
- }
- } else {
- for (int i = 0; i < num_cores; i++) {
- CPU_SET_S(i, size, cpup);
- cores_set++;
- }
- }
- bool affinity_set = (sched_setaffinity(0, size, cpup) == 0);
- CPU_FREE(cpup);
- return affinity_set ? cores_set : num_cores;
-}
-
-} // namespace testing
-} // namespace grpc
-#else
-namespace grpc {
-namespace testing {
-
-// LimitCores is not currently supported for non-Linux platforms
-int LimitCores(const int*, int) { return gpr_cpu_num_cores(); }
-
-} // namespace testing
-} // namespace grpc
-#endif
diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc
index da835b995a..ddaaa7ca75 100644
--- a/test/cpp/qps/qps_json_driver.cc
+++ b/test/cpp/qps/qps_json_driver.cc
@@ -70,9 +70,6 @@ DEFINE_double(error_tolerance, 0.01,
DEFINE_string(qps_server_target_override, "",
"Override QPS server target to configure in client configs."
"Only applicable if there is a single benchmark server.");
-DEFINE_bool(configure_core_lists, true,
- "Provide 'core_list' parameters to workers. Value determined "
- "by cores available and 'core_limit' parameters of the scenarios.");
namespace grpc {
namespace testing {
@@ -80,12 +77,12 @@ namespace testing {
static std::unique_ptr<ScenarioResult> RunAndReport(const Scenario& scenario,
bool* success) {
std::cerr << "RUNNING SCENARIO: " << scenario.name() << "\n";
- auto result = RunScenario(
- scenario.client_config(), scenario.num_clients(),
- scenario.server_config(), scenario.num_servers(),
- scenario.warmup_seconds(), scenario.benchmark_seconds(),
- scenario.spawn_local_worker_count(),
- FLAGS_qps_server_target_override.c_str(), FLAGS_configure_core_lists);
+ auto result =
+ RunScenario(scenario.client_config(), scenario.num_clients(),
+ scenario.server_config(), scenario.num_servers(),
+ scenario.warmup_seconds(), scenario.benchmark_seconds(),
+ scenario.spawn_local_worker_count(),
+ FLAGS_qps_server_target_override.c_str());
// Amend the result with scenario config. Eventually we should adjust
// RunScenario contract so we don't need to touch the result here.
@@ -212,6 +209,7 @@ static bool QpsDriver() {
SearchOfferedLoad(FLAGS_initial_search_value,
FLAGS_targeted_cpu_load, scenario, &success);
gpr_log(GPR_INFO, "targeted_offered_load %f", targeted_offered_load);
+ GetCpuLoad(scenario, targeted_offered_load, &success);
} else {
gpr_log(GPR_ERROR, "Unimplemented search param");
}
diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h
index c3d18e5789..821d5935be 100644
--- a/test/cpp/qps/server.h
+++ b/test/cpp/qps/server.h
@@ -42,7 +42,6 @@
#include "src/proto/grpc/testing/messages.grpc.pb.h"
#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/usage_timer.h"
namespace grpc {
@@ -51,7 +50,7 @@ namespace testing {
class Server {
public:
explicit Server(const ServerConfig& config) : timer_(new UsageTimer) {
- cores_ = LimitCores(config.core_list().data(), config.core_list_size());
+ cores_ = gpr_cpu_num_cores();
if (config.port()) {
port_ = config.port();
diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc
index fe8b5d5423..ad62e03490 100644
--- a/test/cpp/util/create_test_channel.cc
+++ b/test/cpp/util/create_test_channel.cc
@@ -35,11 +35,37 @@
#include <grpc++/create_channel.h>
#include <grpc++/security/credentials.h>
+#include <grpc/support/log.h>
-#include "test/core/end2end/data/ssl_test_data.h"
+#include "test/cpp/util/test_credentials_provider.h"
namespace grpc {
+namespace {
+
+const char kProdTlsCredentialsType[] = "prod_ssl";
+
+class SslCredentialProvider : public testing::CredentialTypeProvider {
+ public:
+ std::shared_ptr<ChannelCredentials> GetChannelCredentials(
+ grpc::ChannelArguments* args) override {
+ return SslCredentials(SslCredentialsOptions());
+ }
+ std::shared_ptr<ServerCredentials> GetServerCredentials() override {
+ return nullptr;
+ }
+};
+
+gpr_once g_once_init_add_prod_ssl_provider = GPR_ONCE_INIT;
+// Register ssl with non-test roots type to the credentials provider.
+void AddProdSslType() {
+ testing::GetCredentialsProvider()->AddSecureType(
+ kProdTlsCredentialsType, std::unique_ptr<testing::CredentialTypeProvider>(
+ new SslCredentialProvider));
+}
+
+} // namespace
+
// When ssl is enabled, if server is empty, override_hostname is used to
// create channel. Otherwise, connect to server and override hostname if
// override_hostname is provided.
@@ -61,16 +87,22 @@ std::shared_ptr<Channel> CreateTestChannel(
const std::shared_ptr<CallCredentials>& creds,
const ChannelArguments& args) {
ChannelArguments channel_args(args);
+ std::shared_ptr<ChannelCredentials> channel_creds;
if (enable_ssl) {
- const char* roots_certs = use_prod_roots ? "" : test_root_cert;
- SslCredentialsOptions ssl_opts = {roots_certs, "", ""};
-
- std::shared_ptr<ChannelCredentials> channel_creds =
- SslCredentials(ssl_opts);
-
- if (!server.empty() && !override_hostname.empty()) {
- channel_args.SetSslTargetNameOverride(override_hostname);
+ if (use_prod_roots) {
+ gpr_once_init(&g_once_init_add_prod_ssl_provider, &AddProdSslType);
+ channel_creds = testing::GetCredentialsProvider()->GetChannelCredentials(
+ kProdTlsCredentialsType, &channel_args);
+ if (!server.empty() && !override_hostname.empty()) {
+ channel_args.SetSslTargetNameOverride(override_hostname);
+ }
+ } else {
+ // override_hostname is discarded as the provider handles it.
+ channel_creds = testing::GetCredentialsProvider()->GetChannelCredentials(
+ testing::kTlsCredentialsType, &channel_args);
}
+ GPR_ASSERT(channel_creds != nullptr);
+
const grpc::string& connect_to =
server.empty() ? override_hostname : server;
if (creds.get()) {
@@ -103,4 +135,18 @@ std::shared_ptr<Channel> CreateTestChannel(const grpc::string& server,
return CreateTestChannel(server, "foo.test.google.fr", enable_ssl, false);
}
+std::shared_ptr<Channel> CreateTestChannel(
+ const grpc::string& server, const grpc::string& credential_type,
+ const std::shared_ptr<CallCredentials>& creds) {
+ ChannelArguments channel_args;
+ std::shared_ptr<ChannelCredentials> channel_creds =
+ testing::GetCredentialsProvider()->GetChannelCredentials(credential_type,
+ &channel_args);
+ GPR_ASSERT(channel_creds != nullptr);
+ if (creds.get()) {
+ channel_creds = CompositeChannelCredentials(channel_creds, creds);
+ }
+ return CreateCustomChannel(server, channel_creds, channel_args);
+}
+
} // namespace grpc
diff --git a/test/cpp/util/create_test_channel.h b/test/cpp/util/create_test_channel.h
index 4ff666dc1b..ce71a97edb 100644
--- a/test/cpp/util/create_test_channel.h
+++ b/test/cpp/util/create_test_channel.h
@@ -59,6 +59,10 @@ std::shared_ptr<Channel> CreateTestChannel(
const std::shared_ptr<CallCredentials>& creds,
const ChannelArguments& args);
+std::shared_ptr<Channel> CreateTestChannel(
+ const grpc::string& server, const grpc::string& credential_type,
+ const std::shared_ptr<CallCredentials>& creds);
+
} // namespace grpc
#endif // GRPC_TEST_CPP_UTIL_CREATE_TEST_CHANNEL_H
diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc
index 0456b96667..909b02a701 100644
--- a/test/cpp/util/test_credentials_provider.cc
+++ b/test/cpp/util/test_credentials_provider.cc
@@ -43,25 +43,9 @@
#include "test/core/end2end/data/ssl_test_data.h"
namespace grpc {
+namespace testing {
namespace {
-using grpc::testing::CredentialTypeProvider;
-
-// Provide test credentials. Thread-safe.
-class CredentialsProvider {
- public:
- virtual ~CredentialsProvider() {}
-
- virtual void AddSecureType(
- const grpc::string& type,
- std::unique_ptr<CredentialTypeProvider> type_provider) = 0;
- 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;
-};
-
class DefaultCredentialsProvider : public CredentialsProvider {
public:
~DefaultCredentialsProvider() override {}
@@ -145,37 +129,21 @@ class DefaultCredentialsProvider : public CredentialsProvider {
added_secure_type_providers_;
};
-gpr_once g_once_init_provider = GPR_ONCE_INIT;
CredentialsProvider* g_provider = nullptr;
-void CreateDefaultProvider() { g_provider = new DefaultCredentialsProvider; }
-
-CredentialsProvider* GetProvider() {
- gpr_once_init(&g_once_init_provider, &CreateDefaultProvider);
- return g_provider;
-}
-
} // namespace
-namespace testing {
-
-void AddSecureType(const grpc::string& type,
- std::unique_ptr<CredentialTypeProvider> type_provider) {
- GetProvider()->AddSecureType(type, std::move(type_provider));
-}
-
-std::shared_ptr<ChannelCredentials> GetChannelCredentials(
- const grpc::string& type, ChannelArguments* args) {
- return GetProvider()->GetChannelCredentials(type, args);
-}
-
-std::shared_ptr<ServerCredentials> GetServerCredentials(
- const grpc::string& type) {
- return GetProvider()->GetServerCredentials(type);
+CredentialsProvider* GetCredentialsProvider() {
+ if (g_provider == nullptr) {
+ g_provider = new DefaultCredentialsProvider;
+ }
+ return g_provider;
}
-std::vector<grpc::string> GetSecureCredentialsTypeList() {
- return GetProvider()->GetSecureCredentialsTypeList();
+void SetCredentialsProvider(CredentialsProvider* provider) {
+ // For now, forbids overriding provider.
+ GPR_ASSERT(g_provider == nullptr);
+ g_provider = provider;
}
} // namespace testing
diff --git a/test/cpp/util/test_credentials_provider.h b/test/cpp/util/test_credentials_provider.h
index 1fb311e556..0bc52ebe4d 100644
--- a/test/cpp/util/test_credentials_provider.h
+++ b/test/cpp/util/test_credentials_provider.h
@@ -59,23 +59,39 @@ class CredentialTypeProvider {
virtual std::shared_ptr<ServerCredentials> GetServerCredentials() = 0;
};
-// Add a secure type in addition to the defaults above
-// (kInsecureCredentialsType, kTlsCredentialsType) that can be returned from the
-// functions below.
-void AddSecureType(const grpc::string& type,
- std::unique_ptr<CredentialTypeProvider> type_provider);
-
-// Provide channel credentials according to the given type. Alter the channel
-// arguments if needed.
-std::shared_ptr<ChannelCredentials> GetChannelCredentials(
- const grpc::string& type, ChannelArguments* args);
-
-// Provide server credentials according to the given type.
-std::shared_ptr<ServerCredentials> GetServerCredentials(
- const grpc::string& type);
-
-// Provide a list of secure credentials type.
-std::vector<grpc::string> GetSecureCredentialsTypeList();
+// Provide test credentials. Thread-safe.
+class CredentialsProvider {
+ public:
+ virtual ~CredentialsProvider() {}
+
+ // Add a secure type in addition to the defaults. The default provider has
+ // (kInsecureCredentialsType, kTlsCredentialsType).
+ virtual void AddSecureType(
+ const grpc::string& type,
+ std::unique_ptr<CredentialTypeProvider> type_provider) = 0;
+
+ // Provide channel credentials according to the given type. Alter the channel
+ // arguments if needed. Return nullptr if type is not registered.
+ virtual std::shared_ptr<ChannelCredentials> GetChannelCredentials(
+ const grpc::string& type, ChannelArguments* args) = 0;
+
+ // Provide server credentials according to the given type.
+ // Return nullptr if type is not registered.
+ virtual std::shared_ptr<ServerCredentials> GetServerCredentials(
+ const grpc::string& type) = 0;
+
+ // Provide a list of secure credentials type.
+ virtual std::vector<grpc::string> GetSecureCredentialsTypeList() = 0;
+};
+
+// Get the current provider. Create a default one if not set.
+// Not thread-safe.
+CredentialsProvider* GetCredentialsProvider();
+
+// Set the global provider. Takes ownership. The previous set provider will be
+// destroyed.
+// Not thread-safe.
+void SetCredentialsProvider(CredentialsProvider* provider);
} // namespace testing
} // namespace grpc