Merge github.com:grpc/grpc into ssl-bad-con

pull/4444/head
Craig Tiller 9 years ago
commit 27d6228855
  1. 6
      include/grpc/support/alloc.h
  2. 2
      src/core/census/context.h
  3. 8
      src/core/compression/message_compress.c
  4. 5
      src/core/iomgr/pollset_posix.c
  5. 5
      src/core/iomgr/tcp_windows.c
  6. 2
      src/core/json/json_reader.c
  7. 5
      src/core/security/credentials.c
  8. 2
      src/core/security/server_secure_chttp2.c
  9. 2
      src/core/support/time_posix.c
  10. 1
      src/core/surface/call_log_batch.c
  11. 8
      src/core/surface/channel.c
  12. 4
      src/core/surface/completion_queue.c
  13. 2
      src/core/surface/server_chttp2.c
  14. 3
      src/core/surface/server_create.c
  15. 2
      src/core/transport/chttp2/frame_data.c
  16. 7
      src/core/transport/chttp2/frame_settings.c
  17. 5
      src/core/transport/chttp2/hpack_encoder.c
  18. 3
      src/core/transport/chttp2/varint.h
  19. 138
      test/core/bad_client/tests/badreq.c
  20. 50
      test/core/bad_client/tests/headers.c
  21. 15
      test/core/bad_client/tests/initial_settings_frame.c
  22. 19
      test/core/bad_client/tests/simple_request.c
  23. 10
      test/core/bad_client/tests/unknown_frame.c
  24. 3
      test/core/client_config/lb_policies_test.c
  25. 22
      test/core/client_config/resolvers/dns_resolver_test.c
  26. 22
      test/core/client_config/resolvers/sockaddr_resolver_test.c
  27. 15
      test/core/compression/compression_test.c
  28. 8
      test/core/compression/message_compress_test.c
  29. 1
      test/core/end2end/fixtures/h2_full+pipe.c
  30. 25
      test/core/end2end/invalid_call_argument_test.c
  31. 12
      test/core/iomgr/sockaddr_utils_test.c
  32. 5
      test/core/json/json_stream_error_test.c
  33. 4
      test/core/security/credentials_test.c
  34. 20
      test/core/support/alloc_test.c
  35. 1
      test/core/support/sync_test.c
  36. 4
      test/core/surface/lame_client_test.c
  37. 5
      test/core/transport/chttp2/varint_test.c
  38. 145
      test/core/transport/connectivity_state_test.c
  39. 2
      test/cpp/end2end/async_end2end_test.cc

