aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Robbie Shade <rjshade@google.com>2015-09-14 13:21:12 -0400
committerGravatar Robbie Shade <rjshade@google.com>2015-09-14 13:21:12 -0400
commitbb84dc00048a9709d7a01d295235d55b540e0a56 (patch)
treed988b6bc41d9edebe256f996ea810901f4ea30dd /test
parentc8cb4ed45d8ce33ede9611e903d3e6e6b28c490f (diff)
parent261666696496174f824d9e43a60559040eda3055 (diff)
Merge remote-tracking branch 'upstream/master' into remove_udp_new_transport_cb
Diffstat (limited to 'test')
-rw-r--r--test/build/empty.c34
-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)2
-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)45
-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)2
-rw-r--r--test/core/end2end/fixtures/h2_ssl.c (renamed from test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c)2
-rw-r--r--test/core/end2end/fixtures/h2_ssl_proxy.c (renamed from test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c)2
-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)16
-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.c4
-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/credentials_test.c185
-rw-r--r--test/core/security/fetch_oauth2.c47
-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.c16
-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
-rw-r--r--test/cpp/client/credentials_test.cc6
-rw-r--r--test/cpp/common/auth_property_iterator_test.cc2
-rw-r--r--test/cpp/common/secure_auth_context_test.cc24
-rw-r--r--test/cpp/end2end/async_end2end_test.cc7
-rw-r--r--test/cpp/end2end/client_crash_test.cc2
-rw-r--r--test/cpp/end2end/client_crash_test_server.cc1
-rw-r--r--test/cpp/end2end/end2end_test.cc192
-rw-r--r--test/cpp/end2end/generic_end2end_test.cc2
-rw-r--r--test/cpp/end2end/mock_test.cc4
-rw-r--r--test/cpp/end2end/server_crash_test.cc2
-rw-r--r--test/cpp/end2end/server_crash_test_client.cc1
-rw-r--r--test/cpp/end2end/shutdown_test.cc4
-rw-r--r--test/cpp/end2end/streaming_throughput_test.cc189
-rw-r--r--test/cpp/end2end/thread_stress_test.cc4
-rw-r--r--test/cpp/end2end/zookeeper_test.cc2
-rw-r--r--test/cpp/interop/client.cc18
-rw-r--r--test/cpp/interop/client_helper.cc22
-rw-r--r--test/cpp/interop/interop_client.cc41
-rw-r--r--test/cpp/interop/interop_client.h8
-rw-r--r--test/cpp/interop/reconnect_interop_server.cc1
-rw-r--r--test/cpp/interop/server.cc2
-rw-r--r--test/cpp/interop/server_helper.cc2
-rw-r--r--test/cpp/interop/server_helper.h2
-rw-r--r--test/cpp/qps/client_sync.cc2
-rw-r--r--test/cpp/qps/driver.cc13
-rw-r--r--test/cpp/qps/perf_db_client.h2
-rw-r--r--test/cpp/qps/qps_worker.cc4
-rw-r--r--test/cpp/qps/server_async.cc11
-rw-r--r--test/cpp/qps/server_sync.cc4
-rw-r--r--test/cpp/util/cli_call_test.cc4
-rw-r--r--test/cpp/util/create_test_channel.cc2
-rw-r--r--test/cpp/util/create_test_channel.h2
-rw-r--r--test/cpp/util/grpc_cli.cc4
-rw-r--r--test/cpp/util/messages.proto1
122 files changed, 1324 insertions, 1043 deletions
diff --git a/test/build/empty.c b/test/build/empty.c
new file mode 100644
index 0000000000..58e4698aee
--- /dev/null
+++ b/test/build/empty.c
@@ -0,0 +1,34 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+int main(void) {}
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 b4a248fb52..3e64cc08e8 100644
--- a/test/core/end2end/fixtures/chttp2_fake_security.c
+++ b/test/core/end2end/fixtures/h2_fakesec.c
@@ -128,7 +128,7 @@ static void chttp2_init_server_fake_secure_fullstack(
grpc_server_credentials *fake_ts_creds =
grpc_fake_transport_security_server_credentials_create();
if (fail_server_auth_check(server_args)) {
- grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL};
grpc_server_credentials_set_auth_metadata_processor(fake_ts_creds,
processor);
}
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 9a545b1e3d..e61e276fff 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_with_oauth2_fullstack.c
+++ b/test/core/end2end/fixtures/h2_oauth2.c
@@ -67,13 +67,21 @@ static const grpc_metadata *find_metadata(const grpc_metadata *md,
return NULL;
}
+typedef struct {
+ size_t pseudo_refcount;
+} test_processor_state;
+
static void process_oauth2_success(void *state, grpc_auth_context *ctx,
const grpc_metadata *md, size_t md_count,
grpc_process_auth_metadata_done_cb cb,
void *user_data) {
const grpc_metadata *oauth2 =
find_metadata(md, md_count, "Authorization", oauth2_md);
- GPR_ASSERT(state == NULL);
+ test_processor_state *s;
+
+ GPR_ASSERT(state != NULL);
+ s = (test_processor_state *)state;
+ GPR_ASSERT(s->pseudo_refcount == 1);
GPR_ASSERT(oauth2 != NULL);
grpc_auth_context_add_cstring_property(ctx, client_identity_property_name,
client_identity);
@@ -88,7 +96,10 @@ static void process_oauth2_failure(void *state, grpc_auth_context *ctx,
void *user_data) {
const grpc_metadata *oauth2 =
find_metadata(md, md_count, "Authorization", oauth2_md);
- GPR_ASSERT(state == NULL);
+ test_processor_state *s;
+ GPR_ASSERT(state != NULL);
+ s = (test_processor_state *)state;
+ GPR_ASSERT(s->pseudo_refcount == 1);
GPR_ASSERT(oauth2 != NULL);
cb(user_data, oauth2, 1, NULL, 0, GRPC_STATUS_UNAUTHENTICATED, NULL);
}
@@ -171,20 +182,34 @@ static int fail_server_auth_check(grpc_channel_args *server_args) {
return 0;
}
+static void processor_destroy(void *state) {
+ test_processor_state *s = (test_processor_state *)state;
+ GPR_ASSERT((s->pseudo_refcount--) == 1);
+ gpr_free(s);
+}
+
+static grpc_auth_metadata_processor test_processor_create(int failing) {
+ test_processor_state *s = gpr_malloc(sizeof(*s));
+ grpc_auth_metadata_processor result;
+ s->pseudo_refcount = 1;
+ result.state = s;
+ result.destroy = processor_destroy;
+ if (failing) {
+ result.process = process_oauth2_failure;
+ } else {
+ result.process = process_oauth2_success;
+ }
+ return result;
+}
+
static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_end2end_test_fixture *f, grpc_channel_args *server_args) {
grpc_ssl_pem_key_cert_pair pem_key_cert_pair = {test_server1_key,
test_server1_cert};
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_key_cert_pair, 1, 0, NULL);
- grpc_auth_metadata_processor processor;
- processor.state = NULL;
- if (fail_server_auth_check(server_args)) {
- processor.process = process_oauth2_failure;
- } else {
- processor.process = process_oauth2_success;
- }
- grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
+ grpc_server_credentials_set_auth_metadata_processor(
+ ssl_creds, test_processor_create(fail_server_auth_check(server_args)));
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
}
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 e7375f15e6..2c605d1471 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_poll.c
+++ b/test/core/end2end/fixtures/h2_ssl+poll.c
@@ -138,7 +138,7 @@ static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
if (fail_server_auth_check(server_args)) {
- grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c b/test/core/end2end/fixtures/h2_ssl.c
index 201d202dff..9193a09b17 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack.c
+++ b/test/core/end2end/fixtures/h2_ssl.c
@@ -138,7 +138,7 @@ static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
if (fail_server_auth_check(server_args)) {
- grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
diff --git a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c b/test/core/end2end/fixtures/h2_ssl_proxy.c
index be0dda25a6..8133a69a0c 100644
--- a/test/core/end2end/fixtures/chttp2_simple_ssl_fullstack_with_proxy.c
+++ b/test/core/end2end/fixtures/h2_ssl_proxy.c
@@ -167,7 +167,7 @@ static void chttp2_init_server_simple_ssl_secure_fullstack(
grpc_server_credentials *ssl_creds =
grpc_ssl_server_credentials_create(NULL, &pem_cert_key_pair, 1, 0, NULL);
if (fail_server_auth_check(server_args)) {
- grpc_auth_metadata_processor processor = {process_auth_failure, NULL};
+ grpc_auth_metadata_processor processor = {process_auth_failure, NULL, NULL};
grpc_server_credentials_set_auth_metadata_processor(ssl_creds, processor);
}
chttp2_init_server_secure_fullstack(f, server_args, ssl_creds);
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 48dd0aa2ce..4e905aafc7 100644
--- a/test/core/end2end/tests/request_response_with_payload_and_call_creds.c
+++ b/test/core/end2end/tests/call_creds.c
@@ -190,7 +190,7 @@ static void request_response_with_payload_and_call_creds(
c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq,
"/foo", "foo.test.google.fr", deadline, NULL);
GPR_ASSERT(c);
- creds = grpc_iam_credentials_create(iam_token, iam_selector, NULL);
+ creds = grpc_google_iam_credentials_create(iam_token, iam_selector, NULL);
GPR_ASSERT(creds != NULL);
GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK);
switch (mode) {
@@ -198,8 +198,8 @@ static void request_response_with_payload_and_call_creds(
break;
case OVERRIDE:
grpc_credentials_release(creds);
- creds = grpc_iam_credentials_create(overridden_iam_token,
- overridden_iam_selector, NULL);
+ creds = grpc_google_iam_credentials_create(overridden_iam_token,
+ overridden_iam_selector, NULL);
GPR_ASSERT(creds != NULL);
GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK);
break;
@@ -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);
@@ -421,7 +421,7 @@ static void test_request_with_server_rejecting_client_creds(
"/foo", "foo.test.google.fr", deadline, NULL);
GPR_ASSERT(c);
- creds = grpc_iam_credentials_create(iam_token, iam_selector, NULL);
+ creds = grpc_google_iam_credentials_create(iam_token, iam_selector, NULL);
GPR_ASSERT(creds != NULL);
GPR_ASSERT(grpc_call_set_credentials(c, creds) == GRPC_CALL_OK);
grpc_credentials_release(creds);
@@ -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 58f63390b0..10f236e945 100644
--- a/test/core/iomgr/udp_server_test.c
+++ b/test/core/iomgr/udp_server_test.c
@@ -51,13 +51,13 @@ static int g_number_of_bytes_read = 0;
static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) {
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));
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/credentials_test.c b/test/core/security/credentials_test.c
index 880fc5da1e..97ebaa0570 100644
--- a/test/core/security/credentials_test.c
+++ b/test/core/security/credentials_test.c
@@ -50,8 +50,8 @@
#include <openssl/rsa.h>
-static const char test_iam_authorization_token[] = "blahblahblhahb";
-static const char test_iam_authority_selector[] = "respectmyauthoritah";
+static const char test_google_iam_authorization_token[] = "blahblahblhahb";
+static const char test_google_iam_authority_selector[] = "respectmyauthoritah";
static const char test_oauth2_bearer_token[] =
"Bearer blaaslkdjfaslkdfasdsfasf";
static const char test_root_cert[] = "I am the root!";
@@ -315,25 +315,29 @@ static void check_metadata(expected_md *expected, grpc_credentials_md *md_elems,
}
}
-static void check_iam_metadata(void *user_data, grpc_credentials_md *md_elems,
- size_t num_md, grpc_credentials_status status) {
+static void check_google_iam_metadata(void *user_data,
+ grpc_credentials_md *md_elems,
+ size_t num_md,
+ grpc_credentials_status status) {
grpc_credentials *c = (grpc_credentials *)user_data;
- expected_md emd[] = {
- {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_iam_authorization_token},
- {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, test_iam_authority_selector}};
+ expected_md emd[] = {{GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
+ test_google_iam_authorization_token},
+ {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
+ test_google_iam_authority_selector}};
GPR_ASSERT(status == GRPC_CREDENTIALS_OK);
GPR_ASSERT(num_md == 2);
check_metadata(emd, md_elems, num_md);
grpc_credentials_unref(c);
}
-static void test_iam_creds(void) {
- grpc_credentials *creds = grpc_iam_credentials_create(
- test_iam_authorization_token, test_iam_authority_selector, NULL);
+static void test_google_iam_creds(void) {
+ grpc_credentials *creds = grpc_google_iam_credentials_create(
+ test_google_iam_authorization_token, test_google_iam_authority_selector,
+ NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(creds));
grpc_credentials_get_request_metadata(creds, NULL, test_service_url,
- check_iam_metadata, creds);
+ check_google_iam_metadata, creds);
}
static void check_access_token_metadata(void *user_data,
@@ -406,21 +410,23 @@ void test_ssl_fake_transport_security_composite_creds_failure(void) {
grpc_credentials_unref(fake_transport_security_creds);
}
-static void check_ssl_oauth2_iam_composite_metadata(
+static void check_ssl_oauth2_google_iam_composite_metadata(
void *user_data, grpc_credentials_md *md_elems, size_t num_md,
grpc_credentials_status status) {
grpc_credentials *c = (grpc_credentials *)user_data;
expected_md emd[] = {
{GRPC_AUTHORIZATION_METADATA_KEY, test_oauth2_bearer_token},
- {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY, test_iam_authorization_token},
- {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY, test_iam_authority_selector}};
+ {GRPC_IAM_AUTHORIZATION_TOKEN_METADATA_KEY,
+ test_google_iam_authorization_token},
+ {GRPC_IAM_AUTHORITY_SELECTOR_METADATA_KEY,
+ test_google_iam_authority_selector}};
GPR_ASSERT(status == GRPC_CREDENTIALS_OK);
GPR_ASSERT(num_md == 3);
check_metadata(emd, md_elems, num_md);
grpc_credentials_unref(c);
}
-static void test_ssl_oauth2_iam_composite_creds(void) {
+static void test_ssl_oauth2_google_iam_composite_creds(void) {
grpc_credentials *ssl_creds =
grpc_ssl_credentials_create(test_root_cert, NULL, NULL);
const grpc_credentials_array *creds_array;
@@ -428,14 +434,15 @@ static void test_ssl_oauth2_iam_composite_creds(void) {
"Authorization", test_oauth2_bearer_token, 0);
grpc_credentials *aux_creds =
grpc_composite_credentials_create(ssl_creds, oauth2_creds, NULL);
- grpc_credentials *iam_creds = grpc_iam_credentials_create(
- test_iam_authorization_token, test_iam_authority_selector, NULL);
+ grpc_credentials *google_iam_creds = grpc_google_iam_credentials_create(
+ test_google_iam_authorization_token, test_google_iam_authority_selector,
+ NULL);
grpc_credentials *composite_creds =
- grpc_composite_credentials_create(aux_creds, iam_creds, NULL);
+ grpc_composite_credentials_create(aux_creds, google_iam_creds, NULL);
grpc_credentials_unref(ssl_creds);
grpc_credentials_unref(oauth2_creds);
grpc_credentials_unref(aux_creds);
- grpc_credentials_unref(iam_creds);
+ grpc_credentials_unref(google_iam_creds);
GPR_ASSERT(strcmp(composite_creds->type, GRPC_CREDENTIALS_TYPE_COMPOSITE) ==
0);
GPR_ASSERT(grpc_credentials_has_request_metadata(composite_creds));
@@ -448,9 +455,9 @@ static void test_ssl_oauth2_iam_composite_creds(void) {
GRPC_CREDENTIALS_TYPE_OAUTH2) == 0);
GPR_ASSERT(strcmp(creds_array->creds_array[2]->type,
GRPC_CREDENTIALS_TYPE_IAM) == 0);
- grpc_credentials_get_request_metadata(composite_creds, NULL, test_service_url,
- check_ssl_oauth2_iam_composite_metadata,
- composite_creds);
+ grpc_credentials_get_request_metadata(
+ composite_creds, NULL, test_service_url,
+ check_ssl_oauth2_google_iam_composite_metadata, composite_creds);
}
static void on_oauth2_creds_get_metadata_success(
@@ -524,7 +531,7 @@ static int httpcli_get_should_not_be_called(
static void test_compute_engine_creds_success(void) {
grpc_credentials *compute_engine_creds =
- grpc_compute_engine_credentials_create(NULL);
+ grpc_google_compute_engine_credentials_create(NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(compute_engine_creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(compute_engine_creds));
@@ -548,7 +555,7 @@ static void test_compute_engine_creds_success(void) {
static void test_compute_engine_creds_failure(void) {
grpc_credentials *compute_engine_creds =
- grpc_compute_engine_credentials_create(NULL);
+ grpc_google_compute_engine_credentials_create(NULL);
grpc_httpcli_set_override(compute_engine_httpcli_get_failure_override,
httpcli_post_should_not_be_called);
GPR_ASSERT(grpc_credentials_has_request_metadata(compute_engine_creds));
@@ -605,7 +612,8 @@ static int refresh_token_httpcli_post_failure(
static void test_refresh_token_creds_success(void) {
grpc_credentials *refresh_token_creds =
- grpc_refresh_token_credentials_create(test_refresh_token_str, NULL);
+ grpc_google_refresh_token_credentials_create(test_refresh_token_str,
+ NULL);
GPR_ASSERT(grpc_credentials_has_request_metadata(refresh_token_creds));
GPR_ASSERT(grpc_credentials_has_request_metadata_only(refresh_token_creds));
@@ -629,7 +637,8 @@ static void test_refresh_token_creds_success(void) {
static void test_refresh_token_creds_failure(void) {
grpc_credentials *refresh_token_creds =
- grpc_refresh_token_credentials_create(test_refresh_token_str, NULL);
+ grpc_google_refresh_token_credentials_create(test_refresh_token_str,
+ NULL);
grpc_httpcli_set_override(httpcli_get_should_not_be_called,
refresh_token_httpcli_post_failure);
GPR_ASSERT(grpc_credentials_has_request_metadata(refresh_token_creds));
@@ -686,119 +695,6 @@ static char *encode_and_sign_jwt_should_not_be_called(
GPR_ASSERT("grpc_jwt_encode_and_sign should not be called" == NULL);
}
-static void validate_service_account_http_request(
- const grpc_httpcli_request *request, const char *body, size_t body_size) {
- /* The content of the assertion is tested extensively in json_token_test. */
- char *expected_body = NULL;
- GPR_ASSERT(body != NULL);
- GPR_ASSERT(body_size != 0);
- gpr_asprintf(&expected_body, "%s%s", GRPC_SERVICE_ACCOUNT_POST_BODY_PREFIX,
- test_signed_jwt);
- GPR_ASSERT(strlen(expected_body) == body_size);
- GPR_ASSERT(memcmp(expected_body, body, body_size) == 0);
- gpr_free(expected_body);
- GPR_ASSERT(request->handshaker == &grpc_httpcli_ssl);
- GPR_ASSERT(strcmp(request->host, GRPC_GOOGLE_OAUTH2_SERVICE_HOST) == 0);
- GPR_ASSERT(strcmp(request->path, GRPC_GOOGLE_OAUTH2_SERVICE_TOKEN_PATH) == 0);
- GPR_ASSERT(request->hdr_count == 1);
- GPR_ASSERT(strcmp(request->hdrs[0].key, "Content-Type") == 0);
- GPR_ASSERT(
- strcmp(request->hdrs[0].value, "application/x-www-form-urlencoded") == 0);
-}
-
-static int service_account_httpcli_post_success(
- const grpc_httpcli_request *request, const char *body, size_t body_size,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
- grpc_httpcli_response response =
- http_response(200, valid_oauth2_json_response);
- validate_service_account_http_request(request, body, body_size);
- on_response(user_data, &response);
- return 1;
-}
-
-static int service_account_httpcli_post_failure(
- const grpc_httpcli_request *request, const char *body, size_t body_size,
- gpr_timespec deadline, grpc_httpcli_response_cb on_response,
- void *user_data) {
- grpc_httpcli_response response = http_response(403, "Not Authorized.");
- validate_service_account_http_request(request, body, body_size);
- on_response(user_data, &response);
- return 1;
-}
-
-static void test_service_account_creds_success(void) {
- char *json_key_string = test_json_key_str();
- grpc_credentials *service_account_creds =
- grpc_service_account_credentials_create(json_key_string, test_scope,
- grpc_max_auth_token_lifetime, NULL);
- GPR_ASSERT(grpc_credentials_has_request_metadata(service_account_creds));
- GPR_ASSERT(grpc_credentials_has_request_metadata_only(service_account_creds));
-
- /* First request: http get should be called. */
- grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success);
- grpc_httpcli_set_override(httpcli_get_should_not_be_called,
- service_account_httpcli_post_success);
- grpc_credentials_get_request_metadata(
- service_account_creds, NULL, test_service_url,
- on_oauth2_creds_get_metadata_success, (void *)test_user_data);
-
- /* Second request: the cached token should be served directly. */
- grpc_jwt_encode_and_sign_set_override(
- encode_and_sign_jwt_should_not_be_called);
- grpc_httpcli_set_override(httpcli_get_should_not_be_called,
- httpcli_post_should_not_be_called);
- grpc_credentials_get_request_metadata(
- service_account_creds, NULL, test_service_url,
- on_oauth2_creds_get_metadata_success, (void *)test_user_data);
-
- gpr_free(json_key_string);
- grpc_credentials_unref(service_account_creds);
- grpc_jwt_encode_and_sign_set_override(NULL);
- grpc_httpcli_set_override(NULL, NULL);
-}
-
-static void test_service_account_creds_http_failure(void) {
- char *json_key_string = test_json_key_str();
- grpc_credentials *service_account_creds =
- grpc_service_account_credentials_create(
- json_key_string, test_scope, grpc_max_auth_token_lifetime, NULL);
- GPR_ASSERT(grpc_credentials_has_request_metadata(service_account_creds));
- GPR_ASSERT(grpc_credentials_has_request_metadata_only(service_account_creds));
-
- grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_success);
- grpc_httpcli_set_override(httpcli_get_should_not_be_called,
- service_account_httpcli_post_failure);
- grpc_credentials_get_request_metadata(
- service_account_creds, NULL, test_service_url,
- on_oauth2_creds_get_metadata_failure, (void *)test_user_data);
-
- gpr_free(json_key_string);
- grpc_credentials_unref(service_account_creds);
- grpc_httpcli_set_override(NULL, NULL);
-}
-
-static void test_service_account_creds_signing_failure(void) {
- char *json_key_string = test_json_key_str();
- grpc_credentials *service_account_creds =
- grpc_service_account_credentials_create(
- json_key_string, test_scope, grpc_max_auth_token_lifetime, NULL);
- GPR_ASSERT(grpc_credentials_has_request_metadata(service_account_creds));
- GPR_ASSERT(grpc_credentials_has_request_metadata_only(service_account_creds));
-
- grpc_jwt_encode_and_sign_set_override(encode_and_sign_jwt_failure);
- grpc_httpcli_set_override(httpcli_get_should_not_be_called,
- httpcli_post_should_not_be_called);
- grpc_credentials_get_request_metadata(
- service_account_creds, NULL, test_service_url,
- on_oauth2_creds_get_metadata_failure, (void *)test_user_data);
-
- gpr_free(json_key_string);
- grpc_credentials_unref(service_account_creds);
- grpc_httpcli_set_override(NULL, NULL);
- grpc_jwt_encode_and_sign_set_override(NULL);
-}
-
static void on_jwt_creds_get_metadata_success(void *user_data,
grpc_credentials_md *md_elems,
size_t num_md,
@@ -922,14 +818,14 @@ static void test_google_default_creds_auth_key(void) {
}
static void test_google_default_creds_access_token(void) {
- grpc_refresh_token_credentials *refresh;
+ grpc_google_refresh_token_credentials *refresh;
grpc_credentials *creds;
grpc_flush_cached_google_default_credentials();
set_google_default_creds_env_var_with_file_contents(
"refresh_token_google_default_creds", test_refresh_token_str);
creds = grpc_google_default_credentials_create();
GPR_ASSERT(creds != NULL);
- refresh = (grpc_refresh_token_credentials *)composite_inner_creds(
+ refresh = (grpc_google_refresh_token_credentials *)composite_inner_creds(
creds, GRPC_CREDENTIALS_TYPE_OAUTH2);
GPR_ASSERT(strcmp(refresh->refresh_token.client_id,
"32555999999.apps.googleusercontent.com") == 0);
@@ -952,17 +848,14 @@ int main(int argc, char **argv) {
test_oauth2_token_fetcher_creds_parsing_missing_token();
test_oauth2_token_fetcher_creds_parsing_missing_token_type();
test_oauth2_token_fetcher_creds_parsing_missing_token_lifetime();
- test_iam_creds();
+ test_google_iam_creds();
test_access_token_creds();
test_ssl_oauth2_composite_creds();
- test_ssl_oauth2_iam_composite_creds();
+ test_ssl_oauth2_google_iam_composite_creds();
test_compute_engine_creds_success();
test_compute_engine_creds_failure();
test_refresh_token_creds_success();
test_refresh_token_creds_failure();
- test_service_account_creds_success();
- test_service_account_creds_http_failure();
- test_service_account_creds_signing_failure();
test_jwt_creds_success();
test_jwt_creds_signing_failure();
test_google_default_creds_auth_key();
diff --git a/test/core/security/fetch_oauth2.c b/test/core/security/fetch_oauth2.c
index 7354a9f8f7..764d8da9b6 100644
--- a/test/core/security/fetch_oauth2.c
+++ b/test/core/security/fetch_oauth2.c
@@ -46,19 +46,6 @@
#include "src/core/support/file.h"
#include "test/core/security/oauth2_utils.h"
-static grpc_credentials *create_service_account_creds(
- const char *json_key_file_path, const char *scope) {
- int success;
- gpr_slice json_key = gpr_load_file(json_key_file_path, 1, &success);
- if (!success) {
- gpr_log(GPR_ERROR, "Could not read file %s.", json_key_file_path);
- exit(1);
- }
- return grpc_service_account_credentials_create(
- (const char *)GPR_SLICE_START_PTR(json_key), scope,
- grpc_max_auth_token_lifetime, NULL);
-}
-
static grpc_credentials *create_refresh_token_creds(
const char *json_refresh_token_file_path) {
int success;
@@ -68,7 +55,7 @@ static grpc_credentials *create_refresh_token_creds(
gpr_log(GPR_ERROR, "Could not read file %s.", json_refresh_token_file_path);
exit(1);
}
- return grpc_refresh_token_credentials_create(
+ return grpc_google_refresh_token_credentials_create(
(const char *)GPR_SLICE_START_PTR(refresh_token), NULL);
}
@@ -80,18 +67,9 @@ int main(int argc, char **argv) {
int use_gce = 0;
char *scope = NULL;
gpr_cmdline *cl = gpr_cmdline_create("fetch_oauth2");
- gpr_cmdline_add_string(cl, "json_key",
- "File path of the json key. Mutually exclusive with "
- "--json_refresh_token.",
- &json_key_file_path);
gpr_cmdline_add_string(cl, "json_refresh_token",
- "File path of the json refresh token. Mutually "
- "exclusive with --json_key.",
+ "File path of the json refresh token.",
&json_refresh_token_file_path);
- gpr_cmdline_add_string(cl, "scope",
- "Space delimited permissions. Only used for "
- "--json_key, ignored otherwise.",
- &scope);
gpr_cmdline_add_flag(
cl, "gce",
"Get a token from the GCE metadata server (only works in GCE).",
@@ -112,7 +90,7 @@ int main(int argc, char **argv) {
"Ignoring json key and scope to get a token from the GCE "
"metadata server.");
}
- creds = grpc_compute_engine_credentials_create(NULL);
+ creds = grpc_google_compute_engine_credentials_create(NULL);
if (creds == NULL) {
gpr_log(GPR_ERROR, "Could not create gce credentials.");
exit(1);
@@ -127,23 +105,8 @@ int main(int argc, char **argv) {
exit(1);
}
} else {
- if (json_key_file_path == NULL) {
- gpr_log(GPR_ERROR, "Missing --json_key option.");
- exit(1);
- }
- if (scope == NULL) {
- gpr_log(GPR_ERROR, "Missing --scope option.");
- exit(1);
- }
-
- creds = create_service_account_creds(json_key_file_path, scope);
- if (creds == NULL) {
- gpr_log(GPR_ERROR,
- "Could not create service account creds. %s does probably not "
- "contain a valid json key.",
- json_key_file_path);
- exit(1);
- }
+ gpr_log(GPR_ERROR, "Missing --gce or --json_refresh_token option.");
+ exit(1);
}
GPR_ASSERT(creds != NULL);
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..be45bae496 100644
--- a/test/core/util/port_posix.c
+++ b/test/core/util/port_posix.c
@@ -102,7 +102,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);
@@ -198,14 +198,13 @@ 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) {
@@ -218,11 +217,10 @@ int grpc_pick_unused_port(void) {
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 +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;
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
diff --git a/test/cpp/client/credentials_test.cc b/test/cpp/client/credentials_test.cc
index 6fb24d71e5..743ad065d1 100644
--- a/test/cpp/client/credentials_test.cc
+++ b/test/cpp/client/credentials_test.cc
@@ -31,7 +31,7 @@
*
*/
-#include <grpc++/credentials.h>
+#include <grpc++/security/credentials.h>
#include <memory>
@@ -45,8 +45,8 @@ class CredentialsTest : public ::testing::Test {
protected:
};
-TEST_F(CredentialsTest, InvalidServiceAccountCreds) {
- std::shared_ptr<Credentials> bad1 = ServiceAccountCredentials("", "", 1);
+TEST_F(CredentialsTest, InvalidGoogleRefreshToken) {
+ std::shared_ptr<Credentials> bad1 = GoogleRefreshTokenCredentials("");
EXPECT_EQ(static_cast<Credentials*>(nullptr), bad1.get());
}
diff --git a/test/cpp/common/auth_property_iterator_test.cc b/test/cpp/common/auth_property_iterator_test.cc
index e6226d6a09..a629ff5a90 100644
--- a/test/cpp/common/auth_property_iterator_test.cc
+++ b/test/cpp/common/auth_property_iterator_test.cc
@@ -32,7 +32,7 @@
*/
#include <grpc/grpc_security.h>
-#include <grpc++/support/auth_context.h>
+#include <grpc++/security/auth_context.h>
#include <gtest/gtest.h>
#include "src/cpp/common/secure_auth_context.h"
#include "test/cpp/util/string_ref_helper.h"
diff --git a/test/cpp/common/secure_auth_context_test.cc b/test/cpp/common/secure_auth_context_test.cc
index 25538c1853..11de646999 100644
--- a/test/cpp/common/secure_auth_context_test.cc
+++ b/test/cpp/common/secure_auth_context_test.cc
@@ -32,7 +32,7 @@
*/
#include <grpc/grpc_security.h>
-#include <grpc++/support/auth_context.h>
+#include <grpc++/security/auth_context.h>
#include <gtest/gtest.h>
#include "src/cpp/common/secure_auth_context.h"
#include "test/cpp/util/string_ref_helper.h"
@@ -50,7 +50,7 @@ class SecureAuthContextTest : public ::testing::Test {};
// Created with nullptr
TEST_F(SecureAuthContextTest, EmptyContext) {
- SecureAuthContext context(nullptr);
+ SecureAuthContext context(nullptr, true);
EXPECT_TRUE(context.GetPeerIdentity().empty());
EXPECT_TRUE(context.GetPeerIdentityPropertyName().empty());
EXPECT_TRUE(context.FindPropertyValues("").empty());
@@ -60,12 +60,12 @@ TEST_F(SecureAuthContextTest, EmptyContext) {
TEST_F(SecureAuthContextTest, Properties) {
grpc_auth_context* ctx = grpc_auth_context_create(NULL);
- grpc_auth_context_add_cstring_property(ctx, "name", "chapi");
- grpc_auth_context_add_cstring_property(ctx, "name", "chapo");
- grpc_auth_context_add_cstring_property(ctx, "foo", "bar");
- EXPECT_EQ(1, grpc_auth_context_set_peer_identity_property_name(ctx, "name"));
+ SecureAuthContext context(ctx, true);
+ context.AddProperty("name", "chapi");
+ context.AddProperty("name", "chapo");
+ context.AddProperty("foo", "bar");
+ EXPECT_TRUE(context.SetPeerIdentityPropertyName("name"));
- SecureAuthContext context(ctx);
std::vector<grpc::string_ref> peer_identity = context.GetPeerIdentity();
EXPECT_EQ(2u, peer_identity.size());
EXPECT_EQ("chapi", ToString(peer_identity[0]));
@@ -78,12 +78,12 @@ TEST_F(SecureAuthContextTest, Properties) {
TEST_F(SecureAuthContextTest, Iterators) {
grpc_auth_context* ctx = grpc_auth_context_create(NULL);
- grpc_auth_context_add_cstring_property(ctx, "name", "chapi");
- grpc_auth_context_add_cstring_property(ctx, "name", "chapo");
- grpc_auth_context_add_cstring_property(ctx, "foo", "bar");
- EXPECT_EQ(1, grpc_auth_context_set_peer_identity_property_name(ctx, "name"));
+ SecureAuthContext context(ctx, true);
+ context.AddProperty("name", "chapi");
+ context.AddProperty("name", "chapo");
+ context.AddProperty("foo", "bar");
+ EXPECT_TRUE(context.SetPeerIdentityPropertyName("name"));
- SecureAuthContext context(ctx);
AuthPropertyIterator iter = context.begin();
EXPECT_TRUE(context.end() != iter);
AuthProperty p0 = *iter;
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index bbcac9ba34..cfb6c21edc 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -39,11 +39,9 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include "test/core/util/port.h"
@@ -202,7 +200,7 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> {
void ResetStub() {
std::shared_ptr<Channel> channel =
CreateChannel(server_address_.str(), InsecureCredentials());
- stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
+ stub_ = grpc::cpp::test::util::TestService::NewStub(channel);
}
void SendRpc(int num_rpcs) {
@@ -753,8 +751,7 @@ TEST_P(AsyncEnd2endTest, UnimplementedRpc) {
std::shared_ptr<Channel> channel =
CreateChannel(server_address_.str(), InsecureCredentials());
std::unique_ptr<grpc::cpp::test::util::UnimplementedService::Stub> stub;
- stub =
- std::move(grpc::cpp::test::util::UnimplementedService::NewStub(channel));
+ stub = grpc::cpp::test::util::UnimplementedService::NewStub(channel);
EchoRequest send_request;
EchoResponse recv_response;
Status recv_status;
diff --git a/test/cpp/end2end/client_crash_test.cc b/test/cpp/end2end/client_crash_test.cc
index 3a6e55216a..058e696166 100644
--- a/test/cpp/end2end/client_crash_test.cc
+++ b/test/cpp/end2end/client_crash_test.cc
@@ -37,11 +37,9 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include "test/core/util/port.h"
diff --git a/test/cpp/end2end/client_crash_test_server.cc b/test/cpp/end2end/client_crash_test_server.cc
index 79a7832874..7ffeecca70 100644
--- a/test/cpp/end2end/client_crash_test_server.cc
+++ b/test/cpp/end2end/client_crash_test_server.cc
@@ -39,7 +39,6 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include "test/cpp/util/echo.grpc.pb.h"
DEFINE_string(address, "", "Address to bind to");
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index 37a6e693e6..bd829d96e1 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -40,11 +40,12 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
+#include <grpc++/security/auth_metadata_processor.h>
+#include <grpc++/security/credentials.h>
+#include <grpc++/security/server_credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include "src/core/security/credentials.h"
@@ -79,14 +80,23 @@ void MaybeEchoDeadline(ServerContext* context, const EchoRequest* request,
}
}
-void CheckServerAuthContext(const ServerContext* context) {
+void CheckServerAuthContext(const ServerContext* context,
+ const grpc::string& expected_client_identity) {
std::shared_ptr<const AuthContext> auth_ctx = context->auth_context();
std::vector<grpc::string_ref> ssl =
auth_ctx->FindPropertyValues("transport_security_type");
EXPECT_EQ(1u, ssl.size());
EXPECT_EQ("ssl", ToString(ssl[0]));
- EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty());
- EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty());
+ if (expected_client_identity.length() == 0) {
+ EXPECT_TRUE(auth_ctx->GetPeerIdentityPropertyName().empty());
+ EXPECT_TRUE(auth_ctx->GetPeerIdentity().empty());
+ EXPECT_FALSE(auth_ctx->IsPeerAuthenticated());
+ } else {
+ auto identity = auth_ctx->GetPeerIdentity();
+ EXPECT_TRUE(auth_ctx->IsPeerAuthenticated());
+ EXPECT_EQ(1u, identity.size());
+ EXPECT_EQ(expected_client_identity, identity[0]);
+ }
}
bool CheckIsLocalhost(const grpc::string& addr) {
@@ -98,6 +108,54 @@ bool CheckIsLocalhost(const grpc::string& addr) {
addr.substr(0, kIpv6.size()) == kIpv6;
}
+class TestAuthMetadataProcessor : public AuthMetadataProcessor {
+ public:
+ static const char kGoodGuy[];
+
+ TestAuthMetadataProcessor(bool is_blocking) : is_blocking_(is_blocking) {}
+
+ std::shared_ptr<Credentials> GetCompatibleClientCreds() {
+ return AccessTokenCredentials(kGoodGuy);
+ }
+ std::shared_ptr<Credentials> GetIncompatibleClientCreds() {
+ return AccessTokenCredentials("Mr Hyde");
+ }
+
+ // Interface implementation
+ bool IsBlocking() const GRPC_OVERRIDE { return is_blocking_; }
+
+ Status Process(const InputMetadata& auth_metadata, AuthContext* context,
+ OutputMetadata* consumed_auth_metadata,
+ OutputMetadata* response_metadata) GRPC_OVERRIDE {
+ EXPECT_TRUE(consumed_auth_metadata != nullptr);
+ EXPECT_TRUE(context != nullptr);
+ EXPECT_TRUE(response_metadata != nullptr);
+ auto auth_md = auth_metadata.find(GRPC_AUTHORIZATION_METADATA_KEY);
+ EXPECT_NE(auth_md, auth_metadata.end());
+ string_ref auth_md_value = auth_md->second;
+ if (auth_md_value.ends_with(kGoodGuy)) {
+ context->AddProperty(kIdentityPropName, kGoodGuy);
+ context->SetPeerIdentityPropertyName(kIdentityPropName);
+ consumed_auth_metadata->insert(
+ std::make_pair(string(auth_md->first.data(), auth_md->first.length()),
+ auth_md->second));
+ return Status::OK;
+ } else {
+ return Status(StatusCode::UNAUTHENTICATED,
+ string("Invalid principal: ") +
+ string(auth_md_value.data(), auth_md_value.length()));
+ }
+ }
+
+ protected:
+ static const char kIdentityPropName[];
+ bool is_blocking_;
+};
+
+const char TestAuthMetadataProcessor::kGoodGuy[] = "Dr Jekyll";
+const char TestAuthMetadataProcessor::kIdentityPropName[] = "novel identity";
+
+
} // namespace
class Proxy : public ::grpc::cpp::test::util::TestService::Service {
@@ -162,8 +220,10 @@ class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
ToString(iter->second));
}
}
- if (request->has_param() && request->param().check_auth_context()) {
- CheckServerAuthContext(context);
+ if (request->has_param() &&
+ (request->param().expected_client_identity().length() > 0 ||
+ request->param().check_auth_context())) {
+ CheckServerAuthContext(context, request->param().expected_client_identity());
}
if (request->has_param() &&
request->param().response_message_length() > 0) {
@@ -259,9 +319,18 @@ class TestServiceImplDupPkg
class End2endTest : public ::testing::TestWithParam<bool> {
protected:
End2endTest()
- : kMaxMessageSize_(8192), special_service_("special") {}
+ : is_server_started_(false),
+ kMaxMessageSize_(8192),
+ special_service_("special") {}
+
+ void TearDown() GRPC_OVERRIDE {
+ if (is_server_started_) {
+ server_->Shutdown();
+ if (proxy_server_) proxy_server_->Shutdown();
+ }
+ }
- void SetUp() GRPC_OVERRIDE {
+ void StartServer(const std::shared_ptr<AuthMetadataProcessor>& processor) {
int port = grpc_pick_unused_port_or_die();
server_address_ << "127.0.0.1:" << port;
// Setup server
@@ -271,22 +340,23 @@ class End2endTest : public ::testing::TestWithParam<bool> {
SslServerCredentialsOptions ssl_opts;
ssl_opts.pem_root_certs = "";
ssl_opts.pem_key_cert_pairs.push_back(pkcp);
- builder.AddListeningPort(server_address_.str(),
- SslServerCredentials(ssl_opts));
+ auto server_creds = SslServerCredentials(ssl_opts);
+ server_creds->SetAuthMetadataProcessor(processor);
+ builder.AddListeningPort(server_address_.str(), server_creds);
builder.RegisterService(&service_);
builder.RegisterService("foo.test.youtube.com", &special_service_);
builder.SetMaxMessageSize(
kMaxMessageSize_); // For testing max message size.
builder.RegisterService(&dup_pkg_service_);
server_ = builder.BuildAndStart();
- }
-
- void TearDown() GRPC_OVERRIDE {
- server_->Shutdown();
- if (proxy_server_) proxy_server_->Shutdown();
+ is_server_started_ = true;
}
void ResetChannel() {
+ if (!is_server_started_) {
+ StartServer(std::shared_ptr<AuthMetadataProcessor>());
+ }
+ EXPECT_TRUE(is_server_started_);
SslCredentialsOptions ssl_opts = {test_root_cert, "", ""};
ChannelArguments args;
args.SetSslTargetNameOverride("foo.test.google.fr");
@@ -310,9 +380,10 @@ class End2endTest : public ::testing::TestWithParam<bool> {
channel_ = CreateChannel(proxyaddr.str(), InsecureCredentials());
}
- stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
+ stub_ = grpc::cpp::test::util::TestService::NewStub(channel_);
}
+ bool is_server_started_;
std::shared_ptr<Channel> channel_;
std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_;
std::unique_ptr<Server> server_;
@@ -562,7 +633,7 @@ TEST_F(End2endTest, DiffPackageServices) {
// rpc and stream should fail on bad credentials.
TEST_F(End2endTest, BadCredentials) {
- std::shared_ptr<Credentials> bad_creds = ServiceAccountCredentials("", "", 1);
+ std::shared_ptr<Credentials> bad_creds = GoogleRefreshTokenCredentials("");
EXPECT_EQ(static_cast<Credentials*>(nullptr), bad_creds.get());
std::shared_ptr<Channel> channel =
CreateChannel(server_address_.str(), bad_creds);
@@ -743,7 +814,7 @@ TEST_F(End2endTest, SetPerCallCredentials) {
EchoResponse response;
ClientContext context;
std::shared_ptr<Credentials> creds =
- IAMCredentials("fake_token", "fake_selector");
+ GoogleIAMCredentials("fake_token", "fake_selector");
context.set_credentials(creds);
request.set_message("Hello");
request.mutable_param()->set_echo_metadata(true);
@@ -780,10 +851,10 @@ TEST_F(End2endTest, OverridePerCallCredentials) {
EchoResponse response;
ClientContext context;
std::shared_ptr<Credentials> creds1 =
- IAMCredentials("fake_token1", "fake_selector1");
+ GoogleIAMCredentials("fake_token1", "fake_selector1");
context.set_credentials(creds1);
std::shared_ptr<Credentials> creds2 =
- IAMCredentials("fake_token2", "fake_selector2");
+ GoogleIAMCredentials("fake_token2", "fake_selector2");
context.set_credentials(creds2);
request.set_message("Hello");
request.mutable_param()->set_echo_metadata(true);
@@ -805,6 +876,82 @@ TEST_F(End2endTest, OverridePerCallCredentials) {
EXPECT_TRUE(s.ok());
}
+TEST_F(End2endTest, NonBlockingAuthMetadataProcessorSuccess) {
+ auto* processor = new TestAuthMetadataProcessor(false);
+ StartServer(std::shared_ptr<AuthMetadataProcessor>(processor));
+ ResetStub(false);
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ context.set_credentials(processor->GetCompatibleClientCreds());
+ request.set_message("Hello");
+ request.mutable_param()->set_echo_metadata(true);
+ request.mutable_param()->set_expected_client_identity(
+ TestAuthMetadataProcessor::kGoodGuy);
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(request.message(), response.message());
+ EXPECT_TRUE(s.ok());
+
+ // Metadata should have been consumed by the processor.
+ EXPECT_FALSE(MetadataContains(
+ context.GetServerTrailingMetadata(), GRPC_AUTHORIZATION_METADATA_KEY,
+ grpc::string("Bearer ") + TestAuthMetadataProcessor::kGoodGuy));
+}
+
+TEST_F(End2endTest, NonBlockingAuthMetadataProcessorFailure) {
+ auto* processor = new TestAuthMetadataProcessor(false);
+ StartServer(std::shared_ptr<AuthMetadataProcessor>(processor));
+ ResetStub(false);
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ context.set_credentials(processor->GetIncompatibleClientCreds());
+ request.set_message("Hello");
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_FALSE(s.ok());
+ EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED);
+}
+
+TEST_F(End2endTest, BlockingAuthMetadataProcessorSuccess) {
+ auto* processor = new TestAuthMetadataProcessor(true);
+ StartServer(std::shared_ptr<AuthMetadataProcessor>(processor));
+ ResetStub(false);
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ context.set_credentials(processor->GetCompatibleClientCreds());
+ request.set_message("Hello");
+ request.mutable_param()->set_echo_metadata(true);
+ request.mutable_param()->set_expected_client_identity(
+ TestAuthMetadataProcessor::kGoodGuy);
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_EQ(request.message(), response.message());
+ EXPECT_TRUE(s.ok());
+
+ // Metadata should have been consumed by the processor.
+ EXPECT_FALSE(MetadataContains(
+ context.GetServerTrailingMetadata(), GRPC_AUTHORIZATION_METADATA_KEY,
+ grpc::string("Bearer ") + TestAuthMetadataProcessor::kGoodGuy));
+}
+
+TEST_F(End2endTest, BlockingAuthMetadataProcessorFailure) {
+ auto* processor = new TestAuthMetadataProcessor(true);
+ StartServer(std::shared_ptr<AuthMetadataProcessor>(processor));
+ ResetStub(false);
+ EchoRequest request;
+ EchoResponse response;
+ ClientContext context;
+ context.set_credentials(processor->GetIncompatibleClientCreds());
+ request.set_message("Hello");
+
+ Status s = stub_->Echo(&context, request, &response);
+ EXPECT_FALSE(s.ok());
+ EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED);
+}
+
// Client sends 20 requests and the server returns CANCELLED status after
// reading 10 requests.
TEST_F(End2endTest, RequestStreamServerEarlyCancelTest) {
@@ -933,8 +1080,7 @@ TEST_F(End2endTest, ChannelState) {
TEST_F(End2endTest, NonExistingService) {
ResetChannel();
std::unique_ptr<grpc::cpp::test::util::UnimplementedService::Stub> stub;
- stub =
- std::move(grpc::cpp::test::util::UnimplementedService::NewStub(channel_));
+ stub = grpc::cpp::test::util::UnimplementedService::NewStub(channel_);
EchoRequest request;
EchoResponse response;
diff --git a/test/cpp/end2end/generic_end2end_test.cc b/test/cpp/end2end/generic_end2end_test.cc
index 7acbc711fb..6a46916728 100644
--- a/test/cpp/end2end/generic_end2end_test.cc
+++ b/test/cpp/end2end/generic_end2end_test.cc
@@ -40,13 +40,11 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/generic/async_generic_service.h>
#include <grpc++/generic/generic_stub.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <grpc++/support/slice.h>
#include <gtest/gtest.h>
diff --git a/test/cpp/end2end/mock_test.cc b/test/cpp/end2end/mock_test.cc
index 077d21aa72..9c35fede8f 100644
--- a/test/cpp/end2end/mock_test.cc
+++ b/test/cpp/end2end/mock_test.cc
@@ -39,11 +39,9 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include "test/core/util/port.h"
@@ -247,7 +245,7 @@ class MockTest : public ::testing::Test {
void ResetStub() {
std::shared_ptr<Channel> channel =
CreateChannel(server_address_.str(), InsecureCredentials());
- stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
+ stub_ = grpc::cpp::test::util::TestService::NewStub(channel);
}
std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_;
diff --git a/test/cpp/end2end/server_crash_test.cc b/test/cpp/end2end/server_crash_test.cc
index 1a0f04e22b..4b6793abe6 100644
--- a/test/cpp/end2end/server_crash_test.cc
+++ b/test/cpp/end2end/server_crash_test.cc
@@ -37,11 +37,9 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include "test/core/util/port.h"
diff --git a/test/cpp/end2end/server_crash_test_client.cc b/test/cpp/end2end/server_crash_test_client.cc
index 6ff42fcb30..17869362c2 100644
--- a/test/cpp/end2end/server_crash_test_client.cc
+++ b/test/cpp/end2end/server_crash_test_client.cc
@@ -40,7 +40,6 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include "test/cpp/util/echo.grpc.pb.h"
DEFINE_string(address, "", "Address to connect to");
diff --git a/test/cpp/end2end/shutdown_test.cc b/test/cpp/end2end/shutdown_test.cc
index 59fec6ad40..0549bb8b5f 100644
--- a/test/cpp/end2end/shutdown_test.cc
+++ b/test/cpp/end2end/shutdown_test.cc
@@ -38,11 +38,9 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include "src/core/support/env.h"
@@ -96,7 +94,7 @@ class ShutdownTest : public ::testing::Test {
void ResetStub() {
string target = "dns:localhost:" + to_string(port_);
channel_ = CreateChannel(target, InsecureCredentials());
- stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
+ stub_ = grpc::cpp::test::util::TestService::NewStub(channel_);
}
string to_string(const int number) {
diff --git a/test/cpp/end2end/streaming_throughput_test.cc b/test/cpp/end2end/streaming_throughput_test.cc
new file mode 100644
index 0000000000..63d49c0425
--- /dev/null
+++ b/test/cpp/end2end/streaming_throughput_test.cc
@@ -0,0 +1,189 @@
+/*
+ *
+ * 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 <atomic>
+#include <mutex>
+#include <thread>
+
+#include <grpc++/channel.h>
+#include <grpc++/client_context.h>
+#include <grpc++/create_channel.h>
+#include <grpc++/security/credentials.h>
+#include <grpc++/security/server_credentials.h>
+#include <grpc++/server.h>
+#include <grpc++/server_builder.h>
+#include <grpc++/server_context.h>
+#include <grpc/grpc.h>
+#include <grpc/support/thd.h>
+#include <grpc/support/time.h>
+#include <gtest/gtest.h>
+
+#include "test/core/util/port.h"
+#include "test/core/util/test_config.h"
+#include "test/cpp/util/echo_duplicate.grpc.pb.h"
+#include "test/cpp/util/echo.grpc.pb.h"
+
+using grpc::cpp::test::util::EchoRequest;
+using grpc::cpp::test::util::EchoResponse;
+using std::chrono::system_clock;
+
+const char* kLargeString = "("
+ "To be, or not to be- that is the question:"
+ "Whether 'tis nobler in the mind to suffer"
+ "The slings and arrows of outrageous fortune"
+ "Or to take arms against a sea of troubles,"
+ "And by opposing end them. To die- to sleep-"
+ "No more; and by a sleep to say we end"
+ "The heartache, and the thousand natural shock"
+ "That flesh is heir to. 'Tis a consummation"
+ "Devoutly to be wish'd. To die- to sleep."
+ "To sleep- perchance to dream: ay, there's the rub!"
+ "For in that sleep of death what dreams may come"
+ "When we have shuffled off this mortal coil,"
+ "Must give us pause. There's the respect"
+ "That makes calamity of so long life."
+ "For who would bear the whips and scorns of time,"
+ "Th' oppressor's wrong, the proud man's contumely,"
+ "The pangs of despis'd love, the law's delay,"
+ "The insolence of office, and the spurns"
+ "That patient merit of th' unworthy takes,"
+ "When he himself might his quietus make"
+ "With a bare bodkin? Who would these fardels bear,"
+ "To grunt and sweat under a weary life,"
+ "But that the dread of something after death-"
+ "The undiscover'd country, from whose bourn"
+ "No traveller returns- puzzles the will,"
+ "And makes us rather bear those ills we have"
+ "Than fly to others that we know not of?"
+ "Thus conscience does make cowards of us all,"
+ "And thus the native hue of resolution"
+ "Is sicklied o'er with the pale cast of thought,"
+ "And enterprises of great pith and moment"
+ "With this regard their currents turn awry"
+ "And lose the name of action.- Soft you now!"
+ "The fair Ophelia!- Nymph, in thy orisons"
+ "Be all my sins rememb'red.";
+
+namespace grpc {
+namespace testing {
+
+class TestServiceImpl : public ::grpc::cpp::test::util::TestService::Service {
+ public:
+ static void BidiStream_Sender(ServerReaderWriter<EchoResponse, EchoRequest>* stream, std::atomic<bool>* should_exit) {
+ EchoResponse response;
+ response.set_message(kLargeString);
+ while (!should_exit->load()) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
+ stream->Write(response);
+ }
+ }
+
+ // Only implement the one method we will be calling for brevity.
+ Status BidiStream(ServerContext* context,
+ ServerReaderWriter<EchoResponse, EchoRequest>* stream)
+ GRPC_OVERRIDE {
+ EchoRequest request;
+ std::atomic<bool> should_exit(false);
+ std::thread sender(std::bind(&TestServiceImpl::BidiStream_Sender, stream, &should_exit));
+
+ while (stream->Read(&request)) {
+ std::this_thread::sleep_for(std::chrono::milliseconds(3));
+ }
+ should_exit.store(true);
+ sender.join();
+ return Status::OK;
+ }
+};
+
+class End2endTest : public ::testing::Test {
+ protected:
+ void SetUp() GRPC_OVERRIDE {
+ int port = grpc_pick_unused_port_or_die();
+ server_address_ << "localhost:" << port;
+ // Setup server
+ ServerBuilder builder;
+ builder.AddListeningPort(server_address_.str(),
+ InsecureServerCredentials());
+ builder.RegisterService(&service_);
+ server_ = builder.BuildAndStart();
+ }
+
+ void TearDown() GRPC_OVERRIDE { server_->Shutdown(); }
+
+ void ResetStub() {
+ std::shared_ptr<Channel> channel = CreateChannel(
+ server_address_.str(), InsecureCredentials());
+ stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
+ }
+
+ std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_;
+ std::unique_ptr<Server> server_;
+ std::ostringstream server_address_;
+ TestServiceImpl service_;
+};
+
+static void Drainer(ClientReaderWriter<EchoRequest, EchoResponse>* reader) {
+ EchoResponse response;
+ while (reader->Read(&response)) {
+ // Just drain out the responses as fast as possible.
+ }
+}
+
+TEST_F(End2endTest, StreamingThroughput) {
+ ResetStub();
+ grpc::ClientContext context;
+ auto stream = stub_->BidiStream(&context);
+
+ auto reader = stream.get();
+ std::thread receiver(std::bind(Drainer, reader));
+
+ for (int i = 0; i < 10000; i++) {
+ EchoRequest request;
+ request.set_message(kLargeString);
+ ASSERT_TRUE(stream->Write(request));
+ if (i % 1000 == 0) {
+ gpr_log(GPR_INFO, "Send count = %d", i);
+ }
+ }
+ stream->WritesDone();
+ receiver.join();
+}
+
+} // namespace testing
+} // namespace grpc
+
+int main(int argc, char** argv) {
+ grpc_test_init(argc, argv);
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc
index 2a16481972..75a07d89c5 100644
--- a/test/cpp/end2end/thread_stress_test.cc
+++ b/test/cpp/end2end/thread_stress_test.cc
@@ -40,11 +40,9 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include "test/core/util/port.h"
@@ -193,7 +191,7 @@ class End2endTest : public ::testing::Test {
void ResetStub() {
std::shared_ptr<Channel> channel =
CreateChannel(server_address_.str(), InsecureCredentials());
- stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel));
+ stub_ = grpc::cpp::test::util::TestService::NewStub(channel);
}
std::unique_ptr<grpc::cpp::test::util::TestService::Stub> stub_;
diff --git a/test/cpp/end2end/zookeeper_test.cc b/test/cpp/end2end/zookeeper_test.cc
index 931541ca34..d4c7f0489f 100644
--- a/test/cpp/end2end/zookeeper_test.cc
+++ b/test/cpp/end2end/zookeeper_test.cc
@@ -34,11 +34,9 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include <grpc/grpc.h>
#include <grpc/grpc_zookeeper.h>
diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc
index cb5232153b..ba44a918db 100644
--- a/test/cpp/interop/client.cc
+++ b/test/cpp/interop/client.cc
@@ -68,7 +68,6 @@ DEFINE_string(test_case, "large_unary",
"cancel_after_begin : cancel stream after starting it; "
"cancel_after_first_response: cancel on first response; "
"timeout_on_sleeping_server: deadline exceeds on stream; "
- "service_account_creds : large_unary with service_account auth; "
"compute_engine_creds: large_unary with compute engine auth; "
"jwt_token_creds: large_unary with JWT token auth; "
"oauth2_auth_token: raw oauth2 access token auth; "
@@ -114,9 +113,6 @@ int main(int argc, char** argv) {
client.DoCancelAfterFirstResponse();
} else if (FLAGS_test_case == "timeout_on_sleeping_server") {
client.DoTimeoutOnSleepingServer();
- } else if (FLAGS_test_case == "service_account_creds") {
- grpc::string json_key = GetServiceAccountJsonKey();
- client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope);
} else if (FLAGS_test_case == "compute_engine_creds") {
client.DoComputeEngineCreds(FLAGS_default_service_account,
FLAGS_oauth_scope);
@@ -124,11 +120,10 @@ int main(int argc, char** argv) {
grpc::string json_key = GetServiceAccountJsonKey();
client.DoJwtTokenCreds(json_key);
} else if (FLAGS_test_case == "oauth2_auth_token") {
- grpc::string json_key = GetServiceAccountJsonKey();
- client.DoOauth2AuthToken(json_key, FLAGS_oauth_scope);
+ client.DoOauth2AuthToken(FLAGS_default_service_account, FLAGS_oauth_scope);
} else if (FLAGS_test_case == "per_rpc_creds") {
grpc::string json_key = GetServiceAccountJsonKey();
- client.DoPerRpcCreds(json_key, FLAGS_oauth_scope);
+ client.DoPerRpcCreds(json_key);
} else if (FLAGS_test_case == "status_code_and_message") {
client.DoStatusWithMessage();
} else if (FLAGS_test_case == "all") {
@@ -146,10 +141,10 @@ int main(int argc, char** argv) {
// service_account_creds and jwt_token_creds can only run with ssl.
if (FLAGS_enable_ssl) {
grpc::string json_key = GetServiceAccountJsonKey();
- client.DoServiceAccountCreds(json_key, FLAGS_oauth_scope);
client.DoJwtTokenCreds(json_key);
- client.DoOauth2AuthToken(json_key, FLAGS_oauth_scope);
- client.DoPerRpcCreds(json_key, FLAGS_oauth_scope);
+ client.DoOauth2AuthToken(
+ FLAGS_default_service_account, FLAGS_oauth_scope);
+ client.DoPerRpcCreds(json_key);
}
// compute_engine_creds only runs in GCE.
} else {
@@ -159,8 +154,7 @@ int main(int argc, char** argv) {
"large_unary|large_compressed_unary|client_streaming|server_streaming|"
"server_compressed_streaming|half_duplex|ping_pong|cancel_after_begin|"
"cancel_after_first_response|timeout_on_sleeping_server|"
- "service_account_creds|compute_engine_creds|jwt_token_creds|"
- "oauth2_auth_token|per_rpc_creds",
+ "compute_engine_creds|jwt_token_creds|oauth2_auth_token|per_rpc_creds",
FLAGS_test_case.c_str());
ret = 1;
}
diff --git a/test/cpp/interop/client_helper.cc b/test/cpp/interop/client_helper.cc
index abc14aeb98..f85aa6ad8e 100644
--- a/test/cpp/interop/client_helper.cc
+++ b/test/cpp/interop/client_helper.cc
@@ -45,7 +45,7 @@
#include <gflags/gflags.h>
#include <grpc++/channel.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
+#include <grpc++/security/credentials.h>
#include "src/cpp/client/secure_credentials.h"
#include "test/core/security/oauth2_utils.h"
@@ -64,16 +64,6 @@ DECLARE_string(oauth_scope);
namespace grpc {
namespace testing {
-namespace {
-std::shared_ptr<Credentials> CreateServiceAccountCredentials() {
- GPR_ASSERT(FLAGS_enable_ssl);
- grpc::string json_key = GetServiceAccountJsonKey();
- std::chrono::seconds token_lifetime = std::chrono::hours(1);
- return ServiceAccountCredentials(json_key, FLAGS_oauth_scope,
- token_lifetime.count());
-}
-} // namespace
-
grpc::string GetServiceAccountJsonKey() {
static grpc::string json_key;
if (json_key.empty()) {
@@ -86,7 +76,7 @@ grpc::string GetServiceAccountJsonKey() {
}
grpc::string GetOauth2AccessToken() {
- std::shared_ptr<Credentials> creds = CreateServiceAccountCredentials();
+ std::shared_ptr<Credentials> creds = GoogleComputeEngineCredentials();
SecureCredentials* secure_creds =
dynamic_cast<SecureCredentials*>(creds.get());
GPR_ASSERT(secure_creds != nullptr);
@@ -107,14 +97,10 @@ std::shared_ptr<Channel> CreateChannelForTestCase(
snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(),
FLAGS_server_port);
- if (test_case == "service_account_creds") {
- std::shared_ptr<Credentials> creds = CreateServiceAccountCredentials();
- return CreateTestChannel(host_port, FLAGS_server_host_override,
- FLAGS_enable_ssl, FLAGS_use_prod_roots, creds);
- } else if (test_case == "compute_engine_creds") {
+ if (test_case == "compute_engine_creds") {
std::shared_ptr<Credentials> creds;
GPR_ASSERT(FLAGS_enable_ssl);
- creds = ComputeEngineCredentials();
+ creds = GoogleComputeEngineCredentials();
return CreateTestChannel(host_port, FLAGS_server_host_override,
FLAGS_enable_ssl, FLAGS_use_prod_roots, creds);
} else if (test_case == "jwt_token_creds") {
diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc
index ca13cdc53d..8124cae67a 100644
--- a/test/cpp/interop/interop_client.cc
+++ b/test/cpp/interop/interop_client.cc
@@ -44,7 +44,7 @@
#include <grpc/support/useful.h>
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
-#include <grpc++/credentials.h>
+#include <grpc++/security/credentials.h>
#include "src/core/transport/stream_op.h"
#include "test/cpp/interop/client_helper.h"
@@ -179,24 +179,6 @@ void InteropClient::DoComputeEngineCreds(
gpr_log(GPR_INFO, "Large unary with compute engine creds done.");
}
-void InteropClient::DoServiceAccountCreds(const grpc::string& username,
- const grpc::string& oauth_scope) {
- gpr_log(GPR_INFO,
- "Sending a large unary rpc with service account credentials ...");
- SimpleRequest request;
- SimpleResponse response;
- request.set_fill_username(true);
- request.set_fill_oauth_scope(true);
- request.set_response_type(PayloadType::COMPRESSABLE);
- PerformLargeUnary(&request, &response);
- GPR_ASSERT(!response.username().empty());
- GPR_ASSERT(!response.oauth_scope().empty());
- GPR_ASSERT(username.find(response.username()) != grpc::string::npos);
- const char* oauth_scope_str = response.oauth_scope().c_str();
- GPR_ASSERT(oauth_scope.find(oauth_scope_str) != grpc::string::npos);
- gpr_log(GPR_INFO, "Large unary with service account creds done.");
-}
-
void InteropClient::DoOauth2AuthToken(const grpc::string& username,
const grpc::string& oauth_scope) {
gpr_log(GPR_INFO,
@@ -214,36 +196,33 @@ void InteropClient::DoOauth2AuthToken(const grpc::string& username,
AssertOkOrPrintErrorStatus(s);
GPR_ASSERT(!response.username().empty());
GPR_ASSERT(!response.oauth_scope().empty());
- GPR_ASSERT(username.find(response.username()) != grpc::string::npos);
+ GPR_ASSERT(username == response.username());
const char* oauth_scope_str = response.oauth_scope().c_str();
GPR_ASSERT(oauth_scope.find(oauth_scope_str) != grpc::string::npos);
gpr_log(GPR_INFO, "Unary with oauth2 access token credentials done.");
}
-void InteropClient::DoPerRpcCreds(const grpc::string& username,
- const grpc::string& oauth_scope) {
+void InteropClient::DoPerRpcCreds(const grpc::string& json_key) {
gpr_log(GPR_INFO,
- "Sending a unary rpc with per-rpc raw oauth2 access token ...");
+ "Sending a unary rpc with per-rpc JWT access token ...");
SimpleRequest request;
SimpleResponse response;
request.set_fill_username(true);
- request.set_fill_oauth_scope(true);
std::unique_ptr<TestService::Stub> stub(TestService::NewStub(channel_));
ClientContext context;
- grpc::string access_token = GetOauth2AccessToken();
- std::shared_ptr<Credentials> creds = AccessTokenCredentials(access_token);
+ std::chrono::seconds token_lifetime = std::chrono::hours(1);
+ std::shared_ptr<Credentials> creds =
+ ServiceAccountJWTAccessCredentials(json_key, token_lifetime.count());
+
context.set_credentials(creds);
Status s = stub->UnaryCall(&context, request, &response);
AssertOkOrPrintErrorStatus(s);
GPR_ASSERT(!response.username().empty());
- GPR_ASSERT(!response.oauth_scope().empty());
- GPR_ASSERT(username.find(response.username()) != grpc::string::npos);
- const char* oauth_scope_str = response.oauth_scope().c_str();
- GPR_ASSERT(oauth_scope.find(oauth_scope_str) != grpc::string::npos);
- gpr_log(GPR_INFO, "Unary with per-rpc oauth2 access token done.");
+ GPR_ASSERT(json_key.find(response.username()) != grpc::string::npos);
+ gpr_log(GPR_INFO, "Unary with per-rpc JWT access token done.");
}
void InteropClient::DoJwtTokenCreds(const grpc::string& username) {
diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h
index 5e26cc82e6..7bcb58571e 100644
--- a/test/cpp/interop/interop_client.h
+++ b/test/cpp/interop/interop_client.h
@@ -68,15 +68,11 @@ class InteropClient {
void DoJwtTokenCreds(const grpc::string& username);
void DoComputeEngineCreds(const grpc::string& default_service_account,
const grpc::string& oauth_scope);
- // username is a string containing the user email
- void DoServiceAccountCreds(const grpc::string& username,
- const grpc::string& oauth_scope);
- // username is a string containing the user email
+ // username the GCE default service account email
void DoOauth2AuthToken(const grpc::string& username,
const grpc::string& oauth_scope);
// username is a string containing the user email
- void DoPerRpcCreds(const grpc::string& username,
- const grpc::string& oauth_scope);
+ void DoPerRpcCreds(const grpc::string& json_key);
private:
void PerformLargeUnary(SimpleRequest* request, SimpleResponse* response);
diff --git a/test/cpp/interop/reconnect_interop_server.cc b/test/cpp/interop/reconnect_interop_server.cc
index d4f171b1d0..f52417bae0 100644
--- a/test/cpp/interop/reconnect_interop_server.cc
+++ b/test/cpp/interop/reconnect_interop_server.cc
@@ -45,7 +45,6 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include "test/core/util/reconnect_server.h"
#include "test/cpp/util/test_config.h"
diff --git a/test/cpp/interop/server.cc b/test/cpp/interop/server.cc
index 4921fde9fa..03b6532447 100644
--- a/test/cpp/interop/server.cc
+++ b/test/cpp/interop/server.cc
@@ -46,7 +46,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
+#include <grpc++/security/server_credentials.h>
#include "test/cpp/interop/server_helper.h"
#include "test/cpp/util/test_config.h"
diff --git a/test/cpp/interop/server_helper.cc b/test/cpp/interop/server_helper.cc
index e897f4ebf0..015198354e 100644
--- a/test/cpp/interop/server_helper.cc
+++ b/test/cpp/interop/server_helper.cc
@@ -36,7 +36,7 @@
#include <memory>
#include <gflags/gflags.h>
-#include <grpc++/server_credentials.h>
+#include <grpc++/security/server_credentials.h>
#include "src/core/surface/call.h"
#include "test/core/end2end/data/ssl_test_data.h"
diff --git a/test/cpp/interop/server_helper.h b/test/cpp/interop/server_helper.h
index 7b6b12cd4d..dc0ae1dccd 100644
--- a/test/cpp/interop/server_helper.h
+++ b/test/cpp/interop/server_helper.h
@@ -38,7 +38,7 @@
#include <grpc/compression.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
+#include <grpc++/security/server_credentials.h>
namespace grpc {
namespace testing {
diff --git a/test/cpp/qps/client_sync.cc b/test/cpp/qps/client_sync.cc
index 123dca6600..beef604856 100644
--- a/test/cpp/qps/client_sync.cc
+++ b/test/cpp/qps/client_sync.cc
@@ -31,8 +31,6 @@
*
*/
-#include <sys/signal.h>
-
#include <cassert>
#include <chrono>
#include <memory>
diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc
index 0e771d6b81..6e71c45935 100644
--- a/test/cpp/qps/driver.cc
+++ b/test/cpp/qps/driver.cc
@@ -31,7 +31,6 @@
*
*/
-#include <unistd.h>
#include <list>
#include <thread>
#include <deque>
@@ -154,14 +153,14 @@ std::unique_ptr<ScenarioResult> RunScenario(
// where class contained in std::vector must have a copy constructor
auto* servers = new ServerData[num_servers];
for (size_t i = 0; i < num_servers; i++) {
- servers[i].stub = std::move(
- Worker::NewStub(CreateChannel(workers[i], InsecureCredentials())));
+ servers[i].stub = Worker::NewStub(CreateChannel(workers[i],
+ InsecureCredentials()));
ServerArgs args;
result_server_config = server_config;
result_server_config.set_host(workers[i]);
*args.mutable_setup() = server_config;
servers[i].stream =
- std::move(servers[i].stub->RunServer(runsc::AllocContext(&contexts)));
+ servers[i].stub->RunServer(runsc::AllocContext(&contexts));
GPR_ASSERT(servers[i].stream->Write(args));
ServerStatus init_status;
GPR_ASSERT(servers[i].stream->Read(&init_status));
@@ -182,14 +181,14 @@ std::unique_ptr<ScenarioResult> RunScenario(
// where class contained in std::vector must have a copy constructor
auto* clients = new ClientData[num_clients];
for (size_t i = 0; i < num_clients; i++) {
- clients[i].stub = std::move(Worker::NewStub(
- CreateChannel(workers[i + num_servers], InsecureCredentials())));
+ clients[i].stub = Worker::NewStub(CreateChannel(workers[i + num_servers],
+ InsecureCredentials()));
ClientArgs args;
result_client_config = client_config;
result_client_config.set_host(workers[i + num_servers]);
*args.mutable_setup() = client_config;
clients[i].stream =
- std::move(clients[i].stub->RunTest(runsc::AllocContext(&contexts)));
+ clients[i].stub->RunTest(runsc::AllocContext(&contexts));
GPR_ASSERT(clients[i].stream->Write(args));
ClientStatus init_status;
GPR_ASSERT(clients[i].stream->Read(&init_status));
diff --git a/test/cpp/qps/perf_db_client.h b/test/cpp/qps/perf_db_client.h
index ae5d17074b..72ebe79c3c 100644
--- a/test/cpp/qps/perf_db_client.h
+++ b/test/cpp/qps/perf_db_client.h
@@ -41,7 +41,7 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
+#include <grpc++/security/credentials.h>
#include "test/cpp/qps/perf_db.grpc.pb.h"
namespace grpc {
diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc
index 51e955a80a..d19499be43 100644
--- a/test/cpp/qps/qps_worker.cc
+++ b/test/cpp/qps/qps_worker.cc
@@ -49,7 +49,7 @@
#include <grpc++/client_context.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
-#include <grpc++/server_credentials.h>
+#include <grpc++/security/server_credentials.h>
#include "test/core/util/grpc_profiler.h"
#include "test/cpp/qps/qpstest.pb.h"
@@ -229,7 +229,7 @@ QpsWorker::QpsWorker(int driver_port, int server_port) {
gpr_free(server_address);
- server_ = std::move(builder.BuildAndStart());
+ server_ = builder.BuildAndStart();
}
QpsWorker::~QpsWorker() {}
diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc
index 77415f42ce..516598a0e2 100644
--- a/test/cpp/qps/server_async.cc
+++ b/test/cpp/qps/server_async.cc
@@ -35,9 +35,6 @@
#include <functional>
#include <memory>
#include <mutex>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/signal.h>
#include <thread>
#include <gflags/gflags.h>
@@ -49,7 +46,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
+#include <grpc++/security/server_credentials.h>
#include <gtest/gtest.h>
#include "test/cpp/qps/qpstest.grpc.pb.h"
@@ -71,7 +68,7 @@ class AsyncQpsServerTest : public Server {
builder.RegisterAsyncService(&async_service_);
for (int i = 0; i < config.threads(); i++) {
- srv_cqs_.emplace_back(std::move(builder.AddCompletionQueue()));
+ srv_cqs_.emplace_back(builder.AddCompletionQueue());
}
server_ = builder.BuildAndStart();
@@ -101,7 +98,9 @@ class AsyncQpsServerTest : public Server {
}
}
~AsyncQpsServerTest() {
- server_->Shutdown();
+ auto deadline = std::chrono::system_clock::now() +
+ std::chrono::seconds(10);
+ server_->Shutdown(deadline);
for (auto ss = shutdown_state_.begin(); ss != shutdown_state_.end(); ++ss) {
(*ss)->set_shutdown();
}
diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc
index 29ec19cd4b..d930ba2464 100644
--- a/test/cpp/qps/server_sync.cc
+++ b/test/cpp/qps/server_sync.cc
@@ -31,8 +31,6 @@
*
*/
-#include <sys/signal.h>
-#include <unistd.h>
#include <thread>
#include <gflags/gflags.h>
@@ -43,7 +41,7 @@
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
+#include <grpc++/security/server_credentials.h>
#include "test/cpp/qps/qpstest.grpc.pb.h"
#include "test/cpp/qps/server.h"
diff --git a/test/cpp/util/cli_call_test.cc b/test/cpp/util/cli_call_test.cc
index 0efa201622..9c8d59987e 100644
--- a/test/cpp/util/cli_call_test.cc
+++ b/test/cpp/util/cli_call_test.cc
@@ -37,11 +37,9 @@
#include <grpc++/channel.h>
#include <grpc++/client_context.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
#include <grpc++/server.h>
#include <grpc++/server_builder.h>
#include <grpc++/server_context.h>
-#include <grpc++/server_credentials.h>
#include <gtest/gtest.h>
#include "test/core/util/port.h"
@@ -92,7 +90,7 @@ class CliCallTest : public ::testing::Test {
void ResetStub() {
channel_ = CreateChannel(server_address_.str(), InsecureCredentials());
- stub_ = std::move(grpc::cpp::test::util::TestService::NewStub(channel_));
+ stub_ = grpc::cpp::test::util::TestService::NewStub(channel_);
}
std::shared_ptr<Channel> channel_;
diff --git a/test/cpp/util/create_test_channel.cc b/test/cpp/util/create_test_channel.cc
index e993d14e71..f0d5bfc7eb 100644
--- a/test/cpp/util/create_test_channel.cc
+++ b/test/cpp/util/create_test_channel.cc
@@ -34,7 +34,7 @@
#include "test/cpp/util/create_test_channel.h"
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
+#include <grpc++/security/credentials.h>
#include "test/core/end2end/data/ssl_test_data.h"
diff --git a/test/cpp/util/create_test_channel.h b/test/cpp/util/create_test_channel.h
index 1263d4ed68..a4750689a0 100644
--- a/test/cpp/util/create_test_channel.h
+++ b/test/cpp/util/create_test_channel.h
@@ -36,7 +36,7 @@
#include <memory>
-#include <grpc++/credentials.h>
+#include <grpc++/security/credentials.h>
namespace grpc {
class Channel;
diff --git a/test/cpp/util/grpc_cli.cc b/test/cpp/util/grpc_cli.cc
index 22cac21f77..334b6efb6a 100644
--- a/test/cpp/util/grpc_cli.cc
+++ b/test/cpp/util/grpc_cli.cc
@@ -1,5 +1,5 @@
/*
- *
+
* Copyright 2015, Google Inc.
* All rights reserved.
*
@@ -67,7 +67,7 @@
#include <grpc/grpc.h>
#include <grpc++/channel.h>
#include <grpc++/create_channel.h>
-#include <grpc++/credentials.h>
+#include <grpc++/security/credentials.h>
#include <grpc++/support/string_ref.h>
#include "test/cpp/util/cli_call.h"
diff --git a/test/cpp/util/messages.proto b/test/cpp/util/messages.proto
index 359d1db74f..a022707be9 100644
--- a/test/cpp/util/messages.proto
+++ b/test/cpp/util/messages.proto
@@ -40,6 +40,7 @@ message RequestParams {
bool check_auth_context = 5;
int32 response_message_length = 6;
bool echo_peer = 7;
+ string expected_client_identity = 8; // will force check_auth_context.
}
message EchoRequest {