aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2017-03-27 18:50:04 +0200
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2017-03-27 18:50:04 +0200
commit8e0684b5d4b69670797d9d297a317aacd7236548 (patch)
tree9eaafb090247ce9b08015c90ac1062f4a10acca9 /test
parentb02dd01584e21565ebea173ceee7568404d23f2b (diff)
parentc4478a103b68100b86f506061cedcb0ce70016ba (diff)
Merge branch 'master' of https://github.com/grpc/grpc into cpp_bazelness
Diffstat (limited to 'test')
-rw-r--r--test/build/c-ares.c43
-rw-r--r--test/core/bad_client/bad_client.c10
-rw-r--r--test/core/client_channel/resolvers/dns_resolver_connectivity_test.c16
-rw-r--r--test/core/end2end/bad_server_response_test.c2
-rw-r--r--test/core/end2end/connection_refused_test.c2
-rw-r--r--test/core/end2end/fixtures/http_proxy_fixture.c2
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer.c12
-rw-r--r--test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6723650944237568bin0 -> 669 bytes
-rw-r--r--test/core/end2end/goaway_server_test.c30
-rw-r--r--test/core/end2end/tests/filter_call_init_fails.c6
-rw-r--r--test/core/end2end/tests/filter_causes_close.c2
-rw-r--r--test/core/http/httpcli_test.c4
-rw-r--r--test/core/http/httpscli_test.c4
-rw-r--r--test/core/iomgr/endpoint_tests.c14
-rw-r--r--test/core/iomgr/error_test.c123
-rw-r--r--test/core/iomgr/ev_epoll_linux_test.c2
-rw-r--r--test/core/iomgr/fd_posix_test.c2
-rw-r--r--test/core/iomgr/pollset_set_test.c3
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c5
-rw-r--r--test/core/iomgr/tcp_client_uv_test.c5
-rw-r--r--test/core/iomgr/tcp_server_posix_test.c5
-rw-r--r--test/core/iomgr/tcp_server_uv_test.c3
-rw-r--r--test/core/iomgr/udp_server_test.c89
-rw-r--r--test/core/memory_usage/client.c5
-rw-r--r--test/core/security/secure_endpoint_test.c10
-rw-r--r--test/core/security/ssl_server_fuzzer.c5
-rw-r--r--test/core/surface/concurrent_connectivity_test.c3
-rw-r--r--test/core/util/mock_endpoint.c5
-rw-r--r--test/core/util/passthru_endpoint.c15
-rw-r--r--test/core/util/reconnect_server.c3
-rw-r--r--test/cpp/common/channel_arguments_test.cc16
-rw-r--r--test/cpp/microbenchmarks/bm_call_create.cc208
-rw-r--r--test/cpp/microbenchmarks/bm_error.cc72
-rw-r--r--test/http2_test/http2_base_server.py35
-rw-r--r--test/http2_test/http2_test_server.py10
-rw-r--r--test/http2_test/test_data_frame_padding.py94
36 files changed, 692 insertions, 173 deletions
diff --git a/test/build/c-ares.c b/test/build/c-ares.c
new file mode 100644
index 0000000000..c954e9397f
--- /dev/null
+++ b/test/build/c-ares.c
@@ -0,0 +1,43 @@
+/*
+ *
+ * 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 <ares.h>
+
+int main(void) {
+ ares_channel channelptr;
+
+ ares_init(&channelptr);
+ ares_destroy(channelptr);
+
+ return 0;
+}
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c
index fdedfe284e..4870dc1a53 100644
--- a/test/core/bad_client/bad_client.c
+++ b/test/core/bad_client/bad_client.c
@@ -163,8 +163,9 @@ void grpc_run_bad_client_test(
gpr_event_wait(&a.done_write, grpc_timeout_seconds_to_deadline(5)));
if (flags & GRPC_BAD_CLIENT_DISCONNECT) {
- grpc_endpoint_shutdown(&exec_ctx, sfd.client,
- GRPC_ERROR_CREATE("Forced Disconnect"));
+ grpc_endpoint_shutdown(
+ &exec_ctx, sfd.client,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect"));
grpc_endpoint_destroy(&exec_ctx, sfd.client);
grpc_exec_ctx_finish(&exec_ctx);
sfd.client = NULL;
@@ -190,8 +191,9 @@ void grpc_run_bad_client_test(
grpc_slice_buffer_destroy_internal(&exec_ctx, &args.incoming);
}
// Shutdown.
- grpc_endpoint_shutdown(&exec_ctx, sfd.client,
- GRPC_ERROR_CREATE("Test Shutdown"));
+ grpc_endpoint_shutdown(
+ &exec_ctx, sfd.client,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
grpc_endpoint_destroy(&exec_ctx, sfd.client);
grpc_exec_ctx_finish(&exec_ctx);
}
diff --git a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
index 187757d5b3..8449afcbbe 100644
--- a/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
+++ b/test/core/client_channel/resolvers/dns_resolver_connectivity_test.c
@@ -48,22 +48,26 @@ static gpr_mu g_mu;
static bool g_fail_resolution = true;
static grpc_combiner *g_combiner;
-static grpc_error *my_resolve_address(const char *name, const char *addr,
- grpc_resolved_addresses **addrs) {
+static void my_resolve_address(grpc_exec_ctx *exec_ctx, const char *addr,
+ const char *default_port,
+ grpc_pollset_set *interested_parties,
+ grpc_closure *on_done,
+ grpc_resolved_addresses **addrs) {
gpr_mu_lock(&g_mu);
- GPR_ASSERT(0 == strcmp("test", name));
+ GPR_ASSERT(0 == strcmp("test", addr));
+ grpc_error *error = GRPC_ERROR_NONE;
if (g_fail_resolution) {
g_fail_resolution = false;
gpr_mu_unlock(&g_mu);
- return GRPC_ERROR_CREATE("Forced Failure");
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Failure");
} else {
gpr_mu_unlock(&g_mu);
*addrs = gpr_malloc(sizeof(**addrs));
(*addrs)->naddrs = 1;
(*addrs)->addrs = gpr_malloc(sizeof(*(*addrs)->addrs));
(*addrs)->addrs[0].len = 123;
- return GRPC_ERROR_NONE;
}
+ grpc_closure_sched(exec_ctx, on_done, error);
}
static grpc_resolver *create_resolver(grpc_exec_ctx *exec_ctx,
@@ -135,7 +139,7 @@ int main(int argc, char **argv) {
grpc_init();
gpr_mu_init(&g_mu);
g_combiner = grpc_combiner_create(NULL);
- grpc_blocking_resolve_address = my_resolve_address;
+ grpc_resolve_address = my_resolve_address;
grpc_channel_args *result = (grpc_channel_args *)1;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
diff --git a/test/core/end2end/bad_server_response_test.c b/test/core/end2end/bad_server_response_test.c
index 39a98e84ca..c37a292af9 100644
--- a/test/core/end2end/bad_server_response_test.c
+++ b/test/core/end2end/bad_server_response_test.c
@@ -303,7 +303,7 @@ static void run_test(const char *response_payload,
/* clean up */
grpc_endpoint_shutdown(&exec_ctx, state.tcp,
- GRPC_ERROR_CREATE("Test Shutdown"));
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
grpc_endpoint_destroy(&exec_ctx, state.tcp);
cleanup_rpc(&exec_ctx);
grpc_exec_ctx_finish(&exec_ctx);
diff --git a/test/core/end2end/connection_refused_test.c b/test/core/end2end/connection_refused_test.c
index 16a3005539..6ded12ad48 100644
--- a/test/core/end2end/connection_refused_test.c
+++ b/test/core/end2end/connection_refused_test.c
@@ -53,7 +53,6 @@ static void *tag(intptr_t i) { return (void *)i; }
static void run_test(bool wait_for_ready, bool use_service_config) {
grpc_channel *chan;
grpc_call *call;
- gpr_timespec deadline = grpc_timeout_seconds_to_deadline(2);
grpc_completion_queue *cq;
cq_verifier *cqv;
grpc_op ops[6];
@@ -98,6 +97,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) {
gpr_log(GPR_INFO, "server: %s", addr);
chan = grpc_insecure_channel_create(addr, args, NULL);
grpc_slice host = grpc_slice_from_static_string("nonexistant");
+ gpr_timespec deadline = grpc_timeout_seconds_to_deadline(2);
call = grpc_channel_create_call(
chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq,
grpc_slice_from_static_string("/service/method"), &host, deadline, NULL);
diff --git a/test/core/end2end/fixtures/http_proxy_fixture.c b/test/core/end2end/fixtures/http_proxy_fixture.c
index bcd1c9914b..451ed268d3 100644
--- a/test/core/end2end/fixtures/http_proxy_fixture.c
+++ b/test/core/end2end/fixtures/http_proxy_fixture.c
@@ -342,7 +342,7 @@ static void on_read_request_done(grpc_exec_ctx* exec_ctx, void* arg,
char* msg;
gpr_asprintf(&msg, "HTTP proxy got request method %s",
conn->http_request.method);
- error = GRPC_ERROR_CREATE(msg);
+ error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
gpr_free(msg);
proxy_connection_failed(exec_ctx, conn, true /* is_client */,
"HTTP proxy read request", error);
diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c
index 0de8b9459a..a0acf5bf60 100644
--- a/test/core/end2end/fuzzers/api_fuzzer.c
+++ b/test/core/end2end/fuzzers/api_fuzzer.c
@@ -390,9 +390,9 @@ static void finish_resolve(grpc_exec_ctx *exec_ctx, void *arg,
*r->addrs = addrs;
grpc_closure_sched(exec_ctx, r->on_done, GRPC_ERROR_NONE);
} else {
- grpc_closure_sched(
- exec_ctx, r->on_done,
- GRPC_ERROR_CREATE_REFERENCING("Resolution failed", &error, 1));
+ grpc_closure_sched(exec_ctx, r->on_done,
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
+ "Resolution failed", &error, 1));
}
gpr_free(r->addr);
@@ -461,8 +461,8 @@ static void sched_connect(grpc_exec_ctx *exec_ctx, grpc_closure *closure,
grpc_endpoint **ep, gpr_timespec deadline) {
if (gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) < 0) {
*ep = NULL;
- grpc_closure_sched(exec_ctx, closure,
- GRPC_ERROR_CREATE("Connect deadline exceeded"));
+ grpc_closure_sched(exec_ctx, closure, GRPC_ERROR_CREATE_FROM_STATIC_STRING(
+ "Connect deadline exceeded"));
return;
}
@@ -719,10 +719,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_test_only_set_slice_hash_seed(0);
if (squelch) gpr_set_log_function(dont_log);
input_stream inp = {data, data + size};
- grpc_resolve_address = my_resolve_address;
grpc_tcp_client_connect_impl = my_tcp_client_connect;
gpr_now_impl = now_impl;
grpc_init();
+ grpc_resolve_address = my_resolve_address;
GPR_ASSERT(g_channel == NULL);
GPR_ASSERT(g_server == NULL);
diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6723650944237568 b/test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6723650944237568
new file mode 100644
index 0000000000..e140fdc705
--- /dev/null
+++ b/test/core/end2end/fuzzers/api_fuzzer_corpus/clusterfuzz-testcase-6723650944237568
Binary files differ
diff --git a/test/core/end2end/goaway_server_test.c b/test/core/end2end/goaway_server_test.c
index a9634bfbae..22d93b321a 100644
--- a/test/core/end2end/goaway_server_test.c
+++ b/test/core/end2end/goaway_server_test.c
@@ -52,9 +52,11 @@ static void *tag(intptr_t i) { return (void *)i; }
static gpr_mu g_mu;
static int g_resolve_port = -1;
-static grpc_error *(*iomgr_resolve_address)(const char *name,
- const char *default_port,
- grpc_resolved_addresses **addrs);
+static void (*iomgr_resolve_address)(grpc_exec_ctx *exec_ctx, const char *addr,
+ const char *default_port,
+ grpc_pollset_set *interested_parties,
+ grpc_closure *on_done,
+ grpc_resolved_addresses **addresses);
static void set_resolve_port(int port) {
gpr_mu_lock(&g_mu);
@@ -62,16 +64,22 @@ static void set_resolve_port(int port) {
gpr_mu_unlock(&g_mu);
}
-static grpc_error *my_resolve_address(const char *name, const char *addr,
- grpc_resolved_addresses **addrs) {
- if (0 != strcmp(name, "test")) {
- return iomgr_resolve_address(name, addr, addrs);
+static void my_resolve_address(grpc_exec_ctx *exec_ctx, const char *addr,
+ const char *default_port,
+ grpc_pollset_set *interested_parties,
+ grpc_closure *on_done,
+ grpc_resolved_addresses **addrs) {
+ if (0 != strcmp(addr, "test")) {
+ iomgr_resolve_address(exec_ctx, addr, default_port, interested_parties,
+ on_done, addrs);
+ return;
}
+ grpc_error *error = GRPC_ERROR_NONE;
gpr_mu_lock(&g_mu);
if (g_resolve_port < 0) {
gpr_mu_unlock(&g_mu);
- return GRPC_ERROR_CREATE("Forced Failure");
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Failure");
} else {
*addrs = gpr_malloc(sizeof(**addrs));
(*addrs)->naddrs = 1;
@@ -83,8 +91,8 @@ static grpc_error *my_resolve_address(const char *name, const char *addr,
sa->sin_port = htons((uint16_t)g_resolve_port);
(*addrs)->addrs[0].len = sizeof(*sa);
gpr_mu_unlock(&g_mu);
- return GRPC_ERROR_NONE;
}
+ grpc_closure_sched(exec_ctx, on_done, error);
}
int main(int argc, char **argv) {
@@ -96,9 +104,9 @@ int main(int argc, char **argv) {
grpc_test_init(argc, argv);
gpr_mu_init(&g_mu);
- iomgr_resolve_address = grpc_blocking_resolve_address;
- grpc_blocking_resolve_address = my_resolve_address;
grpc_init();
+ iomgr_resolve_address = grpc_resolve_address;
+ grpc_resolve_address = my_resolve_address;
int was_cancelled1;
int was_cancelled2;
diff --git a/test/core/end2end/tests/filter_call_init_fails.c b/test/core/end2end/tests/filter_call_init_fails.c
index 65216cf19d..ebfe3b03dc 100644
--- a/test/core/end2end/tests/filter_call_init_fails.c
+++ b/test/core/end2end/tests/filter_call_init_fails.c
@@ -206,9 +206,9 @@ static void test_request(grpc_end2end_test_config config) {
static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
grpc_call_element *elem,
const grpc_call_element_args *args) {
- return grpc_error_set_int(GRPC_ERROR_CREATE("access denied"),
- GRPC_ERROR_INT_GRPC_STATUS,
- GRPC_STATUS_PERMISSION_DENIED);
+ return grpc_error_set_int(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("access denied"),
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_PERMISSION_DENIED);
}
static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
diff --git a/test/core/end2end/tests/filter_causes_close.c b/test/core/end2end/tests/filter_causes_close.c
index c968f30b3b..e6b02eaeee 100644
--- a/test/core/end2end/tests/filter_causes_close.c
+++ b/test/core/end2end/tests/filter_causes_close.c
@@ -210,7 +210,7 @@ static void recv_im_ready(grpc_exec_ctx *exec_ctx, void *arg,
call_data *calld = elem->call_data;
grpc_closure_sched(
exec_ctx, calld->recv_im_ready,
- grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING(
+ grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
"Failure that's not preventable.", &error, 1),
GRPC_ERROR_INT_GRPC_STATUS,
GRPC_STATUS_PERMISSION_DENIED));
diff --git a/test/core/http/httpcli_test.c b/test/core/http/httpcli_test.c
index f690dbaffb..d3b45c4505 100644
--- a/test/core/http/httpcli_test.c
+++ b/test/core/http/httpcli_test.c
@@ -102,7 +102,7 @@ static void test_get(int port) {
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
&worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(20))));
+ n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -144,7 +144,7 @@ static void test_post(int port) {
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
&worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(20))));
+ n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/http/httpscli_test.c b/test/core/http/httpscli_test.c
index 549411037e..acc94091f4 100644
--- a/test/core/http/httpscli_test.c
+++ b/test/core/http/httpscli_test.c
@@ -103,7 +103,7 @@ static void test_get(int port) {
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
&worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(20))));
+ n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
@@ -146,7 +146,7 @@ static void test_post(int port) {
"pollset_work",
grpc_pollset_work(&exec_ctx, grpc_polling_entity_pollset(&g_pops),
&worker, gpr_now(GPR_CLOCK_MONOTONIC),
- n_seconds_time(20))));
+ n_seconds_time(1))));
gpr_mu_unlock(g_mu);
grpc_exec_ctx_finish(&exec_ctx);
gpr_mu_lock(g_mu);
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c
index 94067a8ca4..e274796e23 100644
--- a/test/core/iomgr/endpoint_tests.c
+++ b/test/core/iomgr/endpoint_tests.c
@@ -233,11 +233,13 @@ static void read_and_write_test(grpc_endpoint_test_config config,
if (shutdown) {
gpr_log(GPR_DEBUG, "shutdown read");
- grpc_endpoint_shutdown(&exec_ctx, state.read_ep,
- GRPC_ERROR_CREATE("Test Shutdown"));
+ grpc_endpoint_shutdown(
+ &exec_ctx, state.read_ep,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
gpr_log(GPR_DEBUG, "shutdown write");
- grpc_endpoint_shutdown(&exec_ctx, state.write_ep,
- GRPC_ERROR_CREATE("Test Shutdown"));
+ grpc_endpoint_shutdown(
+ &exec_ctx, state.write_ep,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
}
grpc_exec_ctx_flush(&exec_ctx);
@@ -299,7 +301,7 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) {
grpc_schedule_on_exec_ctx));
wait_for_fail_count(&exec_ctx, &fail_count, 0);
grpc_endpoint_shutdown(&exec_ctx, f.client_ep,
- GRPC_ERROR_CREATE("Test Shutdown"));
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
wait_for_fail_count(&exec_ctx, &fail_count, 1);
grpc_endpoint_read(&exec_ctx, f.client_ep, &slice_buffer,
grpc_closure_create(inc_on_failure, &fail_count,
@@ -311,7 +313,7 @@ static void multiple_shutdown_test(grpc_endpoint_test_config config) {
grpc_schedule_on_exec_ctx));
wait_for_fail_count(&exec_ctx, &fail_count, 3);
grpc_endpoint_shutdown(&exec_ctx, f.client_ep,
- GRPC_ERROR_CREATE("Test Shutdown"));
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown"));
wait_for_fail_count(&exec_ctx, &fail_count, 3);
grpc_slice_buffer_destroy_internal(&exec_ctx, &slice_buffer);
diff --git a/test/core/iomgr/error_test.c b/test/core/iomgr/error_test.c
index 2a6b1b17fd..5c60a4ddb8 100644
--- a/test/core/iomgr/error_test.c
+++ b/test/core/iomgr/error_test.c
@@ -44,7 +44,7 @@
#include "test/core/util/test_config.h"
static void test_set_get_int() {
- grpc_error* error = GRPC_ERROR_CREATE("Test");
+ grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test");
GPR_ASSERT(error);
intptr_t i = 0;
GPR_ASSERT(grpc_error_get_int(error, GRPC_ERROR_INT_FILE_LINE, &i));
@@ -66,26 +66,27 @@ static void test_set_get_int() {
}
static void test_set_get_str() {
- grpc_error* error = GRPC_ERROR_CREATE("Test");
+ grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test");
- GPR_ASSERT(!grpc_error_get_str(error, GRPC_ERROR_STR_SYSCALL));
- GPR_ASSERT(!grpc_error_get_str(error, GRPC_ERROR_STR_TSI_ERROR));
+ grpc_slice str;
+ GPR_ASSERT(!grpc_error_get_str(error, GRPC_ERROR_STR_SYSCALL, &str));
+ GPR_ASSERT(!grpc_error_get_str(error, GRPC_ERROR_STR_TSI_ERROR, &str));
- const char* c = grpc_error_get_str(error, GRPC_ERROR_STR_FILE);
- GPR_ASSERT(c);
- GPR_ASSERT(strstr(c, "error_test.c")); // __FILE__ expands differently on
- // Windows. All should at least
- // contain error_test.c
+ GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_FILE, &str));
+ GPR_ASSERT(strstr((char*)GRPC_SLICE_START_PTR(str),
+ "error_test.c")); // __FILE__ expands differently on
+ // Windows. All should at least
+ // contain error_test.c
- c = grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION);
- GPR_ASSERT(c);
- GPR_ASSERT(!strcmp(c, "Test"));
+ GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_DESCRIPTION, &str));
+ GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "Test",
+ GRPC_SLICE_LENGTH(str)));
- error =
- grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, "longer message");
- c = grpc_error_get_str(error, GRPC_ERROR_STR_GRPC_MESSAGE);
- GPR_ASSERT(c);
- GPR_ASSERT(!strcmp(c, "longer message"));
+ error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE,
+ grpc_slice_from_static_string("longer message"));
+ GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, &str));
+ GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "longer message",
+ GRPC_SLICE_LENGTH(str)));
GRPC_ERROR_UNREF(error);
}
@@ -93,26 +94,28 @@ static void test_set_get_str() {
static void test_copy_and_unref() {
// error1 has one ref
grpc_error* error1 = grpc_error_set_str(
- GRPC_ERROR_CREATE("Test"), GRPC_ERROR_STR_GRPC_MESSAGE, "message");
- const char* c = grpc_error_get_str(error1, GRPC_ERROR_STR_GRPC_MESSAGE);
- GPR_ASSERT(c);
- GPR_ASSERT(!strcmp(c, "message"));
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test"), GRPC_ERROR_STR_GRPC_MESSAGE,
+ grpc_slice_from_static_string("message"));
+ grpc_slice str;
+ GPR_ASSERT(grpc_error_get_str(error1, GRPC_ERROR_STR_GRPC_MESSAGE, &str));
+ GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "message",
+ GRPC_SLICE_LENGTH(str)));
// error 1 has two refs
GRPC_ERROR_REF(error1);
// this gives error3 a ref to the new error, and decrements error1 to one ref
- grpc_error* error3 =
- grpc_error_set_str(error1, GRPC_ERROR_STR_SYSCALL, "syscall");
+ grpc_error* error3 = grpc_error_set_str(
+ error1, GRPC_ERROR_STR_SYSCALL, grpc_slice_from_static_string("syscall"));
GPR_ASSERT(error3 != error1); // should not be the same because of extra ref
- c = grpc_error_get_str(error3, GRPC_ERROR_STR_GRPC_MESSAGE);
- GPR_ASSERT(c);
- GPR_ASSERT(!strcmp(c, "message"));
+ GPR_ASSERT(grpc_error_get_str(error3, GRPC_ERROR_STR_GRPC_MESSAGE, &str));
+ GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "message",
+ GRPC_SLICE_LENGTH(str)));
// error 1 should not have a syscall but 3 should
- GPR_ASSERT(!grpc_error_get_str(error1, GRPC_ERROR_STR_SYSCALL));
- c = grpc_error_get_str(error3, GRPC_ERROR_STR_SYSCALL);
- GPR_ASSERT(c);
- GPR_ASSERT(!strcmp(c, "syscall"));
+ GPR_ASSERT(!grpc_error_get_str(error1, GRPC_ERROR_STR_SYSCALL, &str));
+ GPR_ASSERT(grpc_error_get_str(error3, GRPC_ERROR_STR_SYSCALL, &str));
+ GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), "syscall",
+ GRPC_SLICE_LENGTH(str)));
GRPC_ERROR_UNREF(error1);
GRPC_ERROR_UNREF(error3);
@@ -120,8 +123,10 @@ static void test_copy_and_unref() {
static void test_create_referencing() {
grpc_error* child = grpc_error_set_str(
- GRPC_ERROR_CREATE("Child"), GRPC_ERROR_STR_GRPC_MESSAGE, "message");
- grpc_error* parent = GRPC_ERROR_CREATE_REFERENCING("Parent", &child, 1);
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Child"),
+ GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message"));
+ grpc_error* parent =
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Parent", &child, 1);
GPR_ASSERT(parent);
GRPC_ERROR_UNREF(child);
@@ -130,14 +135,18 @@ static void test_create_referencing() {
static void test_create_referencing_many() {
grpc_error* children[3];
- children[0] = grpc_error_set_str(GRPC_ERROR_CREATE("Child1"),
- GRPC_ERROR_STR_GRPC_MESSAGE, "message");
- children[1] = grpc_error_set_int(GRPC_ERROR_CREATE("Child2"),
- GRPC_ERROR_INT_HTTP2_ERROR, 5);
- children[2] = grpc_error_set_str(GRPC_ERROR_CREATE("Child3"),
- GRPC_ERROR_STR_GRPC_MESSAGE, "message 3");
-
- grpc_error* parent = GRPC_ERROR_CREATE_REFERENCING("Parent", children, 3);
+ children[0] = grpc_error_set_str(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Child1"),
+ GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message"));
+ children[1] =
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Child2"),
+ GRPC_ERROR_INT_HTTP2_ERROR, 5);
+ children[2] = grpc_error_set_str(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Child3"),
+ GRPC_ERROR_STR_GRPC_MESSAGE, grpc_slice_from_static_string("message 3"));
+
+ grpc_error* parent =
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Parent", children, 3);
GPR_ASSERT(parent);
for (size_t i = 0; i < 3; ++i) {
@@ -148,10 +157,11 @@ static void test_create_referencing_many() {
static void print_error_string() {
grpc_error* error =
- grpc_error_set_int(GRPC_ERROR_CREATE("Error"), GRPC_ERROR_INT_GRPC_STATUS,
- GRPC_STATUS_UNIMPLEMENTED);
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"),
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNIMPLEMENTED);
error = grpc_error_set_int(error, GRPC_ERROR_INT_SIZE, 666);
- error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, "message");
+ error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE,
+ grpc_slice_from_static_string("message"));
// gpr_log(GPR_DEBUG, "%s", grpc_error_string(error));
GRPC_ERROR_UNREF(error);
}
@@ -159,15 +169,18 @@ static void print_error_string() {
static void print_error_string_reference() {
grpc_error* children[2];
children[0] = grpc_error_set_str(
- grpc_error_set_int(GRPC_ERROR_CREATE("1"), GRPC_ERROR_INT_GRPC_STATUS,
- GRPC_STATUS_UNIMPLEMENTED),
- GRPC_ERROR_STR_GRPC_MESSAGE, "message for child 1");
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("1"),
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNIMPLEMENTED),
+ GRPC_ERROR_STR_GRPC_MESSAGE,
+ grpc_slice_from_static_string("message for child 1"));
children[1] = grpc_error_set_str(
- grpc_error_set_int(GRPC_ERROR_CREATE("2sd"), GRPC_ERROR_INT_GRPC_STATUS,
- GRPC_STATUS_INTERNAL),
- GRPC_ERROR_STR_GRPC_MESSAGE, "message for child 2");
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("2sd"),
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_INTERNAL),
+ GRPC_ERROR_STR_GRPC_MESSAGE,
+ grpc_slice_from_static_string("message for child 2"));
- grpc_error* parent = GRPC_ERROR_CREATE_REFERENCING("Parent", children, 2);
+ grpc_error* parent =
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Parent", children, 2);
gpr_log(GPR_DEBUG, "%s", grpc_error_string(parent));
@@ -186,15 +199,17 @@ static void test_os_error() {
GPR_ASSERT(grpc_error_get_int(error, GRPC_ERROR_INT_ERRNO, &i));
GPR_ASSERT(i == fake_errno);
- const char* c = grpc_error_get_str(error, GRPC_ERROR_STR_SYSCALL);
- GPR_ASSERT(c);
- GPR_ASSERT(!strcmp(c, syscall));
+ grpc_slice str;
+ GPR_ASSERT(grpc_error_get_str(error, GRPC_ERROR_STR_SYSCALL, &str));
+ GPR_ASSERT(!strncmp((char*)GRPC_SLICE_START_PTR(str), syscall,
+ GRPC_SLICE_LENGTH(str)));
GRPC_ERROR_UNREF(error);
}
static void test_special() {
grpc_error* error = GRPC_ERROR_NONE;
- error = grpc_error_add_child(error, GRPC_ERROR_CREATE("test child"));
+ error = grpc_error_add_child(
+ error, GRPC_ERROR_CREATE_FROM_STATIC_STRING("test child"));
intptr_t i;
GPR_ASSERT(grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, &i));
GPR_ASSERT(i == GRPC_STATUS_OK);
diff --git a/test/core/iomgr/ev_epoll_linux_test.c b/test/core/iomgr/ev_epoll_linux_test.c
index 4ec959995b..d69f9a9d15 100644
--- a/test/core/iomgr/ev_epoll_linux_test.c
+++ b/test/core/iomgr/ev_epoll_linux_test.c
@@ -90,7 +90,7 @@ static void test_fd_cleanup(grpc_exec_ctx *exec_ctx, test_fd *tfds,
for (i = 0; i < num_fds; i++) {
grpc_fd_shutdown(exec_ctx, tfds[i].fd,
- GRPC_ERROR_CREATE("test_fd_cleanup"));
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_fd_cleanup"));
grpc_exec_ctx_flush(exec_ctx);
grpc_fd_orphan(exec_ctx, tfds[i].fd, NULL, &release_fd, "test_fd_cleanup");
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index c1a0ef54d3..81d2692a08 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -133,7 +133,7 @@ static void session_shutdown_cb(grpc_exec_ctx *exec_ctx, void *arg, /*session */
gpr_free(se);
/* Start to shutdown listen fd. */
grpc_fd_shutdown(exec_ctx, sv->em_fd,
- GRPC_ERROR_CREATE("session_shutdown_cb"));
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("session_shutdown_cb"));
}
/* Called when data become readable in a session. */
diff --git a/test/core/iomgr/pollset_set_test.c b/test/core/iomgr/pollset_set_test.c
index f27e9db8c9..3a9d459579 100644
--- a/test/core/iomgr/pollset_set_test.c
+++ b/test/core/iomgr/pollset_set_test.c
@@ -143,7 +143,8 @@ static void cleanup_test_fds(grpc_exec_ctx *exec_ctx, test_fd *tfds,
int release_fd;
for (int i = 0; i < num_fds; i++) {
- grpc_fd_shutdown(exec_ctx, tfds[i].fd, GRPC_ERROR_CREATE("fd cleanup"));
+ grpc_fd_shutdown(exec_ctx, tfds[i].fd,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("fd cleanup"));
grpc_exec_ctx_flush(exec_ctx);
/* grpc_fd_orphan frees the memory allocated for grpc_fd. Normally it also
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index b324b5a65e..2fae6774e8 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -77,8 +77,9 @@ static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) {
GPR_ASSERT(g_connecting != NULL);
GPR_ASSERT(error == GRPC_ERROR_NONE);
- grpc_endpoint_shutdown(exec_ctx, g_connecting,
- GRPC_ERROR_CREATE("must_succeed called"));
+ grpc_endpoint_shutdown(
+ exec_ctx, g_connecting,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called"));
grpc_endpoint_destroy(exec_ctx, g_connecting);
g_connecting = NULL;
finish_connection();
diff --git a/test/core/iomgr/tcp_client_uv_test.c b/test/core/iomgr/tcp_client_uv_test.c
index 064119f11b..92fc393422 100644
--- a/test/core/iomgr/tcp_client_uv_test.c
+++ b/test/core/iomgr/tcp_client_uv_test.c
@@ -73,8 +73,9 @@ static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg,
grpc_error *error) {
GPR_ASSERT(g_connecting != NULL);
GPR_ASSERT(error == GRPC_ERROR_NONE);
- grpc_endpoint_shutdown(exec_ctx, g_connecting,
- GRPC_ERROR_CREATE("must_succeed called"));
+ grpc_endpoint_shutdown(
+ exec_ctx, g_connecting,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("must_succeed called"));
grpc_endpoint_destroy(exec_ctx, g_connecting);
g_connecting = NULL;
finish_connection();
diff --git a/test/core/iomgr/tcp_server_posix_test.c b/test/core/iomgr/tcp_server_posix_test.c
index 6e514324a5..112743b95b 100644
--- a/test/core/iomgr/tcp_server_posix_test.c
+++ b/test/core/iomgr/tcp_server_posix_test.c
@@ -163,7 +163,8 @@ static void test_addr_init_str(test_addr *addr) {
static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
grpc_pollset *pollset,
grpc_tcp_server_acceptor *acceptor) {
- grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_CREATE("Connected"));
+ grpc_endpoint_shutdown(exec_ctx, tcp,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected"));
grpc_endpoint_destroy(exec_ctx, tcp);
on_connect_result temp_result;
@@ -285,7 +286,7 @@ static grpc_error *tcp_connect(grpc_exec_ctx *exec_ctx, const test_addr *remote,
if (g_nconnects != nconnects_before + 1) {
gpr_mu_unlock(g_mu);
close(clifd);
- return GRPC_ERROR_CREATE("Didn't connect");
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Didn't connect");
}
close(clifd);
*result = g_result;
diff --git a/test/core/iomgr/tcp_server_uv_test.c b/test/core/iomgr/tcp_server_uv_test.c
index 0fc74599ea..1e039585c1 100644
--- a/test/core/iomgr/tcp_server_uv_test.c
+++ b/test/core/iomgr/tcp_server_uv_test.c
@@ -115,7 +115,8 @@ static void server_weak_ref_set(server_weak_ref *weak_ref,
static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
grpc_pollset *pollset,
grpc_tcp_server_acceptor *acceptor) {
- grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_CREATE("Connected"));
+ grpc_endpoint_shutdown(exec_ctx, tcp,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected"));
grpc_endpoint_destroy(exec_ctx, tcp);
on_connect_result temp_result;
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index 396ec959cd..12d8406323 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -48,9 +48,12 @@
#include <grpc/support/log.h>
#include <grpc/support/sync.h>
#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "src/core/lib/channel/channel_args.h"
#include "src/core/lib/iomgr/ev_posix.h"
#include "src/core/lib/iomgr/iomgr.h"
+#include "src/core/lib/iomgr/socket_factory_posix.h"
#include "test/core/util/test_config.h"
#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", #x)
@@ -94,16 +97,59 @@ static void on_fd_orphaned(grpc_exec_ctx *exec_ctx, grpc_fd *emfd,
g_number_of_orphan_calls++;
}
+struct test_socket_factory {
+ grpc_socket_factory base;
+ int number_of_socket_calls;
+ int number_of_bind_calls;
+};
+typedef struct test_socket_factory test_socket_factory;
+
+static int test_socket_factory_socket(grpc_socket_factory *factory, int domain,
+ int type, int protocol) {
+ test_socket_factory *f = (test_socket_factory *)factory;
+ f->number_of_socket_calls++;
+ return socket(domain, type, protocol);
+}
+
+static int test_socket_factory_bind(grpc_socket_factory *factory, int sockfd,
+ const grpc_resolved_address *addr) {
+ test_socket_factory *f = (test_socket_factory *)factory;
+ f->number_of_bind_calls++;
+ return bind(sockfd, (struct sockaddr *)addr->addr, (socklen_t)addr->len);
+}
+
+static int test_socket_factory_compare(grpc_socket_factory *a,
+ grpc_socket_factory *b) {
+ return GPR_ICMP(a, b);
+}
+
+static void test_socket_factory_destroy(grpc_socket_factory *factory) {
+ test_socket_factory *f = (test_socket_factory *)factory;
+ gpr_free(f);
+}
+
+static const grpc_socket_factory_vtable test_socket_factory_vtable = {
+ test_socket_factory_socket, test_socket_factory_bind,
+ test_socket_factory_compare, test_socket_factory_destroy};
+
+static test_socket_factory *test_socket_factory_create(void) {
+ test_socket_factory *factory = gpr_malloc(sizeof(test_socket_factory));
+ grpc_socket_factory_init(&factory->base, &test_socket_factory_vtable);
+ factory->number_of_socket_calls = 0;
+ factory->number_of_bind_calls = 0;
+ return factory;
+}
+
static void test_no_op(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_udp_server *s = grpc_udp_server_create();
+ grpc_udp_server *s = grpc_udp_server_create(NULL);
grpc_udp_server_destroy(&exec_ctx, s, NULL);
grpc_exec_ctx_finish(&exec_ctx);
}
static void test_no_op_with_start(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
- grpc_udp_server *s = grpc_udp_server_create();
+ grpc_udp_server *s = grpc_udp_server_create(NULL);
LOG_TEST("test_no_op_with_start");
grpc_udp_server_start(&exec_ctx, s, NULL, 0, NULL);
grpc_udp_server_destroy(&exec_ctx, s, NULL);
@@ -115,7 +161,7 @@ static void test_no_op_with_port(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resolved_address resolved_addr;
struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
- grpc_udp_server *s = grpc_udp_server_create();
+ grpc_udp_server *s = grpc_udp_server_create(NULL);
LOG_TEST("test_no_op_with_port");
memset(&resolved_addr, 0, sizeof(resolved_addr));
@@ -131,12 +177,44 @@ static void test_no_op_with_port(void) {
GPR_ASSERT(g_number_of_orphan_calls == 1);
}
+static void test_no_op_with_port_and_socket_factory(void) {
+ g_number_of_orphan_calls = 0;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_resolved_address resolved_addr;
+ struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
+
+ test_socket_factory *socket_factory = test_socket_factory_create();
+ grpc_arg socket_factory_arg =
+ grpc_socket_factory_to_arg(&socket_factory->base);
+ grpc_channel_args *channel_args =
+ grpc_channel_args_copy_and_add(NULL, &socket_factory_arg, 1);
+ grpc_udp_server *s = grpc_udp_server_create(channel_args);
+ grpc_channel_args_destroy(&exec_ctx, channel_args);
+
+ LOG_TEST("test_no_op_with_port_and_socket_factory");
+
+ memset(&resolved_addr, 0, sizeof(resolved_addr));
+ resolved_addr.len = sizeof(struct sockaddr_in);
+ addr->sin_family = AF_INET;
+ GPR_ASSERT(grpc_udp_server_add_port(s, &resolved_addr, on_read, on_write,
+ on_fd_orphaned));
+ GPR_ASSERT(socket_factory->number_of_socket_calls == 1);
+ GPR_ASSERT(socket_factory->number_of_bind_calls == 1);
+
+ grpc_udp_server_destroy(&exec_ctx, s, NULL);
+ grpc_exec_ctx_finish(&exec_ctx);
+ grpc_socket_factory_unref(&socket_factory->base);
+
+ /* The server had a single FD, which should have been orphaned. */
+ GPR_ASSERT(g_number_of_orphan_calls == 1);
+}
+
static void test_no_op_with_port_and_start(void) {
g_number_of_orphan_calls = 0;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_resolved_address resolved_addr;
struct sockaddr_in *addr = (struct sockaddr_in *)resolved_addr.addr;
- grpc_udp_server *s = grpc_udp_server_create();
+ grpc_udp_server *s = grpc_udp_server_create(NULL);
LOG_TEST("test_no_op_with_port_and_start");
memset(&resolved_addr, 0, sizeof(resolved_addr));
@@ -160,7 +238,7 @@ static void test_receive(int number_of_clients) {
grpc_resolved_address resolved_addr;
struct sockaddr_storage *addr = (struct sockaddr_storage *)resolved_addr.addr;
int clifd, svrfd;
- grpc_udp_server *s = grpc_udp_server_create();
+ grpc_udp_server *s = grpc_udp_server_create(NULL);
int i;
int number_of_reads_before;
gpr_timespec deadline;
@@ -243,6 +321,7 @@ int main(int argc, char **argv) {
test_no_op();
test_no_op_with_start();
test_no_op_with_port();
+ test_no_op_with_port_and_socket_factory();
test_no_op_with_port_and_start();
test_receive(1);
test_receive(10);
diff --git a/test/core/memory_usage/client.c b/test/core/memory_usage/client.c
index 107abbc1b3..51ea51bc12 100644
--- a/test/core/memory_usage/client.c
+++ b/test/core/memory_usage/client.c
@@ -237,6 +237,11 @@ int main(int argc, char **argv) {
0, grpc_slice_from_static_string("Reflector/GetAfterSvrCreation"));
// warmup period
+ for (int i = 0; i < warmup_iterations; i++) {
+ send_snapshot_request(
+ 0, grpc_slice_from_static_string("Reflector/SimpleSnapshot"));
+ }
+
for (call_idx = 0; call_idx < warmup_iterations; ++call_idx) {
init_ping_pong_request(call_idx + 1);
}
diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c
index d2b76bae39..b3775e91a7 100644
--- a/test/core/security/secure_endpoint_test.c
+++ b/test/core/security/secure_endpoint_test.c
@@ -166,10 +166,12 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) {
GPR_ASSERT(incoming.count == 1);
GPR_ASSERT(grpc_slice_eq(s, incoming.slices[0]));
- grpc_endpoint_shutdown(&exec_ctx, f.client_ep,
- GRPC_ERROR_CREATE("test_leftover end"));
- grpc_endpoint_shutdown(&exec_ctx, f.server_ep,
- GRPC_ERROR_CREATE("test_leftover end"));
+ grpc_endpoint_shutdown(
+ &exec_ctx, f.client_ep,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end"));
+ grpc_endpoint_shutdown(
+ &exec_ctx, f.server_ep,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("test_leftover end"));
grpc_endpoint_destroy(&exec_ctx, f.client_ep);
grpc_endpoint_destroy(&exec_ctx, f.server_ep);
grpc_exec_ctx_finish(&exec_ctx);
diff --git a/test/core/security/ssl_server_fuzzer.c b/test/core/security/ssl_server_fuzzer.c
index 7a3612c419..cbbaf9f298 100644
--- a/test/core/security/ssl_server_fuzzer.c
+++ b/test/core/security/ssl_server_fuzzer.c
@@ -115,8 +115,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
// server will wait for more data. Explicitly fail the server by shutting down
// the endpoint.
if (!state.done_callback_called) {
- grpc_endpoint_shutdown(&exec_ctx, mock_endpoint,
- GRPC_ERROR_CREATE("Explicit close"));
+ grpc_endpoint_shutdown(
+ &exec_ctx, mock_endpoint,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Explicit close"));
grpc_exec_ctx_flush(&exec_ctx);
}
diff --git a/test/core/surface/concurrent_connectivity_test.c b/test/core/surface/concurrent_connectivity_test.c
index ff927385d4..2f7c3dfb85 100644
--- a/test/core/surface/concurrent_connectivity_test.c
+++ b/test/core/surface/concurrent_connectivity_test.c
@@ -109,7 +109,8 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *vargs, grpc_endpoint *tcp,
grpc_tcp_server_acceptor *acceptor) {
gpr_free(acceptor);
struct server_thread_args *args = (struct server_thread_args *)vargs;
- grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_CREATE("Connected"));
+ grpc_endpoint_shutdown(exec_ctx, tcp,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected"));
grpc_endpoint_destroy(exec_ctx, tcp);
GRPC_LOG_IF_ERROR("pollset_kick", grpc_pollset_kick(args->pollset, NULL));
}
diff --git a/test/core/util/mock_endpoint.c b/test/core/util/mock_endpoint.c
index b8fed7e14b..c747297984 100644
--- a/test/core/util/mock_endpoint.c
+++ b/test/core/util/mock_endpoint.c
@@ -89,8 +89,9 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
grpc_mock_endpoint *m = (grpc_mock_endpoint *)ep;
gpr_mu_lock(&m->mu);
if (m->on_read) {
- grpc_closure_sched(exec_ctx, m->on_read, GRPC_ERROR_CREATE_REFERENCING(
- "Endpoint Shutdown", &why, 1));
+ grpc_closure_sched(exec_ctx, m->on_read,
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
+ "Endpoint Shutdown", &why, 1));
m->on_read = NULL;
}
gpr_mu_unlock(&m->mu);
diff --git a/test/core/util/passthru_endpoint.c b/test/core/util/passthru_endpoint.c
index 5f27f9ae73..121567fc0d 100644
--- a/test/core/util/passthru_endpoint.c
+++ b/test/core/util/passthru_endpoint.c
@@ -75,7 +75,8 @@ static void me_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
half *m = (half *)ep;
gpr_mu_lock(&m->parent->mu);
if (m->parent->shutdown) {
- grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_CREATE("Already shutdown"));
+ grpc_closure_sched(
+ exec_ctx, cb, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Already shutdown"));
} else if (m->read_buffer.count > 0) {
grpc_slice_buffer_swap(&m->read_buffer, slices);
grpc_closure_sched(exec_ctx, cb, GRPC_ERROR_NONE);
@@ -98,7 +99,7 @@ static void me_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
grpc_error *error = GRPC_ERROR_NONE;
m->parent->stats->num_writes++;
if (m->parent->shutdown) {
- error = GRPC_ERROR_CREATE("Endpoint already shutdown");
+ error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Endpoint already shutdown");
} else if (m->on_read != NULL) {
for (size_t i = 0; i < slices->count; i++) {
grpc_slice_buffer_add(m->on_read_out, grpc_slice_ref(slices->slices[i]));
@@ -126,14 +127,16 @@ static void me_shutdown(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
gpr_mu_lock(&m->parent->mu);
m->parent->shutdown = true;
if (m->on_read) {
- grpc_closure_sched(exec_ctx, m->on_read,
- GRPC_ERROR_CREATE_REFERENCING("Shutdown", &why, 1));
+ grpc_closure_sched(
+ exec_ctx, m->on_read,
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Shutdown", &why, 1));
m->on_read = NULL;
}
m = other_half(m);
if (m->on_read) {
- grpc_closure_sched(exec_ctx, m->on_read,
- GRPC_ERROR_CREATE_REFERENCING("Shutdown", &why, 1));
+ grpc_closure_sched(
+ exec_ctx, m->on_read,
+ GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING("Shutdown", &why, 1));
m->on_read = NULL;
}
gpr_mu_unlock(&m->parent->mu);
diff --git a/test/core/util/reconnect_server.c b/test/core/util/reconnect_server.c
index 7fbd0ca6aa..90af1c107b 100644
--- a/test/core/util/reconnect_server.c
+++ b/test/core/util/reconnect_server.c
@@ -80,7 +80,8 @@ static void on_connect(grpc_exec_ctx *exec_ctx, void *arg, grpc_endpoint *tcp,
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
timestamp_list *new_tail;
peer = grpc_endpoint_get_peer(tcp);
- grpc_endpoint_shutdown(exec_ctx, tcp, GRPC_ERROR_CREATE("Connected"));
+ grpc_endpoint_shutdown(exec_ctx, tcp,
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Connected"));
grpc_endpoint_destroy(exec_ctx, tcp);
if (peer) {
last_colon = strrchr(peer, ':');
diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc
index 9bcc9f99f6..8e7b56cbd6 100644
--- a/test/cpp/common/channel_arguments_test.cc
+++ b/test/cpp/common/channel_arguments_test.cc
@@ -243,6 +243,22 @@ TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) {
channel_args_.SetUserAgentPrefix(prefix);
EXPECT_TRUE(HasArg(arg0));
+
+ // Test if the user agent string is copied correctly
+ ChannelArguments new_channel_args(channel_args_);
+ grpc_channel_args args;
+ SetChannelArgs(new_channel_args, &args);
+ bool found = false;
+ for (size_t i = 0; i < args.num_args; i++) {
+ const grpc_arg& arg = args.args[i];
+ if (arg.type == GRPC_ARG_STRING &&
+ grpc::string(arg.key) == GRPC_ARG_PRIMARY_USER_AGENT_STRING) {
+ EXPECT_FALSE(found);
+ EXPECT_EQ(0, strcmp(arg.value.string, arg0.value.string));
+ found = true;
+ }
+ }
+ EXPECT_TRUE(found);
}
} // namespace testing
diff --git a/test/cpp/microbenchmarks/bm_call_create.cc b/test/cpp/microbenchmarks/bm_call_create.cc
index b34d0d1e12..4af2263e82 100644
--- a/test/cpp/microbenchmarks/bm_call_create.cc
+++ b/test/cpp/microbenchmarks/bm_call_create.cc
@@ -54,6 +54,7 @@ extern "C" {
#include "src/core/lib/channel/http_client_filter.h"
#include "src/core/lib/channel/http_server_filter.h"
#include "src/core/lib/channel/message_size_filter.h"
+#include "src/core/lib/surface/channel.h"
#include "src/core/lib/transport/transport_impl.h"
}
@@ -85,6 +86,9 @@ BENCHMARK(BM_Zalloc)
->Arg(6144)
->Arg(7168);
+////////////////////////////////////////////////////////////////////////////////
+// Benchmarks creating full stacks
+
class BaseChannelFixture {
public:
BaseChannelFixture(grpc_channel *channel) : channel_(channel) {}
@@ -130,6 +134,9 @@ static void BM_CallCreateDestroy(benchmark::State &state) {
BENCHMARK_TEMPLATE(BM_CallCreateDestroy, InsecureChannel);
BENCHMARK_TEMPLATE(BM_CallCreateDestroy, LameChannel);
+////////////////////////////////////////////////////////////////////////////////
+// Benchmarks isolating individual filters
+
static void *tag(int i) {
return reinterpret_cast<void *>(static_cast<intptr_t>(i));
}
@@ -474,4 +481,205 @@ typedef Fixture<&grpc_load_reporting_filter, CHECKS_NOT_LAST>
BENCHMARK_TEMPLATE(BM_IsolatedFilter, LoadReportingFilter, NoOp);
BENCHMARK_TEMPLATE(BM_IsolatedFilter, LoadReportingFilter, SendEmptyMetadata);
+////////////////////////////////////////////////////////////////////////////////
+// Benchmarks isolating grpc_call
+
+namespace isolated_call_filter {
+
+static void StartTransportStreamOp(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ grpc_transport_stream_op *op) {
+ if (op->recv_initial_metadata) {
+ grpc_closure_sched(exec_ctx, op->recv_initial_metadata_ready,
+ GRPC_ERROR_NONE);
+ }
+ if (op->recv_message) {
+ grpc_closure_sched(exec_ctx, op->recv_message_ready, GRPC_ERROR_NONE);
+ }
+ grpc_closure_sched(exec_ctx, op->on_complete, GRPC_ERROR_NONE);
+}
+
+static void StartTransportOp(grpc_exec_ctx *exec_ctx,
+ grpc_channel_element *elem,
+ grpc_transport_op *op) {
+ if (op->disconnect_with_error != GRPC_ERROR_NONE) {
+ GRPC_ERROR_UNREF(op->disconnect_with_error);
+ }
+ grpc_closure_sched(exec_ctx, op->on_consumed, GRPC_ERROR_NONE);
+}
+
+static grpc_error *InitCallElem(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ const grpc_call_element_args *args) {
+ return GRPC_ERROR_NONE;
+}
+
+static void SetPollsetOrPollsetSet(grpc_exec_ctx *exec_ctx,
+ grpc_call_element *elem,
+ grpc_polling_entity *pollent) {}
+
+static void DestroyCallElem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
+ const grpc_call_final_info *final_info,
+ grpc_closure *then_sched_closure) {
+ grpc_closure_sched(exec_ctx, then_sched_closure, GRPC_ERROR_NONE);
+}
+
+grpc_error *InitChannelElem(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem,
+ grpc_channel_element_args *args) {
+ return GRPC_ERROR_NONE;
+}
+
+void DestroyChannelElem(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem) {}
+
+char *GetPeer(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) {
+ return gpr_strdup("peer");
+}
+
+void GetChannelInfo(grpc_exec_ctx *exec_ctx, grpc_channel_element *elem,
+ const grpc_channel_info *channel_info) {}
+
+static const grpc_channel_filter isolated_call_filter = {
+ StartTransportStreamOp,
+ StartTransportOp,
+ 0,
+ InitCallElem,
+ SetPollsetOrPollsetSet,
+ DestroyCallElem,
+ 0,
+ InitChannelElem,
+ DestroyChannelElem,
+ GetPeer,
+ GetChannelInfo,
+ "isolated_call_filter"};
+}
+
+class IsolatedCallFixture : public TrackCounters {
+ public:
+ IsolatedCallFixture() {
+ grpc_channel_stack_builder *builder = grpc_channel_stack_builder_create();
+ grpc_channel_stack_builder_set_name(builder, "dummy");
+ grpc_channel_stack_builder_set_target(builder, "dummy_target");
+ GPR_ASSERT(grpc_channel_stack_builder_append_filter(
+ builder, &isolated_call_filter::isolated_call_filter, NULL, NULL));
+ {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ channel_ = grpc_channel_create_with_builder(&exec_ctx, builder,
+ GRPC_CLIENT_CHANNEL);
+ grpc_exec_ctx_finish(&exec_ctx);
+ }
+ cq_ = grpc_completion_queue_create(NULL);
+ }
+
+ void Finish(benchmark::State &state) {
+ grpc_completion_queue_destroy(cq_);
+ grpc_channel_destroy(channel_);
+ TrackCounters::Finish(state);
+ }
+
+ grpc_channel *channel() const { return channel_; }
+ grpc_completion_queue *cq() const { return cq_; }
+
+ private:
+ grpc_completion_queue *cq_;
+ grpc_channel *channel_;
+};
+
+static void BM_IsolatedCall_NoOp(benchmark::State &state) {
+ IsolatedCallFixture fixture;
+ gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ void *method_hdl =
+ grpc_channel_register_call(fixture.channel(), "/foo/bar", NULL, NULL);
+ while (state.KeepRunning()) {
+ grpc_call_destroy(grpc_channel_create_registered_call(
+ fixture.channel(), nullptr, GRPC_PROPAGATE_DEFAULTS, fixture.cq(),
+ method_hdl, deadline, NULL));
+ }
+ fixture.Finish(state);
+}
+BENCHMARK(BM_IsolatedCall_NoOp);
+
+static void BM_IsolatedCall_Unary(benchmark::State &state) {
+ IsolatedCallFixture fixture;
+ gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ void *method_hdl =
+ grpc_channel_register_call(fixture.channel(), "/foo/bar", NULL, NULL);
+ grpc_slice slice = grpc_slice_from_static_string("hello world");
+ grpc_byte_buffer *send_message = grpc_raw_byte_buffer_create(&slice, 1);
+ grpc_byte_buffer *recv_message = NULL;
+ grpc_status_code status_code;
+ grpc_slice status_details = grpc_empty_slice();
+ grpc_metadata_array recv_initial_metadata;
+ grpc_metadata_array_init(&recv_initial_metadata);
+ grpc_metadata_array recv_trailing_metadata;
+ grpc_metadata_array_init(&recv_trailing_metadata);
+ grpc_op ops[6];
+ memset(ops, 0, sizeof(ops));
+ ops[0].op = GRPC_OP_SEND_INITIAL_METADATA;
+ ops[1].op = GRPC_OP_SEND_MESSAGE;
+ ops[1].data.send_message.send_message = send_message;
+ ops[2].op = GRPC_OP_SEND_CLOSE_FROM_CLIENT;
+ ops[3].op = GRPC_OP_RECV_INITIAL_METADATA;
+ ops[3].data.recv_initial_metadata.recv_initial_metadata =
+ &recv_initial_metadata;
+ ops[4].op = GRPC_OP_RECV_MESSAGE;
+ ops[4].data.recv_message.recv_message = &recv_message;
+ ops[5].op = GRPC_OP_RECV_STATUS_ON_CLIENT;
+ ops[5].data.recv_status_on_client.status = &status_code;
+ ops[5].data.recv_status_on_client.status_details = &status_details;
+ ops[5].data.recv_status_on_client.trailing_metadata = &recv_trailing_metadata;
+ while (state.KeepRunning()) {
+ grpc_call *call = grpc_channel_create_registered_call(
+ fixture.channel(), nullptr, GRPC_PROPAGATE_DEFAULTS, fixture.cq(),
+ method_hdl, deadline, NULL);
+ grpc_call_start_batch(call, ops, 6, tag(1), NULL);
+ grpc_completion_queue_next(fixture.cq(),
+ gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL);
+ grpc_call_destroy(call);
+ }
+ fixture.Finish(state);
+ grpc_metadata_array_destroy(&recv_initial_metadata);
+ grpc_metadata_array_destroy(&recv_trailing_metadata);
+ grpc_byte_buffer_destroy(send_message);
+}
+BENCHMARK(BM_IsolatedCall_Unary);
+
+static void BM_IsolatedCall_StreamingSend(benchmark::State &state) {
+ IsolatedCallFixture fixture;
+ gpr_timespec deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
+ void *method_hdl =
+ grpc_channel_register_call(fixture.channel(), "/foo/bar", NULL, NULL);
+ grpc_slice slice = grpc_slice_from_static_string("hello world");
+ grpc_byte_buffer *send_message = grpc_raw_byte_buffer_create(&slice, 1);
+ grpc_metadata_array recv_initial_metadata;
+ grpc_metadata_array_init(&recv_initial_metadata);
+ grpc_metadata_array recv_trailing_metadata;
+ grpc_metadata_array_init(&recv_trailing_metadata);
+ grpc_op ops[2];
+ memset(ops, 0, sizeof(ops));
+ ops[0].op = GRPC_OP_SEND_INITIAL_METADATA;
+ ops[1].op = GRPC_OP_RECV_INITIAL_METADATA;
+ ops[1].data.recv_initial_metadata.recv_initial_metadata =
+ &recv_initial_metadata;
+ grpc_call *call = grpc_channel_create_registered_call(
+ fixture.channel(), nullptr, GRPC_PROPAGATE_DEFAULTS, fixture.cq(),
+ method_hdl, deadline, NULL);
+ grpc_call_start_batch(call, ops, 2, tag(1), NULL);
+ grpc_completion_queue_next(fixture.cq(), gpr_inf_future(GPR_CLOCK_MONOTONIC),
+ NULL);
+ memset(ops, 0, sizeof(ops));
+ ops[0].op = GRPC_OP_SEND_MESSAGE;
+ ops[0].data.send_message.send_message = send_message;
+ while (state.KeepRunning()) {
+ grpc_call_start_batch(call, ops, 1, tag(2), NULL);
+ grpc_completion_queue_next(fixture.cq(),
+ gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL);
+ }
+ grpc_call_destroy(call);
+ fixture.Finish(state);
+ grpc_metadata_array_destroy(&recv_initial_metadata);
+ grpc_metadata_array_destroy(&recv_trailing_metadata);
+ grpc_byte_buffer_destroy(send_message);
+}
+BENCHMARK(BM_IsolatedCall_StreamingSend);
+
BENCHMARK_MAIN();
diff --git a/test/cpp/microbenchmarks/bm_error.cc b/test/cpp/microbenchmarks/bm_error.cc
index cf7b887728..ea9777bbe6 100644
--- a/test/cpp/microbenchmarks/bm_error.cc
+++ b/test/cpp/microbenchmarks/bm_error.cc
@@ -51,21 +51,30 @@ class ErrorDeleter {
};
typedef std::unique_ptr<grpc_error, ErrorDeleter> ErrorPtr;
-static void BM_ErrorCreate(benchmark::State& state) {
+static void BM_ErrorCreateFromStatic(benchmark::State& state) {
TrackCounters track_counters;
while (state.KeepRunning()) {
- GRPC_ERROR_UNREF(GRPC_ERROR_CREATE("Error"));
+ GRPC_ERROR_UNREF(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"));
}
track_counters.Finish(state);
}
-BENCHMARK(BM_ErrorCreate);
+BENCHMARK(BM_ErrorCreateFromStatic);
+
+static void BM_ErrorCreateFromCopied(benchmark::State& state) {
+ TrackCounters track_counters;
+ while (state.KeepRunning()) {
+ GRPC_ERROR_UNREF(GRPC_ERROR_CREATE_FROM_COPIED_STRING("Error not inline"));
+ }
+ track_counters.Finish(state);
+}
+BENCHMARK(BM_ErrorCreateFromCopied);
static void BM_ErrorCreateAndSetStatus(benchmark::State& state) {
TrackCounters track_counters;
while (state.KeepRunning()) {
- GRPC_ERROR_UNREF(grpc_error_set_int(GRPC_ERROR_CREATE("Error"),
- GRPC_ERROR_INT_GRPC_STATUS,
- GRPC_STATUS_ABORTED));
+ GRPC_ERROR_UNREF(
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"),
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_ABORTED));
}
track_counters.Finish(state);
}
@@ -75,9 +84,10 @@ static void BM_ErrorCreateAndSetIntAndStr(benchmark::State& state) {
TrackCounters track_counters;
while (state.KeepRunning()) {
GRPC_ERROR_UNREF(grpc_error_set_str(
- grpc_error_set_int(GRPC_ERROR_CREATE("GOAWAY received"),
- GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)0),
- GRPC_ERROR_STR_RAW_BYTES, "raw bytes"));
+ grpc_error_set_int(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("GOAWAY received"),
+ GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)0),
+ GRPC_ERROR_STR_RAW_BYTES, grpc_slice_from_static_string("raw bytes")));
}
track_counters.Finish(state);
}
@@ -85,7 +95,7 @@ BENCHMARK(BM_ErrorCreateAndSetIntAndStr);
static void BM_ErrorCreateAndSetIntLoop(benchmark::State& state) {
TrackCounters track_counters;
- grpc_error* error = GRPC_ERROR_CREATE("Error");
+ grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error");
int n = 0;
while (state.KeepRunning()) {
error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, n++);
@@ -97,10 +107,11 @@ BENCHMARK(BM_ErrorCreateAndSetIntLoop);
static void BM_ErrorCreateAndSetStrLoop(benchmark::State& state) {
TrackCounters track_counters;
- grpc_error* error = GRPC_ERROR_CREATE("Error");
+ grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error");
const char* str = "hello";
while (state.KeepRunning()) {
- error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, str);
+ error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE,
+ grpc_slice_from_static_string(str));
}
GRPC_ERROR_UNREF(error);
track_counters.Finish(state);
@@ -109,7 +120,7 @@ BENCHMARK(BM_ErrorCreateAndSetStrLoop);
static void BM_ErrorRefUnref(benchmark::State& state) {
TrackCounters track_counters;
- grpc_error* error = GRPC_ERROR_CREATE("Error");
+ grpc_error* error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error");
while (state.KeepRunning()) {
GRPC_ERROR_UNREF(GRPC_ERROR_REF(error));
}
@@ -138,8 +149,8 @@ BENCHMARK(BM_ErrorGetIntFromNoError);
static void BM_ErrorGetMissingInt(benchmark::State& state) {
TrackCounters track_counters;
- ErrorPtr error(
- grpc_error_set_int(GRPC_ERROR_CREATE("Error"), GRPC_ERROR_INT_INDEX, 1));
+ ErrorPtr error(grpc_error_set_int(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_ERROR_INT_INDEX, 1));
while (state.KeepRunning()) {
intptr_t value;
grpc_error_get_int(error.get(), GRPC_ERROR_INT_OFFSET, &value);
@@ -150,8 +161,8 @@ BENCHMARK(BM_ErrorGetMissingInt);
static void BM_ErrorGetPresentInt(benchmark::State& state) {
TrackCounters track_counters;
- ErrorPtr error(
- grpc_error_set_int(GRPC_ERROR_CREATE("Error"), GRPC_ERROR_INT_OFFSET, 1));
+ ErrorPtr error(grpc_error_set_int(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_ERROR_INT_OFFSET, 1));
while (state.KeepRunning()) {
intptr_t value;
grpc_error_get_int(error.get(), GRPC_ERROR_INT_OFFSET, &value);
@@ -186,7 +197,7 @@ class SimpleError {
private:
const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
- ErrorPtr error_{GRPC_ERROR_CREATE("Error")};
+ ErrorPtr error_{GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error")};
};
class ErrorWithGrpcStatus {
@@ -196,9 +207,9 @@ class ErrorWithGrpcStatus {
private:
const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
- ErrorPtr error_{grpc_error_set_int(GRPC_ERROR_CREATE("Error"),
- GRPC_ERROR_INT_GRPC_STATUS,
- GRPC_STATUS_UNIMPLEMENTED)};
+ ErrorPtr error_{grpc_error_set_int(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_ERROR_INT_GRPC_STATUS,
+ GRPC_STATUS_UNIMPLEMENTED)};
};
class ErrorWithHttpError {
@@ -208,9 +219,9 @@ class ErrorWithHttpError {
private:
const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
- ErrorPtr error_{grpc_error_set_int(GRPC_ERROR_CREATE("Error"),
- GRPC_ERROR_INT_HTTP2_ERROR,
- GRPC_HTTP2_COMPRESSION_ERROR)};
+ ErrorPtr error_{grpc_error_set_int(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_ERROR_INT_HTTP2_ERROR,
+ GRPC_HTTP2_COMPRESSION_ERROR)};
};
class ErrorWithNestedGrpcStatus {
@@ -220,11 +231,12 @@ class ErrorWithNestedGrpcStatus {
private:
const gpr_timespec deadline_ = gpr_inf_future(GPR_CLOCK_MONOTONIC);
- ErrorPtr nested_error_{grpc_error_set_int(GRPC_ERROR_CREATE("Error"),
- GRPC_ERROR_INT_GRPC_STATUS,
- GRPC_STATUS_UNIMPLEMENTED)};
+ ErrorPtr nested_error_{grpc_error_set_int(
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Error"), GRPC_ERROR_INT_GRPC_STATUS,
+ GRPC_STATUS_UNIMPLEMENTED)};
grpc_error* nested_errors_[1] = {nested_error_.get()};
- ErrorPtr error_{GRPC_ERROR_CREATE_REFERENCING("Error", nested_errors_, 1)};
+ ErrorPtr error_{GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
+ "Error", nested_errors_, 1)};
};
template <class Fixture>
@@ -253,8 +265,8 @@ static void BM_ErrorGetStatus(benchmark::State& state) {
Fixture fixture;
while (state.KeepRunning()) {
grpc_status_code status;
- const char* msg;
- grpc_error_get_status(fixture.error(), fixture.deadline(), &status, &msg,
+ grpc_slice slice;
+ grpc_error_get_status(fixture.error(), fixture.deadline(), &status, &slice,
NULL);
}
track_counters.Finish(state);
diff --git a/test/http2_test/http2_base_server.py b/test/http2_test/http2_base_server.py
index 8de028ceb1..e158e9b703 100644
--- a/test/http2_test/http2_base_server.py
+++ b/test/http2_test/http2_base_server.py
@@ -39,6 +39,7 @@ import twisted.internet.protocol
_READ_CHUNK_SIZE = 16384
_GRPC_HEADER_SIZE = 5
+_MIN_SETTINGS_MAX_FRAME_SIZE = 16384
class H2ProtocolBaseServer(twisted.internet.protocol.Protocol):
def __init__(self):
@@ -121,38 +122,46 @@ class H2ProtocolBaseServer(twisted.internet.protocol.Protocol):
)
self.transport.write(self._conn.data_to_send())
- def on_window_update_default(self, event):
- # send pending data, if any
- self.default_send(event.stream_id)
+ def on_window_update_default(self, _, pad_length=None, read_chunk_size=_READ_CHUNK_SIZE):
+ # try to resume sending on all active streams (update might be for connection)
+ for stream_id in self._send_remaining:
+ self.default_send(stream_id, pad_length=pad_length, read_chunk_size=read_chunk_size)
def send_reset_stream(self):
self._conn.reset_stream(self._stream_id)
self.transport.write(self._conn.data_to_send())
- def setup_send(self, data_to_send, stream_id):
+ def setup_send(self, data_to_send, stream_id, pad_length=None, read_chunk_size=_READ_CHUNK_SIZE):
logging.info('Setting up data to send for stream_id: %d' % stream_id)
self._send_remaining[stream_id] = len(data_to_send)
self._send_offset = 0
self._data_to_send = data_to_send
- self.default_send(stream_id)
+ self.default_send(stream_id, pad_length=pad_length, read_chunk_size=read_chunk_size)
- def default_send(self, stream_id):
+ def default_send(self, stream_id, pad_length=None, read_chunk_size=_READ_CHUNK_SIZE):
if not self._send_remaining.has_key(stream_id):
# not setup to send data yet
return
while self._send_remaining[stream_id] > 0:
lfcw = self._conn.local_flow_control_window(stream_id)
- if lfcw == 0:
+ padding_bytes = pad_length + 1 if pad_length is not None else 0
+ if lfcw - padding_bytes <= 0:
+ logging.info('Stream %d. lfcw: %d. padding bytes: %d. not enough quota yet' % (stream_id, lfcw, padding_bytes))
break
- chunk_size = min(lfcw, _READ_CHUNK_SIZE)
+ chunk_size = min(lfcw - padding_bytes, read_chunk_size)
bytes_to_send = min(chunk_size, self._send_remaining[stream_id])
- logging.info('flow_control_window = %d. sending [%d:%d] stream_id %d' %
- (lfcw, self._send_offset, self._send_offset + bytes_to_send,
- stream_id))
+ logging.info('flow_control_window = %d. sending [%d:%d] stream_id %d. includes %d total padding bytes' %
+ (lfcw, self._send_offset, self._send_offset + bytes_to_send + padding_bytes,
+ stream_id, padding_bytes))
+ # The receiver might allow sending frames larger than the http2 minimum
+ # max frame size (16384), but this test should never send more than 16384
+ # for simplicity (which is always legal).
+ if bytes_to_send + padding_bytes > _MIN_SETTINGS_MAX_FRAME_SIZE:
+ raise ValueError("overload: sending %d" % (bytes_to_send + padding_bytes))
data = self._data_to_send[self._send_offset : self._send_offset + bytes_to_send]
try:
- self._conn.send_data(stream_id, data, False)
+ self._conn.send_data(stream_id, data, end_stream=False, pad_length=pad_length)
except h2.exceptions.ProtocolError:
logging.info('Stream %d is closed' % stream_id)
break
@@ -200,5 +209,5 @@ class H2ProtocolBaseServer(twisted.internet.protocol.Protocol):
req_proto_str = recv_buffer[5:5+grpc_msg_size]
sr = messages_pb2.SimpleRequest()
sr.ParseFromString(req_proto_str)
- logging.info('Parsed request for stream %d: response_size=%s' % (stream_id, sr.response_size))
+ logging.info('Parsed simple request for stream %d' % stream_id)
return sr
diff --git a/test/http2_test/http2_test_server.py b/test/http2_test/http2_test_server.py
index 46c3e00d18..6a7849b94a 100644
--- a/test/http2_test/http2_test_server.py
+++ b/test/http2_test/http2_test_server.py
@@ -44,6 +44,7 @@ import test_ping
import test_rst_after_data
import test_rst_after_header
import test_rst_during_data
+import test_data_frame_padding
_TEST_CASE_MAPPING = {
'rst_after_header': test_rst_after_header.TestcaseRstStreamAfterHeader,
@@ -52,6 +53,10 @@ _TEST_CASE_MAPPING = {
'goaway': test_goaway.TestcaseGoaway,
'ping': test_ping.TestcasePing,
'max_streams': test_max_streams.TestcaseSettingsMaxStreams,
+
+ # Positive tests below:
+ 'data_frame_padding': test_data_frame_padding.TestDataFramePadding,
+ 'no_df_padding_sanity_test': test_data_frame_padding.TestDataFramePadding,
}
_exit_code = 0
@@ -73,6 +78,8 @@ class H2Factory(twisted.internet.protocol.Factory):
if self._testcase == 'goaway':
return t(self._num_streams).get_base_server()
+ elif self._testcase == 'no_df_padding_sanity_test':
+ return t(use_padding=False).get_base_server()
else:
return t().get_base_server()
@@ -81,7 +88,8 @@ def parse_arguments():
parser.add_argument('--base_port', type=int, default=8080,
help='base port to run the servers (default: 8080). One test server is '
'started on each incrementing port, beginning with base_port, in the '
- 'following order: goaway,max_streams,ping,rst_after_data,rst_after_header,'
+ 'following order: data_frame_padding,goaway,max_streams,'
+ 'no_df_padding_sanity_test,ping,rst_after_data,rst_after_header,'
'rst_during_data'
)
return parser.parse_args()
diff --git a/test/http2_test/test_data_frame_padding.py b/test/http2_test/test_data_frame_padding.py
new file mode 100644
index 0000000000..e1db28faed
--- /dev/null
+++ b/test/http2_test/test_data_frame_padding.py
@@ -0,0 +1,94 @@
+# 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.
+
+import http2_base_server
+import logging
+import messages_pb2
+
+# Set the number of padding bytes per data frame to be very large
+# relative to the number of data bytes for each data frame sent.
+_LARGE_PADDING_LENGTH = 255
+_SMALL_READ_CHUNK_SIZE = 5
+
+class TestDataFramePadding(object):
+ """
+ In response to an incoming request, this test sends headers, followed by
+ data, followed by a reset stream frame. Client asserts that the RPC failed.
+ Client needs to deliver the complete message to the application layer.
+ """
+ def __init__(self, use_padding=True):
+ self._base_server = http2_base_server.H2ProtocolBaseServer()
+ self._base_server._handlers['DataReceived'] = self.on_data_received
+ self._base_server._handlers['WindowUpdated'] = self.on_window_update
+ self._base_server._handlers['RequestReceived'] = self.on_request_received
+
+ # _total_updates maps stream ids to total flow control updates received
+ self._total_updates = {}
+ # zero window updates so far for connection window (stream id '0')
+ self._total_updates[0] = 0
+ self._read_chunk_size = _SMALL_READ_CHUNK_SIZE
+
+ if use_padding:
+ self._pad_length = _LARGE_PADDING_LENGTH
+ else:
+ self._pad_length = None
+
+ def get_base_server(self):
+ return self._base_server
+
+ def on_data_received(self, event):
+ logging.info('on data received. Stream id: %d. Data length: %d' % (event.stream_id, len(event.data)))
+ self._base_server.on_data_received_default(event)
+ if len(event.data) == 0:
+ return
+ sr = self._base_server.parse_received_data(event.stream_id)
+ stream_bytes = ''
+ # Check if full grpc msg has been read into the recv buffer yet
+ if sr:
+ response_data = self._base_server.default_response_data(sr.response_size)
+ logging.info('Stream id: %d. total resp size: %d' % (event.stream_id, len(response_data)))
+ # Begin sending the response. Add ``self._pad_length`` padding to each
+ # data frame and split the whole message into data frames each carrying
+ # only self._read_chunk_size of data.
+ # The purpose is to have the majority of the data frame response bytes
+ # be padding bytes, since ``self._pad_length`` >> ``self._read_chunk_size``.
+ self._base_server.setup_send(response_data , event.stream_id, pad_length=self._pad_length, read_chunk_size=self._read_chunk_size)
+
+ def on_request_received(self, event):
+ self._base_server.on_request_received_default(event)
+ logging.info('on request received. Stream id: %s.' % event.stream_id)
+ self._total_updates[event.stream_id] = 0
+
+ # Log debug info and try to resume sending on all currently active streams.
+ def on_window_update(self, event):
+ logging.info('on window update. Stream id: %s. Delta: %s' % (event.stream_id, event.delta))
+ self._total_updates[event.stream_id] += event.delta
+ total = self._total_updates[event.stream_id]
+ logging.info('... - total updates for stream %d : %d' % (event.stream_id, total))
+ self._base_server.on_window_update_default(event, pad_length=self._pad_length, read_chunk_size=self._read_chunk_size)