@ -41,9 +41,9 @@ extern "C" {
#endif
typedef struct gpr_allocation_functions {
void *(*malloc_fn)(size_t size);
void *(*realloc_fn)(void *ptr, size_t size);
void (*free_fn)(void *ptr);
void *(*malloc_fn)(size_t size);
void *(*realloc_fn)(void *ptr, size_t size);
void (*free_fn)(void *ptr);
} gpr_allocation_functions;
/* malloc, never returns NULL */

@ -41,7 +41,7 @@
/* census_context is the in-memory representation of information needed to
* maintain tracing, RPC statistics and resource usage information. */
struct census_context {
census_tag_set *tags; /* Opaque data structure for census tags. */
census_tag_set *tags; /* Opaque data structure for census tags. */
};
#endif /* GRPC_INTERNAL_CORE_CENSUS_CONTEXT_H */

@ -91,13 +91,11 @@ error:
return 0;
}
static void *zalloc_gpr(void* opaque, unsigned int items, unsigned int size) {
static void* zalloc_gpr(void* opaque, unsigned int items, unsigned int size) {
return gpr_malloc(items * size);
}
static void zfree_gpr(void* opaque, void *address) {
gpr_free(address);
}
static void zfree_gpr(void* opaque, void* address) { gpr_free(address); }
static int zlib_compress(gpr_slice_buffer* input, gpr_slice_buffer* output,
int gzip) {
@ -157,7 +155,7 @@ static int copy(gpr_slice_buffer* input, gpr_slice_buffer* output) {
}
static int compress_inner(grpc_compression_algorithm algorithm,
gpr_slice_buffer* input, gpr_slice_buffer* output) {
gpr_slice_buffer* input, gpr_slice_buffer* output) {
switch (algorithm) {
case GRPC_COMPRESS_NONE:
/* the fallback path always needs to be send uncompressed: we simply

@ -624,9 +624,8 @@ static void basic_pollset_destroy(grpc_pollset *pollset) {
}
static const grpc_pollset_vtable basic_pollset = {
basic_pollset_add_fd,
basic_pollset_maybe_work_and_unlock, basic_pollset_destroy,
basic_pollset_destroy};
basic_pollset_add_fd, basic_pollset_maybe_work_and_unlock,
basic_pollset_destroy, basic_pollset_destroy};
static void become_basic_pollset(grpc_pollset *pollset, grpc_fd *fd_or_null) {
pollset->vtable = &basic_pollset;

@ -197,7 +197,8 @@ static void win_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
tcp->read_slice = gpr_slice_malloc(8192);
buffer.len = (ULONG)GPR_SLICE_LENGTH(tcp->read_slice); // we know slice size fits in 32bit.
buffer.len = (ULONG)GPR_SLICE_LENGTH(
tcp->read_slice); // we know slice size fits in 32bit.
buffer.buf = (char *)GPR_SLICE_START_PTR(tcp->read_slice);
TCP_REF(tcp, "read");
@ -291,7 +292,7 @@ static void win_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep,
for (i = 0; i < tcp->write_slices->count; i++) {
len = GPR_SLICE_LENGTH(tcp->write_slices->slices[i]);
GPR_ASSERT(len <= ULONG_MAX);
buffers[i].len = (ULONG) len;
buffers[i].len = (ULONG)len;
buffers[i].buf = (char *)GPR_SLICE_START_PTR(tcp->write_slices->slices[i]);
}

@ -232,7 +232,7 @@ grpc_json_reader_status grpc_json_reader_run(grpc_json_reader *reader) {
reader->state = GRPC_JSON_STATE_END;
break;
default:
GPR_UNREACHABLE_CODE(return GRPC_JSON_INTERNAL_ERROR);
GPR_UNREACHABLE_CODE(return GRPC_JSON_INTERNAL_ERROR);
}
}
break;

@ -512,8 +512,9 @@ grpc_call_credentials *grpc_service_account_jwt_access_credentials_create(
"token_lifetime="
"gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
5, (json_key, (long long)token_lifetime.tv_sec, (int)token_lifetime.tv_nsec,
(int)token_lifetime.clock_type, reserved));
5,
(json_key, (long long)token_lifetime.tv_sec, (int)token_lifetime.tv_nsec,
(int)token_lifetime.clock_type, reserved));
GPR_ASSERT(reserved == NULL);
return grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
grpc_auth_json_key_create_from_string(json_key), token_lifetime);

@ -209,7 +209,7 @@ int grpc_server_add_secure_http2_port(grpc_server *server, const char *addr,
tcp, (struct sockaddr *)&resolved->addrs[i].addr,
resolved->addrs[i].len);
port_temp = grpc_tcp_listener_get_port(listener);
if (port_temp >= 0) {
if (port_temp > 0) {
if (port_num == -1) {
port_num = port_temp;
} else {

@ -47,7 +47,7 @@ static struct timespec timespec_from_gpr(gpr_timespec gts) {
struct timespec rv;
if (sizeof(time_t) < sizeof(gpr_int64)) {
/* fine to assert, as this is only used in gpr_sleep_until */
GPR_ASSERT(gts.tv_sec <= INT32_MAX && gts.tv_sec >= INT32_MIN);
GPR_ASSERT(gts.tv_sec <= INT32_MAX && gts.tv_sec >= INT32_MIN);
}
rv.tv_sec = (time_t)gts.tv_sec;
rv.tv_nsec = gts.tv_nsec;

@ -116,4 +116,3 @@ void grpc_call_log_batch(char *file, int line, gpr_log_severity severity,
gpr_free(tmp);
}
}

@ -198,8 +198,8 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel,
"deadline=gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
10, (channel, parent_call, (unsigned)propagation_mask, cq, method, host,
(long long)deadline.tv_sec, (int)deadline.tv_nsec, (int)deadline.clock_type,
reserved));
(long long)deadline.tv_sec, (int)deadline.tv_nsec,
(int)deadline.clock_type, reserved));
GPR_ASSERT(!reserved);
return grpc_channel_create_call_internal(
channel, parent_call, propagation_mask, cq,
@ -242,8 +242,8 @@ grpc_call *grpc_channel_create_registered_call(
"deadline=gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
9, (channel, parent_call, (unsigned)propagation_mask, completion_queue,
registered_call_handle, (long long)deadline.tv_sec, (int)deadline.tv_nsec,
(int)deadline.clock_type, reserved));
registered_call_handle, (long long)deadline.tv_sec,
(int)deadline.tv_nsec, (int)deadline.clock_type, reserved));
GPR_ASSERT(!reserved);
return grpc_channel_create_call_internal(
channel, parent_call, propagation_mask, completion_queue,

@ -249,8 +249,8 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc,
"cc=%p, "
"deadline=gpr_timespec { tv_sec: %lld, tv_nsec: %d, clock_type: %d }, "
"reserved=%p)",
5, (cc, (long long)deadline.tv_sec, (int)deadline.tv_nsec, (int)deadline.clock_type,
reserved));
5, (cc, (long long)deadline.tv_sec, (int)deadline.tv_nsec,
(int)deadline.clock_type, reserved));
GPR_ASSERT(!reserved);
deadline = gpr_convert_clock_type(deadline, GPR_CLOCK_MONOTONIC);

