aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2015-09-15 15:20:26 -0700
committerGravatar Julien Boeuf <jboeuf@google.com>2015-09-15 15:20:26 -0700
commitfd2f7331fa97f735879a8759ac9fc8591969011b (patch)
treeda031f982ee5d1d21fd71e6c4bc9d80365c7d6e2 /test/core
parent1928d496a237c3850365e2557ae41ae73125fc80 (diff)
parent9ed4be48955e3b65b0540f70060b7191d8c1eef1 (diff)
Merge branch 'master' of github.com:grpc/grpc into core_creds_plugin
Diffstat (limited to 'test/core')
-rw-r--r--test/core/bad_client/bad_client.c19
-rwxr-xr-xtest/core/bad_client/gen_build_yaml.py (renamed from test/core/bad_client/gen_build_json.py)7
-rw-r--r--test/core/channel/channel_args_test.c11
-rw-r--r--test/core/client_config/uri_parser_test.c37
-rw-r--r--test/core/compression/message_compress_test.c2
-rw-r--r--test/core/end2end/dualstack_socket_test.c33
-rw-r--r--test/core/end2end/fixtures/h2_compress.c (renamed from test/core/end2end/fixtures/chttp2_fullstack_compression.c)0
-rw-r--r--test/core/end2end/fixtures/h2_fakesec.c (renamed from test/core/end2end/fixtures/chttp2_fake_security.c)0
-rw-r--r--test/core/end2end/fixtures/h2_full+poll.c (renamed from test/core/end2end/fixtures/chttp2_fullstack_with_poll.c)0
-rw-r--r--test/core/end2end/fixtures/h2_full.c (renamed from test/core/end2end/fixtures/chttp2_fullstack.c)0
-rw-r--r--test/core/end2end/fixtures/h2_oauth2.c (renamed from test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c)0
-rw-r--r--test/core/end2end/fixtures/h2_proxy.c (renamed from test/core/end2end/fixtures/chttp2_fullstack_with_proxy.c)0
-rw-r--r--test/core/end2end/fixtures/h2_sockpair+trace.c (renamed from test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c)0
-rw-r--r--test/core/end2end/fixtures/h2_sockpair.c (renamed from test/core/end2end/fixtures/chttp2_socket_pair.c)0
-rw-r--r--test/core/end2end/fixtures/h2_sockpair_1byte.c (renamed from test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c)0
-rw-r--r--test/core/end2end/fixtures/h2_ssl+poll.c (renamed from test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c)0
-rw-r--r--test/core/end2end/fixtures/h2_ssl.c (renamed from test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c)0
-rw-r--r--test/core/end2end/fixtures/h2_ssl_proxy.c (renamed from test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c)0
-rw-r--r--test/core/end2end/fixtures/h2_uds+poll.c (renamed from test/core/end2end/fixtures/chttp2_fullstack_uds_posix_with_poll.c)0
-rw-r--r--test/core/end2end/fixtures/h2_uds.c (renamed from test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c)0
-rwxr-xr-xtest/core/end2end/gen_build_yaml.py (renamed from test/core/end2end/gen_build_json.py)75
-rw-r--r--test/core/end2end/no_server_test.c4
-rw-r--r--test/core/end2end/tests/bad_hostname.c2
-rw-r--r--test/core/end2end/tests/binary_metadata.c (renamed from test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c)6
-rw-r--r--test/core/end2end/tests/call_creds.c (renamed from test/core/end2end/tests/request_response_with_payload_and_call_creds.c)8
-rw-r--r--test/core/end2end/tests/cancel_after_accept.c4
-rw-r--r--test/core/end2end/tests/cancel_after_client_done.c (renamed from test/core/end2end/tests/cancel_after_accept_and_writes_closed.c)4
-rw-r--r--test/core/end2end/tests/cancel_after_invoke.c2
-rw-r--r--test/core/end2end/tests/cancel_before_invoke.c4
-rw-r--r--test/core/end2end/tests/census_simple_request.c4
-rw-r--r--test/core/end2end/tests/compressed_payload.c (renamed from test/core/end2end/tests/request_with_compressed_payload.c)6
-rw-r--r--test/core/end2end/tests/default_host.c4
-rw-r--r--test/core/end2end/tests/disappearing_server.c4
-rw-r--r--test/core/end2end/tests/graceful_server_shutdown.c4
-rw-r--r--test/core/end2end/tests/high_initial_seqno.c (renamed from test/core/end2end/tests/simple_request_with_high_initial_sequence_number.c)4
-rw-r--r--test/core/end2end/tests/invoke_large_request.c6
-rw-r--r--test/core/end2end/tests/large_metadata.c (renamed from test/core/end2end/tests/request_with_large_metadata.c)8
-rw-r--r--test/core/end2end/tests/max_concurrent_streams.c16
-rw-r--r--test/core/end2end/tests/max_message_length.c4
-rw-r--r--test/core/end2end/tests/metadata.c (renamed from test/core/end2end/tests/request_response_with_metadata_and_payload.c)6
-rw-r--r--test/core/end2end/tests/payload.c (renamed from test/core/end2end/tests/request_response_with_payload.c)6
-rw-r--r--test/core/end2end/tests/ping_pong_streaming.c14
-rw-r--r--test/core/end2end/tests/registered_call.c4
-rw-r--r--test/core/end2end/tests/request_with_flags.c2
-rw-r--r--test/core/end2end/tests/request_with_payload.c6
-rw-r--r--test/core/end2end/tests/server_finishes_request.c4
-rw-r--r--test/core/end2end/tests/shutdown_finishes_calls.c (renamed from test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c)4
-rw-r--r--test/core/end2end/tests/shutdown_finishes_tags.c (renamed from test/core/end2end/tests/early_server_shutdown_finishes_tags.c)0
-rw-r--r--test/core/end2end/tests/simple_delayed_request.c4
-rw-r--r--test/core/end2end/tests/simple_request.c4
-rw-r--r--test/core/end2end/tests/trailing_metadata.c (renamed from test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c)6
-rw-r--r--test/core/fling/client.c9
-rw-r--r--test/core/fling/fling_stream_test.c4
-rw-r--r--test/core/fling/fling_test.c2
-rw-r--r--test/core/fling/server.c4
-rw-r--r--test/core/httpcli/httpcli_test.c2
-rw-r--r--test/core/iomgr/alarm_heap_test.c65
-rw-r--r--test/core/iomgr/endpoint_pair_test.c77
-rw-r--r--test/core/iomgr/endpoint_tests.c269
-rw-r--r--test/core/iomgr/fd_posix_test.c5
-rw-r--r--test/core/iomgr/tcp_posix_test.c188
-rw-r--r--test/core/iomgr/udp_server_test.c14
-rw-r--r--test/core/json/json_rewrite.c32
-rw-r--r--test/core/json/json_rewrite_test.c31
-rw-r--r--test/core/profiling/timers_test.c16
-rw-r--r--test/core/security/base64_test.c4
-rw-r--r--test/core/security/json_token_test.c11
-rw-r--r--test/core/security/secure_endpoint_test.c60
-rw-r--r--test/core/support/murmur_hash_test.c6
-rw-r--r--test/core/support/slice_test.c16
-rw-r--r--test/core/support/stack_lockfree_test.c19
-rw-r--r--test/core/support/time_test.c18
-rw-r--r--test/core/surface/byte_buffer_reader_test.c8
-rw-r--r--test/core/surface/completion_queue_test.c12
-rw-r--r--test/core/surface/lame_client_test.c2
-rw-r--r--test/core/transport/chttp2/hpack_table_test.c4
-rw-r--r--test/core/transport/chttp2/stream_encoder_test.c22
-rw-r--r--test/core/transport/chttp2/stream_map_test.c40
-rw-r--r--test/core/transport/metadata_test.c12
-rw-r--r--test/core/util/parse_hexstring.c6
-rw-r--r--test/core/util/port_posix.c108
-rw-r--r--test/core/util/port_windows.c120
-rw-r--r--test/core/util/reconnect_server.c9
-rw-r--r--test/core/util/test_config.c4
-rw-r--r--test/core/util/test_config.h18
85 files changed, 867 insertions, 688 deletions
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c
index 24bf5d3625..41ac83b7b7 100644
--- a/test/core/bad_client/bad_client.c
+++ b/test/core/bad_client/bad_client.c
@@ -59,7 +59,7 @@ static void thd_func(void *arg) {
gpr_event_set(&a->done_thd, (void *)1);
}
-static void done_write(void *arg, grpc_endpoint_cb_status status) {
+static void done_write(void *arg, int success) {
thd_args *a = arg;
gpr_event_set(&a->done_write, (void *)1);
}
@@ -85,6 +85,8 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator,
grpc_mdctx *mdctx = grpc_mdctx_create();
gpr_slice slice =
gpr_slice_from_copied_buffer(client_payload, client_payload_length);
+ gpr_slice_buffer outgoing;
+ grpc_iomgr_closure done_write_closure;
hex = gpr_dump(client_payload, client_payload_length,
GPR_DUMP_HEX | GPR_DUMP_ASCII);
@@ -122,14 +124,18 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator,
/* Start validator */
gpr_thd_new(&id, thd_func, &a, NULL);
+ gpr_slice_buffer_init(&outgoing);
+ gpr_slice_buffer_add(&outgoing, slice);
+ grpc_iomgr_closure_init(&done_write_closure, done_write, &a);
+
/* Write data */
- switch (grpc_endpoint_write(sfd.client, &slice, 1, done_write, &a)) {
- case GRPC_ENDPOINT_WRITE_DONE:
+ switch (grpc_endpoint_write(sfd.client, &outgoing, &done_write_closure)) {
+ case GRPC_ENDPOINT_DONE:
done_write(&a, 1);
break;
- case GRPC_ENDPOINT_WRITE_PENDING:
+ case GRPC_ENDPOINT_PENDING:
break;
- case GRPC_ENDPOINT_WRITE_ERROR:
+ case GRPC_ENDPOINT_ERROR:
done_write(&a, 0);
break;
}
@@ -139,6 +145,7 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator,
gpr_event_wait(&a.done_write, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5)));
if (flags & GRPC_BAD_CLIENT_DISCONNECT) {
+ grpc_endpoint_shutdown(sfd.client);
grpc_endpoint_destroy(sfd.client);
sfd.client = NULL;
}
@@ -147,6 +154,7 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator,
/* Shutdown */
if (sfd.client) {
+ grpc_endpoint_shutdown(sfd.client);
grpc_endpoint_destroy(sfd.client);
}
grpc_server_shutdown_and_notify(a.server, a.cq, NULL);
@@ -155,6 +163,7 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator,
.type == GRPC_OP_COMPLETE);
grpc_server_destroy(a.server);
grpc_completion_queue_destroy(a.cq);
+ gpr_slice_buffer_destroy(&outgoing);
grpc_shutdown();
}
diff --git a/test/core/bad_client/gen_build_json.py b/test/core/bad_client/gen_build_yaml.py
index 33bf65ac04..02dda10be0 100755
--- a/test/core/bad_client/gen_build_json.py
+++ b/test/core/bad_client/gen_build_yaml.py
@@ -32,8 +32,8 @@
"""Generates the appropriate build.json data for all the end2end tests."""
-import simplejson
import collections
+import yaml
TestOptions = collections.namedtuple('TestOptions', 'flaky')
default_test_options = TestOptions(False)
@@ -58,6 +58,7 @@ def main():
'headers': [
'test/core/bad_client/bad_client.h'
],
+ 'vs_proj_dir': 'test',
'deps': [
'grpc_test_util_unsecure',
'grpc_unsecure',
@@ -72,7 +73,7 @@ def main():
'language': 'c',
'secure': 'no',
'src': ['test/core/bad_client/tests/%s.c' % t],
- 'flaky': 'invoke_large_request' in t,
+ 'vs_proj_dir': 'test',
'deps': [
'bad_client_test',
'grpc_test_util_unsecure',
@@ -82,7 +83,7 @@ def main():
]
}
for t in sorted(BAD_CLIENT_TESTS.keys())]}
- print simplejson.dumps(json, sort_keys=True, indent=2 * ' ')
+ print yaml.dump(json)
if __name__ == '__main__':
diff --git a/test/core/channel/channel_args_test.c b/test/core/channel/channel_args_test.c
index 87f006acde..0b74dee41e 100644
--- a/test/core/channel/channel_args_test.c
+++ b/test/core/channel/channel_args_test.c
@@ -85,12 +85,13 @@ static void test_set_compression_algorithm(void) {
static void test_compression_algorithm_states(void) {
grpc_channel_args *ch_args, *ch_args_wo_gzip, *ch_args_wo_gzip_deflate;
- int states_bitset;
+ unsigned states_bitset;
size_t i;
ch_args = grpc_channel_args_copy_and_add(NULL, NULL, 0);
/* by default, all enabled */
- states_bitset = grpc_channel_args_compression_algorithm_get_states(ch_args);
+ states_bitset =
+ (unsigned)grpc_channel_args_compression_algorithm_get_states(ch_args);
for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
GPR_ASSERT(GPR_BITGET(states_bitset, i));
@@ -104,7 +105,7 @@ static void test_compression_algorithm_states(void) {
&ch_args_wo_gzip, GRPC_COMPRESS_DEFLATE, 0);
GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate);
- states_bitset = grpc_channel_args_compression_algorithm_get_states(
+ states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states(
ch_args_wo_gzip_deflate);
for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (i == GRPC_COMPRESS_GZIP || i == GRPC_COMPRESS_DEFLATE) {
@@ -119,8 +120,8 @@ static void test_compression_algorithm_states(void) {
&ch_args_wo_gzip_deflate, GRPC_COMPRESS_GZIP, 1);
GPR_ASSERT(ch_args_wo_gzip == ch_args_wo_gzip_deflate);
- states_bitset =
- grpc_channel_args_compression_algorithm_get_states(ch_args_wo_gzip);
+ states_bitset = (unsigned)grpc_channel_args_compression_algorithm_get_states(
+ ch_args_wo_gzip);
for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (i == GRPC_COMPRESS_DEFLATE) {
GPR_ASSERT(GPR_BITGET(states_bitset, i) == 0);
diff --git a/test/core/client_config/uri_parser_test.c b/test/core/client_config/uri_parser_test.c
index d324029c7e..580c18b699 100644
--- a/test/core/client_config/uri_parser_test.c
+++ b/test/core/client_config/uri_parser_test.c
@@ -40,12 +40,15 @@
#include "test/core/util/test_config.h"
static void test_succeeds(const char *uri_text, const char *scheme,
- const char *authority, const char *path) {
+ const char *authority, const char *path,
+ const char *query, const char* fragment) {
grpc_uri *uri = grpc_uri_parse(uri_text, 0);
GPR_ASSERT(uri);
GPR_ASSERT(0 == strcmp(scheme, uri->scheme));
GPR_ASSERT(0 == strcmp(authority, uri->authority));
GPR_ASSERT(0 == strcmp(path, uri->path));
+ GPR_ASSERT(0 == strcmp(query, uri->query));
+ GPR_ASSERT(0 == strcmp(fragment, uri->fragment));
grpc_uri_destroy(uri);
}
@@ -55,17 +58,29 @@ static void test_fails(const char *uri_text) {
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
- test_succeeds("http://www.google.com", "http", "www.google.com", "");
- test_succeeds("dns:///foo", "dns", "", "/foo");
- test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "");
- test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom");
- test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom");
+ test_succeeds("http://www.google.com", "http", "www.google.com", "", "", "");
+ test_succeeds("dns:///foo", "dns", "", "/foo", "", "");
+ test_succeeds("http://www.google.com:90", "http", "www.google.com:90", "", "",
+ "");
+ test_succeeds("a192.4-df:foo.coom", "a192.4-df", "", "foo.coom", "", "");
+ test_succeeds("a+b:foo.coom", "a+b", "", "foo.coom", "", "");
test_succeeds("zookeeper://127.0.0.1:2181/foo/bar", "zookeeper",
- "127.0.0.1:2181", "/foo/bar");
+ "127.0.0.1:2181", "/foo/bar", "", "");
+ test_succeeds("http://www.google.com?yay-i'm-using-queries", "http",
+ "www.google.com", "", "yay-i'm-using-queries", "");
+ test_succeeds("dns:foo.com#fragment-all-the-things", "dns", "", "foo.com", "",
+ "fragment-all-the-things");
+ test_succeeds("http:?legit", "http", "", "", "legit", "");
+ test_succeeds("unix:#this-is-ok-too", "unix", "", "", "", "this-is-ok-too");
+ test_succeeds("http:?legit#twice", "http", "", "", "legit", "twice");
+ test_succeeds("http://foo?bar#lol?", "http", "foo", "", "bar", "lol?");
+ test_succeeds("http://foo?bar#lol?/", "http", "foo", "", "bar", "lol?/");
+
test_fails("xyz");
- test_fails("http://www.google.com?why-are-you-using-queries");
- test_fails("dns:foo.com#fragments-arent-supported-here");
- test_fails("http:?huh");
- test_fails("unix:#yeah-right");
+ test_fails("http:?dangling-pct-%0");
+ test_fails("http://foo?[bar]");
+ test_fails("http://foo?x[bar]");
+ test_fails("http://foo?bar#lol#");
+
return 0;
}
diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c
index 495841c79f..98da6a1eaa 100644
--- a/test/core/compression/message_compress_test.c
+++ b/test/core/compression/message_compress_test.c
@@ -149,7 +149,7 @@ static gpr_slice create_test_value(test_value id) {
static void test_bad_data(void) {
gpr_slice_buffer input;
gpr_slice_buffer output;
- int i;
+ grpc_compression_algorithm i;
gpr_slice_buffer_init(&input);
gpr_slice_buffer_init(&output);
diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c
index fcc12952bf..fec9667db8 100644
--- a/test/core/end2end/dualstack_socket_test.c
+++ b/test/core/end2end/dualstack_socket_test.c
@@ -40,6 +40,7 @@
#include <grpc/support/string_util.h>
#include "src/core/support/string.h"
+#include "src/core/iomgr/resolve_address.h"
#include "src/core/iomgr/socket_utils_posix.h"
#include "test/core/end2end/cq_verifier.h"
@@ -186,7 +187,7 @@ void test_connect(const char *server_host, const char *client_host, int port,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
if (expect_ok) {
@@ -212,7 +213,7 @@ void test_connect(const char *server_host, const char *client_host, int port,
op->data.recv_close_on_server.cancelled = &was_cancelled;
op->flags = 0;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -263,6 +264,15 @@ void test_connect(const char *server_host, const char *client_host, int port,
gpr_free(details);
}
+int external_dns_works(const char *host) {
+ grpc_resolved_addresses *res = grpc_blocking_resolve_address(host, "80");
+ if (res != NULL) {
+ grpc_resolved_addresses_destroy(res);
+ return 1;
+ }
+ return 0;
+}
+
int main(int argc, char **argv) {
int do_ipv6 = 1;
@@ -308,6 +318,25 @@ int main(int argc, char **argv) {
test_connect("::1", "ipv4:127.0.0.1", 0, 0);
test_connect("127.0.0.1", "ipv6:[::1]", 0, 0);
}
+
+ if (!external_dns_works("loopback46.unittest.grpc.io")) {
+ gpr_log(GPR_INFO, "Skipping tests that depend on *.unittest.grpc.io.");
+ } else {
+ test_connect("loopback46.unittest.grpc.io",
+ "loopback4.unittest.grpc.io", 0, 1);
+ test_connect("loopback4.unittest.grpc.io",
+ "loopback46.unittest.grpc.io", 0, 1);
+ if (do_ipv6) {
+ test_connect("loopback46.unittest.grpc.io",
+ "loopback6.unittest.grpc.io", 0, 1);
+ test_connect("loopback6.unittest.grpc.io",
+ "loopback46.unittest.grpc.io", 0, 1);
+ test_connect("loopback4.unittest.grpc.io",
+ "loopback6.unittest.grpc.io", 0, 0);
+ test_connect("loopback6.unittest.grpc.io",
+ "loopback4.unittest.grpc.io", 0, 0);
+ }
+ }
}
grpc_shutdown();
diff --git a/test/core/end2end/fixtures/chttp2_fullstack_compression.c b/test/core/end2end/fixtures/h2_compress.c
index 6e7a1faf55..6e7a1faf55 100644
--- a/test/core/end2end/fixtures/chttp2_fullstack_compression.c
+++ b/test/core/end2end/fixtures/h2_compress.c
diff --git a/test/core/end2end/fixtures/chttp2_fake_security.c b/test/core/end2end/fixtures/h2_fakesec.c
index 3e64cc08e8..3e64cc08e8 100644
--- a/test/core/end2end/fixtures/chttp2_fake_security.c
+++ b/test/core/end2end/fixtures/h2_fakesec.c
diff --git a/test/core/end2end/fixtures/chttp2_fullstack_with_poll.c b/test/core/end2end/fixtures/h2_full+poll.c
index 48feefc931..48feefc931 100644
--- a/test/core/end2end/fixtures/chttp2_fullstack_with_poll.c
+++ b/test/core/end2end/fixtures/h2_full+poll.c
diff --git a/test/core/end2end/fixtures/chttp2_fullstack.c b/test/core/end2end/fixtures/h2_full.c
index 0170dcf0e5..0170dcf0e5 100644
--- a/test/core/end2end/fixtures/chttp2_fullstack.c
+++ b/test/core/end2end/fixtures/h2_full.c
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c b/test/core/end2end/fixtures/h2_oauth2.c
index e61e276fff..e61e276fff 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c
+++ b/test/core/end2end/fixtures/h2_oauth2.c
diff --git a/test/core/end2end/fixtures/chttp2_fullstack_with_proxy.c b/test/core/end2end/fixtures/h2_proxy.c
index 44083e2676..44083e2676 100644
--- a/test/core/end2end/fixtures/chttp2_fullstack_with_proxy.c
+++ b/test/core/end2end/fixtures/h2_proxy.c
diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c b/test/core/end2end/fixtures/h2_sockpair+trace.c
index 588c4b23e1..588c4b23e1 100644
--- a/test/core/end2end/fixtures/chttp2_socket_pair_with_grpc_trace.c
+++ b/test/core/end2end/fixtures/h2_sockpair+trace.c
diff --git a/test/core/end2end/fixtures/chttp2_socket_pair.c b/test/core/end2end/fixtures/h2_sockpair.c
index 16a04fbebf..16a04fbebf 100644
--- a/test/core/end2end/fixtures/chttp2_socket_pair.c
+++ b/test/core/end2end/fixtures/h2_sockpair.c
diff --git a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c b/test/core/end2end/fixtures/h2_sockpair_1byte.c
index 94fc36f5ec..94fc36f5ec 100644
--- a/test/core/end2end/fixtures/chttp2_socket_pair_one_byte_at_a_time.c
+++ b/test/core/end2end/fixtures/h2_sockpair_1byte.c
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c b/test/core/end2end/fixtures/h2_ssl+poll.c
index 2c605d1471..2c605d1471 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c
+++ b/test/core/end2end/fixtures/h2_ssl+poll.c
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c b/test/core/end2end/fixtures/h2_ssl.c
index 9193a09b17..9193a09b17 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
+++ b/test/core/end2end/fixtures/h2_ssl.c
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c b/test/core/end2end/fixtures/h2_ssl_proxy.c
index 8133a69a0c..8133a69a0c 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c
+++ b/test/core/end2end/fixtures/h2_ssl_proxy.c
diff --git a/test/core/end2end/fixtures/chttp2_fullstack_uds_posix_with_poll.c b/test/core/end2end/fixtures/h2_uds+poll.c
index 05b9ea0949..05b9ea0949 100644
--- a/test/core/end2end/fixtures/chttp2_fullstack_uds_posix_with_poll.c
+++ b/test/core/end2end/fixtures/h2_uds+poll.c
diff --git a/test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c b/test/core/end2end/fixtures/h2_uds.c
index 59d39bbb0f..59d39bbb0f 100644
--- a/test/core/end2end/fixtures/chttp2_fullstack_uds_posix.c
+++ b/test/core/end2end/fixtures/h2_uds.c
diff --git a/test/core/end2end/gen_build_json.py b/test/core/end2end/gen_build_yaml.py
index 6f10b78dad..46cdb80c86 100755
--- a/test/core/end2end/gen_build_json.py
+++ b/test/core/end2end/gen_build_yaml.py
@@ -32,8 +32,9 @@
"""Generates the appropriate build.json data for all the end2end tests."""
-import simplejson
+import yaml
import collections
+import hashlib
FixtureOptions = collections.namedtuple('FixtureOptions', 'fullstack includes_proxy dns_resolver secure platforms ci_mac')
@@ -42,22 +43,23 @@ socketpair_unsecure_fixture_options = default_unsecure_fixture_options._replace(
default_secure_fixture_options = default_unsecure_fixture_options._replace(secure=True)
uds_fixture_options = default_unsecure_fixture_options._replace(dns_resolver=False, platforms=['linux', 'mac', 'posix'])
+
# maps fixture name to whether it requires the security library
END2END_FIXTURES = {
- 'chttp2_fake_security': default_secure_fixture_options._replace(ci_mac=False),
- 'chttp2_fullstack': default_unsecure_fixture_options,
- 'chttp2_fullstack_compression': default_unsecure_fixture_options,
- 'chttp2_fullstack_uds_posix': uds_fixture_options,
- 'chttp2_fullstack_uds_posix_with_poll': uds_fixture_options._replace(platforms=['linux']),
- 'chttp2_fullstack_with_poll': default_unsecure_fixture_options._replace(platforms=['linux']),
- 'chttp2_fullstack_with_proxy': default_unsecure_fixture_options._replace(includes_proxy=True, ci_mac=False),
- 'chttp2_simple_ssl_fullstack': default_secure_fixture_options,
- 'chttp2_simple_ssl_fullstack_with_poll': default_secure_fixture_options._replace(platforms=['linux']),
- 'chttp2_simple_ssl_fullstack_with_proxy': default_secure_fixture_options._replace(includes_proxy=True, ci_mac=False),
- 'chttp2_simple_ssl_with_oauth2_fullstack': default_secure_fixture_options._replace(ci_mac=False),
- 'chttp2_socket_pair': socketpair_unsecure_fixture_options._replace(ci_mac=False),
- 'chttp2_socket_pair_one_byte_at_a_time': socketpair_unsecure_fixture_options._replace(ci_mac=False),
- 'chttp2_socket_pair_with_grpc_trace': socketpair_unsecure_fixture_options,
+ 'h2_fakesec': default_secure_fixture_options._replace(ci_mac=False),
+ 'h2_full': default_unsecure_fixture_options,
+ 'h2_compress': default_unsecure_fixture_options,
+ 'h2_uds': uds_fixture_options,
+ 'h2_uds+poll': uds_fixture_options._replace(platforms=['linux']),
+ 'h2_full+poll': default_unsecure_fixture_options._replace(platforms=['linux']),
+ 'h2_proxy': default_unsecure_fixture_options._replace(includes_proxy=True, ci_mac=False),
+ 'h2_ssl': default_secure_fixture_options,
+ 'h2_ssl+poll': default_secure_fixture_options._replace(platforms=['linux']),
+ 'h2_ssl_proxy': default_secure_fixture_options._replace(includes_proxy=True, ci_mac=False),
+ 'h2_oauth2': default_secure_fixture_options._replace(ci_mac=False),
+ 'h2_sockpair': socketpair_unsecure_fixture_options._replace(ci_mac=False),
+ 'h2_sockpair_1byte': socketpair_unsecure_fixture_options._replace(ci_mac=False),
+ 'h2_sockpair+trace': socketpair_unsecure_fixture_options,
}
TestOptions = collections.namedtuple('TestOptions', 'needs_fullstack needs_dns proxyable flaky secure')
@@ -67,7 +69,7 @@ connectivity_test_options = default_test_options._replace(needs_fullstack=True)
# maps test names to options
END2END_TESTS = {
'bad_hostname': default_test_options,
- 'cancel_after_accept_and_writes_closed': default_test_options,
+ 'cancel_after_client_done': default_test_options,
'cancel_after_accept': default_test_options,
'cancel_after_invoke': default_test_options,
'cancel_before_invoke': default_test_options,
@@ -76,8 +78,8 @@ END2END_TESTS = {
'channel_connectivity': connectivity_test_options._replace(proxyable=False),
'default_host': default_test_options._replace(needs_fullstack=True, needs_dns=True),
'disappearing_server': connectivity_test_options,
- 'early_server_shutdown_finishes_inflight_calls': default_test_options,
- 'early_server_shutdown_finishes_tags': default_test_options,
+ 'shutdown_finishes_calls': default_test_options,
+ 'shutdown_finishes_tags': default_test_options,
'empty_batch': default_test_options,
'graceful_server_shutdown': default_test_options,
'invoke_large_request': default_test_options,
@@ -86,19 +88,19 @@ END2END_TESTS = {
'no_op': default_test_options,
'ping_pong_streaming': default_test_options,
'registered_call': default_test_options,
- 'request_response_with_binary_metadata_and_payload': default_test_options,
- 'request_response_with_metadata_and_payload': default_test_options,
- 'request_response_with_payload_and_call_creds': default_test_options._replace(secure=True),
- 'request_response_with_payload': default_test_options,
- 'request_response_with_trailing_metadata_and_payload': default_test_options,
- 'request_with_compressed_payload': default_test_options._replace(proxyable=False),
+ 'binary_metadata': default_test_options,
+ 'metadata': default_test_options,
+ 'call_creds': default_test_options._replace(secure=True),
+ 'payload': default_test_options,
+ 'trailing_metadata': default_test_options,
+ 'compressed_payload': default_test_options._replace(proxyable=False),
'request_with_flags': default_test_options._replace(proxyable=False),
- 'request_with_large_metadata': default_test_options,
+ 'large_metadata': default_test_options,
'request_with_payload': default_test_options,
'server_finishes_request': default_test_options,
'simple_delayed_request': connectivity_test_options,
'simple_request': default_test_options,
- 'simple_request_with_high_initial_sequence_number': default_test_options,
+ 'high_initial_seqno': default_test_options,
}
@@ -142,22 +144,24 @@ def main():
'name': 'end2end_fixture_%s' % f,
'build': 'private',
'language': 'c',
- 'secure': 'check' if END2END_FIXTURES[f].secure else 'no',
+ 'secure': 'check' if END2END_FIXTURES[f].secure else False,
'src': ['test/core/end2end/fixtures/%s.c' % f],
'platforms': [ 'linux', 'mac', 'posix' ] if f.endswith('_posix') else END2END_FIXTURES[f].platforms,
'deps': sec_deps if END2END_FIXTURES[f].secure else unsec_deps,
'headers': ['test/core/end2end/end2end_tests.h'],
+ 'vs_proj_dir': 'test',
}
for f in sorted(END2END_FIXTURES.keys())] + [
{
'name': 'end2end_test_%s' % t,
'build': 'private',
'language': 'c',
- 'secure': 'check' if END2END_TESTS[t].secure else 'no',
+ 'secure': 'check' if END2END_TESTS[t].secure else False,
'src': ['test/core/end2end/tests/%s.c' % t],
'headers': ['test/core/end2end/tests/cancel_test_helpers.h',
'test/core/end2end/end2end_tests.h'],
- 'deps': sec_deps if END2END_TESTS[t].secure else unsec_deps
+ 'deps': sec_deps if END2END_TESTS[t].secure else unsec_deps,
+ 'vs_proj_dir': 'test',
}
for t in sorted(END2END_TESTS.keys())] + [
{
@@ -168,7 +172,8 @@ def main():
"test/core/end2end/data/test_root_cert.c",
"test/core/end2end/data/server1_cert.c",
"test/core/end2end/data/server1_key.c"
- ]
+ ],
+ 'vs_proj_dir': 'test',
}
],
'targets': [
@@ -184,13 +189,14 @@ def main():
else without(END2END_FIXTURES[f].platforms, 'mac')),
'deps': [
'end2end_fixture_%s' % f,
- 'end2end_test_%s' % t] + sec_deps
+ 'end2end_test_%s' % t] + sec_deps,
+ 'vs_proj_dir': 'test',
}
for f in sorted(END2END_FIXTURES.keys())
for t in sorted(END2END_TESTS.keys())
if compatible(f, t)] + [
{
- 'name': '%s_%s_unsecure_test' % (f, t),
+ 'name': '%s_%s_nosec_test' % (f, t),
'build': 'test',
'language': 'c',
'secure': 'no',
@@ -202,11 +208,12 @@ def main():
else without(END2END_FIXTURES[f].platforms, 'mac')),
'deps': [
'end2end_fixture_%s' % f,
- 'end2end_test_%s' % t] + unsec_deps
+ 'end2end_test_%s' % t] + unsec_deps,
+ 'vs_proj_dir': 'test',
}
for f in sorted(END2END_FIXTURES.keys()) if not END2END_FIXTURES[f].secure
for t in sorted(END2END_TESTS.keys()) if compatible(f, t) and not END2END_TESTS[t].secure]}
- print simplejson.dumps(json, sort_keys=True, indent=2 * ' ')
+ print yaml.dump(json)
if __name__ == '__main__':
diff --git a/test/core/end2end/no_server_test.c b/test/core/end2end/no_server_test.c
index 619627ddd2..c391003141 100644
--- a/test/core/end2end/no_server_test.c
+++ b/test/core/end2end/no_server_test.c
@@ -79,8 +79,8 @@ int main(int argc, char **argv) {
op->flags = 0;
op->reserved = NULL;
op++;
- GPR_ASSERT(GRPC_CALL_OK ==
- grpc_call_start_batch(call, ops, op - ops, tag(1), NULL));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(
+ call, ops, (size_t)(op - ops), tag(1), NULL));
/* verify that all tags get completed */
cq_expect_completion(cqv, tag(1), 1);
cq_verify(cqv);
diff --git a/test/core/end2end/tests/bad_hostname.c b/test/core/end2end/tests/bad_hostname.c
index 8f28fa1e63..93e2df1e43 100644
--- a/test/core/end2end/tests/bad_hostname.c
+++ b/test/core/end2end/tests/bad_hostname.c
@@ -146,7 +146,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(1), 1);
diff --git a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c b/test/core/end2end/tests/binary_metadata.c
index 2345f94044..21e0bbcc49 100644
--- a/test/core/end2end/tests/request_response_with_binary_metadata_and_payload.c
+++ b/test/core/end2end/tests/binary_metadata.c
@@ -191,7 +191,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -213,7 +213,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -237,7 +237,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
diff --git a/test/core/end2end/tests/request_response_with_payload_and_call_creds.c b/test/core/end2end/tests/call_creds.c
index 75c5bba5bd..4e905aafc7 100644
--- a/test/core/end2end/tests/request_response_with_payload_and_call_creds.c
+++ b/test/core/end2end/tests/call_creds.c
@@ -247,7 +247,7 @@ static void request_response_with_payload_and_call_creds(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -280,7 +280,7 @@ static void request_response_with_payload_and_call_creds(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -304,7 +304,7 @@ static void request_response_with_payload_and_call_creds(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
@@ -464,7 +464,7 @@ static void test_request_with_server_rejecting_client_creds(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(error == GRPC_CALL_OK);
cq_expect_completion(cqv, tag(1), 1);
diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c
index 313e0b05bd..10e62275ab 100644
--- a/test/core/end2end/tests/cancel_after_accept.c
+++ b/test/core/end2end/tests/cancel_after_accept.c
@@ -165,7 +165,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error = grpc_server_request_call(f.server, &s, &call_details,
@@ -195,7 +195,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(3), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(3), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, NULL));
diff --git a/test/core/end2end/tests/cancel_after_accept_and_writes_closed.c b/test/core/end2end/tests/cancel_after_client_done.c
index 2430a6d218..4fed5be5f7 100644
--- a/test/core/end2end/tests/cancel_after_accept_and_writes_closed.c
+++ b/test/core/end2end/tests/cancel_after_client_done.c
@@ -169,7 +169,7 @@ static void test_cancel_after_accept_and_writes_closed(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error = grpc_server_request_call(f.server, &s, &call_details,
@@ -199,7 +199,7 @@ static void test_cancel_after_accept_and_writes_closed(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(3), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(3), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
GPR_ASSERT(GRPC_CALL_OK == mode.initiate_cancel(c, NULL));
diff --git a/test/core/end2end/tests/cancel_after_invoke.c b/test/core/end2end/tests/cancel_after_invoke.c
index 9991ee02f0..40595e4c7b 100644
--- a/test/core/end2end/tests/cancel_after_invoke.c
+++ b/test/core/end2end/tests/cancel_after_invoke.c
@@ -101,7 +101,7 @@ static void end_test(grpc_end2end_test_fixture *f) {
/* Cancel after invoke, no payload */
static void test_cancel_after_invoke(grpc_end2end_test_config config,
- cancellation_mode mode, int test_ops) {
+ cancellation_mode mode, size_t test_ops) {
grpc_op ops[6];
grpc_op *op;
grpc_call *c;
diff --git a/test/core/end2end/tests/cancel_before_invoke.c b/test/core/end2end/tests/cancel_before_invoke.c
index 8b582e0c42..c049e0c2d6 100644
--- a/test/core/end2end/tests/cancel_before_invoke.c
+++ b/test/core/end2end/tests/cancel_before_invoke.c
@@ -99,7 +99,7 @@ static void end_test(grpc_end2end_test_fixture *f) {
/* Cancel before invoke */
static void test_cancel_before_invoke(grpc_end2end_test_config config,
- int test_ops) {
+ size_t test_ops) {
grpc_op ops[6];
grpc_op *op;
grpc_call *c;
@@ -189,7 +189,7 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config,
}
void grpc_end2end_tests(grpc_end2end_test_config config) {
- int i;
+ size_t i;
for (i = 1; i <= 6; i++) {
test_cancel_before_invoke(config, i);
}
diff --git a/test/core/end2end/tests/census_simple_request.c b/test/core/end2end/tests/census_simple_request.c
index 36b9e92884..adf855ca60 100644
--- a/test/core/end2end/tests/census_simple_request.c
+++ b/test/core/end2end/tests/census_simple_request.c
@@ -145,7 +145,7 @@ static void test_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -173,7 +173,7 @@ static void test_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/request_with_compressed_payload.c b/test/core/end2end/tests/compressed_payload.c
index 299943c548..c50eaba8b2 100644
--- a/test/core/end2end/tests/request_with_compressed_payload.c
+++ b/test/core/end2end/tests/compressed_payload.c
@@ -186,7 +186,7 @@ static void request_with_payload_template(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -215,7 +215,7 @@ static void request_with_payload_template(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -234,7 +234,7 @@ static void request_with_payload_template(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
diff --git a/test/core/end2end/tests/default_host.c b/test/core/end2end/tests/default_host.c
index 57f65b834b..7b62505a9a 100644
--- a/test/core/end2end/tests/default_host.c
+++ b/test/core/end2end/tests/default_host.c
@@ -154,7 +154,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(error == GRPC_CALL_OK);
error =
@@ -191,7 +191,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(error == GRPC_CALL_OK);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/disappearing_server.c b/test/core/end2end/tests/disappearing_server.c
index 09762705e3..de3ea16f66 100644
--- a/test/core/end2end/tests/disappearing_server.c
+++ b/test/core/end2end/tests/disappearing_server.c
@@ -131,7 +131,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_fixture *f,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -163,7 +163,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_fixture *f,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/graceful_server_shutdown.c b/test/core/end2end/tests/graceful_server_shutdown.c
index d4e7a1ac6d..df420a9846 100644
--- a/test/core/end2end/tests/graceful_server_shutdown.c
+++ b/test/core/end2end/tests/graceful_server_shutdown.c
@@ -146,7 +146,7 @@ static void test_early_server_shutdown_finishes_inflight_calls(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -178,7 +178,7 @@ static void test_early_server_shutdown_finishes_inflight_calls(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/simple_request_with_high_initial_sequence_number.c b/test/core/end2end/tests/high_initial_seqno.c
index 0067bb4bef..44d6a60c10 100644
--- a/test/core/end2end/tests/simple_request_with_high_initial_sequence_number.c
+++ b/test/core/end2end/tests/high_initial_seqno.c
@@ -149,7 +149,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -177,7 +177,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/invoke_large_request.c b/test/core/end2end/tests/invoke_large_request.c
index 7677084511..f79d146da1 100644
--- a/test/core/end2end/tests/invoke_large_request.c
+++ b/test/core/end2end/tests/invoke_large_request.c
@@ -171,7 +171,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -192,7 +192,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -216,7 +216,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
diff --git a/test/core/end2end/tests/request_with_large_metadata.c b/test/core/end2end/tests/large_metadata.c
index 98e47aaf98..87529639a7 100644
--- a/test/core/end2end/tests/request_with_large_metadata.c
+++ b/test/core/end2end/tests/large_metadata.c
@@ -121,7 +121,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) {
char *details = NULL;
size_t details_capacity = 0;
int was_cancelled = 2;
- const int large_size = 64 * 1024;
+ const size_t large_size = 64 * 1024;
c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
"/foo", "foo.test.google.fr", deadline, NULL);
@@ -167,7 +167,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -188,7 +188,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -207,7 +207,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c
index 0ba620b851..87eb4dd451 100644
--- a/test/core/end2end/tests/max_concurrent_streams.c
+++ b/test/core/end2end/tests/max_concurrent_streams.c
@@ -147,7 +147,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -175,7 +175,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -280,7 +280,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c1, ops, op - ops, tag(301), NULL);
+ error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(301), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
op = ops;
@@ -297,7 +297,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c1, ops, op - ops, tag(302), NULL);
+ error = grpc_call_start_batch(c1, ops, (size_t)(op - ops), tag(302), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
op = ops;
@@ -310,7 +310,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c2, ops, op - ops, tag(401), NULL);
+ error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(401), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
op = ops;
@@ -327,7 +327,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c2, ops, op - ops, tag(402), NULL);
+ error = grpc_call_start_batch(c2, ops, (size_t)(op - ops), tag(402), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
got_client_start = 0;
@@ -372,7 +372,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s1, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s1, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -406,7 +406,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s2, ops, op - ops, tag(202), NULL);
+ error = grpc_call_start_batch(s2, ops, (size_t)(op - ops), tag(202), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(live_call + 2), 1);
diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c
index 2b9560716f..782b9d0f26 100644
--- a/test/core/end2end/tests/max_message_length.c
+++ b/test/core/end2end/tests/max_message_length.c
@@ -167,7 +167,7 @@ static void test_max_message_length(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -183,7 +183,7 @@ static void test_max_message_length(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/request_response_with_metadata_and_payload.c b/test/core/end2end/tests/metadata.c
index a4cc27896c..d0604cc6b6 100644
--- a/test/core/end2end/tests/request_response_with_metadata_and_payload.c
+++ b/test/core/end2end/tests/metadata.c
@@ -175,7 +175,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -197,7 +197,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -221,7 +221,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
diff --git a/test/core/end2end/tests/request_response_with_payload.c b/test/core/end2end/tests/payload.c
index ff00ae6d9d..0b303268fc 100644
--- a/test/core/end2end/tests/request_response_with_payload.c
+++ b/test/core/end2end/tests/payload.c
@@ -164,7 +164,7 @@ static void request_response_with_payload(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -185,7 +185,7 @@ static void request_response_with_payload(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -209,7 +209,7 @@ static void request_response_with_payload(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
diff --git a/test/core/end2end/tests/ping_pong_streaming.c b/test/core/end2end/tests/ping_pong_streaming.c
index 43abda4d7f..39682d8bc5 100644
--- a/test/core/end2end/tests/ping_pong_streaming.c
+++ b/test/core/end2end/tests/ping_pong_streaming.c
@@ -154,7 +154,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -175,7 +175,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(101), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(101), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
for (i = 0; i < messages; i++) {
@@ -193,7 +193,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(2), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
op = ops;
@@ -202,7 +202,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
cq_verify(cqv);
@@ -213,7 +213,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
cq_expect_completion(cqv, tag(2), 1);
@@ -233,7 +233,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(3), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
op = ops;
@@ -244,7 +244,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(104), NULL);
+ 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(1), 1);
diff --git a/test/core/end2end/tests/registered_call.c b/test/core/end2end/tests/registered_call.c
index eddce6ded4..b3156e0248 100644
--- a/test/core/end2end/tests/registered_call.c
+++ b/test/core/end2end/tests/registered_call.c
@@ -148,7 +148,7 @@ static void simple_request_body(grpc_end2end_test_fixture f, void *rc) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -176,7 +176,7 @@ static void simple_request_body(grpc_end2end_test_fixture f, void *rc) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/request_with_flags.c b/test/core/end2end/tests/request_with_flags.c
index eb2e5dc7e8..b9cdf5168c 100644
--- a/test/core/end2end/tests/request_with_flags.c
+++ b/test/core/end2end/tests/request_with_flags.c
@@ -160,7 +160,7 @@ static void test_invoke_request_with_flags(
op->reserved = NULL;
op++;
expectation = call_start_batch_expected_result;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(expectation == error);
if (expectation == GRPC_CALL_OK) {
diff --git a/test/core/end2end/tests/request_with_payload.c b/test/core/end2end/tests/request_with_payload.c
index 149dbaeb00..a323b43ab0 100644
--- a/test/core/end2end/tests/request_with_payload.c
+++ b/test/core/end2end/tests/request_with_payload.c
@@ -158,7 +158,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call(
@@ -178,7 +178,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -197,7 +197,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
diff --git a/test/core/end2end/tests/server_finishes_request.c b/test/core/end2end/tests/server_finishes_request.c
index 8bacc6c730..bdc18a5e38 100644
--- a/test/core/end2end/tests/server_finishes_request.c
+++ b/test/core/end2end/tests/server_finishes_request.c
@@ -145,7 +145,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -173,7 +173,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c b/test/core/end2end/tests/shutdown_finishes_calls.c
index 233bc9bee2..ad7def09a9 100644
--- a/test/core/end2end/tests/early_server_shutdown_finishes_inflight_calls.c
+++ b/test/core/end2end/tests/shutdown_finishes_calls.c
@@ -139,7 +139,7 @@ static void test_early_server_shutdown_finishes_inflight_calls(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -155,7 +155,7 @@ static void test_early_server_shutdown_finishes_inflight_calls(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
/* shutdown and destroy the server */
diff --git a/test/core/end2end/tests/early_server_shutdown_finishes_tags.c b/test/core/end2end/tests/shutdown_finishes_tags.c
index 9b678a1754..9b678a1754 100644
--- a/test/core/end2end/tests/early_server_shutdown_finishes_tags.c
+++ b/test/core/end2end/tests/shutdown_finishes_tags.c
diff --git a/test/core/end2end/tests/simple_delayed_request.c b/test/core/end2end/tests/simple_delayed_request.c
index 9133aacc35..14e0ac8f66 100644
--- a/test/core/end2end/tests/simple_delayed_request.c
+++ b/test/core/end2end/tests/simple_delayed_request.c
@@ -140,7 +140,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
config.init_server(f, server_args);
@@ -170,7 +170,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config,
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c
index 0f62d958ae..a874640837 100644
--- a/test/core/end2end/tests/simple_request.c
+++ b/test/core/end2end/tests/simple_request.c
@@ -155,7 +155,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -192,7 +192,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
diff --git a/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c b/test/core/end2end/tests/trailing_metadata.c
index 8b764751f6..c040b9fac1 100644
--- a/test/core/end2end/tests/request_response_with_trailing_metadata_and_payload.c
+++ b/test/core/end2end/tests/trailing_metadata.c
@@ -178,7 +178,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(c, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
error =
@@ -200,7 +200,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(102), NULL);
+ error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
cq_expect_completion(cqv, tag(102), 1);
@@ -225,7 +225,7 @@ static void test_request_response_with_metadata_and_payload(
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(s, ops, op - ops, tag(103), NULL);
+ 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(103), 1);
diff --git a/test/core/fling/client.c b/test/core/fling/client.c
index 54c9274510..a53411c2f5 100644
--- a/test/core/fling/client.c
+++ b/test/core/fling/client.c
@@ -92,8 +92,9 @@ static void step_ping_pong_request(void) {
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(call, ops, op - ops, (void *)1, NULL));
+ GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops,
+ (size_t)(op - ops),
+ (void *)1, NULL));
grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
grpc_call_destroy(call);
grpc_byte_buffer_destroy(response_payload_recv);
@@ -129,7 +130,7 @@ static void step_ping_pong_stream(void) {
static double now(void) {
gpr_timespec tv = gpr_now(GPR_CLOCK_REALTIME);
- return 1e9 * tv.tv_sec + tv.tv_nsec;
+ return 1e9 * (double)tv.tv_sec + tv.tv_nsec;
}
typedef struct {
@@ -188,7 +189,7 @@ int main(int argc, char **argv) {
channel = grpc_insecure_channel_create(target, NULL, NULL);
cq = grpc_completion_queue_create(NULL);
- the_buffer = grpc_raw_byte_buffer_create(&slice, payload_size);
+ the_buffer = grpc_raw_byte_buffer_create(&slice, (size_t)payload_size);
histogram = gpr_histogram_create(0.01, 60e9);
sc.init();
diff --git a/test/core/fling/fling_stream_test.c b/test/core/fling/fling_stream_test.c
index 4d9253c0ad..78a73372aa 100644
--- a/test/core/fling/fling_stream_test.c
+++ b/test/core/fling/fling_stream_test.c
@@ -60,10 +60,10 @@ int main(int argc, char **argv) {
pid_t svr, cli;
/* seed rng with pid, so we don't end up with the same random numbers as a
concurrently running test binary */
- srand(getpid());
+ srand((unsigned)getpid());
/* figure out where we are */
if (lslash) {
- memcpy(root, me, lslash - me);
+ memcpy(root, me, (size_t)(lslash - me));
root[lslash - me] = 0;
} else {
strcpy(root, ".");
diff --git a/test/core/fling/fling_test.c b/test/core/fling/fling_test.c
index 29d9050704..cf43ecfd2d 100644
--- a/test/core/fling/fling_test.c
+++ b/test/core/fling/fling_test.c
@@ -51,7 +51,7 @@ int main(int argc, char **argv) {
gpr_subprocess *svr, *cli;
/* figure out where we are */
if (lslash) {
- memcpy(root, me, lslash - me);
+ memcpy(root, me, (size_t)(lslash - me));
root[lslash - me] = 0;
} else {
strcpy(root, ".");
diff --git a/test/core/fling/server.c b/test/core/fling/server.c
index 0430ff9ab7..5aace03520 100644
--- a/test/core/fling/server.c
+++ b/test/core/fling/server.c
@@ -123,7 +123,7 @@ static void handle_unary_method(void) {
op->data.recv_close_on_server.cancelled = &was_cancelled;
op++;
- error = grpc_call_start_batch(call, unary_ops, op - unary_ops,
+ error = grpc_call_start_batch(call, unary_ops, (size_t)(op - unary_ops),
tag(FLING_SERVER_BATCH_OPS_FOR_UNARY), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
}
@@ -197,7 +197,7 @@ int main(int argc, char **argv) {
grpc_test_init(1, fake_argv);
grpc_init();
- srand(clock());
+ srand((unsigned)clock());
cl = gpr_cmdline_create("fling server");
gpr_cmdline_add_string(cl, "bind", "Bind host:port", &addr);
diff --git a/test/core/httpcli/httpcli_test.c b/test/core/httpcli/httpcli_test.c
index 42b2661c0a..cf2b10c021 100644
--- a/test/core/httpcli/httpcli_test.c
+++ b/test/core/httpcli/httpcli_test.c
@@ -134,7 +134,7 @@ int main(int argc, char **argv) {
/* figure out where we are */
if (lslash) {
- memcpy(root, me, lslash - me);
+ memcpy(root, me, (size_t)(lslash - me));
root[lslash - me] = 0;
} else {
strcpy(root, ".");
diff --git a/test/core/iomgr/alarm_heap_test.c b/test/core/iomgr/alarm_heap_test.c
index 66b6e4cb64..13bf7e43f6 100644
--- a/test/core/iomgr/alarm_heap_test.c
+++ b/test/core/iomgr/alarm_heap_test.c
@@ -48,9 +48,9 @@ static gpr_timespec random_deadline(void) {
return ts;
}
-static grpc_alarm *create_test_elements(int num_elements) {
+static grpc_alarm *create_test_elements(size_t num_elements) {
grpc_alarm *elems = gpr_malloc(num_elements * sizeof(grpc_alarm));
- int i;
+ size_t i;
for (i = 0; i < num_elements; i++) {
elems[i].deadline = random_deadline();
}
@@ -63,24 +63,25 @@ static int cmp_elem(const void *a, const void *b) {
return i - j;
}
-static int *all_top(grpc_alarm_heap *pq, int *n) {
- int *vec = NULL;
- int *need_to_check_children;
- int num_need_to_check_children = 0;
+static size_t *all_top(grpc_alarm_heap *pq, size_t *n) {
+ size_t *vec = NULL;
+ size_t *need_to_check_children;
+ size_t num_need_to_check_children = 0;
*n = 0;
if (pq->alarm_count == 0) return vec;
- need_to_check_children = gpr_malloc(pq->alarm_count * sizeof(int));
+ need_to_check_children =
+ gpr_malloc(pq->alarm_count * sizeof(*need_to_check_children));
need_to_check_children[num_need_to_check_children++] = 0;
- vec = gpr_malloc(pq->alarm_count * sizeof(int));
+ vec = gpr_malloc(pq->alarm_count * sizeof(*vec));
while (num_need_to_check_children > 0) {
- int ind = need_to_check_children[0];
- int leftchild, rightchild;
+ size_t ind = need_to_check_children[0];
+ size_t leftchild, rightchild;
num_need_to_check_children--;
memmove(need_to_check_children, need_to_check_children + 1,
- num_need_to_check_children * sizeof(int));
+ num_need_to_check_children * sizeof(*need_to_check_children));
vec[(*n)++] = ind;
- leftchild = 1 + 2 * ind;
+ leftchild = 1u + 2u * ind;
if (leftchild < pq->alarm_count) {
if (gpr_time_cmp(pq->alarms[leftchild]->deadline,
pq->alarms[ind]->deadline) >= 0) {
@@ -101,13 +102,14 @@ static int *all_top(grpc_alarm_heap *pq, int *n) {
}
static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq,
- gpr_uint8 *inpq, int num_elements) {
+ gpr_uint8 *inpq, size_t num_elements) {
gpr_timespec max_deadline = gpr_inf_past(GPR_CLOCK_REALTIME);
- int *max_deadline_indices = gpr_malloc(num_elements * sizeof(int));
- int *top_elements;
- int num_max_deadline_indices = 0;
- int num_top_elements;
- int i;
+ size_t *max_deadline_indices =
+ gpr_malloc(num_elements * sizeof(*max_deadline_indices));
+ size_t *top_elements;
+ size_t num_max_deadline_indices = 0;
+ size_t num_top_elements;
+ size_t i;
for (i = 0; i < num_elements; ++i) {
if (inpq[i] && gpr_time_cmp(elements[i].deadline, max_deadline) >= 0) {
if (gpr_time_cmp(elements[i].deadline, max_deadline) > 0) {
@@ -117,7 +119,8 @@ static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq,
max_deadline_indices[num_max_deadline_indices++] = elements[i].heap_index;
}
}
- qsort(max_deadline_indices, num_max_deadline_indices, sizeof(int), cmp_elem);
+ qsort(max_deadline_indices, num_max_deadline_indices,
+ sizeof(*max_deadline_indices), cmp_elem);
top_elements = all_top(pq, &num_top_elements);
GPR_ASSERT(num_top_elements == num_max_deadline_indices);
for (i = 0; i < num_top_elements; i++) {
@@ -128,7 +131,7 @@ static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq,
}
static int contains(grpc_alarm_heap *pq, grpc_alarm *el) {
- int i;
+ size_t i;
for (i = 0; i < pq->alarm_count; i++) {
if (pq->alarms[i] == el) return 1;
}
@@ -136,10 +139,10 @@ static int contains(grpc_alarm_heap *pq, grpc_alarm *el) {
}
static void check_valid(grpc_alarm_heap *pq) {
- int i;
+ size_t i;
for (i = 0; i < pq->alarm_count; ++i) {
- int left_child = 1 + 2 * i;
- int right_child = left_child + 1;
+ size_t left_child = 1u + 2u * i;
+ size_t right_child = left_child + 1u;
if (left_child < pq->alarm_count) {
GPR_ASSERT(gpr_time_cmp(pq->alarms[i]->deadline,
pq->alarms[left_child]->deadline) >= 0);
@@ -153,9 +156,9 @@ static void check_valid(grpc_alarm_heap *pq) {
static void test1(void) {
grpc_alarm_heap pq;
- const int num_test_elements = 200;
- const int num_test_operations = 10000;
- int i;
+ const size_t num_test_elements = 200;
+ const size_t num_test_operations = 10000;
+ size_t i;
grpc_alarm *test_elements = create_test_elements(num_test_elements);
gpr_uint8 *inpq = gpr_malloc(num_test_elements);
@@ -182,7 +185,7 @@ static void test1(void) {
check_pq_top(test_elements, &pq, inpq, num_test_elements);
for (i = 0; i < num_test_operations; ++i) {
- int elem_num = rand() % num_test_elements;
+ size_t elem_num = (size_t)rand() % num_test_elements;
grpc_alarm *el = &test_elements[elem_num];
if (!inpq[elem_num]) { /* not in pq */
GPR_ASSERT(!contains(&pq, el));
@@ -209,11 +212,11 @@ static void test1(void) {
static void shrink_test(void) {
grpc_alarm_heap pq;
- int i;
- int expected_size;
+ size_t i;
+ size_t expected_size;
/* A large random number to allow for multiple shrinkages, at least 512. */
- const int num_elements = rand() % 2000 + 512;
+ const size_t num_elements = (size_t)rand() % 2000 + 512;
grpc_alarm_heap_init(&pq);
@@ -243,7 +246,7 @@ static void shrink_test(void) {
4 times the Size and not less than 2 times, but never goes below 16. */
expected_size = pq.alarm_count;
while (pq.alarm_count > 0) {
- const int which = rand() % pq.alarm_count;
+ const size_t which = (size_t)rand() % pq.alarm_count;
grpc_alarm *te = pq.alarms[which];
grpc_alarm_heap_remove(&pq, te);
gpr_free(te);
diff --git a/test/core/iomgr/endpoint_pair_test.c b/test/core/iomgr/endpoint_pair_test.c
new file mode 100644
index 0000000000..3abde5ac35
--- /dev/null
+++ b/test/core/iomgr/endpoint_pair_test.c
@@ -0,0 +1,77 @@
+/*
+ *
+ * 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 "src/core/iomgr/tcp_posix.h"
+
+#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
+#include "src/core/iomgr/endpoint_pair.h"
+#include "test/core/util/test_config.h"
+#include "test/core/iomgr/endpoint_tests.h"
+
+static grpc_pollset g_pollset;
+
+static void clean_up(void) {}
+
+static grpc_endpoint_test_fixture create_fixture_endpoint_pair(
+ size_t slice_size) {
+ grpc_endpoint_test_fixture f;
+ grpc_endpoint_pair p = grpc_iomgr_create_endpoint_pair("test", slice_size);
+
+ f.client_ep = p.client;
+ f.server_ep = p.server;
+ grpc_endpoint_add_to_pollset(f.client_ep, &g_pollset);
+ grpc_endpoint_add_to_pollset(f.server_ep, &g_pollset);
+
+ return f;
+}
+
+static grpc_endpoint_test_config configs[] = {
+ {"tcp/tcp_socketpair", create_fixture_endpoint_pair, clean_up},
+};
+
+static void destroy_pollset(void *p) { grpc_pollset_destroy(p); }
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+ grpc_pollset_init(&g_pollset);
+ grpc_endpoint_tests(configs[0], &g_pollset);
+ grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset);
+ grpc_shutdown();
+
+ return 0;
+}
diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c
index 6ef8e9ca3b..853b9a32c2 100644
--- a/test/core/iomgr/endpoint_tests.c
+++ b/test/core/iomgr/endpoint_tests.c
@@ -39,6 +39,7 @@
#include <grpc/support/slice.h>
#include <grpc/support/log.h>
#include <grpc/support/time.h>
+#include <grpc/support/useful.h>
#include "test/core/util/test_config.h"
/*
@@ -59,8 +60,7 @@
static grpc_pollset *g_pollset;
-size_t count_and_unref_slices(gpr_slice *slices, size_t nslices,
- int *current_data) {
+size_t count_slices(gpr_slice *slices, size_t nslices, int *current_data) {
size_t num_bytes = 0;
size_t i;
size_t j;
@@ -72,7 +72,6 @@ size_t count_and_unref_slices(gpr_slice *slices, size_t nslices,
*current_data = (*current_data + 1) % 256;
}
num_bytes += GPR_SLICE_LENGTH(slices[i]);
- gpr_slice_unref(slices[i]);
}
return num_bytes;
}
@@ -87,7 +86,7 @@ static grpc_endpoint_test_fixture begin_test(grpc_endpoint_test_config config,
static void end_test(grpc_endpoint_test_config config) { config.clean_up(); }
static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
- size_t *num_blocks, int *current_data) {
+ size_t *num_blocks, gpr_uint8 *current_data) {
size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0);
gpr_slice *slices = malloc(sizeof(gpr_slice) * nslices);
size_t num_bytes_left = num_bytes;
@@ -103,7 +102,7 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
buf = GPR_SLICE_START_PTR(slices[i]);
for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) {
buf[j] = *current_data;
- *current_data = (*current_data + 1) % 256;
+ (*current_data)++;
}
}
GPR_ASSERT(num_bytes_left == 0);
@@ -118,89 +117,81 @@ struct read_and_write_test_state {
size_t current_write_size;
size_t bytes_written;
int current_read_data;
- int current_write_data;
+ gpr_uint8 current_write_data;
int read_done;
int write_done;
+ gpr_slice_buffer incoming;
+ gpr_slice_buffer outgoing;
+ grpc_iomgr_closure done_read;
+ grpc_iomgr_closure done_write;
};
-static void read_and_write_test_read_handler(void *data, gpr_slice *slices,
- size_t nslices,
- grpc_endpoint_cb_status error) {
+static void read_and_write_test_read_handler(void *data, int success) {
struct read_and_write_test_state *state = data;
- GPR_ASSERT(error != GRPC_ENDPOINT_CB_ERROR);
- if (error == GRPC_ENDPOINT_CB_SHUTDOWN) {
- gpr_log(GPR_INFO, "Read handler shutdown");
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
- state->read_done = 1;
- grpc_pollset_kick(g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
- return;
- }
- state->bytes_read +=
- count_and_unref_slices(slices, nslices, &state->current_read_data);
- if (state->bytes_read == state->target_bytes) {
+loop:
+ state->bytes_read += count_slices(
+ state->incoming.slices, state->incoming.count, &state->current_read_data);
+ if (state->bytes_read == state->target_bytes || !success) {
gpr_log(GPR_INFO, "Read handler done");
gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
- state->read_done = 1;
+ state->read_done = 1 + success;
grpc_pollset_kick(g_pollset, NULL);
gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
- } else {
- grpc_endpoint_notify_on_read(state->read_ep,
- read_and_write_test_read_handler, data);
+ } else if (success) {
+ switch (grpc_endpoint_read(state->read_ep, &state->incoming,
+ &state->done_read)) {
+ case GRPC_ENDPOINT_ERROR:
+ success = 0;
+ goto loop;
+ case GRPC_ENDPOINT_DONE:
+ success = 1;
+ goto loop;
+ case GRPC_ENDPOINT_PENDING:
+ break;
+ }
}
}
-static void read_and_write_test_write_handler(void *data,
- grpc_endpoint_cb_status error) {
+static void read_and_write_test_write_handler(void *data, int success) {
struct read_and_write_test_state *state = data;
gpr_slice *slices = NULL;
size_t nslices;
- grpc_endpoint_write_status write_status;
-
- GPR_ASSERT(error != GRPC_ENDPOINT_CB_ERROR);
-
- gpr_log(GPR_DEBUG, "%s: error=%d", "read_and_write_test_write_handler",
- error);
-
- if (error == GRPC_ENDPOINT_CB_SHUTDOWN) {
- gpr_log(GPR_INFO, "Write handler shutdown");
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
- state->write_done = 1;
- grpc_pollset_kick(g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
- return;
- }
-
- for (;;) {
- /* Need to do inline writes until they don't succeed synchronously or we
- finish writing */
- state->bytes_written += state->current_write_size;
- if (state->target_bytes - state->bytes_written <
- state->current_write_size) {
- state->current_write_size = state->target_bytes - state->bytes_written;
- }
- if (state->current_write_size == 0) {
- break;
- }
-
- slices = allocate_blocks(state->current_write_size, 8192, &nslices,
- &state->current_write_data);
- write_status =
- grpc_endpoint_write(state->write_ep, slices, nslices,
- read_and_write_test_write_handler, state);
- gpr_log(GPR_DEBUG, "write_status=%d", write_status);
- GPR_ASSERT(write_status != GRPC_ENDPOINT_WRITE_ERROR);
- free(slices);
- if (write_status == GRPC_ENDPOINT_WRITE_PENDING) {
- return;
+ grpc_endpoint_op_status write_status;
+
+ if (success) {
+ for (;;) {
+ /* Need to do inline writes until they don't succeed synchronously or we
+ finish writing */
+ state->bytes_written += state->current_write_size;
+ if (state->target_bytes - state->bytes_written <
+ state->current_write_size) {
+ state->current_write_size = state->target_bytes - state->bytes_written;
+ }
+ if (state->current_write_size == 0) {
+ break;
+ }
+
+ slices = allocate_blocks(state->current_write_size, 8192, &nslices,
+ &state->current_write_data);
+ gpr_slice_buffer_reset_and_unref(&state->outgoing);
+ gpr_slice_buffer_addn(&state->outgoing, slices, nslices);
+ write_status = grpc_endpoint_write(state->write_ep, &state->outgoing,
+ &state->done_write);
+ free(slices);
+ if (write_status == GRPC_ENDPOINT_PENDING) {
+ return;
+ } else if (write_status == GRPC_ENDPOINT_ERROR) {
+ goto cleanup;
+ }
}
+ GPR_ASSERT(state->bytes_written == state->target_bytes);
}
- GPR_ASSERT(state->bytes_written == state->target_bytes);
+cleanup:
gpr_log(GPR_INFO, "Write handler done");
gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
- state->write_done = 1;
+ state->write_done = 1 + success;
grpc_pollset_kick(g_pollset, NULL);
gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
}
@@ -216,6 +207,8 @@ static void read_and_write_test(grpc_endpoint_test_config config,
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20);
grpc_endpoint_test_fixture f =
begin_test(config, "read_and_write_test", slice_size);
+ gpr_log(GPR_DEBUG, "num_bytes=%d write_size=%d slice_size=%d shutdown=%d",
+ num_bytes, write_size, slice_size, shutdown);
if (shutdown) {
gpr_log(GPR_INFO, "Start read and write shutdown test");
@@ -234,16 +227,31 @@ static void read_and_write_test(grpc_endpoint_test_config config,
state.write_done = 0;
state.current_read_data = 0;
state.current_write_data = 0;
+ grpc_iomgr_closure_init(&state.done_read, read_and_write_test_read_handler,
+ &state);
+ grpc_iomgr_closure_init(&state.done_write, read_and_write_test_write_handler,
+ &state);
+ gpr_slice_buffer_init(&state.outgoing);
+ gpr_slice_buffer_init(&state.incoming);
/* Get started by pretending an initial write completed */
/* NOTE: Sets up initial conditions so we can have the same write handler
for the first iteration as for later iterations. It does the right thing
even when bytes_written is unsigned. */
state.bytes_written -= state.current_write_size;
- read_and_write_test_write_handler(&state, GRPC_ENDPOINT_CB_OK);
+ read_and_write_test_write_handler(&state, 1);
- grpc_endpoint_notify_on_read(state.read_ep, read_and_write_test_read_handler,
- &state);
+ switch (
+ grpc_endpoint_read(state.read_ep, &state.incoming, &state.done_read)) {
+ case GRPC_ENDPOINT_PENDING:
+ break;
+ case GRPC_ENDPOINT_ERROR:
+ read_and_write_test_read_handler(&state, 0);
+ break;
+ case GRPC_ENDPOINT_DONE:
+ read_and_write_test_read_handler(&state, 1);
+ break;
+ }
if (shutdown) {
gpr_log(GPR_DEBUG, "shutdown read");
@@ -261,129 +269,22 @@ static void read_and_write_test(grpc_endpoint_test_config config,
}
gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
+ end_test(config);
+ gpr_slice_buffer_destroy(&state.outgoing);
+ gpr_slice_buffer_destroy(&state.incoming);
grpc_endpoint_destroy(state.read_ep);
grpc_endpoint_destroy(state.write_ep);
- end_test(config);
-}
-
-struct timeout_test_state {
- int io_done;
-};
-
-typedef struct {
- int done;
- grpc_endpoint *ep;
-} shutdown_during_write_test_state;
-
-static void shutdown_during_write_test_read_handler(
- void *user_data, gpr_slice *slices, size_t nslices,
- grpc_endpoint_cb_status error) {
- size_t i;
- shutdown_during_write_test_state *st = user_data;
-
- for (i = 0; i < nslices; i++) {
- gpr_slice_unref(slices[i]);
- }
-
- if (error != GRPC_ENDPOINT_CB_OK) {
- grpc_endpoint_destroy(st->ep);
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
- st->done = error;
- grpc_pollset_kick(g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
- } else {
- grpc_endpoint_notify_on_read(
- st->ep, shutdown_during_write_test_read_handler, user_data);
- }
-}
-
-static void shutdown_during_write_test_write_handler(
- void *user_data, grpc_endpoint_cb_status error) {
- shutdown_during_write_test_state *st = user_data;
- gpr_log(GPR_INFO, "shutdown_during_write_test_write_handler: error = %d",
- error);
- if (error == 0) {
- /* This happens about 0.5% of the time when run under TSAN, and is entirely
- legitimate, but means we aren't testing the path we think we are. */
- /* TODO(klempner): Change this test to retry the write in that case */
- gpr_log(GPR_ERROR,
- "shutdown_during_write_test_write_handler completed unexpectedly");
- }
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
- st->done = 1;
- grpc_pollset_kick(g_pollset, NULL);
- gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
-}
-
-static void shutdown_during_write_test(grpc_endpoint_test_config config,
- size_t slice_size) {
- /* test that shutdown with a pending write creates no leaks */
- gpr_timespec deadline;
- size_t size;
- size_t nblocks;
- int current_data = 1;
- shutdown_during_write_test_state read_st;
- shutdown_during_write_test_state write_st;
- gpr_slice *slices;
- grpc_endpoint_test_fixture f =
- begin_test(config, "shutdown_during_write_test", slice_size);
-
- gpr_log(GPR_INFO, "testing shutdown during a write");
-
- read_st.ep = f.client_ep;
- write_st.ep = f.server_ep;
- read_st.done = 0;
- write_st.done = 0;
-
- grpc_endpoint_notify_on_read(
- read_st.ep, shutdown_during_write_test_read_handler, &read_st);
- for (size = 1;; size *= 2) {
- slices = allocate_blocks(size, 1, &nblocks, &current_data);
- switch (grpc_endpoint_write(write_st.ep, slices, nblocks,
- shutdown_during_write_test_write_handler,
- &write_st)) {
- case GRPC_ENDPOINT_WRITE_DONE:
- break;
- case GRPC_ENDPOINT_WRITE_ERROR:
- gpr_log(GPR_ERROR, "error writing");
- abort();
- case GRPC_ENDPOINT_WRITE_PENDING:
- grpc_endpoint_shutdown(write_st.ep);
- deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10);
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
- while (!write_st.done) {
- grpc_pollset_worker worker;
- GPR_ASSERT(gpr_time_cmp(gpr_now(deadline.clock_type), deadline) < 0);
- grpc_pollset_work(g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- deadline);
- }
- gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
- grpc_endpoint_destroy(write_st.ep);
- gpr_mu_lock(GRPC_POLLSET_MU(g_pollset));
- while (!read_st.done) {
- grpc_pollset_worker worker;
- GPR_ASSERT(gpr_time_cmp(gpr_now(deadline.clock_type), deadline) < 0);
- grpc_pollset_work(g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- deadline);
- }
- gpr_mu_unlock(GRPC_POLLSET_MU(g_pollset));
- gpr_free(slices);
- end_test(config);
- return;
- }
- gpr_free(slices);
- }
-
- gpr_log(GPR_ERROR, "should never reach here");
- abort();
}
void grpc_endpoint_tests(grpc_endpoint_test_config config,
grpc_pollset *pollset) {
+ size_t i;
g_pollset = pollset;
read_and_write_test(config, 10000000, 100000, 8192, 0);
read_and_write_test(config, 1000000, 100000, 1, 0);
read_and_write_test(config, 100000000, 100000, 1, 1);
- shutdown_during_write_test(config, 1000);
+ for (i = 1; i < 1000; i = GPR_MAX(i + 1, i * 5 / 4)) {
+ read_and_write_test(config, 40320, i, i, 0);
+ }
g_pollset = NULL;
}
diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c
index 8bba87d61f..75959069c0 100644
--- a/test/core/iomgr/fd_posix_test.c
+++ b/test/core/iomgr/fd_posix_test.c
@@ -83,7 +83,8 @@ static void create_test_socket(int port, int *socket_fd,
/* Use local address for test */
sin->sin_family = AF_INET;
sin->sin_addr.s_addr = htonl(0x7f000001);
- sin->sin_port = htons(port);
+ GPR_ASSERT(port >= 0 && port < 65536);
+ sin->sin_port = htons((gpr_uint16)port);
}
/* Dummy gRPC callback */
@@ -419,7 +420,7 @@ static void test_grpc_fd_change(void) {
int flags;
int sv[2];
char data;
- int result;
+ ssize_t result;
grpc_iomgr_closure first_closure;
grpc_iomgr_closure second_closure;
diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c
index 6ad832231f..59c498edff 100644
--- a/test/core/iomgr/tcp_posix_test.c
+++ b/test/core/iomgr/tcp_posix_test.c
@@ -81,7 +81,7 @@ static ssize_t fill_socket(int fd) {
int i;
unsigned char buf[256];
for (i = 0; i < 256; ++i) {
- buf[i] = i;
+ buf[i] = (gpr_uint8)i;
}
do {
write_bytes = write(fd, buf, 256);
@@ -99,13 +99,13 @@ static size_t fill_socket_partial(int fd, size_t bytes) {
unsigned char *buf = malloc(bytes);
unsigned i;
for (i = 0; i < bytes; ++i) {
- buf[i] = i % 256;
+ buf[i] = (gpr_uint8)(i % 256);
}
do {
write_bytes = write(fd, buf, bytes - total_bytes);
if (write_bytes > 0) {
- total_bytes += write_bytes;
+ total_bytes += (size_t)write_bytes;
}
} while ((write_bytes >= 0 || errno == EINTR) && bytes > total_bytes);
@@ -116,13 +116,15 @@ static size_t fill_socket_partial(int fd, size_t bytes) {
struct read_socket_state {
grpc_endpoint *ep;
- ssize_t read_bytes;
- ssize_t target_read_bytes;
+ size_t read_bytes;
+ size_t target_read_bytes;
+ gpr_slice_buffer incoming;
+ grpc_iomgr_closure read_cb;
};
-static ssize_t count_and_unref_slices(gpr_slice *slices, size_t nslices,
- int *current_data) {
- ssize_t num_bytes = 0;
+static size_t count_slices(gpr_slice *slices, size_t nslices,
+ int *current_data) {
+ size_t num_bytes = 0;
unsigned i, j;
unsigned char *buf;
for (i = 0; i < nslices; ++i) {
@@ -132,39 +134,49 @@ static ssize_t count_and_unref_slices(gpr_slice *slices, size_t nslices,
*current_data = (*current_data + 1) % 256;
}
num_bytes += GPR_SLICE_LENGTH(slices[i]);
- gpr_slice_unref(slices[i]);
}
return num_bytes;
}
-static void read_cb(void *user_data, gpr_slice *slices, size_t nslices,
- grpc_endpoint_cb_status error) {
+static void read_cb(void *user_data, int success) {
struct read_socket_state *state = (struct read_socket_state *)user_data;
- ssize_t read_bytes;
+ size_t read_bytes;
int current_data;
- GPR_ASSERT(error == GRPC_ENDPOINT_CB_OK);
+ GPR_ASSERT(success);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
current_data = state->read_bytes % 256;
- read_bytes = count_and_unref_slices(slices, nslices, &current_data);
+ read_bytes = count_slices(state->incoming.slices, state->incoming.count,
+ &current_data);
state->read_bytes += read_bytes;
gpr_log(GPR_INFO, "Read %d bytes of %d", read_bytes,
state->target_read_bytes);
if (state->read_bytes >= state->target_read_bytes) {
- /* empty */
+ gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
} else {
- grpc_endpoint_notify_on_read(state->ep, read_cb, state);
+ switch (grpc_endpoint_read(state->ep, &state->incoming, &state->read_cb)) {
+ case GRPC_ENDPOINT_DONE:
+ gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ read_cb(user_data, 1);
+ break;
+ case GRPC_ENDPOINT_ERROR:
+ gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ read_cb(user_data, 0);
+ break;
+ case GRPC_ENDPOINT_PENDING:
+ gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ break;
+ }
}
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
}
/* Write to a socket, then read from it using the grpc_tcp API. */
-static void read_test(ssize_t num_bytes, ssize_t slice_size) {
+static void read_test(size_t num_bytes, size_t slice_size) {
int sv[2];
grpc_endpoint *ep;
struct read_socket_state state;
- ssize_t written_bytes;
+ size_t written_bytes;
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20);
gpr_log(GPR_INFO, "Read test of size %d, slice size %d", num_bytes,
@@ -181,8 +193,19 @@ static void read_test(ssize_t num_bytes, ssize_t slice_size) {
state.ep = ep;
state.read_bytes = 0;
state.target_read_bytes = written_bytes;
+ gpr_slice_buffer_init(&state.incoming);
+ grpc_iomgr_closure_init(&state.read_cb, read_cb, &state);
- grpc_endpoint_notify_on_read(ep, read_cb, &state);
+ switch (grpc_endpoint_read(ep, &state.incoming, &state.read_cb)) {
+ case GRPC_ENDPOINT_DONE:
+ read_cb(&state, 1);
+ break;
+ case GRPC_ENDPOINT_ERROR:
+ read_cb(&state, 0);
+ break;
+ case GRPC_ENDPOINT_PENDING:
+ break;
+ }
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
while (state.read_bytes < state.target_read_bytes) {
@@ -193,12 +216,13 @@ static void read_test(ssize_t num_bytes, ssize_t slice_size) {
GPR_ASSERT(state.read_bytes == state.target_read_bytes);
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_slice_buffer_destroy(&state.incoming);
grpc_endpoint_destroy(ep);
}
/* Write to a socket until it fills up, then read from it using the grpc_tcp
API. */
-static void large_read_test(ssize_t slice_size) {
+static void large_read_test(size_t slice_size) {
int sv[2];
grpc_endpoint *ep;
struct read_socket_state state;
@@ -218,9 +242,20 @@ static void large_read_test(ssize_t slice_size) {
state.ep = ep;
state.read_bytes = 0;
- state.target_read_bytes = written_bytes;
+ state.target_read_bytes = (size_t)written_bytes;
+ gpr_slice_buffer_init(&state.incoming);
+ grpc_iomgr_closure_init(&state.read_cb, read_cb, &state);
- grpc_endpoint_notify_on_read(ep, read_cb, &state);
+ switch (grpc_endpoint_read(ep, &state.incoming, &state.read_cb)) {
+ case GRPC_ENDPOINT_DONE:
+ read_cb(&state, 1);
+ break;
+ case GRPC_ENDPOINT_ERROR:
+ read_cb(&state, 0);
+ break;
+ case GRPC_ENDPOINT_PENDING:
+ break;
+ }
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
while (state.read_bytes < state.target_read_bytes) {
@@ -231,6 +266,7 @@ static void large_read_test(ssize_t slice_size) {
GPR_ASSERT(state.read_bytes == state.target_read_bytes);
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ gpr_slice_buffer_destroy(&state.incoming);
grpc_endpoint_destroy(ep);
}
@@ -239,11 +275,11 @@ struct write_socket_state {
int write_done;
};
-static gpr_slice *allocate_blocks(ssize_t num_bytes, ssize_t slice_size,
- size_t *num_blocks, int *current_data) {
- size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0);
+static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size,
+ size_t *num_blocks, gpr_uint8 *current_data) {
+ size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1u : 0u);
gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices);
- ssize_t num_bytes_left = num_bytes;
+ size_t num_bytes_left = num_bytes;
unsigned i, j;
unsigned char *buf;
*num_blocks = nslices;
@@ -255,15 +291,14 @@ static gpr_slice *allocate_blocks(ssize_t num_bytes, ssize_t slice_size,
buf = GPR_SLICE_START_PTR(slices[i]);
for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) {
buf[j] = *current_data;
- *current_data = (*current_data + 1) % 256;
+ (*current_data)++;
}
}
GPR_ASSERT(num_bytes_left == 0);
return slices;
}
-static void write_done(void *user_data /* write_socket_state */,
- grpc_endpoint_cb_status error) {
+static void write_done(void *user_data /* write_socket_state */, int success) {
struct write_socket_state *state = (struct write_socket_state *)user_data;
gpr_log(GPR_INFO, "Write done callback called");
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
@@ -299,7 +334,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) {
GPR_ASSERT(buf[i] == current);
current = (current + 1) % 256;
}
- bytes_left -= bytes_read;
+ bytes_left -= (size_t)bytes_read;
if (bytes_left == 0) break;
}
flags = fcntl(fd, F_GETFL, 0);
@@ -331,14 +366,16 @@ static ssize_t drain_socket(int fd) {
/* Write to a socket using the grpc_tcp API, then drain it directly.
Note that if the write does not complete immediately we need to drain the
socket in parallel with the read. */
-static void write_test(ssize_t num_bytes, ssize_t slice_size) {
+static void write_test(size_t num_bytes, size_t slice_size) {
int sv[2];
grpc_endpoint *ep;
struct write_socket_state state;
ssize_t read_bytes;
size_t num_blocks;
gpr_slice *slices;
- int current_data = 0;
+ gpr_uint8 current_data = 0;
+ gpr_slice_buffer outgoing;
+ grpc_iomgr_closure write_done_closure;
gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20);
gpr_log(GPR_INFO, "Start write test with %d bytes, slice size %d", num_bytes,
@@ -355,74 +392,21 @@ static void write_test(ssize_t num_bytes, ssize_t slice_size) {
slices = allocate_blocks(num_bytes, slice_size, &num_blocks, &current_data);
- if (grpc_endpoint_write(ep, slices, num_blocks, write_done, &state) ==
- GRPC_ENDPOINT_WRITE_DONE) {
- /* Write completed immediately */
- read_bytes = drain_socket(sv[0]);
- GPR_ASSERT(read_bytes == num_bytes);
- } else {
- drain_socket_blocking(sv[0], num_bytes, num_bytes);
- gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
- for (;;) {
- grpc_pollset_worker worker;
- if (state.write_done) {
- break;
- }
- grpc_pollset_work(&g_pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC),
- deadline);
- }
- gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
- }
+ gpr_slice_buffer_init(&outgoing);
+ gpr_slice_buffer_addn(&outgoing, slices, num_blocks);
+ grpc_iomgr_closure_init(&write_done_closure, write_done, &state);
- grpc_endpoint_destroy(ep);
- gpr_free(slices);
-}
-
-static void read_done_for_write_error(void *ud, gpr_slice *slices,
- size_t nslices,
- grpc_endpoint_cb_status error) {
- GPR_ASSERT(error != GRPC_ENDPOINT_CB_OK);
- GPR_ASSERT(nslices == 0);
-}
-
-/* Write to a socket using the grpc_tcp API, then drain it directly.
- Note that if the write does not complete immediately we need to drain the
- socket in parallel with the read. */
-static void write_error_test(ssize_t num_bytes, ssize_t slice_size) {
- int sv[2];
- grpc_endpoint *ep;
- struct write_socket_state state;
- size_t num_blocks;
- gpr_slice *slices;
- int current_data = 0;
- grpc_pollset_worker worker;
- gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20);
-
- gpr_log(GPR_INFO, "Start write error test with %d bytes, slice size %d",
- num_bytes, slice_size);
-
- create_sockets(sv);
-
- ep = grpc_tcp_create(grpc_fd_create(sv[1], "write_error_test"),
- GRPC_TCP_DEFAULT_READ_SLICE_SIZE, "test");
- grpc_endpoint_add_to_pollset(ep, &g_pollset);
-
- close(sv[0]);
-
- state.ep = ep;
- state.write_done = 0;
-
- slices = allocate_blocks(num_bytes, slice_size, &num_blocks, &current_data);
-
- switch (grpc_endpoint_write(ep, slices, num_blocks, write_done, &state)) {
- case GRPC_ENDPOINT_WRITE_DONE:
- case GRPC_ENDPOINT_WRITE_ERROR:
+ switch (grpc_endpoint_write(ep, &outgoing, &write_done_closure)) {
+ case GRPC_ENDPOINT_DONE:
/* Write completed immediately */
+ read_bytes = drain_socket(sv[0]);
+ GPR_ASSERT((size_t)read_bytes == num_bytes);
break;
- case GRPC_ENDPOINT_WRITE_PENDING:
- grpc_endpoint_notify_on_read(ep, read_done_for_write_error, NULL);
+ case GRPC_ENDPOINT_PENDING:
+ drain_socket_blocking(sv[0], num_bytes, num_bytes);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
for (;;) {
+ grpc_pollset_worker worker;
if (state.write_done) {
break;
}
@@ -431,14 +415,18 @@ static void write_error_test(ssize_t num_bytes, ssize_t slice_size) {
}
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
break;
+ case GRPC_ENDPOINT_ERROR:
+ gpr_log(GPR_ERROR, "endpoint got error");
+ abort();
}
+ gpr_slice_buffer_destroy(&outgoing);
grpc_endpoint_destroy(ep);
- free(slices);
+ gpr_free(slices);
}
void run_tests(void) {
- int i = 0;
+ size_t i = 0;
read_test(100, 8192);
read_test(10000, 8192);
@@ -454,10 +442,6 @@ void run_tests(void) {
write_test(100000, 137);
for (i = 1; i < 1000; i = GPR_MAX(i + 1, i * 5 / 4)) {
- write_error_test(40320, i);
- }
-
- for (i = 1; i < 1000; i = GPR_MAX(i + 1, i * 5 / 4)) {
write_test(40320, i);
}
}
diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c
index c91752b937..24b6b1c717 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -49,17 +49,15 @@ static grpc_pollset g_pollset;
static int g_number_of_reads = 0;
static int g_number_of_bytes_read = 0;
-static void on_connect(void *arg, grpc_endpoint *udp) {}
-
-static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) {
+static void on_read(int fd) {
char read_buffer[512];
- int byte_count;
+ ssize_t byte_count;
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
byte_count = recv(fd, read_buffer, sizeof(read_buffer), 0);
g_number_of_reads++;
- g_number_of_bytes_read += byte_count;
+ g_number_of_bytes_read += (int)byte_count;
grpc_pollset_kick(&g_pollset, NULL);
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
@@ -73,7 +71,7 @@ static void test_no_op(void) {
static void test_no_op_with_start(void) {
grpc_udp_server *s = grpc_udp_server_create();
LOG_TEST("test_no_op_with_start");
- grpc_udp_server_start(s, NULL, 0, on_connect, NULL);
+ grpc_udp_server_start(s, NULL, 0);
grpc_udp_server_destroy(s, NULL, NULL);
}
@@ -100,7 +98,7 @@ static void test_no_op_with_port_and_start(void) {
GPR_ASSERT(grpc_udp_server_add_port(s, (struct sockaddr *)&addr, sizeof(addr),
on_read));
- grpc_udp_server_start(s, NULL, 0, on_connect, NULL);
+ grpc_udp_server_start(s, NULL, 0);
grpc_udp_server_destroy(s, NULL, NULL);
}
@@ -130,7 +128,7 @@ static void test_receive(int number_of_clients) {
GPR_ASSERT(addr_len <= sizeof(addr));
pollsets[0] = &g_pollset;
- grpc_udp_server_start(s, pollsets, 1, on_connect, NULL);
+ grpc_udp_server_start(s, pollsets, 1);
gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
diff --git a/test/core/json/json_rewrite.c b/test/core/json/json_rewrite.c
index 02f60a3163..82cc4090f3 100644
--- a/test/core/json/json_rewrite.c
+++ b/test/core/json/json_rewrite.c
@@ -34,8 +34,9 @@
#include <stdio.h>
#include <stdlib.h>
-#include <grpc/support/cmdline.h>
#include <grpc/support/alloc.h>
+#include <grpc/support/cmdline.h>
+#include <grpc/support/log.h>
#include "src/core/json/json_reader.h"
#include "src/core/json/json_writer.h"
@@ -81,7 +82,7 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char,
static void check_string(json_reader_userdata* state, size_t needed) {
if (state->free_space >= needed) return;
needed -= state->free_space;
- needed = (needed + 0xff) & ~0xff;
+ needed = (needed + 0xffu) & ~0xffu;
state->scratchpad = gpr_realloc(state->scratchpad, state->allocated + needed);
state->free_space += needed;
state->allocated += needed;
@@ -96,29 +97,30 @@ static void json_reader_string_clear(void* userdata) {
static void json_reader_string_add_char(void* userdata, gpr_uint32 c) {
json_reader_userdata* state = userdata;
check_string(state, 1);
- state->scratchpad[state->string_len++] = c;
+ GPR_ASSERT(c < 256);
+ state->scratchpad[state->string_len++] = (char)c;
}
static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {
if (c <= 0x7f) {
json_reader_string_add_char(userdata, c);
} else if (c <= 0x7ff) {
- int b1 = 0xc0 | ((c >> 6) & 0x1f);
- int b2 = 0x80 | (c & 0x3f);
+ gpr_uint32 b1 = 0xc0u | ((c >> 6u) & 0x1fu);
+ gpr_uint32 b2 = 0x80u | (c & 0x3fu);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
- } else if (c <= 0xffff) {
- int b1 = 0xe0 | ((c >> 12) & 0x0f);
- int b2 = 0x80 | ((c >> 6) & 0x3f);
- int b3 = 0x80 | (c & 0x3f);
+ } else if (c <= 0xffffu) {
+ gpr_uint32 b1 = 0xe0u | ((c >> 12u) & 0x0fu);
+ gpr_uint32 b2 = 0x80u | ((c >> 6u) & 0x3fu);
+ gpr_uint32 b3 = 0x80u | (c & 0x3fu);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
json_reader_string_add_char(userdata, b3);
- } else if (c <= 0x1fffff) {
- int b1 = 0xf0 | ((c >> 18) & 0x07);
- int b2 = 0x80 | ((c >> 12) & 0x3f);
- int b3 = 0x80 | ((c >> 6) & 0x3f);
- int b4 = 0x80 | (c & 0x3f);
+ } else if (c <= 0x1fffffu) {
+ gpr_uint32 b1 = 0xf0u | ((c >> 18u) & 0x07u);
+ gpr_uint32 b2 = 0x80u | ((c >> 12u) & 0x3fu);
+ gpr_uint32 b3 = 0x80u | ((c >> 6u) & 0x3fu);
+ gpr_uint32 b4 = 0x80u | (c & 0x3fu);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
json_reader_string_add_char(userdata, b3);
@@ -132,7 +134,7 @@ static gpr_uint32 json_reader_read_char(void* userdata) {
r = fgetc(state->in);
if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF;
- return r;
+ return (gpr_uint32)r;
}
static void json_reader_container_begins(void* userdata, grpc_json_type type) {
diff --git a/test/core/json/json_rewrite_test.c b/test/core/json/json_rewrite_test.c
index f5859322ea..d26ef53b2d 100644
--- a/test/core/json/json_rewrite_test.c
+++ b/test/core/json/json_rewrite_test.c
@@ -93,7 +93,7 @@ grpc_json_writer_vtable writer_vtable = {json_writer_output_char,
static void check_string(json_reader_userdata* state, size_t needed) {
if (state->free_space >= needed) return;
needed -= state->free_space;
- needed = (needed + 0xff) & ~0xff;
+ needed = (needed + 0xffu) & ~0xffu;
state->scratchpad = gpr_realloc(state->scratchpad, state->allocated + needed);
state->free_space += needed;
state->allocated += needed;
@@ -108,29 +108,30 @@ static void json_reader_string_clear(void* userdata) {
static void json_reader_string_add_char(void* userdata, gpr_uint32 c) {
json_reader_userdata* state = userdata;
check_string(state, 1);
- state->scratchpad[state->string_len++] = c;
+ GPR_ASSERT(c <= 256);
+ state->scratchpad[state->string_len++] = (char)c;
}
static void json_reader_string_add_utf32(void* userdata, gpr_uint32 c) {
if (c <= 0x7f) {
json_reader_string_add_char(userdata, c);
- } else if (c <= 0x7ff) {
- int b1 = 0xc0 | ((c >> 6) & 0x1f);
- int b2 = 0x80 | (c & 0x3f);
+ } else if (c <= 0x7ffu) {
+ gpr_uint32 b1 = 0xc0u | ((c >> 6u) & 0x1fu);
+ gpr_uint32 b2 = 0x80u | (c & 0x3fu);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
- } else if (c <= 0xffff) {
- int b1 = 0xe0 | ((c >> 12) & 0x0f);
- int b2 = 0x80 | ((c >> 6) & 0x3f);
- int b3 = 0x80 | (c & 0x3f);
+ } else if (c <= 0xffffu) {
+ gpr_uint32 b1 = 0xe0u | ((c >> 12u) & 0x0fu);
+ gpr_uint32 b2 = 0x80u | ((c >> 6u) & 0x3fu);
+ gpr_uint32 b3 = 0x80u | (c & 0x3fu);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
json_reader_string_add_char(userdata, b3);
- } else if (c <= 0x1fffff) {
- int b1 = 0xf0 | ((c >> 18) & 0x07);
- int b2 = 0x80 | ((c >> 12) & 0x3f);
- int b3 = 0x80 | ((c >> 6) & 0x3f);
- int b4 = 0x80 | (c & 0x3f);
+ } else if (c <= 0x1fffffu) {
+ gpr_uint32 b1 = 0xf0u | ((c >> 18u) & 0x07u);
+ gpr_uint32 b2 = 0x80u | ((c >> 12u) & 0x3fu);
+ gpr_uint32 b3 = 0x80u | ((c >> 6u) & 0x3fu);
+ gpr_uint32 b4 = 0x80u | (c & 0x3fu);
json_reader_string_add_char(userdata, b1);
json_reader_string_add_char(userdata, b2);
json_reader_string_add_char(userdata, b3);
@@ -151,7 +152,7 @@ static gpr_uint32 json_reader_read_char(void* userdata) {
r = fgetc(state->in);
if (r == EOF) r = GRPC_JSON_READ_CHAR_EOF;
- return r;
+ return (gpr_uint32)r;
}
static void json_reader_container_begins(void* userdata, grpc_json_type type) {
diff --git a/test/core/profiling/timers_test.c b/test/core/profiling/timers_test.c
index 12b08c115e..b79cde64bd 100644
--- a/test/core/profiling/timers_test.c
+++ b/test/core/profiling/timers_test.c
@@ -35,22 +35,22 @@
#include <stdlib.h>
#include "test/core/util/test_config.h"
-void test_log_events(int num_seqs) {
- int start = 0;
- int *state;
+void test_log_events(size_t num_seqs) {
+ size_t start = 0;
+ size_t *state;
state = calloc(num_seqs, sizeof(state[0]));
while (start < num_seqs) {
- int i;
- int row;
+ size_t i;
+ size_t row;
if (state[start] == 3) { /* Already done with this posn */
start++;
continue;
}
- row = rand() % 10; /* how many in a row */
+ row = (size_t)rand() % 10; /* how many in a row */
for (i = start; (i < start + row) && (i < num_seqs); i++) {
- int j;
- int advance = 1 + rand() % 3; /* how many to advance by */
+ size_t j;
+ size_t advance = 1 + (size_t)rand() % 3; /* how many to advance by */
for (j = 0; j < advance; j++) {
switch (state[i]) {
case 0:
diff --git a/test/core/security/base64_test.c b/test/core/security/base64_test.c
index f8b7ebf554..6d49b6d1a1 100644
--- a/test/core/security/base64_test.c
+++ b/test/core/security/base64_test.c
@@ -70,7 +70,7 @@ static void test_full_range_encode_decode_b64(int url_safe, int multiline) {
size_t i;
char *b64;
gpr_slice orig_decoded;
- for (i = 0; i < sizeof(orig); i++) orig[i] = (char)i;
+ for (i = 0; i < sizeof(orig); i++) orig[i] = (gpr_uint8)i;
/* Try all the different paddings. */
for (i = 0; i < 3; i++) {
@@ -122,7 +122,7 @@ static void test_url_safe_unsafe_mismtach_failure(void) {
char *b64;
gpr_slice orig_decoded;
int url_safe = 1;
- for (i = 0; i < sizeof(orig); i++) orig[i] = (char)i;
+ for (i = 0; i < sizeof(orig); i++) orig[i] = (gpr_uint8)i;
b64 = grpc_base64_encode(orig, sizeof(orig), url_safe, 0);
orig_decoded = grpc_base64_decode(b64, !url_safe);
diff --git a/test/core/security/json_token_test.c b/test/core/security/json_token_test.c
index 0bac61eb54..740fd018b6 100644
--- a/test/core/security/json_token_test.c
+++ b/test/core/security/json_token_test.c
@@ -391,20 +391,21 @@ static void test_jwt_encode_and_sign(
char *jwt = jwt_encode_and_sign_func(&json_key);
const char *dot = strchr(jwt, '.');
GPR_ASSERT(dot != NULL);
- parsed_header = parse_json_part_from_jwt(jwt, dot - jwt, &scratchpad);
+ parsed_header =
+ parse_json_part_from_jwt(jwt, (size_t)(dot - jwt), &scratchpad);
GPR_ASSERT(parsed_header != NULL);
check_jwt_header(parsed_header);
- offset = dot - jwt + 1;
+ offset = (size_t)(dot - jwt) + 1;
grpc_json_destroy(parsed_header);
gpr_free(scratchpad);
dot = strchr(jwt + offset, '.');
GPR_ASSERT(dot != NULL);
- parsed_claim =
- parse_json_part_from_jwt(jwt + offset, dot - (jwt + offset), &scratchpad);
+ parsed_claim = parse_json_part_from_jwt(
+ jwt + offset, (size_t)(dot - (jwt + offset)), &scratchpad);
GPR_ASSERT(parsed_claim != NULL);
check_jwt_claim_func(parsed_claim);
- offset = dot - jwt + 1;
+ offset = (size_t)(dot - jwt) + 1;
grpc_json_destroy(parsed_claim);
gpr_free(scratchpad);
diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c
index a8368fc842..047d37748d 100644
--- a/test/core/security/secure_endpoint_test.c
+++ b/test/core/security/secure_endpoint_test.c
@@ -39,6 +39,7 @@
#include "src/core/security/secure_endpoint.h"
#include "src/core/iomgr/endpoint_pair.h"
#include "src/core/iomgr/iomgr.h"
+#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
@@ -135,62 +136,26 @@ static grpc_endpoint_test_config configs[] = {
secure_endpoint_create_fixture_tcp_socketpair_leftover, clean_up},
};
-static void verify_leftover(void *user_data, gpr_slice *slices, size_t nslices,
- grpc_endpoint_cb_status error) {
- gpr_slice s =
- gpr_slice_from_copied_string("hello world 12345678900987654321");
-
- GPR_ASSERT(error == GRPC_ENDPOINT_CB_OK);
- GPR_ASSERT(nslices == 1);
-
- GPR_ASSERT(0 == gpr_slice_cmp(s, slices[0]));
- gpr_slice_unref(slices[0]);
- gpr_slice_unref(s);
- *(int *)user_data = 1;
-}
-
static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) {
grpc_endpoint_test_fixture f = config.create_fixture(slice_size);
- int verified = 0;
+ gpr_slice_buffer incoming;
+ gpr_slice s =
+ gpr_slice_from_copied_string("hello world 12345678900987654321");
gpr_log(GPR_INFO, "Start test left over");
- grpc_endpoint_notify_on_read(f.client_ep, verify_leftover, &verified);
- GPR_ASSERT(verified == 1);
+ gpr_slice_buffer_init(&incoming);
+ GPR_ASSERT(grpc_endpoint_read(f.client_ep, &incoming, NULL) ==
+ GRPC_ENDPOINT_DONE);
+ GPR_ASSERT(incoming.count == 1);
+ GPR_ASSERT(0 == gpr_slice_cmp(s, incoming.slices[0]));
grpc_endpoint_shutdown(f.client_ep);
grpc_endpoint_shutdown(f.server_ep);
grpc_endpoint_destroy(f.client_ep);
grpc_endpoint_destroy(f.server_ep);
- clean_up();
-}
-
-static void destroy_early(void *user_data, gpr_slice *slices, size_t nslices,
- grpc_endpoint_cb_status error) {
- grpc_endpoint_test_fixture *f = user_data;
- gpr_slice s =
- gpr_slice_from_copied_string("hello world 12345678900987654321");
-
- GPR_ASSERT(error == GRPC_ENDPOINT_CB_OK);
- GPR_ASSERT(nslices == 1);
-
- grpc_endpoint_shutdown(f->client_ep);
- grpc_endpoint_destroy(f->client_ep);
-
- GPR_ASSERT(0 == gpr_slice_cmp(s, slices[0]));
- gpr_slice_unref(slices[0]);
gpr_slice_unref(s);
-}
+ gpr_slice_buffer_destroy(&incoming);
-/* test which destroys the ep before finishing reading */
-static void test_destroy_ep_early(grpc_endpoint_test_config config,
- size_t slice_size) {
- grpc_endpoint_test_fixture f = config.create_fixture(slice_size);
- gpr_log(GPR_INFO, "Start test destroy early");
-
- grpc_endpoint_notify_on_read(f.client_ep, destroy_early, &f);
-
- grpc_endpoint_shutdown(f.server_ep);
- grpc_endpoint_destroy(f.server_ep);
clean_up();
}
@@ -199,13 +164,12 @@ static void destroy_pollset(void *p) { grpc_pollset_destroy(p); }
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
- grpc_iomgr_init();
+ grpc_init();
grpc_pollset_init(&g_pollset);
grpc_endpoint_tests(configs[0], &g_pollset);
test_leftover(configs[1], 1);
- test_destroy_ep_early(configs[1], 1);
grpc_pollset_shutdown(&g_pollset, destroy_pollset, &g_pollset);
- grpc_iomgr_shutdown();
+ grpc_shutdown();
return 0;
}
diff --git a/test/core/support/murmur_hash_test.c b/test/core/support/murmur_hash_test.c
index 2462abf7de..1762486776 100644
--- a/test/core/support/murmur_hash_test.c
+++ b/test/core/support/murmur_hash_test.c
@@ -48,7 +48,7 @@ static void verification_test(hash_func hash, gpr_uint32 expected) {
gpr_uint8 key[256];
gpr_uint32 hashes[256];
gpr_uint32 final = 0;
- int i;
+ size_t i;
memset(key, 0, sizeof(key));
memset(hashes, 0, sizeof(hashes));
@@ -57,8 +57,8 @@ static void verification_test(hash_func hash, gpr_uint32 expected) {
the seed */
for (i = 0; i < 256; i++) {
- key[i] = (uint8_t)i;
- hashes[i] = hash(key, i, 256 - i);
+ key[i] = (gpr_uint8)i;
+ hashes[i] = hash(key, i, (gpr_uint32)(256u - i));
}
/* Then hash the result array */
diff --git a/test/core/support/slice_test.c b/test/core/support/slice_test.c
index 3ca87427dd..1d202f0618 100644
--- a/test/core/support/slice_test.c
+++ b/test/core/support/slice_test.c
@@ -66,7 +66,7 @@ static void test_slice_malloc_returns_something_sensible(void) {
}
/* We must be able to write to every byte of the data */
for (i = 0; i < length; i++) {
- GPR_SLICE_START_PTR(slice)[i] = (char)i;
+ GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
}
/* And finally we must succeed in destroying the slice */
gpr_slice_unref(slice);
@@ -116,7 +116,7 @@ static void test_slice_sub_works(unsigned length) {
beginning of the slice. */
slice = gpr_slice_malloc(length);
for (i = 0; i < length; i++) {
- GPR_SLICE_START_PTR(slice)[i] = i;
+ GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
}
/* Ensure that for all subsets length is correct and that we start on the
@@ -143,10 +143,10 @@ static void check_head_tail(gpr_slice slice, gpr_slice head, gpr_slice tail) {
GPR_SLICE_START_PTR(tail), GPR_SLICE_LENGTH(tail)));
}
-static void test_slice_split_head_works(int length) {
+static void test_slice_split_head_works(size_t length) {
gpr_slice slice;
gpr_slice head, tail;
- int i;
+ size_t i;
LOG_TEST_NAME("test_slice_split_head_works");
gpr_log(GPR_INFO, "length=%d", length);
@@ -155,7 +155,7 @@ static void test_slice_split_head_works(int length) {
beginning of the slice. */
slice = gpr_slice_malloc(length);
for (i = 0; i < length; i++) {
- GPR_SLICE_START_PTR(slice)[i] = i;
+ GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
}
/* Ensure that for all subsets length is correct and that we start on the
@@ -171,10 +171,10 @@ static void test_slice_split_head_works(int length) {
gpr_slice_unref(slice);
}
-static void test_slice_split_tail_works(int length) {
+static void test_slice_split_tail_works(size_t length) {
gpr_slice slice;
gpr_slice head, tail;
- int i;
+ size_t i;
LOG_TEST_NAME("test_slice_split_tail_works");
gpr_log(GPR_INFO, "length=%d", length);
@@ -183,7 +183,7 @@ static void test_slice_split_tail_works(int length) {
beginning of the slice. */
slice = gpr_slice_malloc(length);
for (i = 0; i < length; i++) {
- GPR_SLICE_START_PTR(slice)[i] = i;
+ GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
}
/* Ensure that for all subsets length is correct and that we start on the
diff --git a/test/core/support/stack_lockfree_test.c b/test/core/support/stack_lockfree_test.c
index 02ec3154d5..0f49e6fa52 100644
--- a/test/core/support/stack_lockfree_test.c
+++ b/test/core/support/stack_lockfree_test.c
@@ -46,9 +46,10 @@
#define MAX_THREADS 32
-static void test_serial_sized(int size) {
+static void test_serial_sized(size_t size) {
gpr_stack_lockfree *stack = gpr_stack_lockfree_create(size);
- int i;
+ size_t i;
+ size_t j;
/* First try popping empty */
GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1);
@@ -60,12 +61,11 @@ static void test_serial_sized(int size) {
/* Now add repeatedly more items and check them */
for (i = 1; i < size; i *= 2) {
- int j;
for (j = 0; j <= i; j++) {
- GPR_ASSERT(gpr_stack_lockfree_push(stack, j) == (j == 0));
+ GPR_ASSERT(gpr_stack_lockfree_push(stack, (int)j) == (j == 0));
}
for (j = 0; j <= i; j++) {
- GPR_ASSERT(gpr_stack_lockfree_pop(stack) == i - j);
+ GPR_ASSERT(gpr_stack_lockfree_pop(stack) == (int)(i - j));
}
GPR_ASSERT(gpr_stack_lockfree_pop(stack) == -1);
}
@@ -74,7 +74,7 @@ static void test_serial_sized(int size) {
}
static void test_serial() {
- int i;
+ size_t i;
for (i = 128; i < MAX_STACK_SIZE; i *= 2) {
test_serial_sized(i);
}
@@ -107,7 +107,7 @@ static void test_mt_body(void *v) {
}
}
-static void test_mt_sized(int size, int nth) {
+static void test_mt_sized(size_t size, int nth) {
gpr_stack_lockfree *stack;
struct test_arg args[MAX_THREADS];
gpr_thd_id thds[MAX_THREADS];
@@ -118,7 +118,7 @@ static void test_mt_sized(int size, int nth) {
stack = gpr_stack_lockfree_create(size);
for (i = 0; i < nth; i++) {
args[i].stack = stack;
- args[i].stack_size = size;
+ args[i].stack_size = (int)size;
args[i].nthreads = nth;
args[i].rank = i;
args[i].sum = 0;
@@ -137,7 +137,8 @@ static void test_mt_sized(int size, int nth) {
}
static void test_mt() {
- int size, nth;
+ size_t size;
+ int nth;
for (nth = 1; nth < MAX_THREADS; nth++) {
for (size = 128; size < MAX_STACK_SIZE; size *= 2) {
test_mt_sized(size, nth);
diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c
index 594863c278..ce35edd83c 100644
--- a/test/core/support/time_test.c
+++ b/test/core/support/time_test.c
@@ -43,14 +43,14 @@
#include <grpc/support/time.h>
#include "test/core/util/test_config.h"
-static void to_fp(void *arg, const char *buf, int len) {
+static void to_fp(void *arg, const char *buf, size_t len) {
fwrite(buf, 1, len, (FILE *)arg);
}
/* Convert gpr_uintmax x to ascii base b (2..16), and write with
(*writer)(arg, ...), zero padding to "chars" digits). */
static void u_to_s(gpr_uintmax x, unsigned base, int chars,
- void (*writer)(void *arg, const char *buf, int len),
+ void (*writer)(void *arg, const char *buf, size_t len),
void *arg) {
char buf[64];
char *p = buf + sizeof(buf);
@@ -59,25 +59,25 @@ static void u_to_s(gpr_uintmax x, unsigned base, int chars,
x /= base;
chars--;
} while (x != 0 || chars > 0);
- (*writer)(arg, p, buf + sizeof(buf) - p);
+ (*writer)(arg, p, (size_t)(buf + sizeof(buf) - p));
}
/* Convert gpr_intmax x to ascii base b (2..16), and write with
(*writer)(arg, ...), zero padding to "chars" digits). */
static void i_to_s(gpr_intmax x, unsigned base, int chars,
- void (*writer)(void *arg, const char *buf, int len),
+ void (*writer)(void *arg, const char *buf, size_t len),
void *arg) {
if (x < 0) {
(*writer)(arg, "-", 1);
- u_to_s(-x, base, chars - 1, writer, arg);
+ u_to_s((gpr_uintmax)-x, base, chars - 1, writer, arg);
} else {
- u_to_s(x, base, chars, writer, arg);
+ u_to_s((gpr_uintmax)x, base, chars, writer, arg);
}
}
/* Convert ts to ascii, and write with (*writer)(arg, ...). */
static void ts_to_s(gpr_timespec t,
- void (*writer)(void *arg, const char *buf, int len),
+ void (*writer)(void *arg, const char *buf, size_t len),
void *arg) {
if (t.tv_sec < 0 && t.tv_nsec != 0) {
t.tv_sec++;
@@ -96,7 +96,7 @@ static void test_values(void) {
x = gpr_inf_future(GPR_CLOCK_REALTIME);
fprintf(stderr, "far future ");
- u_to_s(x.tv_sec, 16, 16, &to_fp, stderr);
+ i_to_s(x.tv_sec, 16, 16, &to_fp, stderr);
fprintf(stderr, "\n");
GPR_ASSERT(x.tv_sec >= INT_MAX);
fprintf(stderr, "far future ");
@@ -105,7 +105,7 @@ static void test_values(void) {
x = gpr_inf_past(GPR_CLOCK_REALTIME);
fprintf(stderr, "far past ");
- u_to_s(x.tv_sec, 16, 16, &to_fp, stderr);
+ i_to_s(x.tv_sec, 16, 16, &to_fp, stderr);
fprintf(stderr, "\n");
GPR_ASSERT(x.tv_sec <= INT_MIN);
fprintf(stderr, "far past ");
diff --git a/test/core/surface/byte_buffer_reader_test.c b/test/core/surface/byte_buffer_reader_test.c
index d9c60e4212..560e0ac7b2 100644
--- a/test/core/surface/byte_buffer_reader_test.c
+++ b/test/core/surface/byte_buffer_reader_test.c
@@ -113,14 +113,14 @@ static void test_read_none_compressed_slice(void) {
}
static void read_compressed_slice(grpc_compression_algorithm algorithm,
- int input_size) {
+ size_t input_size) {
gpr_slice input_slice;
gpr_slice_buffer sliceb_in;
gpr_slice_buffer sliceb_out;
grpc_byte_buffer *buffer;
grpc_byte_buffer_reader reader;
gpr_slice read_slice;
- int read_count = 0;
+ size_t read_count = 0;
gpr_slice_buffer_init(&sliceb_in);
gpr_slice_buffer_init(&sliceb_out);
@@ -149,13 +149,13 @@ static void read_compressed_slice(grpc_compression_algorithm algorithm,
}
static void test_read_gzip_compressed_slice(void) {
- const int INPUT_SIZE = 2048;
+ const size_t INPUT_SIZE = 2048;
LOG_TEST("test_read_gzip_compressed_slice");
read_compressed_slice(GRPC_COMPRESS_GZIP, INPUT_SIZE);
}
static void test_read_deflate_compressed_slice(void) {
- const int INPUT_SIZE = 2048;
+ const size_t INPUT_SIZE = 2048;
LOG_TEST("test_read_deflate_compressed_slice");
read_compressed_slice(GRPC_COMPRESS_DEFLATE, INPUT_SIZE);
}
diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c
index a5298a25e0..0eeb5dac45 100644
--- a/test/core/surface/completion_queue_test.c
+++ b/test/core/surface/completion_queue_test.c
@@ -177,7 +177,7 @@ typedef struct test_thread_options {
gpr_event on_phase1_done;
gpr_event *phase2;
gpr_event on_finished;
- int events_triggered;
+ size_t events_triggered;
int id;
grpc_completion_queue *cc;
} test_thread_options;
@@ -251,14 +251,14 @@ static void consumer_thread(void *arg) {
}
}
-static void test_threading(int producers, int consumers) {
+static void test_threading(size_t producers, size_t consumers) {
test_thread_options *options =
gpr_malloc((producers + consumers) * sizeof(test_thread_options));
gpr_event phase1 = GPR_EVENT_INIT;
gpr_event phase2 = GPR_EVENT_INIT;
grpc_completion_queue *cc = grpc_completion_queue_create(NULL);
- int i;
- int total_consumed = 0;
+ size_t i;
+ size_t total_consumed = 0;
static int optid = 101;
gpr_log(GPR_INFO, "%s: %d producers, %d consumers", "test_threading",
@@ -325,7 +325,7 @@ static void test_threading(int producers, int consumers) {
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
- grpc_iomgr_init();
+ grpc_init();
test_no_op();
test_wait_empty();
test_shutdown_then_next_polling();
@@ -336,6 +336,6 @@ int main(int argc, char **argv) {
test_threading(1, 10);
test_threading(10, 1);
test_threading(10, 10);
- grpc_iomgr_shutdown();
+ grpc_shutdown();
return 0;
}
diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c
index 96434193c9..0d29bea555 100644
--- a/test/core/surface/lame_client_test.c
+++ b/test/core/surface/lame_client_test.c
@@ -82,7 +82,7 @@ int main(int argc, char **argv) {
op->flags = 0;
op->reserved = NULL;
op++;
- error = grpc_call_start_batch(call, ops, op - ops, tag(1), NULL);
+ error = grpc_call_start_batch(call, ops, (size_t)(op - ops), tag(1), NULL);
GPR_ASSERT(GRPC_CALL_OK == error);
/* the call should immediately fail */
diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c
index 15b37d17b6..aa3e273a6c 100644
--- a/test/core/transport/chttp2/hpack_table_test.c
+++ b/test/core/transport/chttp2/hpack_table_test.c
@@ -49,8 +49,8 @@ static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_mdstr *mdstr,
GPR_ASSERT(gpr_slice_str_cmp(mdstr->slice, str) == 0);
}
-static void assert_index(const grpc_chttp2_hptbl *tbl, int idx, const char *key,
- const char *value) {
+static void assert_index(const grpc_chttp2_hptbl *tbl, gpr_uint32 idx,
+ const char *key, const char *value) {
grpc_mdelem *md = grpc_chttp2_hptbl_lookup(tbl, idx);
assert_str(tbl, md->key, key);
assert_str(tbl, md->value, value);
diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c
index e6731ff195..71db98c69e 100644
--- a/test/core/transport/chttp2/stream_encoder_test.c
+++ b/test/core/transport/chttp2/stream_encoder_test.c
@@ -52,14 +52,14 @@ int g_failure = 0;
grpc_stream_op_buffer g_sopb;
void **to_delete = NULL;
-int num_to_delete = 0;
-int cap_to_delete = 0;
+size_t num_to_delete = 0;
+size_t cap_to_delete = 0;
static gpr_slice create_test_slice(size_t length) {
gpr_slice slice = gpr_slice_malloc(length);
size_t i;
for (i = 0; i < length; i++) {
- GPR_SLICE_START_PTR(slice)[i] = i;
+ GPR_SLICE_START_PTR(slice)[i] = (gpr_uint8)i;
}
return slice;
}
@@ -75,8 +75,8 @@ static void verify_sopb(size_t window_available, int eof,
gpr_slice_buffer_init(&output);
grpc_sopb_init(&encops);
GPR_ASSERT(expect_window_used ==
- grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops, window_available,
- &encops));
+ grpc_chttp2_preencode(g_sopb.ops, &g_sopb.nops,
+ (gpr_uint32)window_available, &encops));
grpc_chttp2_encode(encops.ops, encops.nops, eof, 0xdeadbeef, &g_compressor,
&output);
encops.nops = 0;
@@ -126,8 +126,8 @@ static void test_small_data_framing(void) {
verify_sopb(10, 0, 5, "000005 0000 deadbeef 00000000ff");
}
-static void add_sopb_headers(int n, ...) {
- int i;
+static void add_sopb_headers(size_t n, ...) {
+ size_t i;
grpc_metadata_batch b;
va_list l;
grpc_linked_mdelem *e = gpr_malloc(sizeof(*e) * n);
@@ -196,10 +196,10 @@ static void test_basic_headers(void) {
}
static void encode_int_to_str(int i, char *p) {
- p[0] = 'a' + i % 26;
+ p[0] = (char)('a' + i % 26);
i /= 26;
GPR_ASSERT(i < 26);
- p[1] = 'a' + i;
+ p[1] = (char)('a' + i);
p[2] = 0;
}
@@ -246,7 +246,7 @@ static void randstr(char *p, int bufsz) {
int i;
int len = 1 + rand() % bufsz;
for (i = 0; i < len; i++) {
- p[i] = 'a' + rand() % 26;
+ p[i] = (char)('a' + rand() % 26);
}
p[len] = 0;
}
@@ -336,7 +336,7 @@ static void run_test(void (*test)(), const char *name) {
}
int main(int argc, char **argv) {
- int i;
+ size_t i;
grpc_test_init(argc, argv);
TEST(test_small_data_framing);
TEST(test_basic_headers);
diff --git a/test/core/transport/chttp2/stream_map_test.c b/test/core/transport/chttp2/stream_map_test.c
index b0bb3a8904..81fb80f84f 100644
--- a/test/core/transport/chttp2/stream_map_test.c
+++ b/test/core/transport/chttp2/stream_map_test.c
@@ -82,9 +82,9 @@ static void test_double_deletion(void) {
}
/* test add & lookup */
-static void test_basic_add_find(size_t n) {
+static void test_basic_add_find(gpr_uint32 n) {
grpc_chttp2_stream_map map;
- size_t i;
+ gpr_uint32 i;
size_t got;
LOG_TEST("test_basic_add_find");
@@ -107,15 +107,15 @@ static void test_basic_add_find(size_t n) {
/* verify that for_each gets the right values during test_delete_evens_XXX */
static void verify_for_each(void *user_data, gpr_uint32 stream_id, void *ptr) {
- size_t *for_each_check = user_data;
+ gpr_uint32 *for_each_check = user_data;
GPR_ASSERT(ptr);
GPR_ASSERT(*for_each_check == stream_id);
*for_each_check += 2;
}
-static void check_delete_evens(grpc_chttp2_stream_map *map, size_t n) {
- size_t for_each_check = 1;
- size_t i;
+static void check_delete_evens(grpc_chttp2_stream_map *map, gpr_uint32 n) {
+ gpr_uint32 for_each_check = 1;
+ gpr_uint32 i;
size_t got;
GPR_ASSERT(NULL == grpc_chttp2_stream_map_find(map, 0));
@@ -139,9 +139,9 @@ static void check_delete_evens(grpc_chttp2_stream_map *map, size_t n) {
/* add a bunch of keys, delete the even ones, and make sure the map is
consistent */
-static void test_delete_evens_sweep(size_t n) {
+static void test_delete_evens_sweep(gpr_uint32 n) {
grpc_chttp2_stream_map map;
- size_t i;
+ gpr_uint32 i;
LOG_TEST("test_delete_evens_sweep");
gpr_log(GPR_INFO, "n = %d", n);
@@ -152,7 +152,8 @@ static void test_delete_evens_sweep(size_t n) {
}
for (i = 1; i <= n; i++) {
if ((i & 1) == 0) {
- GPR_ASSERT((void *)i == grpc_chttp2_stream_map_delete(&map, i));
+ GPR_ASSERT((void *)(gpr_uintptr)i ==
+ grpc_chttp2_stream_map_delete(&map, i));
}
}
check_delete_evens(&map, n);
@@ -161,9 +162,9 @@ static void test_delete_evens_sweep(size_t n) {
/* add a bunch of keys, delete the even ones immediately, and make sure the map
is consistent */
-static void test_delete_evens_incremental(size_t n) {
+static void test_delete_evens_incremental(gpr_uint32 n) {
grpc_chttp2_stream_map map;
- size_t i;
+ gpr_uint32 i;
LOG_TEST("test_delete_evens_incremental");
gpr_log(GPR_INFO, "n = %d", n);
@@ -181,10 +182,10 @@ static void test_delete_evens_incremental(size_t n) {
/* add a bunch of keys, delete old ones after some time, ensure the
backing array does not grow */
-static void test_periodic_compaction(size_t n) {
+static void test_periodic_compaction(gpr_uint32 n) {
grpc_chttp2_stream_map map;
- size_t i;
- size_t del;
+ gpr_uint32 i;
+ gpr_uint32 del;
LOG_TEST("test_periodic_compaction");
gpr_log(GPR_INFO, "n = %d", n);
@@ -192,10 +193,11 @@ static void test_periodic_compaction(size_t n) {
grpc_chttp2_stream_map_init(&map, 16);
GPR_ASSERT(map.capacity == 16);
for (i = 1; i <= n; i++) {
- grpc_chttp2_stream_map_add(&map, i, (void *)i);
+ grpc_chttp2_stream_map_add(&map, i, (void *)(gpr_uintptr)i);
if (i > 8) {
del = i - 8;
- GPR_ASSERT((void *)del == grpc_chttp2_stream_map_delete(&map, del));
+ GPR_ASSERT((void *)(gpr_uintptr)del ==
+ grpc_chttp2_stream_map_delete(&map, del));
}
}
GPR_ASSERT(map.capacity == 16);
@@ -203,9 +205,9 @@ static void test_periodic_compaction(size_t n) {
}
int main(int argc, char **argv) {
- int n = 1;
- int prev = 1;
- int tmp;
+ gpr_uint32 n = 1;
+ gpr_uint32 prev = 1;
+ gpr_uint32 tmp;
grpc_test_init(argc, argv);
diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c
index 4a4d4bcb8a..1861442bb1 100644
--- a/test/core/transport/metadata_test.c
+++ b/test/core/transport/metadata_test.c
@@ -177,11 +177,11 @@ static void test_spin_creating_the_same_thing(void) {
static void test_things_stick_around(void) {
grpc_mdctx *ctx;
- int i, j;
+ size_t i, j;
char *buffer;
- int nstrs = 1000;
+ size_t nstrs = 1000;
grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs);
- int *shuf = gpr_malloc(sizeof(int) * nstrs);
+ size_t *shuf = gpr_malloc(sizeof(size_t) * nstrs);
grpc_mdstr *test;
LOG_TEST("test_things_stick_around");
@@ -201,9 +201,9 @@ static void test_things_stick_around(void) {
}
for (i = 0; i < nstrs; i++) {
- int p = rand() % nstrs;
- int q = rand() % nstrs;
- int temp = shuf[p];
+ size_t p = (size_t)rand() % nstrs;
+ size_t q = (size_t)rand() % nstrs;
+ size_t temp = shuf[p];
shuf[p] = shuf[q];
shuf[q] = temp;
}
diff --git a/test/core/util/parse_hexstring.c b/test/core/util/parse_hexstring.c
index bf5bc84b48..eced3173d1 100644
--- a/test/core/util/parse_hexstring.c
+++ b/test/core/util/parse_hexstring.c
@@ -35,7 +35,7 @@
#include <grpc/support/log.h>
gpr_slice parse_hexstring(const char *hexstring) {
- int nibbles = 0;
+ size_t nibbles = 0;
const char *p = 0;
gpr_uint8 *out;
gpr_uint8 temp;
@@ -54,10 +54,10 @@ gpr_slice parse_hexstring(const char *hexstring) {
temp = 0;
for (p = hexstring; *p; p++) {
if (*p >= '0' && *p <= '9') {
- temp = (temp << 4) | (*p - '0');
+ temp = (gpr_uint8)(temp << 4) | (gpr_uint8)(*p - '0');
nibbles++;
} else if (*p >= 'a' && *p <= 'f') {
- temp = (temp << 4) | (*p - 'a' + 10);
+ temp = (gpr_uint8)(temp << 4) | (gpr_uint8)(*p - 'a' + 10);
nibbles++;
}
if (nibbles == 2) {
diff --git a/test/core/util/port_posix.c b/test/core/util/port_posix.c
index 836e62a541..03f4c4912e 100644
--- a/test/core/util/port_posix.c
+++ b/test/core/util/port_posix.c
@@ -47,6 +47,7 @@
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include <grpc/support/string_util.h>
#include "src/core/httpcli/httpcli.h"
#include "src/core/support/env.h"
@@ -66,7 +67,70 @@ static int has_port_been_chosen(int port) {
return 0;
}
-static void free_chosen_ports() { gpr_free(chosen_ports); }
+typedef struct freereq {
+ grpc_pollset pollset;
+ int done;
+} freereq;
+
+static void destroy_pollset_and_shutdown(void *p) {
+ grpc_pollset_destroy(p);
+ grpc_shutdown();
+}
+
+static void freed_port_from_server(void *arg,
+ const grpc_httpcli_response *response) {
+ freereq *pr = arg;
+ gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset));
+ pr->done = 1;
+ grpc_pollset_kick(&pr->pollset, NULL);
+ gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset));
+}
+
+static void free_port_using_server(char *server, int port) {
+ grpc_httpcli_context context;
+ grpc_httpcli_request req;
+ freereq pr;
+ char *path;
+
+ grpc_init();
+
+ memset(&pr, 0, sizeof(pr));
+ memset(&req, 0, sizeof(req));
+ grpc_pollset_init(&pr.pollset);
+
+ req.host = server;
+ gpr_asprintf(&path, "/drop/%d", port);
+ req.path = path;
+
+ grpc_httpcli_context_init(&context);
+ grpc_httpcli_get(&context, &pr.pollset, &req,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), freed_port_from_server,
+ &pr);
+ gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset));
+ while (!pr.done) {
+ grpc_pollset_worker worker;
+ grpc_pollset_work(&pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC),
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
+ }
+ gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset));
+
+ grpc_httpcli_context_destroy(&context);
+ grpc_pollset_shutdown(&pr.pollset, destroy_pollset_and_shutdown, &pr.pollset);
+ gpr_free(path);
+}
+
+static void free_chosen_ports() {
+ char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
+ if (env != NULL) {
+ size_t i;
+ for (i = 0; i < num_chosen_ports; i++) {
+ free_port_using_server(env, chosen_ports[i]);
+ }
+ gpr_free(env);
+ }
+
+ gpr_free(chosen_ports);
+}
static void chose_port(int port) {
if (chosen_ports == NULL) {
@@ -102,7 +166,7 @@ static int is_port_available(int *port, int is_tcp) {
/* Try binding to port */
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = INADDR_ANY;
- addr.sin_port = htons(*port);
+ addr.sin_port = htons((gpr_uint16)*port);
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
gpr_log(GPR_DEBUG, "bind(port=%d) failed: %s", *port, strerror(errno));
close(fd);
@@ -131,6 +195,9 @@ static int is_port_available(int *port, int is_tcp) {
typedef struct portreq {
grpc_pollset pollset;
int port;
+ int retries;
+ char *server;
+ grpc_httpcli_context *ctx;
} portreq;
static void got_port_from_server(void *arg,
@@ -138,6 +205,19 @@ static void got_port_from_server(void *arg,
size_t i;
int port = 0;
portreq *pr = arg;
+ if (!response || response->status != 200) {
+ grpc_httpcli_request req;
+ memset(&req, 0, sizeof(req));
+ GPR_ASSERT(pr->retries < 10);
+ pr->retries++;
+ req.host = pr->server;
+ req.path = "/get";
+ gpr_log(GPR_DEBUG, "failed port pick from server: retrying");
+ sleep(1);
+ grpc_httpcli_get(pr->ctx, &pr->pollset, &req, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10),
+ got_port_from_server, pr);
+ return;
+ }
GPR_ASSERT(response);
GPR_ASSERT(response->status == 200);
for (i = 0; i < response->body_length; i++) {
@@ -151,11 +231,6 @@ static void got_port_from_server(void *arg,
gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset));
}
-static void destroy_pollset_and_shutdown(void *p) {
- grpc_pollset_destroy(p);
- grpc_shutdown();
-}
-
static int pick_port_using_server(char *server) {
grpc_httpcli_context context;
grpc_httpcli_request req;
@@ -167,6 +242,8 @@ static int pick_port_using_server(char *server) {
memset(&req, 0, sizeof(req));
grpc_pollset_init(&pr.pollset);
pr.port = -1;
+ pr.server = server;
+ pr.ctx = &context;
req.host = server;
req.path = "/get";
@@ -198,31 +275,30 @@ int grpc_pick_unused_port(void) {
races with other processes on kernels that want to reuse the same
port numbers over and over. */
- /* In alternating iterations we try UDP ports before TCP ports UDP
+ /* In alternating iterations we trial UDP ports before TCP ports UDP
ports -- it could be the case that this machine has been using up
UDP ports and they are scarcer. */
/* Type of port to first pick in next iteration */
int is_tcp = 1;
- int try
- = 0;
+ int trial = 0;
char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
if (env) {
int port = pick_port_using_server(env);
gpr_free(env);
if (port != 0) {
- return port;
+ chose_port(port);
}
+ return port;
}
for (;;) {
int port;
- try
- ++;
- if (try == 1) {
+ trial++;
+ if (trial == 1) {
port = getpid() % (65536 - 30000) + 30000;
- } else if (try <= NUM_RANDOM_PORTS_TO_PICK) {
+ } else if (trial <= NUM_RANDOM_PORTS_TO_PICK) {
port = rand() % (65536 - 30000) + 30000;
} else {
port = 0;
@@ -239,7 +315,7 @@ int grpc_pick_unused_port(void) {
GPR_ASSERT(port > 0);
/* Check that the port # is free for the other type of socket also */
if (!is_port_available(&port, !is_tcp)) {
- /* In the next iteration try to bind to the other type first
+ /* In the next iteration trial to bind to the other type first
because perhaps it is more rare. */
is_tcp = !is_tcp;
continue;
diff --git a/test/core/util/port_windows.c b/test/core/util/port_windows.c
index 5b072f805a..a57fe692e1 100644
--- a/test/core/util/port_windows.c
+++ b/test/core/util/port_windows.c
@@ -35,7 +35,6 @@
#include "test/core/util/test_config.h"
#if defined(GPR_WINSOCK_SOCKET) && defined(GRPC_TEST_PICK_PORT)
-#include "src/core/iomgr/sockaddr_utils.h"
#include "test/core/util/port.h"
#include <process.h>
@@ -43,10 +42,40 @@
#include <errno.h>
#include <string.h>
+#include <grpc/grpc.h>
+#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include "src/core/support/env.h"
+#include "src/core/httpcli/httpcli.h"
+#include "src/core/iomgr/sockaddr_utils.h"
+
#define NUM_RANDOM_PORTS_TO_PICK 100
+static int *chosen_ports = NULL;
+static size_t num_chosen_ports = 0;
+
+static int has_port_been_chosen(int port) {
+ size_t i;
+ for (i = 0; i < num_chosen_ports; i++) {
+ if (chosen_ports[i] == port) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+static void free_chosen_ports() { gpr_free(chosen_ports); }
+
+static void chose_port(int port) {
+ if (chosen_ports == NULL) {
+ atexit(free_chosen_ports);
+ }
+ num_chosen_ports++;
+ chosen_ports = gpr_realloc(chosen_ports, sizeof(int) * num_chosen_ports);
+ chosen_ports[num_chosen_ports - 1] = port;
+}
+
static int is_port_available(int *port, int is_tcp) {
const int proto = is_tcp ? IPPROTO_TCP : 0;
const SOCKET fd = socket(AF_INET, is_tcp ? SOCK_STREAM : SOCK_DGRAM, proto);
@@ -99,6 +128,67 @@ static int is_port_available(int *port, int is_tcp) {
return 1;
}
+typedef struct portreq {
+ grpc_pollset pollset;
+ int port;
+} portreq;
+
+static void got_port_from_server(void *arg,
+ const grpc_httpcli_response *response) {
+ size_t i;
+ int port = 0;
+ portreq *pr = arg;
+ GPR_ASSERT(response);
+ GPR_ASSERT(response->status == 200);
+ for (i = 0; i < response->body_length; i++) {
+ GPR_ASSERT(response->body[i] >= '0' && response->body[i] <= '9');
+ port = port * 10 + response->body[i] - '0';
+ }
+ GPR_ASSERT(port > 1024);
+ gpr_mu_lock(GRPC_POLLSET_MU(&pr->pollset));
+ pr->port = port;
+ grpc_pollset_kick(&pr->pollset, NULL);
+ gpr_mu_unlock(GRPC_POLLSET_MU(&pr->pollset));
+}
+
+static void destroy_pollset_and_shutdown(void *p) {
+ grpc_pollset_destroy(p);
+ grpc_shutdown();
+}
+
+static int pick_port_using_server(char *server) {
+ grpc_httpcli_context context;
+ grpc_httpcli_request req;
+ portreq pr;
+
+ grpc_init();
+
+ memset(&pr, 0, sizeof(pr));
+ memset(&req, 0, sizeof(req));
+ grpc_pollset_init(&pr.pollset);
+ pr.port = -1;
+
+ req.host = server;
+ req.path = "/get";
+
+ grpc_httpcli_context_init(&context);
+ grpc_httpcli_get(&context, &pr.pollset, &req,
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(10), got_port_from_server,
+ &pr);
+ gpr_mu_lock(GRPC_POLLSET_MU(&pr.pollset));
+ while (pr.port == -1) {
+ grpc_pollset_worker worker;
+ grpc_pollset_work(&pr.pollset, &worker, gpr_now(GPR_CLOCK_MONOTONIC),
+ GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1));
+ }
+ gpr_mu_unlock(GRPC_POLLSET_MU(&pr.pollset));
+
+ grpc_httpcli_context_destroy(&context);
+ grpc_pollset_shutdown(&pr.pollset, destroy_pollset_and_shutdown, &pr.pollset);
+
+ return pr.port;
+}
+
int grpc_pick_unused_port(void) {
/* We repeatedly pick a port and then see whether or not it is
available for use both as a TCP socket and a UDP socket. First, we
@@ -108,27 +198,38 @@ int grpc_pick_unused_port(void) {
races with other processes on kernels that want to reuse the same
port numbers over and over. */
- /* In alternating iterations we try UDP ports before TCP ports UDP
+ /* In alternating iterations we trial UDP ports before TCP ports UDP
ports -- it could be the case that this machine has been using up
UDP ports and they are scarcer. */
/* Type of port to first pick in next iteration */
int is_tcp = 1;
- int try
- = 0;
+ int trial = 0;
+
+ char *env = gpr_getenv("GRPC_TEST_PORT_SERVER");
+ if (env) {
+ int port = pick_port_using_server(env);
+ gpr_free(env);
+ if (port != 0) {
+ return port;
+ }
+ }
for (;;) {
int port;
- try
- ++;
- if (try == 1) {
+ trial++;
+ if (trial == 1) {
port = _getpid() % (65536 - 30000) + 30000;
- } else if (try <= NUM_RANDOM_PORTS_TO_PICK) {
+ } else if (trial <= NUM_RANDOM_PORTS_TO_PICK) {
port = rand() % (65536 - 30000) + 30000;
} else {
port = 0;
}
+ if (has_port_been_chosen(port)) {
+ continue;
+ }
+
if (!is_port_available(&port, is_tcp)) {
continue;
}
@@ -136,7 +237,7 @@ int grpc_pick_unused_port(void) {
GPR_ASSERT(port > 0);
/* Check that the port # is free for the other type of socket also */
if (!is_port_available(&port, !is_tcp)) {
- /* In the next iteration try to bind to the other type first
+ /* In the next iteration trial to bind to the other type first
because perhaps it is more rare. */
is_tcp = !is_tcp;
continue;
@@ -145,6 +246,7 @@ int grpc_pick_unused_port(void) {
/* TODO(ctiller): consider caching this port in some structure, to avoid
handing it out again */
+ chose_port(port);
return port;
}
diff --git a/test/core/util/reconnect_server.c b/test/core/util/reconnect_server.c
index a06cb50b3a..71fb69b54f 100644
--- a/test/core/util/reconnect_server.c
+++ b/test/core/util/reconnect_server.c
@@ -33,7 +33,6 @@
#include "test/core/util/reconnect_server.h"
-#include <arpa/inet.h>
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/host_port.h>
@@ -42,6 +41,7 @@
#include <grpc/support/time.h>
#include <string.h>
#include "src/core/iomgr/endpoint.h"
+#include "src/core/iomgr/sockaddr.h"
#include "src/core/iomgr/tcp_server.h"
#include "test/core/util/port.h"
@@ -81,7 +81,8 @@ static void on_connect(void *arg, grpc_endpoint *tcp) {
} else {
if (last_colon == NULL) {
gpr_log(GPR_ERROR, "peer does not contain a ':'");
- } else if (strncmp(server->peer, peer, last_colon - peer) != 0) {
+ } else if (strncmp(server->peer, peer, (size_t)(last_colon - peer)) !=
+ 0) {
gpr_log(GPR_ERROR, "mismatched peer! %s vs %s", server->peer, peer);
}
gpr_free(peer);
@@ -115,8 +116,8 @@ void reconnect_server_start(reconnect_server *server, int port) {
int port_added;
addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- inet_pton(AF_INET, "0.0.0.0", &addr.sin_addr);
+ addr.sin_port = htons((gpr_uint16)port);
+ memset(&addr.sin_addr, 0, sizeof(addr.sin_addr));
server->tcp_server = grpc_tcp_server_create();
port_added =
diff --git a/test/core/util/test_config.c b/test/core/util/test_config.c
index 685bdff530..f5d5cdb57c 100644
--- a/test/core/util/test_config.c
+++ b/test/core/util/test_config.c
@@ -42,12 +42,12 @@ double g_fixture_slowdown_factor = 1.0;
#if GPR_GETPID_IN_UNISTD_H
#include <unistd.h>
-static int seed(void) { return getpid(); }
+static unsigned seed(void) { return (unsigned)getpid(); }
#endif
#if GPR_GETPID_IN_PROCESS_H
#include <process.h>
-static int seed(void) { return _getpid(); }
+static unsigned seed(void) { return _getpid(); }
#endif
#if GPR_WINDOWS_CRASH_HANDLER
diff --git a/test/core/util/test_config.h b/test/core/util/test_config.h
index ccef8620c1..15b71747fb 100644
--- a/test/core/util/test_config.h
+++ b/test/core/util/test_config.h
@@ -54,15 +54,17 @@ extern double g_fixture_slowdown_factor;
(GRPC_TEST_SLOWDOWN_BUILD_FACTOR * GRPC_TEST_SLOWDOWN_MACHINE_FACTOR * \
g_fixture_slowdown_factor)
-#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \
- gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \
- gpr_time_from_millis(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \
- GPR_TIMESPAN))
+#define GRPC_TIMEOUT_SECONDS_TO_DEADLINE(x) \
+ gpr_time_add( \
+ gpr_now(GPR_CLOCK_MONOTONIC), \
+ gpr_time_from_millis((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \
+ GPR_TIMESPAN))
-#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \
- gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), \
- gpr_time_from_micros(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x), \
- GPR_TIMESPAN))
+#define GRPC_TIMEOUT_MILLIS_TO_DEADLINE(x) \
+ gpr_time_add( \
+ gpr_now(GPR_CLOCK_MONOTONIC), \
+ gpr_time_from_micros((long)(GRPC_TEST_SLOWDOWN_FACTOR * 1e3 * (x)), \
+ GPR_TIMESPAN))
#ifndef GRPC_TEST_CUSTOM_PICK_PORT
#define GRPC_TEST_PICK_PORT