@ -109,7 +109,7 @@ int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) {
tcp, (struct sockaddr *)&resolved->addrs[i].addr,
resolved->addrs[i].len);
port_temp = grpc_tcp_listener_get_port(listener);
if (port_temp >= 0) {
if (port_temp > 0) {
if (port_num == -1) {
port_num = port_temp;
} else {

@ -47,6 +47,5 @@ grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved) {
filters[num_filters++] = &grpc_server_census_filter;
}
GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
return grpc_server_create_from_filters(filters, num_filters,
args);
return grpc_server_create_from_filters(filters, num_filters, args);
}

@ -118,7 +118,7 @@ void grpc_chttp2_encode_data(gpr_uint32 id, gpr_slice_buffer *inbuf,
hdr = gpr_slice_malloc(9);
p = GPR_SLICE_START_PTR(hdr);
GPR_ASSERT(write_bytes < (1<<24));
GPR_ASSERT(write_bytes < (1 << 24));
*p++ = (gpr_uint8)(write_bytes >> 16);
*p++ = (gpr_uint8)(write_bytes >> 8);
*p++ = (gpr_uint8)(write_bytes);

@ -44,7 +44,7 @@
#include "src/core/transport/chttp2/http2_errors.h"
#include "src/core/transport/chttp2_transport.h"
#define MAX_MAX_HEADER_LIST_SIZE (1024*1024*1024)
#define MAX_MAX_HEADER_LIST_SIZE (1024 * 1024 * 1024)
/* HTTP/2 mandated initial connection settings */
const grpc_chttp2_setting_parameters
@ -62,8 +62,9 @@ const grpc_chttp2_setting_parameters
GRPC_CHTTP2_FLOW_CONTROL_ERROR},
{"MAX_FRAME_SIZE", 16384, 16384, 16777215,
GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_CHTTP2_PROTOCOL_ERROR},
{"MAX_HEADER_LIST_SIZE", MAX_MAX_HEADER_LIST_SIZE, 0, MAX_MAX_HEADER_LIST_SIZE,
GRPC_CHTTP2_CLAMP_INVALID_VALUE, GRPC_CHTTP2_PROTOCOL_ERROR},
{"MAX_HEADER_LIST_SIZE", MAX_MAX_HEADER_LIST_SIZE, 0,
MAX_MAX_HEADER_LIST_SIZE, GRPC_CHTTP2_CLAMP_INVALID_VALUE,
GRPC_CHTTP2_PROTOCOL_ERROR},
};
static gpr_uint8 *fill_header(gpr_uint8 *out, gpr_uint32 length,

@ -366,8 +366,9 @@ static void hpack_enc(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem,
if (GPR_SLICE_START_PTR(elem->key->slice)[0] != ':') { /* regular header */
st->seen_regular_header = 1;
} else {
GPR_ASSERT(st->seen_regular_header == 0 &&
"Reserved header (colon-prefixed) happening after regular ones.");
GPR_ASSERT(
st->seen_regular_header == 0 &&
"Reserved header (colon-prefixed) happening after regular ones.");
}
inc_filter(HASH_FRAGMENT_1(elem_hash), &c->filter_elems_sum, c->filter_elems);

@ -66,7 +66,8 @@ void grpc_chttp2_hpack_write_varint_tail(gpr_uint32 tail_value,
if ((length) == 1u) { \
(tgt)[0] = (gpr_uint8)((prefix_or) | (n)); \
} else { \
(tgt)[0] = (prefix_or) | (gpr_uint8)GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \
(tgt)[0] = \
(prefix_or) | (gpr_uint8)GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits); \
grpc_chttp2_hpack_write_varint_tail( \
(n)-GRPC_CHTTP2_MAX_IN_PREFIX(prefix_bits), (tgt) + 1, (length)-1); \
} \

@ -38,8 +38,8 @@
#include "test/core/end2end/cq_verifier.h"
#include "src/core/surface/server.h"
#define PFX_STR \
"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
#define PFX_STR \
"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \
"\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */
static void verifier(grpc_server *server, grpc_completion_queue *cq) {
@ -54,76 +54,86 @@ int main(int argc, char **argv) {
grpc_test_init(argc, argv);
/* invalid content type */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
"\x00\x00\xc2\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c""content-type\x09text/html"
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
"\x10\x02te\x08trailers"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
GRPC_RUN_BAD_CLIENT_TEST(
verifier, PFX_STR
"\x00\x00\xc2\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c"
"content-type\x09text/html"
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
"\x10\x02te\x08trailers"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
/* invalid te */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
"\x00\x00\xcb\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c""content-type\x10""application/grpc"
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
"\x10\x02te\x0a""frobnicate"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
GRPC_RUN_BAD_CLIENT_TEST(
verifier, PFX_STR
"\x00\x00\xcb\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c"
"content-type\x10"
"application/grpc"
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
"\x10\x02te\x0a"
"frobnicate"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
/* two path headers */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
"\x00\x00\xd9\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x05:path\x08/foo/bah"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c""content-type\x10""application/grpc"
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
"\x10\x02te\x08trailers"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
GRPC_RUN_BAD_CLIENT_TEST(
verifier, PFX_STR
"\x00\x00\xd9\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x05:path\x08/foo/bah"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c"
"content-type\x10"
"application/grpc"
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
"\x10\x02te\x08trailers"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
/* bad accept-encoding algorithm */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
"\x00\x00\xd2\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c""content-type\x10""application/grpc"
"\x10\x14grpc-accept-encoding\x1enobody-knows-the-trouble-i-see"
"\x10\x02te\x08trailers"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
GRPC_RUN_BAD_CLIENT_TEST(
verifier, PFX_STR
"\x00\x00\xd2\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c"
"content-type\x10"
"application/grpc"
"\x10\x14grpc-accept-encoding\x1enobody-knows-the-trouble-i-see"
"\x10\x02te\x08trailers"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
/* bad grpc-encoding algorithm */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
"\x00\x00\xf5\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c""content-type\x10""application/grpc"
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
"\x10\x0dgrpc-encoding\x1cyou-dont-know-how-to-do-this"
"\x10\x02te\x08trailers"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
GRPC_RUN_BAD_CLIENT_TEST(
verifier, PFX_STR
"\x00\x00\xf5\x01\x04\x00\x00\x00\x01"
"\x10\x05:path\x08/foo/bar"
"\x10\x07:scheme\x04http"
"\x10\x07:method\x04POST"
"\x10\x0a:authority\x09localhost"
"\x10\x0c"
"content-type\x10"
"application/grpc"
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip"
"\x10\x0dgrpc-encoding\x1cyou-dont-know-how-to-do-this"
"\x10\x02te\x08trailers"
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)",
GRPC_BAD_CLIENT_DISCONNECT);
return 0;
}

@ -40,9 +40,9 @@
static void verifier(grpc_server *server, grpc_completion_queue *cq) {
while (grpc_server_has_open_connections(server)) {
GPR_ASSERT(grpc_completion_queue_next(
cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20), NULL)
.type == GRPC_QUEUE_TIMEOUT);
GPR_ASSERT(grpc_completion_queue_next(cq,
GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20),
NULL).type == GRPC_QUEUE_TIMEOUT);
}
}
@ -126,24 +126,29 @@ int main(int argc, char **argv) {
0);
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x04\x01\x04\x00\x00\x00\x01"
"\x7f\x7f\x01""a",
"\x7f\x7f\x01"
"a",
0);
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x04\x01\x04\x00\x00\x00\x01"
"\x0f\x7f\x01""a",
"\x0f\x7f\x01"
"a",
0);
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x04\x01\x04\x00\x00\x00\x01"
"\x1f\x7f\x01""a",
"\x1f\x7f\x01"
"a",
0);
/* test nvr, not indexed in static table */
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x03\x01\x04\x00\x00\x00\x01"
"\x01\x01""a",
"\x01\x01"
"a",
GRPC_BAD_CLIENT_DISCONNECT);
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x03\x01\x04\x00\x00\x00\x01"
"\x11\x01""a",
"\x11\x01"
"a",
GRPC_BAD_CLIENT_DISCONNECT);
/* illegal op code */
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
@ -228,14 +233,12 @@ int main(int argc, char **argv) {
GRPC_BAD_CLIENT_DISCONNECT);
/* dynamic table size update: set to default */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x03\x01\x04\x00\x00\x00\x01"
"\x3f\xe1\x1f",
GRPC_BAD_CLIENT_DISCONNECT);
/* dynamic table size update: set too large */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x03\x01\x04\x00\x00\x00\x01"
"\x3f\xf1\x1f",
0);
@ -251,42 +254,35 @@ int main(int argc, char **argv) {
0);
/* non-ending header followed by continuation frame */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x00\x01\x00\x00\x00\x00\x01"
"\x00\x00\x00\x09\x04\x00\x00\x00\x01",
GRPC_BAD_CLIENT_DISCONNECT);
/* non-ending header followed by non-continuation frame */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x00\x01\x00\x00\x00\x00\x01"
"\x00\x00\x00\x00\x04\x00\x00\x00\x01",
0);
/* non-ending header followed by a continuation frame for a different stream */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
/* non-ending header followed by a continuation frame for a different stream
*/
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x00\x01\x04\x00\x00\x00\x01"
"\x00\x00\x00\x01\x00\x00\x00\x00\x03"
"\x00\x00\x00\x09\x04\x00\x00\x00\x01",
0);
/* opening with a continuation frame */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
"\x00\x00\x00\x09\x04\x00\x00\x00\x01",
0);
PFX_STR "\x00\x00\x00\x09\x04\x00\x00\x00\x01", 0);
/* three header frames */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x00\x01\x04\x00\x00\x00\x01"
"\x00\x00\x00\x01\x04\x00\x00\x00\x01"
"\x00\x00\x00\x01\x04\x00\x00\x00\x01",
GRPC_BAD_CLIENT_DISCONNECT);
/* an invalid header found with fuzzing */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
"\x00\x00\x00\x01\x39\x67\xed\x1d\x64",
PFX_STR "\x00\x00\x00\x01\x39\x67\xed\x1d\x64",
GRPC_BAD_CLIENT_DISCONNECT);
/* a badly encoded timeout value */

@ -97,24 +97,23 @@ int main(int argc, char **argv) {
PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00",
GRPC_BAD_CLIENT_DISCONNECT);
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff",
PFX_STR ONE_SETTING_HDR "\x00\x06\xff\xff\xff\xff",
GRPC_BAD_CLIENT_DISCONNECT);
/* update intiial window size */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00",
PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00",
GRPC_BAD_CLIENT_DISCONNECT);
/* ack with data */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x00\x04\x00\x00\x00\x00\x00"
"\x00\x00\x01\x04\x01\x00\x00\x00\x00", 0);
"\x00\x00\x01\x04\x01\x00\x00\x00\x00",
0);
/* settings frame with invalid flags */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR
"\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0);
PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0);
/* unknown settings should be ignored */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00",
PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00",
GRPC_BAD_CLIENT_DISCONNECT);
return 0;

@ -51,7 +51,8 @@
"\x10\x0c" \
"content-type\x10" \
"application/grpc" \
"\x10\x14grpc-accept-encoding\x15""deflate,identity,gzip" \
"\x10\x14grpc-accept-encoding\x15" \
"deflate,identity,gzip" \
"\x10\x02te\x08trailers" \
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)"
@ -65,12 +66,16 @@
"\x10\x07:scheme\x04http" \
"\x10\x07:method\x04POST" \
"\x10\x04host\x09localhost" \
"\x10\x0c""content-type\x1e""application/grpc+this-is-valid" \
"\x10\x0c" \
"content-type\x1e" \
"application/grpc+this-is-valid" \
"\x10\x14grpc-accept-encoding\x15identity,deflate,gzip" \
"\x10\x02te\x08trailers" \
"\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" \
"\x10\x0cgrpc-timeout\x03""10S" \
"\x10\x0cgrpc-timeout\x02""5S"
"\x10\x0cgrpc-timeout\x03" \
"10S" \
"\x10\x0cgrpc-timeout\x02" \
"5S"
static void *tag(gpr_intptr t) { return (void *)t; }
@ -130,8 +135,10 @@ int main(int argc, char **argv) {
GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
PFX_STR "\x00\x00\x00\x08\x10\x00\x00\x00\x01", 0);
/* push a window update with bad data */
GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
PFX_STR "\x00\x00\x04\x08\x00\x00\x00\x00\x01" "\xff\xff\xff\xff", 0);
GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, PFX_STR
"\x00\x00\x04\x08\x00\x00\x00\x00\x01"
"\xff\xff\xff\xff",
0);
/* push a short goaway */
GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
PFX_STR "\x00\x00\x04\x07\x00\x00\x00\x00\x00", 0);

@ -40,9 +40,9 @@
static void verifier(grpc_server *server, grpc_completion_queue *cq) {
while (grpc_server_has_open_connections(server)) {
GPR_ASSERT(grpc_completion_queue_next(
cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20), NULL)
.type == GRPC_QUEUE_TIMEOUT);
GPR_ASSERT(grpc_completion_queue_next(cq,
GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20),
NULL).type == GRPC_QUEUE_TIMEOUT);
}
}
@ -50,8 +50,8 @@ int main(int argc, char **argv) {
grpc_test_init(argc, argv);
/* test adding prioritization data */
GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR
"\x00\x00\x00\x88\x00\x00\x00\x00\x01",
GRPC_RUN_BAD_CLIENT_TEST(verifier,
PFX_STR "\x00\x00\x00\x88\x00\x00\x00\x00\x01",
GRPC_BAD_CLIENT_DISCONNECT);
return 0;

@ -716,7 +716,8 @@ int main(int argc, char **argv) {
grpc_test_init(argc, argv);
grpc_init();
GPR_ASSERT(grpc_lb_policy_create("this-lb-policy-does-not-exist", NULL) == NULL);
GPR_ASSERT(grpc_lb_policy_create("this-lb-policy-does-not-exist", NULL) ==
NULL);
GPR_ASSERT(grpc_lb_policy_create(NULL, NULL) == NULL);
/* everything is fine, all servers stay up the whole time and life's peachy */

@ -41,28 +41,27 @@
#include "test/core/util/test_config.h"
static void subchannel_factory_ref(grpc_subchannel_factory *scv) {}
static void subchannel_factory_unref(grpc_exec_ctx *exec_ctx,
static void subchannel_factory_unref(grpc_exec_ctx *exec_ctx,
grpc_subchannel_factory *scv) {}
static grpc_subchannel *subchannel_factory_create_subchannel(grpc_exec_ctx *exec_ctx,
grpc_subchannel_factory *factory,
grpc_subchannel_args *args) {
static grpc_subchannel *subchannel_factory_create_subchannel(
grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory,
grpc_subchannel_args *args) {
GPR_UNREACHABLE_CODE(return NULL);
}
static const grpc_subchannel_factory_vtable sc_vtable = {
subchannel_factory_ref,
subchannel_factory_unref,
subchannel_factory_create_subchannel
};
subchannel_factory_ref, subchannel_factory_unref,
subchannel_factory_create_subchannel};
static grpc_subchannel_factory sc_factory = { &sc_vtable };
static grpc_subchannel_factory sc_factory = {&sc_vtable};
static void test_succeeds(grpc_resolver_factory *factory, const char *string) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_uri *uri = grpc_uri_parse(string, 0);
grpc_resolver_args args;
grpc_resolver *resolver;
gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, factory->vtable->scheme);
gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
factory->vtable->scheme);
GPR_ASSERT(uri);
memset(&args, 0, sizeof(args));
args.uri = uri;
@ -79,7 +78,8 @@ static void test_fails(grpc_resolver_factory *factory, const char *string) {
grpc_uri *uri = grpc_uri_parse(string, 0);
grpc_resolver_args args;
grpc_resolver *resolver;
gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, factory->vtable->scheme);
gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string,
factory->vtable->scheme);
GPR_ASSERT(uri);
memset(&args, 0, sizeof(args));
args.uri = uri;

@ -41,28 +41,27 @@
#include "test/core/util/test_config.h"
static void subchannel_factory_ref(grpc_subchannel_factory *scv) {}
static void subchannel_factory_unref(grpc_exec_ctx *exec_ctx,
static void subchannel_factory_unref(grpc_exec_ctx *exec_ctx,
grpc_subchannel_factory *scv) {}
static grpc_subchannel *subchannel_factory_create_subchannel(grpc_exec_ctx *exec_ctx,
grpc_subchannel_factory *factory,
grpc_subchannel_args *args) {
static grpc_subchannel *subchannel_factory_create_subchannel(
grpc_exec_ctx *exec_ctx, grpc_subchannel_factory *factory,
grpc_subchannel_args *args) {
GPR_UNREACHABLE_CODE(return NULL);
}
static const grpc_subchannel_factory_vtable sc_vtable = {
subchannel_factory_ref,
subchannel_factory_unref,
subchannel_factory_create_subchannel
};
subchannel_factory_ref, subchannel_factory_unref,
subchannel_factory_create_subchannel};
static grpc_subchannel_factory sc_factory = { &sc_vtable };
static grpc_subchannel_factory sc_factory = {&sc_vtable};
static void test_succeeds(grpc_resolver_factory *factory, const char *string) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
grpc_uri *uri = grpc_uri_parse(string, 0);
grpc_resolver_args args;
grpc_resolver *resolver;
gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string, factory->vtable->scheme);
gpr_log(GPR_DEBUG, "test: '%s' should be valid for '%s'", string,
factory->vtable->scheme);
GPR_ASSERT(uri);
memset(&args, 0, sizeof(args));
args.uri = uri;
@ -79,7 +78,8 @@ static void test_fails(grpc_resolver_factory *factory, const char *string) {
grpc_uri *uri = grpc_uri_parse(string, 0);
grpc_resolver_args args;
grpc_resolver *resolver;
gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string, factory->vtable->scheme);
gpr_log(GPR_DEBUG, "test: '%s' should be invalid for '%s'", string,
factory->vtable->scheme);
GPR_ASSERT(uri);
memset(&args, 0, sizeof(args));
args.uri = uri;

@ -92,14 +92,14 @@ static void test_compression_algorithm_name(void) {
/* the value of "name" is undefined upon failure */
}
static void test_compression_algorithm_for_level(void) {
size_t i;
grpc_compression_level levels[] = {
GRPC_COMPRESS_LEVEL_NONE, GRPC_COMPRESS_LEVEL_LOW,
GRPC_COMPRESS_LEVEL_MED, GRPC_COMPRESS_LEVEL_HIGH};
grpc_compression_algorithm algorithms[] = {GRPC_COMPRESS_NONE,
GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_DEFLATE};
grpc_compression_algorithm algorithms[] = {
GRPC_COMPRESS_NONE, GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_DEFLATE,
GRPC_COMPRESS_DEFLATE};
gpr_log(GPR_DEBUG, "test_compression_algorithm_for_level");
for (i = 0; i < GPR_ARRAY_SIZE(levels); i++) {
@ -115,19 +115,22 @@ static void test_compression_enable_disable_algorithm(void) {
gpr_log(GPR_DEBUG, "test_compression_enable_disable_algorithm");
grpc_compression_options_init(&options);
for (algorithm = GRPC_COMPRESS_NONE; algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
for (algorithm = GRPC_COMPRESS_NONE;
algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
/* all algorithms are enabled by default */
GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options,
algorithm) != 0);
}
/* disable one by one */
for (algorithm = GRPC_COMPRESS_NONE; algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
for (algorithm = GRPC_COMPRESS_NONE;
algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
grpc_compression_options_disable_algorithm(&options, algorithm);
GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options,
algorithm) == 0);
}
/* re-enable one by one */
for (algorithm = GRPC_COMPRESS_NONE; algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
for (algorithm = GRPC_COMPRESS_NONE;
algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
grpc_compression_options_enable_algorithm(&options, algorithm);
GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options,
algorithm) != 0);

@ -236,8 +236,8 @@ static void test_bad_compression_algorithm(void) {
gpr_slice_buffer_init(&input);
gpr_slice_buffer_init(&output);
gpr_slice_buffer_add(&input, gpr_slice_from_copied_string(
"Never gonna give you up"));
gpr_slice_buffer_add(&input,
gpr_slice_from_copied_string("Never gonna give you up"));
was_compressed =
grpc_msg_compress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output);
GPR_ASSERT(0 == was_compressed);
@ -264,8 +264,8 @@ static void test_bad_decompression_algorithm(void) {
grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT, &input, &output);
GPR_ASSERT(0 == was_decompressed);
was_decompressed =
grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT + 123, &input, &output);
was_decompressed = grpc_msg_decompress(GRPC_COMPRESS_ALGORITHMS_COUNT + 123,
&input, &output);
GPR_ASSERT(0 == was_decompressed);
gpr_slice_buffer_destroy(&input);

@ -51,7 +51,6 @@
#include "test/core/util/test_config.h"
#include "src/core/iomgr/wakeup_fd_posix.h"
typedef struct fullstack_fixture_data {
char *localaddr;
} fullstack_fixture_data;

@ -131,16 +131,15 @@ static void cleanup_test() {
grpc_server_shutdown_and_notify(g_state.server, g_state.cq, tag(1000));
GPR_ASSERT(grpc_completion_queue_pluck(g_state.cq, tag(1000),
GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5),
NULL)
.type == GRPC_OP_COMPLETE);
NULL).type == GRPC_OP_COMPLETE);
grpc_server_destroy(g_state.server);
grpc_call_details_destroy(&g_state.call_details);
grpc_metadata_array_destroy(&g_state.server_initial_metadata_recv);
}
grpc_completion_queue_shutdown(g_state.cq);
while (grpc_completion_queue_next(g_state.cq,
gpr_inf_future(GPR_CLOCK_REALTIME), NULL)
.type != GRPC_QUEUE_SHUTDOWN)
gpr_inf_future(GPR_CLOCK_REALTIME),
NULL).type != GRPC_QUEUE_SHUTDOWN)
;
grpc_completion_queue_destroy(g_state.cq);
}
@ -300,9 +299,9 @@ static void test_receive_initial_metadata_twice_at_client() {
op->flags = 0;
op->reserved = NULL;
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), NULL));
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1), NULL));
cleanup_test();
}
@ -316,9 +315,9 @@ static void test_receive_message_with_invalid_flags() {
op->flags = 1;
op->reserved = NULL;
op++;
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_FLAGS == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), NULL));
GPR_ASSERT(GRPC_CALL_ERROR_INVALID_FLAGS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1), NULL));
cleanup_test();
}
@ -337,9 +336,9 @@ static void test_receive_two_messages_at_the_same_time() {
op->flags = 0;
op->reserved = NULL;
op++;
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS == grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops),
tag(1), NULL));
GPR_ASSERT(GRPC_CALL_ERROR_TOO_MANY_OPERATIONS ==
grpc_call_start_batch(g_state.call, g_state.ops,
(size_t)(op - g_state.ops), tag(1), NULL));
cleanup_test();
}

@ -244,14 +244,14 @@ static void test_sockaddr_set_get_port(void) {
gpr_log(GPR_DEBUG, "test_sockaddr_set_get_port");
input4 = make_addr4(kIPv4, sizeof(kIPv4));
GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input4) == 12345);
GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr*)&input4, 54321));
GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input4) == 54321);
GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input4) == 12345);
GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr *)&input4, 54321));
GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input4) == 54321);
input6 = make_addr6(kIPv6, sizeof(kIPv6));
GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input6) == 12345);
GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr*)&input6, 54321));
GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input6) == 54321);
GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input6) == 12345);
GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr *)&input6, 54321));
GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr *)&input6) == 54321);
memset(&dummy, 0, sizeof(dummy));
dummy.sa_family = 123;

@ -54,9 +54,8 @@ static gpr_uint32 read_char(void *userdata) {
}
static grpc_json_reader_vtable reader_vtable = {
string_clear, NULL, NULL, read_char, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL
};
string_clear, NULL, NULL, read_char, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL};
static void read_error() {
grpc_json_reader reader;

@ -910,9 +910,7 @@ static int default_creds_gce_detection_httpcli_get_success_override(
return 1;
}
static char *null_well_known_creds_path_getter(void) {
return NULL;
}
static char *null_well_known_creds_path_getter(void) { return NULL; }
static void test_google_default_creds_gce(void) {
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;

@ -35,17 +35,11 @@
#include <grpc/support/alloc.h>
#include "test/core/util/test_config.h"
static void *fake_malloc(size_t size) {
return (void*)size;
}
static void *fake_malloc(size_t size) { return (void *)size; }
static void *fake_realloc(void *addr, size_t size) {
return (void*)size;
}
static void *fake_realloc(void *addr, size_t size) { return (void *)size; }
static void fake_free(void *addr) {
*((gpr_intptr*)addr) = 0xdeadd00d;
}
static void fake_free(void *addr) { *((gpr_intptr *)addr) = 0xdeadd00d; }
static void test_custom_allocs() {
const gpr_allocation_functions default_fns = gpr_get_allocation_functions();
@ -54,16 +48,16 @@ static void test_custom_allocs() {
gpr_allocation_functions fns = {fake_malloc, fake_realloc, fake_free};
gpr_set_allocation_functions(fns);
GPR_ASSERT((void*)0xdeadbeef == gpr_malloc(0xdeadbeef));
GPR_ASSERT((void*)0xcafed00d == gpr_realloc(0, 0xcafed00d));
GPR_ASSERT((void *)0xdeadbeef == gpr_malloc(0xdeadbeef));
GPR_ASSERT((void *)0xcafed00d == gpr_realloc(0, 0xcafed00d));
gpr_free(&addr_to_free);
GPR_ASSERT(addr_to_free == 0xdeadd00d);
/* Restore and check we don't get funky values and that we don't leak */
gpr_set_allocation_functions(default_fns);
GPR_ASSERT((void*)1 != (i = gpr_malloc(sizeof(*i))));
GPR_ASSERT((void*)2 != (i = gpr_realloc(i, 2)));
GPR_ASSERT((void *)1 != (i = gpr_malloc(sizeof(*i))));
GPR_ASSERT((void *)2 != (i = gpr_realloc(i, 2)));
gpr_free(i);
}

@ -430,7 +430,6 @@ static void refinc(void *v /*=m*/) {
mark_thread_done(m);
}
/* Wait until m->event is set to (void *)1, then decrement m->refcount by 1
(m->threads * m->iterations * m->incr_step) times, and ensure that the last
decrement caused the counter to reach zero, then mark thread as done. */

@ -48,12 +48,12 @@ grpc_closure transport_op_cb;
static void *tag(gpr_intptr x) { return (void *)x; }
void verify_connectivity(grpc_exec_ctx *exec_ctx, void *arg, int success) {
grpc_transport_op* op = arg;
grpc_transport_op *op = arg;
GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE == *op->connectivity_state);
GPR_ASSERT(success);
}
void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) { }
void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) {}
void test_transport_op(grpc_channel *channel) {
grpc_transport_op op;

@ -47,14 +47,15 @@ static void test_varint(gpr_uint32 value, gpr_uint32 prefix_bits,
gpr_log(GPR_DEBUG, "Test: 0x%08x", value);
GPR_ASSERT(nbytes == expect_length);
slice = gpr_slice_malloc(nbytes);
GRPC_CHTTP2_WRITE_VARINT(value, prefix_bits, prefix_or, GPR_SLICE_START_PTR(slice), nbytes);
GRPC_CHTTP2_WRITE_VARINT(value, prefix_bits, prefix_or,
GPR_SLICE_START_PTR(slice), nbytes);
GPR_ASSERT(gpr_slice_cmp(expect, slice) == 0);
gpr_slice_unref(expect);
gpr_slice_unref(slice);
}
#define TEST_VARINT(value, prefix_bits, prefix_or, expect) \
test_varint(value, prefix_bits, prefix_or, expect, sizeof(expect)-1)
test_varint(value, prefix_bits, prefix_or, expect, sizeof(expect) - 1)
int main(int argc, char **argv) {
grpc_test_init(argc, argv);

@ -39,96 +39,107 @@
#include "test/core/util/test_config.h"
#define THE_ARG ((void*)0xcafebabe)
#define THE_ARG ((void *)0xcafebabe)
int g_counter;
static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, int success) {
GPR_ASSERT(success);
GPR_ASSERT(arg == THE_ARG);
g_counter++;
GPR_ASSERT(success);
GPR_ASSERT(arg == THE_ARG);
g_counter++;
}
static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, int success) {
GPR_ASSERT(!success);
GPR_ASSERT(arg == THE_ARG);
g_counter++;
GPR_ASSERT(!success);
GPR_ASSERT(arg == THE_ARG);
g_counter++;
}
static void test_connectivity_state_name(void) {
gpr_log(GPR_DEBUG, "test_connectivity_state_name");
GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_IDLE), "IDLE"));
GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_CONNECTING), "CONNECTING"));
GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_READY), "READY"));
GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_TRANSIENT_FAILURE), "TRANSIENT_FAILURE"));
GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_FATAL_FAILURE), "FATAL_FAILURE"));
gpr_log(GPR_DEBUG, "test_connectivity_state_name");
GPR_ASSERT(0 ==
strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_IDLE), "IDLE"));
GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_CONNECTING),
"CONNECTING"));
GPR_ASSERT(0 ==
strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_READY), "READY"));
GPR_ASSERT(
0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_TRANSIENT_FAILURE),
"TRANSIENT_FAILURE"));
GPR_ASSERT(0 ==
strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_FATAL_FAILURE),
"FATAL_FAILURE"));
}
static void test_check(void) {
grpc_connectivity_state_tracker tracker;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_check");
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx");
GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
grpc_connectivity_state_tracker tracker;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_check");
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx");
GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
}
static void test_subscribe_then_unsubscribe(void) {
grpc_connectivity_state_tracker tracker;
grpc_closure *closure = grpc_closure_create(must_fail, THE_ARG);
grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe");
g_counter = 0;
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx");
GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, &state, closure));
grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_IDLE);
GPR_ASSERT(g_counter == 0);
grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, NULL, closure);
grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_IDLE);
GPR_ASSERT(g_counter == 1);
grpc_connectivity_state_tracker tracker;
grpc_closure *closure = grpc_closure_create(must_fail, THE_ARG);
grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_subscribe_then_unsubscribe");
g_counter = 0;
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx");
GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker,
&state, closure));
grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_IDLE);
GPR_ASSERT(g_counter == 0);
grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, NULL,
closure);
grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_IDLE);
GPR_ASSERT(g_counter == 1);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
}
static void test_subscribe_then_destroy(void) {
grpc_connectivity_state_tracker tracker;
grpc_closure *closure = grpc_closure_create(must_succeed, THE_ARG);
grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_subscribe_then_destroy");
g_counter = 0;
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx");
GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, &state, closure));
grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_IDLE);
GPR_ASSERT(g_counter == 0);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
GPR_ASSERT(g_counter == 1);
grpc_connectivity_state_tracker tracker;
grpc_closure *closure = grpc_closure_create(must_succeed, THE_ARG);
grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_subscribe_then_destroy");
g_counter = 0;
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx");
GPR_ASSERT(grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker,
&state, closure));
grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_IDLE);
GPR_ASSERT(g_counter == 0);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
GPR_ASSERT(g_counter == 1);
}
static void test_subscribe_with_failure_then_destroy(void) {
grpc_connectivity_state_tracker tracker;
grpc_closure *closure = grpc_closure_create(must_fail, THE_ARG);
grpc_connectivity_state state = GRPC_CHANNEL_FATAL_FAILURE;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy");
g_counter = 0;
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_FATAL_FAILURE, "xxx");
GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change(&exec_ctx, &tracker, &state, closure));
grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
GPR_ASSERT(g_counter == 0);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
GPR_ASSERT(g_counter == 1);
grpc_connectivity_state_tracker tracker;
grpc_closure *closure = grpc_closure_create(must_fail, THE_ARG);
grpc_connectivity_state state = GRPC_CHANNEL_FATAL_FAILURE;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy");
g_counter = 0;
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_FATAL_FAILURE, "xxx");
GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change(
&exec_ctx, &tracker, &state, closure));
grpc_exec_ctx_flush(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
GPR_ASSERT(g_counter == 0);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
GPR_ASSERT(g_counter == 1);
}
int main(int argc, char **argv) {

@ -184,7 +184,7 @@ class AsyncEnd2endTest : public ::testing::TestWithParam<bool> {
// in the same server, so first test that (for coverage)
ServerBuilder build_bad;
build_bad.AddListeningPort(server_address_.str(),
grpc::InsecureServerCredentials());
grpc::InsecureServerCredentials());
build_bad.RegisterAsyncService(&service_);
grpc::cpp::test::util::TestService::Service sync_service;
build_bad.RegisterService(&sync_service);

Loading…
Cancel
Save