From 34a57d0346afe95e11104462c30dc468b0cb0b89 Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Mon, 23 Oct 2017 15:33:21 -0700 Subject: rename all test core files to cc and a lot of C++ style conversions --- test/core/bad_client/bad_client.c | 211 --------------- test/core/bad_client/bad_client.cc | 211 +++++++++++++++ test/core/bad_client/gen_build_yaml.py | 4 +- test/core/bad_client/generate_tests.bzl | 4 +- test/core/bad_client/tests/badreq.c | 125 --------- test/core/bad_client/tests/badreq.cc | 125 +++++++++ test/core/bad_client/tests/connection_prefix.c | 60 ----- test/core/bad_client/tests/connection_prefix.cc | 60 +++++ test/core/bad_client/tests/head_of_line_blocking.c | 136 ---------- .../core/bad_client/tests/head_of_line_blocking.cc | 136 ++++++++++ test/core/bad_client/tests/headers.c | 293 --------------------- test/core/bad_client/tests/headers.cc | 293 +++++++++++++++++++++ .../core/bad_client/tests/initial_settings_frame.c | 108 -------- .../bad_client/tests/initial_settings_frame.cc | 108 ++++++++ test/core/bad_client/tests/large_metadata.c | 240 ----------------- test/core/bad_client/tests/large_metadata.cc | 240 +++++++++++++++++ .../bad_client/tests/server_registered_method.c | 124 --------- .../bad_client/tests/server_registered_method.cc | 124 +++++++++ test/core/bad_client/tests/simple_request.c | 166 ------------ test/core/bad_client/tests/simple_request.cc | 166 ++++++++++++ test/core/bad_client/tests/unknown_frame.c | 44 ---- test/core/bad_client/tests/unknown_frame.cc | 44 ++++ test/core/bad_client/tests/window_overflow.c | 98 ------- test/core/bad_client/tests/window_overflow.cc | 98 +++++++ 24 files changed, 1609 insertions(+), 1609 deletions(-) delete mode 100644 test/core/bad_client/bad_client.c create mode 100644 test/core/bad_client/bad_client.cc delete mode 100644 test/core/bad_client/tests/badreq.c create mode 100644 test/core/bad_client/tests/badreq.cc delete mode 100644 test/core/bad_client/tests/connection_prefix.c create mode 100644 test/core/bad_client/tests/connection_prefix.cc delete mode 100644 test/core/bad_client/tests/head_of_line_blocking.c create mode 100644 test/core/bad_client/tests/head_of_line_blocking.cc delete mode 100644 test/core/bad_client/tests/headers.c create mode 100644 test/core/bad_client/tests/headers.cc delete mode 100644 test/core/bad_client/tests/initial_settings_frame.c create mode 100644 test/core/bad_client/tests/initial_settings_frame.cc delete mode 100644 test/core/bad_client/tests/large_metadata.c create mode 100644 test/core/bad_client/tests/large_metadata.cc delete mode 100644 test/core/bad_client/tests/server_registered_method.c create mode 100644 test/core/bad_client/tests/server_registered_method.cc delete mode 100644 test/core/bad_client/tests/simple_request.c create mode 100644 test/core/bad_client/tests/simple_request.cc delete mode 100644 test/core/bad_client/tests/unknown_frame.c create mode 100644 test/core/bad_client/tests/unknown_frame.cc delete mode 100644 test/core/bad_client/tests/window_overflow.c create mode 100644 test/core/bad_client/tests/window_overflow.cc (limited to 'test/core/bad_client') diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c deleted file mode 100644 index b7b28a9ac4..0000000000 --- a/test/core/bad_client/bad_client.c +++ /dev/null @@ -1,211 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include -#include -#include -#include - -#include "src/core/ext/filters/http/server/http_server_filter.h" -#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" -#include "src/core/lib/channel/channel_stack.h" -#include "src/core/lib/iomgr/endpoint_pair.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/support/murmur_hash.h" -#include "src/core/lib/support/string.h" -#include "src/core/lib/surface/completion_queue.h" -#include "src/core/lib/surface/server.h" - -typedef struct { - grpc_server *server; - grpc_completion_queue *cq; - grpc_bad_client_server_side_validator validator; - void *registered_method; - gpr_event done_thd; - gpr_event done_write; -} thd_args; - -static void thd_func(void *arg) { - thd_args *a = (thd_args *)arg; - a->validator(a->server, a->cq, a->registered_method); - gpr_event_set(&a->done_thd, (void *)1); -} - -static void done_write(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - thd_args *a = (thd_args *)arg; - gpr_event_set(&a->done_write, (void *)1); -} - -static void server_setup_transport(void *ts, grpc_transport *transport) { - thd_args *a = (thd_args *)ts; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_server_setup_transport(&exec_ctx, a->server, transport, NULL, - grpc_server_get_channel_args(a->server)); - grpc_exec_ctx_finish(&exec_ctx); -} - -static void read_done(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - gpr_event *read_done = (gpr_event *)arg; - gpr_event_set(read_done, (void *)1); -} - -void grpc_run_bad_client_test( - grpc_bad_client_server_side_validator server_validator, - grpc_bad_client_client_stream_validator client_validator, - const char *client_payload, size_t client_payload_length, uint32_t flags) { - grpc_endpoint_pair sfd; - thd_args a; - gpr_thd_id id; - char *hex; - grpc_transport *transport; - grpc_slice slice = - grpc_slice_from_copied_buffer(client_payload, client_payload_length); - grpc_slice_buffer outgoing; - grpc_closure done_write_closure; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_completion_queue *shutdown_cq; - - if (client_payload_length < 4 * 1024) { - hex = gpr_dump(client_payload, client_payload_length, - GPR_DUMP_HEX | GPR_DUMP_ASCII); - - /* Add a debug log */ - gpr_log(GPR_INFO, "TEST: %s", hex); - - gpr_free(hex); - } else { - gpr_log(GPR_INFO, "TEST: (%" PRIdPTR " byte long string)", - client_payload_length); - } - - /* Init grpc */ - grpc_init(); - - /* Create endpoints */ - sfd = grpc_iomgr_create_endpoint_pair("fixture", NULL); - - /* Create server, completion events */ - a.server = grpc_server_create(NULL, NULL); - a.cq = grpc_completion_queue_create_for_next(NULL); - gpr_event_init(&a.done_thd); - gpr_event_init(&a.done_write); - a.validator = server_validator; - grpc_server_register_completion_queue(a.server, a.cq, NULL); - a.registered_method = - grpc_server_register_method(a.server, GRPC_BAD_CLIENT_REGISTERED_METHOD, - GRPC_BAD_CLIENT_REGISTERED_HOST, - GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, 0); - grpc_server_start(a.server); - transport = grpc_create_chttp2_transport(&exec_ctx, NULL, sfd.server, 0); - server_setup_transport(&a, transport); - grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); - grpc_exec_ctx_finish(&exec_ctx); - - /* Bind everything into the same pollset */ - grpc_endpoint_add_to_pollset(&exec_ctx, sfd.client, grpc_cq_pollset(a.cq)); - grpc_endpoint_add_to_pollset(&exec_ctx, sfd.server, grpc_cq_pollset(a.cq)); - - /* Check a ground truth */ - GPR_ASSERT(grpc_server_has_open_connections(a.server)); - - /* Start validator */ - gpr_thd_new(&id, thd_func, &a, NULL); - - grpc_slice_buffer_init(&outgoing); - grpc_slice_buffer_add(&outgoing, slice); - GRPC_CLOSURE_INIT(&done_write_closure, done_write, &a, - grpc_schedule_on_exec_ctx); - - /* Write data */ - grpc_endpoint_write(&exec_ctx, sfd.client, &outgoing, &done_write_closure); - grpc_exec_ctx_finish(&exec_ctx); - - /* Await completion, unless the request is large and write may not finish - * before the peer shuts down. */ - if (!(flags & GRPC_BAD_CLIENT_LARGE_REQUEST)) { - GPR_ASSERT( - gpr_event_wait(&a.done_write, grpc_timeout_seconds_to_deadline(5))); - } - - if (flags & GRPC_BAD_CLIENT_DISCONNECT) { - grpc_endpoint_shutdown( - &exec_ctx, sfd.client, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); - grpc_endpoint_destroy(&exec_ctx, sfd.client); - grpc_exec_ctx_finish(&exec_ctx); - sfd.client = NULL; - } - - GPR_ASSERT(gpr_event_wait(&a.done_thd, grpc_timeout_seconds_to_deadline(5))); - - if (sfd.client != NULL) { - // Validate client stream, if requested. - if (client_validator != NULL) { - gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5); - grpc_slice_buffer incoming; - grpc_slice_buffer_init(&incoming); - // We may need to do multiple reads to read the complete server response. - while (true) { - gpr_event read_done_event; - gpr_event_init(&read_done_event); - grpc_closure read_done_closure; - GRPC_CLOSURE_INIT(&read_done_closure, read_done, &read_done_event, - grpc_schedule_on_exec_ctx); - grpc_endpoint_read(&exec_ctx, sfd.client, &incoming, - &read_done_closure); - grpc_exec_ctx_finish(&exec_ctx); - do { - GPR_ASSERT(gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0); - GPR_ASSERT(grpc_completion_queue_next( - a.cq, grpc_timeout_milliseconds_to_deadline(100), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } while (!gpr_event_get(&read_done_event)); - if (client_validator(&incoming)) break; - gpr_log(GPR_INFO, - "client validator failed; trying additional read " - "in case we didn't get all the data"); - } - grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming); - } - // Shutdown. - grpc_endpoint_shutdown( - &exec_ctx, sfd.client, - GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); - grpc_endpoint_destroy(&exec_ctx, sfd.client); - grpc_exec_ctx_finish(&exec_ctx); - } - - GPR_ASSERT( - gpr_event_wait(&a.done_write, grpc_timeout_seconds_to_deadline(1))); - shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); - grpc_server_shutdown_and_notify(a.server, shutdown_cq, NULL); - GPR_ASSERT(grpc_completion_queue_pluck( - shutdown_cq, NULL, grpc_timeout_seconds_to_deadline(1), NULL) - .type == GRPC_OP_COMPLETE); - grpc_completion_queue_destroy(shutdown_cq); - grpc_server_destroy(a.server); - grpc_completion_queue_destroy(a.cq); - grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); - - grpc_exec_ctx_finish(&exec_ctx); - grpc_shutdown(); -} diff --git a/test/core/bad_client/bad_client.cc b/test/core/bad_client/bad_client.cc new file mode 100644 index 0000000000..b7b28a9ac4 --- /dev/null +++ b/test/core/bad_client/bad_client.cc @@ -0,0 +1,211 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include +#include +#include +#include + +#include "src/core/ext/filters/http/server/http_server_filter.h" +#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" +#include "src/core/lib/channel/channel_stack.h" +#include "src/core/lib/iomgr/endpoint_pair.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/support/murmur_hash.h" +#include "src/core/lib/support/string.h" +#include "src/core/lib/surface/completion_queue.h" +#include "src/core/lib/surface/server.h" + +typedef struct { + grpc_server *server; + grpc_completion_queue *cq; + grpc_bad_client_server_side_validator validator; + void *registered_method; + gpr_event done_thd; + gpr_event done_write; +} thd_args; + +static void thd_func(void *arg) { + thd_args *a = (thd_args *)arg; + a->validator(a->server, a->cq, a->registered_method); + gpr_event_set(&a->done_thd, (void *)1); +} + +static void done_write(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { + thd_args *a = (thd_args *)arg; + gpr_event_set(&a->done_write, (void *)1); +} + +static void server_setup_transport(void *ts, grpc_transport *transport) { + thd_args *a = (thd_args *)ts; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_server_setup_transport(&exec_ctx, a->server, transport, NULL, + grpc_server_get_channel_args(a->server)); + grpc_exec_ctx_finish(&exec_ctx); +} + +static void read_done(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { + gpr_event *read_done = (gpr_event *)arg; + gpr_event_set(read_done, (void *)1); +} + +void grpc_run_bad_client_test( + grpc_bad_client_server_side_validator server_validator, + grpc_bad_client_client_stream_validator client_validator, + const char *client_payload, size_t client_payload_length, uint32_t flags) { + grpc_endpoint_pair sfd; + thd_args a; + gpr_thd_id id; + char *hex; + grpc_transport *transport; + grpc_slice slice = + grpc_slice_from_copied_buffer(client_payload, client_payload_length); + grpc_slice_buffer outgoing; + grpc_closure done_write_closure; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_completion_queue *shutdown_cq; + + if (client_payload_length < 4 * 1024) { + hex = gpr_dump(client_payload, client_payload_length, + GPR_DUMP_HEX | GPR_DUMP_ASCII); + + /* Add a debug log */ + gpr_log(GPR_INFO, "TEST: %s", hex); + + gpr_free(hex); + } else { + gpr_log(GPR_INFO, "TEST: (%" PRIdPTR " byte long string)", + client_payload_length); + } + + /* Init grpc */ + grpc_init(); + + /* Create endpoints */ + sfd = grpc_iomgr_create_endpoint_pair("fixture", NULL); + + /* Create server, completion events */ + a.server = grpc_server_create(NULL, NULL); + a.cq = grpc_completion_queue_create_for_next(NULL); + gpr_event_init(&a.done_thd); + gpr_event_init(&a.done_write); + a.validator = server_validator; + grpc_server_register_completion_queue(a.server, a.cq, NULL); + a.registered_method = + grpc_server_register_method(a.server, GRPC_BAD_CLIENT_REGISTERED_METHOD, + GRPC_BAD_CLIENT_REGISTERED_HOST, + GRPC_SRM_PAYLOAD_READ_INITIAL_BYTE_BUFFER, 0); + grpc_server_start(a.server); + transport = grpc_create_chttp2_transport(&exec_ctx, NULL, sfd.server, 0); + server_setup_transport(&a, transport); + grpc_chttp2_transport_start_reading(&exec_ctx, transport, NULL); + grpc_exec_ctx_finish(&exec_ctx); + + /* Bind everything into the same pollset */ + grpc_endpoint_add_to_pollset(&exec_ctx, sfd.client, grpc_cq_pollset(a.cq)); + grpc_endpoint_add_to_pollset(&exec_ctx, sfd.server, grpc_cq_pollset(a.cq)); + + /* Check a ground truth */ + GPR_ASSERT(grpc_server_has_open_connections(a.server)); + + /* Start validator */ + gpr_thd_new(&id, thd_func, &a, NULL); + + grpc_slice_buffer_init(&outgoing); + grpc_slice_buffer_add(&outgoing, slice); + GRPC_CLOSURE_INIT(&done_write_closure, done_write, &a, + grpc_schedule_on_exec_ctx); + + /* Write data */ + grpc_endpoint_write(&exec_ctx, sfd.client, &outgoing, &done_write_closure); + grpc_exec_ctx_finish(&exec_ctx); + + /* Await completion, unless the request is large and write may not finish + * before the peer shuts down. */ + if (!(flags & GRPC_BAD_CLIENT_LARGE_REQUEST)) { + GPR_ASSERT( + gpr_event_wait(&a.done_write, grpc_timeout_seconds_to_deadline(5))); + } + + if (flags & GRPC_BAD_CLIENT_DISCONNECT) { + grpc_endpoint_shutdown( + &exec_ctx, sfd.client, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Forced Disconnect")); + grpc_endpoint_destroy(&exec_ctx, sfd.client); + grpc_exec_ctx_finish(&exec_ctx); + sfd.client = NULL; + } + + GPR_ASSERT(gpr_event_wait(&a.done_thd, grpc_timeout_seconds_to_deadline(5))); + + if (sfd.client != NULL) { + // Validate client stream, if requested. + if (client_validator != NULL) { + gpr_timespec deadline = grpc_timeout_seconds_to_deadline(5); + grpc_slice_buffer incoming; + grpc_slice_buffer_init(&incoming); + // We may need to do multiple reads to read the complete server response. + while (true) { + gpr_event read_done_event; + gpr_event_init(&read_done_event); + grpc_closure read_done_closure; + GRPC_CLOSURE_INIT(&read_done_closure, read_done, &read_done_event, + grpc_schedule_on_exec_ctx); + grpc_endpoint_read(&exec_ctx, sfd.client, &incoming, + &read_done_closure); + grpc_exec_ctx_finish(&exec_ctx); + do { + GPR_ASSERT(gpr_time_cmp(deadline, gpr_now(deadline.clock_type)) > 0); + GPR_ASSERT(grpc_completion_queue_next( + a.cq, grpc_timeout_milliseconds_to_deadline(100), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } while (!gpr_event_get(&read_done_event)); + if (client_validator(&incoming)) break; + gpr_log(GPR_INFO, + "client validator failed; trying additional read " + "in case we didn't get all the data"); + } + grpc_slice_buffer_destroy_internal(&exec_ctx, &incoming); + } + // Shutdown. + grpc_endpoint_shutdown( + &exec_ctx, sfd.client, + GRPC_ERROR_CREATE_FROM_STATIC_STRING("Test Shutdown")); + grpc_endpoint_destroy(&exec_ctx, sfd.client); + grpc_exec_ctx_finish(&exec_ctx); + } + + GPR_ASSERT( + gpr_event_wait(&a.done_write, grpc_timeout_seconds_to_deadline(1))); + shutdown_cq = grpc_completion_queue_create_for_pluck(NULL); + grpc_server_shutdown_and_notify(a.server, shutdown_cq, NULL); + GPR_ASSERT(grpc_completion_queue_pluck( + shutdown_cq, NULL, grpc_timeout_seconds_to_deadline(1), NULL) + .type == GRPC_OP_COMPLETE); + grpc_completion_queue_destroy(shutdown_cq); + grpc_server_destroy(a.server); + grpc_completion_queue_destroy(a.cq); + grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); + + grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); +} diff --git a/test/core/bad_client/gen_build_yaml.py b/test/core/bad_client/gen_build_yaml.py index 61cf1f7cd7..14c8a27334 100755 --- a/test/core/bad_client/gen_build_yaml.py +++ b/test/core/bad_client/gen_build_yaml.py @@ -46,7 +46,7 @@ def main(): 'build': 'private', 'language': 'c', 'src': [ - 'test/core/bad_client/bad_client.c' + 'test/core/bad_client/bad_client.cc' ], 'headers': [ 'test/core/bad_client/bad_client.h' @@ -66,7 +66,7 @@ def main(): 'build': 'test', 'language': 'c', 'secure': 'no', - 'src': ['test/core/bad_client/tests/%s.c' % t], + 'src': ['test/core/bad_client/tests/%s.cc' % t], 'vs_proj_dir': 'test', 'exclude_iomgrs': ['uv'], 'deps': [ diff --git a/test/core/bad_client/generate_tests.bzl b/test/core/bad_client/generate_tests.bzl index 58b48d688f..cdea9cc2d1 100755 --- a/test/core/bad_client/generate_tests.bzl +++ b/test/core/bad_client/generate_tests.bzl @@ -38,7 +38,7 @@ BAD_CLIENT_TESTS = { def grpc_bad_client_tests(): native.cc_library( name = 'bad_client_test', - srcs = ['bad_client.c'], + srcs = ['bad_client.cc'], hdrs = ['bad_client.h'], copts = ['-std=c99'], deps = ['//test/core/util:grpc_test_util', '//:grpc', '//:gpr', '//test/core/end2end:cq_verifier'] @@ -46,7 +46,7 @@ def grpc_bad_client_tests(): for t, topt in BAD_CLIENT_TESTS.items(): native.cc_test( name = '%s_bad_client_test' % t, - srcs = ['tests/%s.c' % t], + srcs = ['tests/%s.cc' % t], deps = [':bad_client_test'], copts = ['-std=c99'], ) diff --git a/test/core/bad_client/tests/badreq.c b/test/core/bad_client/tests/badreq.c deleted file mode 100644 index 7d9a103e43..0000000000 --- a/test/core/bad_client/tests/badreq.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -#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, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* invalid content type */ - GRPC_RUN_BAD_CLIENT_TEST( - verifier, NULL, 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, NULL, 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, NULL, 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, NULL, 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, NULL, 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; -} diff --git a/test/core/bad_client/tests/badreq.cc b/test/core/bad_client/tests/badreq.cc new file mode 100644 index 0000000000..7d9a103e43 --- /dev/null +++ b/test/core/bad_client/tests/badreq.cc @@ -0,0 +1,125 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +#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, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* invalid content type */ + GRPC_RUN_BAD_CLIENT_TEST( + verifier, NULL, 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, NULL, 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, NULL, 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, NULL, 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, NULL, 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; +} diff --git a/test/core/bad_client/tests/connection_prefix.c b/test/core/bad_client/tests/connection_prefix.c deleted file mode 100644 index 6cc4b72314..0000000000 --- a/test/core/bad_client/tests/connection_prefix.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/surface/server.h" -#include "test/core/bad_client/bad_client.h" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRIX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI *X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTPX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0X", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\rX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\nX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\rX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSMX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\rX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\r\nX", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\r\n\rX", - 0); - return 0; -} diff --git a/test/core/bad_client/tests/connection_prefix.cc b/test/core/bad_client/tests/connection_prefix.cc new file mode 100644 index 0000000000..6cc4b72314 --- /dev/null +++ b/test/core/bad_client/tests/connection_prefix.cc @@ -0,0 +1,60 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/surface/server.h" +#include "test/core/bad_client/bad_client.h" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRIX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI *X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTPX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0X", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\rX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\nX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\rX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSMX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\rX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\r\nX", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, "PRI * HTTP/2.0\r\n\r\nSM\r\n\rX", + 0); + return 0; +} diff --git a/test/core/bad_client/tests/head_of_line_blocking.c b/test/core/bad_client/tests/head_of_line_blocking.c deleted file mode 100644 index 04485d501f..0000000000 --- a/test/core/bad_client/tests/head_of_line_blocking.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include - -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -static const char prefix[] = - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" - // settings frame - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" - // stream 1 headers: generated from server_registered_method.headers in this - // directory - "\x00\x00\xd0\x01\x04\x00\x00\x00\x01" - "\x10\x05:path\x0f/registered/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\x08trailers" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - // data frame for stream 1: advertise a 10000 byte payload (that we won't - // fulfill) - "\x00\x00\x05\x00\x00\x00\x00\x00\x01" - "\x01\x00\x00\x27\x10" - // stream 3 headers: generated from server_registered_method.headers in this - // directory - "\x00\x00\xd0\x01\x04\x00\x00\x00\x03" - "\x10\x05:path\x0f/registered/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\x08trailers" - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - // data frame for stream 3: advertise a 10000 byte payload (that we will - // fulfill) - "\x00\x00\x05\x00\x00\x00\x00\x00\x03" - "\x01\x00\x00\x27\x10" - ""; - -static void *tag(intptr_t t) { return (void *)t; } - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - gpr_timespec deadline; - grpc_byte_buffer *payload = NULL; - - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_registered_call(server, registered_method, &s, - &deadline, &request_metadata_recv, - &payload, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(payload != NULL); - - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_unref(s); - grpc_byte_buffer_destroy(payload); - cq_verifier_destroy(cqv); -} - -char *g_buffer; -size_t g_cap = 0; -size_t g_count = 0; - -static void addbuf(const void *data, size_t len) { - if (g_count + len > g_cap) { - g_cap = GPR_MAX(g_count + len, g_cap * 2); - g_buffer = gpr_realloc(g_buffer, g_cap); - } - memcpy(g_buffer + g_count, data, len); - g_count += len; -} - -int main(int argc, char **argv) { - int i; - grpc_test_init(argc, argv); - -#define NUM_FRAMES 10 -#define FRAME_SIZE 1000 - - addbuf(prefix, sizeof(prefix) - 1); - for (i = 0; i < NUM_FRAMES; i++) { - uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), - (uint8_t)(FRAME_SIZE >> 8), - (uint8_t)FRAME_SIZE, - 0, - 0, - 0, - 0, - 0, - 3}; - uint8_t msg[FRAME_SIZE]; - memset(msg, 'a', sizeof(msg)); - addbuf(hdr, sizeof(hdr)); - addbuf(msg, FRAME_SIZE); - } - grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, 0); - gpr_free(g_buffer); - - return 0; -} diff --git a/test/core/bad_client/tests/head_of_line_blocking.cc b/test/core/bad_client/tests/head_of_line_blocking.cc new file mode 100644 index 0000000000..cb89423907 --- /dev/null +++ b/test/core/bad_client/tests/head_of_line_blocking.cc @@ -0,0 +1,136 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include + +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +static const char prefix[] = + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" + // settings frame + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" + // stream 1 headers: generated from server_registered_method.headers in this + // directory + "\x00\x00\xd0\x01\x04\x00\x00\x00\x01" + "\x10\x05:path\x0f/registered/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\x08trailers" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + // data frame for stream 1: advertise a 10000 byte payload (that we won't + // fulfill) + "\x00\x00\x05\x00\x00\x00\x00\x00\x01" + "\x01\x00\x00\x27\x10" + // stream 3 headers: generated from server_registered_method.headers in this + // directory + "\x00\x00\xd0\x01\x04\x00\x00\x00\x03" + "\x10\x05:path\x0f/registered/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\x08trailers" + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + // data frame for stream 3: advertise a 10000 byte payload (that we will + // fulfill) + "\x00\x00\x05\x00\x00\x00\x00\x00\x03" + "\x01\x00\x00\x27\x10" + ""; + +static void *tag(intptr_t t) { return (void *)t; } + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + gpr_timespec deadline; + grpc_byte_buffer *payload = NULL; + + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_registered_call(server, registered_method, &s, + &deadline, &request_metadata_recv, + &payload, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(payload != NULL); + + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_unref(s); + grpc_byte_buffer_destroy(payload); + cq_verifier_destroy(cqv); +} + +char *g_buffer; +size_t g_cap = 0; +size_t g_count = 0; + +static void addbuf(const void *data, size_t len) { + if (g_count + len > g_cap) { + g_cap = GPR_MAX(g_count + len, g_cap * 2); + g_buffer = static_cast(gpr_realloc(g_buffer, g_cap)); + } + memcpy(g_buffer + g_count, data, len); + g_count += len; +} + +int main(int argc, char **argv) { + int i; + grpc_test_init(argc, argv); + +#define NUM_FRAMES 10 +#define FRAME_SIZE 1000 + + addbuf(prefix, sizeof(prefix) - 1); + for (i = 0; i < NUM_FRAMES; i++) { + uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), + (uint8_t)(FRAME_SIZE >> 8), + (uint8_t)FRAME_SIZE, + 0, + 0, + 0, + 0, + 0, + 3}; + uint8_t msg[FRAME_SIZE]; + memset(msg, 'a', sizeof(msg)); + addbuf(hdr, sizeof(hdr)); + addbuf(msg, FRAME_SIZE); + } + grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, 0); + gpr_free(g_buffer); + + return 0; +} diff --git a/test/core/bad_client/tests/headers.c b/test/core/bad_client/tests/headers.c deleted file mode 100644 index c704dbbcb6..0000000000 --- a/test/core/bad_client/tests/headers.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/surface/server.h" -#include "test/core/bad_client/bad_client.h" - -#define PFX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* partial http2 header prefixes */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x04", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x05", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x04\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x04\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - - /* test adding prioritization data */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x01\x01\x24\x00\x00\x00\x01" - "\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x02\x01\x24\x00\x00\x00\x01" - "\x00\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x24\x00\x00\x00\x01" - "\x00\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - - /* test looking up an invalid index */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x01\x01\x04\x00\x00\x00\x01" - "\xfe", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x7f\x7f\x01" - "a", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x0f\x7f\x01" - "a", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x1f\x7f\x01" - "a", - 0); - /* test nvr, not indexed in static table */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x01\x01" - "a", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x11\x01" - "a", - GRPC_BAD_CLIENT_DISCONNECT); - /* illegal op code */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x01\x01\x04\x00\x00\x00\x01" - "\x80", - 0); - /* parse some long indices */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x02\x01\x04\x00\x00\x00\x01" - "\xff\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\xff\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x06\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x07\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80\x80", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80\x80\x00", - 0); - /* overflow on byte 4 */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x06\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x7f", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x06\x01\x04\x00\x00\x00\x01" - "\xff\xff\xff\xff\xff\x0f", - GRPC_BAD_CLIENT_DISCONNECT); - /* overflow after byte 4 */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x08\x01\x04\x00\x00\x00\x01" - "\xff\x80\x80\x80\x80\x80\x80\x02", - 0); - /* end of headers mid-opcode */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x01\x01\x04\x00\x00\x00\x01" - "\x01", - GRPC_BAD_CLIENT_DISCONNECT); - - /* dynamic table size update: set to default */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, 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, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x3f\xf1\x1f", - 0); - /* dynamic table size update: set twice */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x20\x3f\xe1\x1f", - GRPC_BAD_CLIENT_DISCONNECT); - /* dynamic table size update: set thrice */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x20\x20\x20", - 0); - - /* non-ending header followed by continuation frame */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, 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, NULL, 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, NULL, 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, NULL, - PFX_STR "\x00\x00\x00\x09\x04\x00\x00\x00\x01", 0); - /* three header frames */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, 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, NULL, - PFX_STR "\x00\x00\x00\x01\x39\x67\xed\x1d\x64", - GRPC_BAD_CLIENT_DISCONNECT); - - /* a badly encoded timeout value */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x19\x01\x04\x00\x00\x00\x01" - "\x10\x0cgrpc-timeout\x0a" - "15 seconds", - GRPC_BAD_CLIENT_DISCONNECT); - /* a badly encoded timeout value: twice (catches caching) */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x19\x01\x04\x00\x00\x00\x01" - "\x10\x0cgrpc-timeout\x0a" - "15 seconds" - "\x00\x00\x19\x01\x04\x00\x00\x00\x03" - "\x10\x0cgrpc-timeout\x0a" - "15 seconds", - GRPC_BAD_CLIENT_DISCONNECT); - - return 0; -} diff --git a/test/core/bad_client/tests/headers.cc b/test/core/bad_client/tests/headers.cc new file mode 100644 index 0000000000..c704dbbcb6 --- /dev/null +++ b/test/core/bad_client/tests/headers.cc @@ -0,0 +1,293 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/surface/server.h" +#include "test/core/bad_client/bad_client.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* partial http2 header prefixes */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x04", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x05", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x01\x04\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x04\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x01\x04\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + + /* test adding prioritization data */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x01\x01\x24\x00\x00\x00\x01" + "\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x02\x01\x24\x00\x00\x00\x01" + "\x00\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + + /* test looking up an invalid index */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x01\x01\x04\x00\x00\x00\x01" + "\xfe", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\x7f\x7f\x01" + "a", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\x0f\x7f\x01" + "a", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\x1f\x7f\x01" + "a", + 0); + /* test nvr, not indexed in static table */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x01\x01" + "a", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x11\x01" + "a", + GRPC_BAD_CLIENT_DISCONNECT); + /* illegal op code */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x01\x01\x04\x00\x00\x00\x01" + "\x80", + 0); + /* parse some long indices */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x02\x01\x04\x00\x00\x00\x01" + "\xff\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\xff\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x06\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x07\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80\x80", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80\x80\x00", + 0); + /* overflow on byte 4 */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x06\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x7f", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x06\x01\x04\x00\x00\x00\x01" + "\xff\xff\xff\xff\xff\x0f", + GRPC_BAD_CLIENT_DISCONNECT); + /* overflow after byte 4 */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x08\x01\x04\x00\x00\x00\x01" + "\xff\x80\x80\x80\x80\x80\x80\x02", + 0); + /* end of headers mid-opcode */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x01\x01\x04\x00\x00\x00\x01" + "\x01", + GRPC_BAD_CLIENT_DISCONNECT); + + /* dynamic table size update: set to default */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, 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, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x3f\xf1\x1f", + 0); + /* dynamic table size update: set twice */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x04\x01\x04\x00\x00\x00\x01" + "\x20\x3f\xe1\x1f", + GRPC_BAD_CLIENT_DISCONNECT); + /* dynamic table size update: set thrice */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x03\x01\x04\x00\x00\x00\x01" + "\x20\x20\x20", + 0); + + /* non-ending header followed by continuation frame */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, 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, NULL, 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, NULL, 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, NULL, + PFX_STR "\x00\x00\x00\x09\x04\x00\x00\x00\x01", 0); + /* three header frames */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, 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, NULL, + PFX_STR "\x00\x00\x00\x01\x39\x67\xed\x1d\x64", + GRPC_BAD_CLIENT_DISCONNECT); + + /* a badly encoded timeout value */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x19\x01\x04\x00\x00\x00\x01" + "\x10\x0cgrpc-timeout\x0a" + "15 seconds", + GRPC_BAD_CLIENT_DISCONNECT); + /* a badly encoded timeout value: twice (catches caching) */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x19\x01\x04\x00\x00\x00\x01" + "\x10\x0cgrpc-timeout\x0a" + "15 seconds" + "\x00\x00\x19\x01\x04\x00\x00\x00\x03" + "\x10\x0cgrpc-timeout\x0a" + "15 seconds", + GRPC_BAD_CLIENT_DISCONNECT); + + return 0; +} diff --git a/test/core/bad_client/tests/initial_settings_frame.c b/test/core/bad_client/tests/initial_settings_frame.c deleted file mode 100644 index 0696ef9383..0000000000 --- a/test/core/bad_client/tests/initial_settings_frame.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/surface/server.h" -#include "test/core/bad_client/bad_client.h" - -#define PFX_STR "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" -#define ONE_SETTING_HDR "\x00\x00\x06\x04\x00\x00\x00\x00\x00" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* various partial prefixes */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x06", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x06", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x06", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x01", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\xff", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - /* must not send frames with stream id != 0 */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0); - /* settings frame must be a multiple of six bytes long */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0); - /* some settings values are illegal */ - /* max frame size = 0 */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - 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, NULL, - PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - /* ack with data */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" - "\x00\x00\x01\x04\x01\x00\x00\x00\x00", - 0); - /* settings frame with invalid flags */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0); - /* unknown settings should be ignored */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - - return 0; -} diff --git a/test/core/bad_client/tests/initial_settings_frame.cc b/test/core/bad_client/tests/initial_settings_frame.cc new file mode 100644 index 0000000000..0696ef9383 --- /dev/null +++ b/test/core/bad_client/tests/initial_settings_frame.cc @@ -0,0 +1,108 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/surface/server.h" +#include "test/core/bad_client/bad_client.h" + +#define PFX_STR "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" +#define ONE_SETTING_HDR "\x00\x00\x06\x04\x00\x00\x00\x00\x00" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* various partial prefixes */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x06", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x06", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x06", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x01", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\xff", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR "\x00\x00\x00\x04\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + /* must not send frames with stream id != 0 */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x00\x00\x00\x00\x01", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x00\x40\x00\x00\x00", 0); + /* settings frame must be a multiple of six bytes long */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x01\x04\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x02\x04\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x03\x04\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x04\x04\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x05\x04\x00\x00\x00\x00\x00", 0); + /* some settings values are illegal */ + /* max frame size = 0 */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR ONE_SETTING_HDR "\x00\x05\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + 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, NULL, + PFX_STR ONE_SETTING_HDR "\x00\x04\x00\x01\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + /* ack with data */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" + "\x00\x00\x01\x04\x01\x00\x00\x00\x00", + 0); + /* settings frame with invalid flags */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x04\x10\x00\x00\x00\x00", 0); + /* unknown settings should be ignored */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR ONE_SETTING_HDR "\x00\x99\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + + return 0; +} diff --git a/test/core/bad_client/tests/large_metadata.c b/test/core/bad_client/tests/large_metadata.c deleted file mode 100644 index ca3d234be9..0000000000 --- a/test/core/bad_client/tests/large_metadata.c +++ /dev/null @@ -1,240 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include -#include -#include "src/core/lib/support/string.h" -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -// The large-metadata headers that we're adding for this test are not -// actually appended to this in a single string, since the string would -// be longer than the C99 string literal limit. Instead, we dynamically -// construct it by adding the large headers one at a time. - -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame */ \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* headers: generated from \ - large_metadata.headers in this \ - directory */ \ - "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \ - "\x00" \ - "5{\x01\x05\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\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -// Each large-metadata header is constructed from these start and end -// strings, with a two-digit number in between. -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR "\x10\x0duser-header" -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR \ - "~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ - "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - -// The size of each large-metadata header string. -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE \ - ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR) - 1) + 2 + \ - (sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR) - 1)) - -// The number of headers we're adding and the total size of the client -// payload. -#define NUM_HEADERS 46 -#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE \ - ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1) + \ - (NUM_HEADERS * PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE) + 1) - -#define PFX_TOO_MUCH_METADATA_FROM_SERVER_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame: sets \ - MAX_HEADER_LIST_SIZE to 8K */ \ - "\x00\x00\x06\x04\x00\x00\x00\x00\x00\x00\x06\x00\x00\x20\x00" /* headers: \ - generated \ - from \ - simple_request.headers \ - in this \ - directory \ - */ \ - "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \ - "\x00\x00\xc9\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\x15" \ - "deflate,identity,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -static void *tag(intptr_t t) { return (void *)t; } - -static void server_verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - grpc_call_details call_details; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - - grpc_call_details_init(&call_details); - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_call(server, &s, &call_details, - &request_metadata_recv, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); - - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_details_destroy(&call_details); - grpc_call_unref(s); - cq_verifier_destroy(cqv); -} - -static void server_verifier_sends_too_much_metadata(grpc_server *server, - grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - grpc_call_details call_details; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - - grpc_call_details_init(&call_details); - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_call(server, &s, &call_details, - &request_metadata_recv, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); - - const size_t metadata_value_size = 8 * 1024; - grpc_metadata meta; - meta.key = grpc_slice_from_static_string("key"); - meta.value = grpc_slice_malloc(metadata_value_size); - memset(GRPC_SLICE_START_PTR(meta.value), 'a', metadata_value_size); - - grpc_op op; - memset(&op, 0, sizeof(op)); - op.op = GRPC_OP_SEND_INITIAL_METADATA; - op.data.send_initial_metadata.count = 1; - op.data.send_initial_metadata.metadata = &meta; - op.flags = 0; - op.reserved = NULL; - error = grpc_call_start_batch(s, &op, 1, tag(102), NULL); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(102), 0); // Operation fails. - cq_verify(cqv); - - grpc_slice_unref(meta.value); - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_details_destroy(&call_details); - grpc_call_unref(s); - cq_verifier_destroy(cqv); -} - -static bool client_validator(grpc_slice_buffer *incoming) { - for (size_t i = 0; i < incoming->count; ++i) { - const char *s = (const char *)GRPC_SLICE_START_PTR(incoming->slices[i]); - char *hex = gpr_dump(s, GRPC_SLICE_LENGTH(incoming->slices[i]), - GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_INFO, "RESPONSE SLICE %" PRIdPTR ": %s", i, hex); - gpr_free(hex); - } - - // Get last frame from incoming slice buffer. - grpc_slice_buffer last_frame_buffer; - grpc_slice_buffer_init(&last_frame_buffer); - grpc_slice_buffer_trim_end(incoming, 13, &last_frame_buffer); - GPR_ASSERT(last_frame_buffer.count == 1); - grpc_slice last_frame = last_frame_buffer.slices[0]; - - const uint8_t *p = GRPC_SLICE_START_PTR(last_frame); - bool success = - // Length == 4 - *p++ != 0 || *p++ != 0 || *p++ != 4 || - // Frame type (RST_STREAM) - *p++ != 3 || - // Flags - *p++ != 0 || - // Stream ID. - *p++ != 0 || *p++ != 0 || *p++ != 0 || *p++ != 1 || - // Payload (error code) - *p++ == 0 || *p++ == 0 || *p++ == 0 || *p == 0 || *p == 11; - - if (!success) { - gpr_log(GPR_INFO, "client expected RST_STREAM frame, not found"); - } - - grpc_slice_buffer_destroy(&last_frame_buffer); - return success; -} - -int main(int argc, char **argv) { - int i; - - grpc_test_init(argc, argv); - - // Test sending more metadata than the server will accept. - gpr_strvec headers; - gpr_strvec_init(&headers); - for (i = 0; i < NUM_HEADERS; ++i) { - char *str; - gpr_asprintf(&str, "%s%02d%s", - PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR, i, - PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR); - gpr_strvec_add(&headers, str); - } - size_t headers_len; - const char *client_headers = gpr_strvec_flatten(&headers, &headers_len); - gpr_strvec_destroy(&headers); - char client_payload[PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE] = - PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR; - memcpy( - client_payload + sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1, - client_headers, headers_len); - GRPC_RUN_BAD_CLIENT_TEST(server_verifier, client_validator, client_payload, - 0); - gpr_free((void *)client_headers); - - // Test sending more metadata than the client will accept. - GRPC_RUN_BAD_CLIENT_TEST(server_verifier_sends_too_much_metadata, - client_validator, - PFX_TOO_MUCH_METADATA_FROM_SERVER_STR, 0); - - return 0; -} diff --git a/test/core/bad_client/tests/large_metadata.cc b/test/core/bad_client/tests/large_metadata.cc new file mode 100644 index 0000000000..ca3d234be9 --- /dev/null +++ b/test/core/bad_client/tests/large_metadata.cc @@ -0,0 +1,240 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include +#include +#include "src/core/lib/support/string.h" +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +// The large-metadata headers that we're adding for this test are not +// actually appended to this in a single string, since the string would +// be longer than the C99 string literal limit. Instead, we dynamically +// construct it by adding the large headers one at a time. + +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame */ \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* headers: generated from \ + large_metadata.headers in this \ + directory */ \ + "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \ + "\x00" \ + "5{\x01\x05\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\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +// Each large-metadata header is constructed from these start and end +// strings, with a two-digit number in between. +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR "\x10\x0duser-header" +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR \ + "~aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" \ + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + +// The size of each large-metadata header string. +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE \ + ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR) - 1) + 2 + \ + (sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR) - 1)) + +// The number of headers we're adding and the total size of the client +// payload. +#define NUM_HEADERS 46 +#define PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE \ + ((sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1) + \ + (NUM_HEADERS * PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_SIZE) + 1) + +#define PFX_TOO_MUCH_METADATA_FROM_SERVER_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" /* settings frame: sets \ + MAX_HEADER_LIST_SIZE to 8K */ \ + "\x00\x00\x06\x04\x00\x00\x00\x00\x00\x00\x06\x00\x00\x20\x00" /* headers: \ + generated \ + from \ + simple_request.headers \ + in this \ + directory \ + */ \ + "\x00\x00\x00\x04\x01\x00\x00\x00\x00" \ + "\x00\x00\xc9\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\x15" \ + "deflate,identity,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +static void *tag(intptr_t t) { return (void *)t; } + +static void server_verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + grpc_call_details call_details; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + + grpc_call_details_init(&call_details); + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_call(server, &s, &call_details, + &request_metadata_recv, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + grpc_call_unref(s); + cq_verifier_destroy(cqv); +} + +static void server_verifier_sends_too_much_metadata(grpc_server *server, + grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + grpc_call_details call_details; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + + grpc_call_details_init(&call_details); + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_call(server, &s, &call_details, + &request_metadata_recv, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + + const size_t metadata_value_size = 8 * 1024; + grpc_metadata meta; + meta.key = grpc_slice_from_static_string("key"); + meta.value = grpc_slice_malloc(metadata_value_size); + memset(GRPC_SLICE_START_PTR(meta.value), 'a', metadata_value_size); + + grpc_op op; + memset(&op, 0, sizeof(op)); + op.op = GRPC_OP_SEND_INITIAL_METADATA; + op.data.send_initial_metadata.count = 1; + op.data.send_initial_metadata.metadata = &meta; + op.flags = 0; + op.reserved = NULL; + error = grpc_call_start_batch(s, &op, 1, tag(102), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(102), 0); // Operation fails. + cq_verify(cqv); + + grpc_slice_unref(meta.value); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + grpc_call_unref(s); + cq_verifier_destroy(cqv); +} + +static bool client_validator(grpc_slice_buffer *incoming) { + for (size_t i = 0; i < incoming->count; ++i) { + const char *s = (const char *)GRPC_SLICE_START_PTR(incoming->slices[i]); + char *hex = gpr_dump(s, GRPC_SLICE_LENGTH(incoming->slices[i]), + GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_INFO, "RESPONSE SLICE %" PRIdPTR ": %s", i, hex); + gpr_free(hex); + } + + // Get last frame from incoming slice buffer. + grpc_slice_buffer last_frame_buffer; + grpc_slice_buffer_init(&last_frame_buffer); + grpc_slice_buffer_trim_end(incoming, 13, &last_frame_buffer); + GPR_ASSERT(last_frame_buffer.count == 1); + grpc_slice last_frame = last_frame_buffer.slices[0]; + + const uint8_t *p = GRPC_SLICE_START_PTR(last_frame); + bool success = + // Length == 4 + *p++ != 0 || *p++ != 0 || *p++ != 4 || + // Frame type (RST_STREAM) + *p++ != 3 || + // Flags + *p++ != 0 || + // Stream ID. + *p++ != 0 || *p++ != 0 || *p++ != 0 || *p++ != 1 || + // Payload (error code) + *p++ == 0 || *p++ == 0 || *p++ == 0 || *p == 0 || *p == 11; + + if (!success) { + gpr_log(GPR_INFO, "client expected RST_STREAM frame, not found"); + } + + grpc_slice_buffer_destroy(&last_frame_buffer); + return success; +} + +int main(int argc, char **argv) { + int i; + + grpc_test_init(argc, argv); + + // Test sending more metadata than the server will accept. + gpr_strvec headers; + gpr_strvec_init(&headers); + for (i = 0; i < NUM_HEADERS; ++i) { + char *str; + gpr_asprintf(&str, "%s%02d%s", + PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_START_STR, i, + PFX_TOO_MUCH_METADATA_FROM_CLIENT_HEADER_END_STR); + gpr_strvec_add(&headers, str); + } + size_t headers_len; + const char *client_headers = gpr_strvec_flatten(&headers, &headers_len); + gpr_strvec_destroy(&headers); + char client_payload[PFX_TOO_MUCH_METADATA_FROM_CLIENT_PAYLOAD_SIZE] = + PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR; + memcpy( + client_payload + sizeof(PFX_TOO_MUCH_METADATA_FROM_CLIENT_PREFIX_STR) - 1, + client_headers, headers_len); + GRPC_RUN_BAD_CLIENT_TEST(server_verifier, client_validator, client_payload, + 0); + gpr_free((void *)client_headers); + + // Test sending more metadata than the client will accept. + GRPC_RUN_BAD_CLIENT_TEST(server_verifier_sends_too_much_metadata, + client_validator, + PFX_TOO_MUCH_METADATA_FROM_SERVER_STR, 0); + + return 0; +} diff --git a/test/core/bad_client/tests/server_registered_method.c b/test/core/bad_client/tests/server_registered_method.c deleted file mode 100644 index f52350302b..0000000000 --- a/test/core/bad_client/tests/server_registered_method.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -#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 */ \ - "\x00\x00\xd0\x01\x04\x00\x00\x00\x01" \ - "\x10\x05:path\x0f/registered/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\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -static void *tag(intptr_t t) { return (void *)t; } - -static void verifier_succeeds(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - gpr_timespec deadline; - grpc_byte_buffer *payload = NULL; - - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_registered_call(server, registered_method, &s, - &deadline, &request_metadata_recv, - &payload, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(payload != NULL); - - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_unref(s); - grpc_byte_buffer_destroy(payload); - cq_verifier_destroy(cqv); -} - -static void verifier_fails(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* body generated with - * tools/codegen/core/gen_server_registered_method_bad_client_test_body.py */ - GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, - PFX_STR "\x00\x00\x00\x00\x00\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, - PFX_STR "\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, PFX_STR - "\x00\x00\x02\x00\x00\x00\x00\x00\x01\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, PFX_STR - "\x00\x00\x03\x00\x00\x00\x00\x00\x01\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_fails, NULL, - PFX_STR "\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_succeeds, NULL, - PFX_STR "\x00\x00\x05\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00", 0); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_fails, NULL, - PFX_STR "\x00\x00\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_succeeds, NULL, - PFX_STR "\x00\x00\x06\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00", - 0); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_fails, NULL, - PFX_STR "\x00\x00\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_fails, NULL, - PFX_STR "\x00\x00\x06\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00", - GRPC_BAD_CLIENT_DISCONNECT); - GRPC_RUN_BAD_CLIENT_TEST( - verifier_succeeds, NULL, PFX_STR - "\x00\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00", - 0); - - return 0; -} diff --git a/test/core/bad_client/tests/server_registered_method.cc b/test/core/bad_client/tests/server_registered_method.cc new file mode 100644 index 0000000000..f52350302b --- /dev/null +++ b/test/core/bad_client/tests/server_registered_method.cc @@ -0,0 +1,124 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +#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 */ \ + "\x00\x00\xd0\x01\x04\x00\x00\x00\x01" \ + "\x10\x05:path\x0f/registered/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\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +static void *tag(intptr_t t) { return (void *)t; } + +static void verifier_succeeds(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + gpr_timespec deadline; + grpc_byte_buffer *payload = NULL; + + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_registered_call(server, registered_method, &s, + &deadline, &request_metadata_recv, + &payload, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(payload != NULL); + + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_unref(s); + grpc_byte_buffer_destroy(payload); + cq_verifier_destroy(cqv); +} + +static void verifier_fails(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* body generated with + * tools/codegen/core/gen_server_registered_method_bad_client_test_body.py */ + GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, + PFX_STR "\x00\x00\x00\x00\x00\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, + PFX_STR "\x00\x00\x01\x00\x00\x00\x00\x00\x01\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, PFX_STR + "\x00\x00\x02\x00\x00\x00\x00\x00\x01\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier_fails, NULL, PFX_STR + "\x00\x00\x03\x00\x00\x00\x00\x00\x01\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_fails, NULL, + PFX_STR "\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_succeeds, NULL, + PFX_STR "\x00\x00\x05\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00", 0); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_fails, NULL, + PFX_STR "\x00\x00\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_succeeds, NULL, + PFX_STR "\x00\x00\x06\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x01\x00", + 0); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_fails, NULL, + PFX_STR "\x00\x00\x05\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_fails, NULL, + PFX_STR "\x00\x00\x06\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST( + verifier_succeeds, NULL, PFX_STR + "\x00\x00\x07\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x02\x00\x00", + 0); + + return 0; +} diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c deleted file mode 100644 index a516632819..0000000000 --- a/test/core/bad_client/tests/simple_request.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include "src/core/lib/surface/server.h" -#include "test/core/end2end/cq_verifier.h" - -#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 */ \ - "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ - simple_request.headers in this \ - directory */ \ - "\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\x15" \ - "deflate,identity,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -#define PFX_STR_UNUSUAL \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ - "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ - simple_request_unusual.headers \ - in this directory */ \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x04host\x09localhost" \ - "\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" - -#define PFX_STR_UNUSUAL2 \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ - "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ - simple_request_unusual2.headers \ - in this directory */ \ - "\x10\x05:path\x08/foo/bar" \ - "\x10\x07:scheme\x04http" \ - "\x10\x07:method\x04POST" \ - "\x10\x04host\x09localhost" \ - "\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" - -static void *tag(intptr_t t) { return (void *)t; } - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - grpc_call_error error; - grpc_call *s; - grpc_call_details call_details; - cq_verifier *cqv = cq_verifier_create(cq); - grpc_metadata_array request_metadata_recv; - - grpc_call_details_init(&call_details); - grpc_metadata_array_init(&request_metadata_recv); - - error = grpc_server_request_call(server, &s, &call_details, - &request_metadata_recv, cq, cq, tag(101)); - GPR_ASSERT(GRPC_CALL_OK == error); - CQ_EXPECT_COMPLETION(cqv, tag(101), 1); - cq_verify(cqv); - - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); - - grpc_metadata_array_destroy(&request_metadata_recv); - grpc_call_details_destroy(&call_details); - grpc_call_unref(s); - cq_verifier_destroy(cqv); -} - -static void failure_verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* basic request: check that things are working */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR, 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR_UNUSUAL, 0); - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR_UNUSUAL2, 0); - - /* push an illegal data frame */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR - "\x00\x00\x05\x00\x00\x00\x00\x00\x01" - "\x34\x00\x00\x00\x00", - 0); - - /* push a data frame with bad flags */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x00\x02\x00\x00\x00\x01", 0); - /* push a window update with a bad length */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x00\x01\x08\x00\x00\x00\x00\x01", 0); - /* push a window update with bad flags */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - 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, NULL, 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, NULL, - PFX_STR "\x00\x00\x04\x07\x00\x00\x00\x00\x00", 0); - /* disconnect before sending goaway */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x01\x12\x07\x00\x00\x00\x00\x00", - GRPC_BAD_CLIENT_DISCONNECT); - /* push a rst_stream with a bad length */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x00\x01\x03\x00\x00\x00\x00\x01", 0); - /* push a rst_stream with bad flags */ - GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, - PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0); - - return 0; -} diff --git a/test/core/bad_client/tests/simple_request.cc b/test/core/bad_client/tests/simple_request.cc new file mode 100644 index 0000000000..a516632819 --- /dev/null +++ b/test/core/bad_client/tests/simple_request.cc @@ -0,0 +1,166 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include "src/core/lib/surface/server.h" +#include "test/core/end2end/cq_verifier.h" + +#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 */ \ + "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request.headers in this \ + directory */ \ + "\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\x15" \ + "deflate,identity,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +#define PFX_STR_UNUSUAL \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request_unusual.headers \ + in this directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x04host\x09localhost" \ + "\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" + +#define PFX_STR_UNUSUAL2 \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" /* settings frame */ \ + "\x00\x00\xf4\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request_unusual2.headers \ + in this directory */ \ + "\x10\x05:path\x08/foo/bar" \ + "\x10\x07:scheme\x04http" \ + "\x10\x07:method\x04POST" \ + "\x10\x04host\x09localhost" \ + "\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" + +static void *tag(intptr_t t) { return (void *)t; } + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + grpc_call_error error; + grpc_call *s; + grpc_call_details call_details; + cq_verifier *cqv = cq_verifier_create(cq); + grpc_metadata_array request_metadata_recv; + + grpc_call_details_init(&call_details); + grpc_metadata_array_init(&request_metadata_recv); + + error = grpc_server_request_call(server, &s, &call_details, + &request_metadata_recv, cq, cq, tag(101)); + GPR_ASSERT(GRPC_CALL_OK == error); + CQ_EXPECT_COMPLETION(cqv, tag(101), 1); + cq_verify(cqv); + + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + grpc_call_unref(s); + cq_verifier_destroy(cqv); +} + +static void failure_verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* basic request: check that things are working */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR, 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR_UNUSUAL, 0); + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR_UNUSUAL2, 0); + + /* push an illegal data frame */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, PFX_STR + "\x00\x00\x05\x00\x00\x00\x00\x00\x01" + "\x34\x00\x00\x00\x00", + 0); + + /* push a data frame with bad flags */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x00\x02\x00\x00\x00\x01", 0); + /* push a window update with a bad length */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x00\x01\x08\x00\x00\x00\x00\x01", 0); + /* push a window update with bad flags */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + 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, NULL, 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, NULL, + PFX_STR "\x00\x00\x04\x07\x00\x00\x00\x00\x00", 0); + /* disconnect before sending goaway */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x01\x12\x07\x00\x00\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + /* push a rst_stream with a bad length */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x00\x01\x03\x00\x00\x00\x00\x01", 0); + /* push a rst_stream with bad flags */ + GRPC_RUN_BAD_CLIENT_TEST(failure_verifier, NULL, + PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0); + + return 0; +} diff --git a/test/core/bad_client/tests/unknown_frame.c b/test/core/bad_client/tests/unknown_frame.c deleted file mode 100644 index 448803d12b..0000000000 --- a/test/core/bad_client/tests/unknown_frame.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/lib/surface/server.h" -#include "test/core/bad_client/bad_client.h" - -#define PFX_STR \ - "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ - "\x00\x00\x00\x04\x00\x00\x00\x00\x00" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - - /* test adding prioritization data */ - GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, - PFX_STR "\x00\x00\x00\x88\x00\x00\x00\x00\x01", - GRPC_BAD_CLIENT_DISCONNECT); - - return 0; -} diff --git a/test/core/bad_client/tests/unknown_frame.cc b/test/core/bad_client/tests/unknown_frame.cc new file mode 100644 index 0000000000..448803d12b --- /dev/null +++ b/test/core/bad_client/tests/unknown_frame.cc @@ -0,0 +1,44 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "src/core/lib/surface/server.h" +#include "test/core/bad_client/bad_client.h" + +#define PFX_STR \ + "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n" \ + "\x00\x00\x00\x04\x00\x00\x00\x00\x00" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* test adding prioritization data */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, NULL, + PFX_STR "\x00\x00\x00\x88\x00\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + + return 0; +} diff --git a/test/core/bad_client/tests/window_overflow.c b/test/core/bad_client/tests/window_overflow.c deleted file mode 100644 index e4b5f9711b..0000000000 --- a/test/core/bad_client/tests/window_overflow.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "test/core/bad_client/bad_client.h" - -#include - -#include - -#include "src/core/lib/surface/server.h" - -#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 */ \ - "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ - simple_request.headers in this \ - directory */ \ - "\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\x15" \ - "deflate,identity,gzip" \ - "\x10\x02te\x08trailers" \ - "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" - -static void verifier(grpc_server *server, grpc_completion_queue *cq, - void *registered_method) { - while (grpc_server_has_open_connections(server)) { - GPR_ASSERT(grpc_completion_queue_next( - cq, grpc_timeout_milliseconds_to_deadline(20), NULL) - .type == GRPC_QUEUE_TIMEOUT); - } -} - -char *g_buffer; -size_t g_cap = 0; -size_t g_count = 0; - -static void addbuf(const void *data, size_t len) { - if (g_count + len > g_cap) { - g_cap = GPR_MAX(g_count + len, g_cap * 2); - g_buffer = gpr_realloc(g_buffer, g_cap); - } - memcpy(g_buffer + g_count, data, len); - g_count += len; -} - -int main(int argc, char **argv) { - int i, j; -#define MAX_FRAME_SIZE 16384 -#define MESSAGES_PER_FRAME (MAX_FRAME_SIZE / 5) -#define FRAME_SIZE (MESSAGES_PER_FRAME * 5) -#define SEND_SIZE (6 * 1024 * 1024) -#define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1) - grpc_test_init(argc, argv); - - addbuf(PFX_STR, sizeof(PFX_STR) - 1); - for (i = 0; i < NUM_FRAMES; i++) { - uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), - (uint8_t)(FRAME_SIZE >> 8), - (uint8_t)FRAME_SIZE, - 0, - 0, - 0, - 0, - 0, - 1}; - addbuf(hdr, sizeof(hdr)); - for (j = 0; j < MESSAGES_PER_FRAME; j++) { - uint8_t message[5] = {0, 0, 0, 0, 0}; - addbuf(message, sizeof(message)); - } - } - grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, - GRPC_BAD_CLIENT_LARGE_REQUEST); - gpr_free(g_buffer); - - return 0; -} diff --git a/test/core/bad_client/tests/window_overflow.cc b/test/core/bad_client/tests/window_overflow.cc new file mode 100644 index 0000000000..40552e5345 --- /dev/null +++ b/test/core/bad_client/tests/window_overflow.cc @@ -0,0 +1,98 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include "test/core/bad_client/bad_client.h" + +#include + +#include + +#include "src/core/lib/surface/server.h" + +#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 */ \ + "\x00\x00\xc9\x01\x04\x00\x00\x00\x01" /* headers: generated from \ + simple_request.headers in this \ + directory */ \ + "\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\x15" \ + "deflate,identity,gzip" \ + "\x10\x02te\x08trailers" \ + "\x10\x0auser-agent\"bad-client grpc-c/0.12.0.0 (linux)" + +static void verifier(grpc_server *server, grpc_completion_queue *cq, + void *registered_method) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +char *g_buffer; +size_t g_cap = 0; +size_t g_count = 0; + +static void addbuf(const void *data, size_t len) { + if (g_count + len > g_cap) { + g_cap = GPR_MAX(g_count + len, g_cap * 2); + g_buffer = static_cast(gpr_realloc(g_buffer, g_cap)); + } + memcpy(g_buffer + g_count, data, len); + g_count += len; +} + +int main(int argc, char **argv) { + int i, j; +#define MAX_FRAME_SIZE 16384 +#define MESSAGES_PER_FRAME (MAX_FRAME_SIZE / 5) +#define FRAME_SIZE (MESSAGES_PER_FRAME * 5) +#define SEND_SIZE (6 * 1024 * 1024) +#define NUM_FRAMES (SEND_SIZE / FRAME_SIZE + 1) + grpc_test_init(argc, argv); + + addbuf(PFX_STR, sizeof(PFX_STR) - 1); + for (i = 0; i < NUM_FRAMES; i++) { + uint8_t hdr[9] = {(uint8_t)(FRAME_SIZE >> 16), + (uint8_t)(FRAME_SIZE >> 8), + (uint8_t)FRAME_SIZE, + 0, + 0, + 0, + 0, + 0, + 1}; + addbuf(hdr, sizeof(hdr)); + for (j = 0; j < MESSAGES_PER_FRAME; j++) { + uint8_t message[5] = {0, 0, 0, 0, 0}; + addbuf(message, sizeof(message)); + } + } + grpc_run_bad_client_test(verifier, NULL, g_buffer, g_count, + GRPC_BAD_CLIENT_LARGE_REQUEST); + gpr_free(g_buffer); + + return 0; +} -- cgit v1.2.3 From e92294c587a65a3ab30ca9cff141305c1b54cb0a Mon Sep 17 00:00:00 2001 From: Yash Tibrewal Date: Tue, 31 Oct 2017 12:19:35 -0700 Subject: Remove test/core/census --- test/core/bad_client/generate_tests.bzl | 2 - test/core/census/BUILD | 82 ---- test/core/census/context_test.cc | 363 ------------------ test/core/census/intrusive_hash_map_test.cc | 284 -------------- test/core/census/mlog_test.cc | 574 ---------------------------- test/core/census/resource_test.cc | 154 -------- test/core/census/trace_context_test.cc | 215 ----------- 7 files changed, 1674 deletions(-) delete mode 100644 test/core/census/BUILD delete mode 100644 test/core/census/context_test.cc delete mode 100644 test/core/census/intrusive_hash_map_test.cc delete mode 100644 test/core/census/mlog_test.cc delete mode 100644 test/core/census/resource_test.cc delete mode 100644 test/core/census/trace_context_test.cc (limited to 'test/core/bad_client') diff --git a/test/core/bad_client/generate_tests.bzl b/test/core/bad_client/generate_tests.bzl index cdea9cc2d1..022edf3ff3 100755 --- a/test/core/bad_client/generate_tests.bzl +++ b/test/core/bad_client/generate_tests.bzl @@ -40,7 +40,6 @@ def grpc_bad_client_tests(): name = 'bad_client_test', srcs = ['bad_client.cc'], hdrs = ['bad_client.h'], - copts = ['-std=c99'], deps = ['//test/core/util:grpc_test_util', '//:grpc', '//:gpr', '//test/core/end2end:cq_verifier'] ) for t, topt in BAD_CLIENT_TESTS.items(): @@ -48,6 +47,5 @@ def grpc_bad_client_tests(): name = '%s_bad_client_test' % t, srcs = ['tests/%s.cc' % t], deps = [':bad_client_test'], - copts = ['-std=c99'], ) diff --git a/test/core/census/BUILD b/test/core/census/BUILD deleted file mode 100644 index 70a0e79932..0000000000 --- a/test/core/census/BUILD +++ /dev/null @@ -1,82 +0,0 @@ -# Copyright 2016 gRPC authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_cc_test", "grpc_cc_binary", "grpc_package") - -grpc_package(name = "test/core/census") - -licenses(["notice"]) # Apache v2 - -grpc_cc_test( - name = "context_test", - srcs = ["context_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:gpr_test_util", - "//test/core/util:grpc_test_util", - ], -) - -grpc_cc_test( - name = "mlog_test", - srcs = ["mlog_test.cc"], - language = "C++", - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:gpr_test_util", - "//test/core/util:grpc_test_util", - ], -) - -grpc_cc_test( - name = "resource_test", - srcs = ["resource_test.cc"], - language = "C++", - data = [ - ":data/resource_empty_name.pb", - ":data/resource_full.pb", - ":data/resource_minimal_good.pb", - ":data/resource_no_name.pb", - ":data/resource_no_numerator.pb", - ":data/resource_no_unit.pb", - ], - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:gpr_test_util", - "//test/core/util:grpc_test_util", - ], -) - -grpc_cc_test( - name = "trace_context_test", - srcs = ["trace_context_test.cc"], - language = "C++", - data = [ - ":data/context_empty.pb", - ":data/context_full.pb", - ":data/context_no_span_options.pb", - ":data/context_span_only.pb", - ":data/context_trace_only.pb", - ], - deps = [ - "//:gpr", - "//:grpc", - "//test/core/util:gpr_test_util", - "//test/core/util:grpc_test_util", - ], -) diff --git a/test/core/census/context_test.cc b/test/core/census/context_test.cc deleted file mode 100644 index ca5a6ec5cd..0000000000 --- a/test/core/census/context_test.cc +++ /dev/null @@ -1,363 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -// Test census_context functions, including encoding/decoding - -#include -#include -#include -#include -#include -#include -#include -#include "test/core/util/test_config.h" - -// A set of tags Used to create a basic context for testing. Note that -// replace_add_delete_test() relies on specific offsets into this array - if -// you add or delete entries, you will also need to change the test. -#define BASIC_TAG_COUNT 8 -static census_tag basic_tags[BASIC_TAG_COUNT] = { - /* 0 */ {"key0", "tag value", 0}, - /* 1 */ {"k1", "a", CENSUS_TAG_PROPAGATE}, - /* 2 */ {"k2", "a longer tag value supercalifragilisticexpialiadocious", - CENSUS_TAG_STATS}, - /* 3 */ {"key_three", "", 0}, - /* 4 */ {"a_really_really_really_really_long_key_4", "random", - CENSUS_TAG_PROPAGATE | CENSUS_TAG_STATS}, - /* 5 */ {"k5", "v5", CENSUS_TAG_PROPAGATE}, - /* 6 */ {"k6", "v6", CENSUS_TAG_STATS}, - /* 7 */ {"k7", "v7", CENSUS_TAG_PROPAGATE | CENSUS_TAG_STATS}}; - -// Set of tags used to modify the basic context. Note that -// replace_add_delete_test() relies on specific offsets into this array - if -// you add or delete entries, you will also need to change the test. Other -// tests that rely on specific instances have XXX_XXX_OFFSET definitions (also -// change the defines below if you add/delete entires). -#define MODIFY_TAG_COUNT 10 -static census_tag modify_tags[MODIFY_TAG_COUNT] = { -#define REPLACE_VALUE_OFFSET 0 - /* 0 */ {"key0", "replace key0", 0}, // replaces tag value only -#define ADD_TAG_OFFSET 1 - /* 1 */ {"new_key", "xyzzy", CENSUS_TAG_STATS}, // new tag -#define DELETE_TAG_OFFSET 2 - /* 2 */ {"k5", NULL, 0}, // should delete tag - /* 3 */ {"k5", NULL, 0}, // try deleting already-deleted tag - /* 4 */ {"non-existent", NULL, 0}, // delete non-existent tag -#define REPLACE_FLAG_OFFSET 5 - /* 5 */ {"k1", "a", 0}, // change flags only - /* 6 */ {"k7", "bar", CENSUS_TAG_STATS}, // change flags and value - /* 7 */ {"k2", "", CENSUS_TAG_PROPAGATE}, // more value and flags change - /* 8 */ {"k5", "bar", 0}, // add back tag, with different value - /* 9 */ {"foo", "bar", CENSUS_TAG_PROPAGATE}, // another new tag -}; - -// Utility function to compare tags. Returns true if all fields match. -static bool compare_tag(const census_tag *t1, const census_tag *t2) { - return (strcmp(t1->key, t2->key) == 0 && strcmp(t1->value, t2->value) == 0 && - t1->flags == t2->flags); -} - -// Utility function to validate a tag exists in context. -static bool validate_tag(const census_context *context, const census_tag *tag) { - census_tag tag2; - if (census_context_get_tag(context, tag->key, &tag2) != 1) return false; - return compare_tag(tag, &tag2); -} - -// Create an empty context. -static void empty_test(void) { - struct census_context *context = census_context_create(NULL, NULL, 0, NULL); - GPR_ASSERT(context != NULL); - const census_context_status *status = census_context_get_status(context); - census_context_status expected = {0, 0, 0, 0, 0, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_destroy(context); -} - -// Test create and iteration over basic context. -static void basic_test(void) { - const census_context_status *status; - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, &status); - census_context_status expected = {4, 4, 0, 8, 0, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_iterator it; - census_context_initialize_iterator(context, &it); - census_tag tag; - while (census_context_next_tag(&it, &tag)) { - // can't rely on tag return order: make sure it matches exactly one. - int matches = 0; - for (int i = 0; i < BASIC_TAG_COUNT; i++) { - if (compare_tag(&tag, &basic_tags[i])) matches++; - } - GPR_ASSERT(matches == 1); - } - census_context_destroy(context); -} - -// Test census_context_get_tag(). -static void lookup_by_key_test(void) { - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - census_tag tag; - for (int i = 0; i < BASIC_TAG_COUNT; i++) { - GPR_ASSERT(census_context_get_tag(context, basic_tags[i].key, &tag) == 1); - GPR_ASSERT(compare_tag(&tag, &basic_tags[i])); - } - // non-existent keys - GPR_ASSERT(census_context_get_tag(context, "key", &tag) == 0); - GPR_ASSERT(census_context_get_tag(context, "key01", &tag) == 0); - GPR_ASSERT(census_context_get_tag(context, "k9", &tag) == 0); - GPR_ASSERT(census_context_get_tag(context, "random", &tag) == 0); - GPR_ASSERT(census_context_get_tag(context, "", &tag) == 0); - census_context_destroy(context); -} - -// Try creating context with invalid entries. -static void invalid_test(void) { - char key[300]; - memset(key, 'k', 299); - key[299] = 0; - char value[300]; - memset(value, 'v', 299); - value[299] = 0; - census_tag tag = {key, value, 0}; - // long keys, short value. Key lengths (including terminator) should be - // <= 255 (CENSUS_MAX_TAG_KV_LEN) - value[3] = 0; - GPR_ASSERT(strlen(value) == 3); - GPR_ASSERT(strlen(key) == 299); - const census_context_status *status; - struct census_context *context = - census_context_create(NULL, &tag, 1, &status); - census_context_status expected = {0, 0, 0, 0, 0, 1, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_destroy(context); - key[CENSUS_MAX_TAG_KV_LEN] = 0; - GPR_ASSERT(strlen(key) == CENSUS_MAX_TAG_KV_LEN); - context = census_context_create(NULL, &tag, 1, &status); - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_destroy(context); - key[CENSUS_MAX_TAG_KV_LEN - 1] = 0; - GPR_ASSERT(strlen(key) == CENSUS_MAX_TAG_KV_LEN - 1); - context = census_context_create(NULL, &tag, 1, &status); - census_context_status expected2 = {0, 1, 0, 1, 0, 0, 0}; - GPR_ASSERT(memcmp(status, &expected2, sizeof(expected2)) == 0); - census_context_destroy(context); - // now try with long values - value[3] = 'v'; - GPR_ASSERT(strlen(value) == 299); - context = census_context_create(NULL, &tag, 1, &status); - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_destroy(context); - value[CENSUS_MAX_TAG_KV_LEN] = 0; - GPR_ASSERT(strlen(value) == CENSUS_MAX_TAG_KV_LEN); - context = census_context_create(NULL, &tag, 1, &status); - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_destroy(context); - value[CENSUS_MAX_TAG_KV_LEN - 1] = 0; - GPR_ASSERT(strlen(value) == CENSUS_MAX_TAG_KV_LEN - 1); - context = census_context_create(NULL, &tag, 1, &status); - GPR_ASSERT(memcmp(status, &expected2, sizeof(expected2)) == 0); - census_context_destroy(context); - // 0 length key. - key[0] = 0; - GPR_ASSERT(strlen(key) == 0); - context = census_context_create(NULL, &tag, 1, &status); - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_destroy(context); - // invalid key character - key[0] = 31; // 32 (' ') is the first valid character value - key[1] = 0; - GPR_ASSERT(strlen(key) == 1); - context = census_context_create(NULL, &tag, 1, &status); - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_destroy(context); - // invalid value character - key[0] = ' '; - value[5] = 127; // 127 (DEL) is ('~' + 1) - value[8] = 0; - GPR_ASSERT(strlen(key) == 1); - GPR_ASSERT(strlen(value) == 8); - context = census_context_create(NULL, &tag, 1, &status); - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_context_destroy(context); -} - -// Make a copy of a context -static void copy_test(void) { - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_context_status *status; - struct census_context *context2 = - census_context_create(context, NULL, 0, &status); - census_context_status expected = {4, 4, 0, 0, 0, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - for (int i = 0; i < BASIC_TAG_COUNT; i++) { - census_tag tag; - GPR_ASSERT(census_context_get_tag(context2, basic_tags[i].key, &tag) == 1); - GPR_ASSERT(compare_tag(&tag, &basic_tags[i])); - } - census_context_destroy(context); - census_context_destroy(context2); -} - -// replace a single tag value -static void replace_value_test(void) { - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_context_status *status; - struct census_context *context2 = census_context_create( - context, modify_tags + REPLACE_VALUE_OFFSET, 1, &status); - census_context_status expected = {4, 4, 0, 0, 1, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag tag; - GPR_ASSERT(census_context_get_tag( - context2, modify_tags[REPLACE_VALUE_OFFSET].key, &tag) == 1); - GPR_ASSERT(compare_tag(&tag, &modify_tags[REPLACE_VALUE_OFFSET])); - census_context_destroy(context); - census_context_destroy(context2); -} - -// replace a single tags flags -static void replace_flags_test(void) { - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_context_status *status; - struct census_context *context2 = census_context_create( - context, modify_tags + REPLACE_FLAG_OFFSET, 1, &status); - census_context_status expected = {3, 5, 0, 0, 1, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag tag; - GPR_ASSERT(census_context_get_tag( - context2, modify_tags[REPLACE_FLAG_OFFSET].key, &tag) == 1); - GPR_ASSERT(compare_tag(&tag, &modify_tags[REPLACE_FLAG_OFFSET])); - census_context_destroy(context); - census_context_destroy(context2); -} - -// delete a single tag. -static void delete_tag_test(void) { - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_context_status *status; - struct census_context *context2 = census_context_create( - context, modify_tags + DELETE_TAG_OFFSET, 1, &status); - census_context_status expected = {3, 4, 1, 0, 0, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag tag; - GPR_ASSERT(census_context_get_tag( - context2, modify_tags[DELETE_TAG_OFFSET].key, &tag) == 0); - census_context_destroy(context); - census_context_destroy(context2); -} - -// add a single new tag. -static void add_tag_test(void) { - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_context_status *status; - struct census_context *context2 = - census_context_create(context, modify_tags + ADD_TAG_OFFSET, 1, &status); - census_context_status expected = {4, 5, 0, 1, 0, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - census_tag tag; - GPR_ASSERT(census_context_get_tag(context2, modify_tags[ADD_TAG_OFFSET].key, - &tag) == 1); - GPR_ASSERT(compare_tag(&tag, &modify_tags[ADD_TAG_OFFSET])); - census_context_destroy(context); - census_context_destroy(context2); -} - -// test many changes at once. -static void replace_add_delete_test(void) { - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - const census_context_status *status; - struct census_context *context2 = - census_context_create(context, modify_tags, MODIFY_TAG_COUNT, &status); - census_context_status expected = {3, 7, 1, 3, 4, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - // validate context contents. Use specific indices into the two arrays - // holding tag values. - GPR_ASSERT(validate_tag(context2, &basic_tags[3])); - GPR_ASSERT(validate_tag(context2, &basic_tags[4])); - GPR_ASSERT(validate_tag(context2, &basic_tags[6])); - GPR_ASSERT(validate_tag(context2, &modify_tags[0])); - GPR_ASSERT(validate_tag(context2, &modify_tags[1])); - GPR_ASSERT(validate_tag(context2, &modify_tags[5])); - GPR_ASSERT(validate_tag(context2, &modify_tags[6])); - GPR_ASSERT(validate_tag(context2, &modify_tags[7])); - GPR_ASSERT(validate_tag(context2, &modify_tags[8])); - GPR_ASSERT(validate_tag(context2, &modify_tags[9])); - GPR_ASSERT(!validate_tag(context2, &basic_tags[0])); - GPR_ASSERT(!validate_tag(context2, &basic_tags[1])); - GPR_ASSERT(!validate_tag(context2, &basic_tags[2])); - GPR_ASSERT(!validate_tag(context2, &basic_tags[5])); - GPR_ASSERT(!validate_tag(context2, &basic_tags[7])); - census_context_destroy(context); - census_context_destroy(context2); -} - -#define BUF_SIZE 200 - -// test encode/decode. -static void encode_decode_test(void) { - char buffer[BUF_SIZE]; - struct census_context *context = - census_context_create(NULL, basic_tags, BASIC_TAG_COUNT, NULL); - // Test with too small a buffer - GPR_ASSERT(census_context_encode(context, buffer, 2) == 0); - // Test with sufficient buffer - size_t buf_used = census_context_encode(context, buffer, BUF_SIZE); - GPR_ASSERT(buf_used != 0); - census_context *context2 = census_context_decode(buffer, buf_used); - GPR_ASSERT(context2 != NULL); - const census_context_status *status = census_context_get_status(context2); - census_context_status expected = {4, 0, 0, 0, 0, 0, 0}; - GPR_ASSERT(memcmp(status, &expected, sizeof(expected)) == 0); - for (int i = 0; i < BASIC_TAG_COUNT; i++) { - census_tag tag; - if (CENSUS_TAG_IS_PROPAGATED(basic_tags[i].flags)) { - GPR_ASSERT(census_context_get_tag(context2, basic_tags[i].key, &tag) == - 1); - GPR_ASSERT(compare_tag(&tag, &basic_tags[i])); - } else { - GPR_ASSERT(census_context_get_tag(context2, basic_tags[i].key, &tag) == - 0); - } - } - census_context_destroy(context2); - census_context_destroy(context); -} - -int main(int argc, char *argv[]) { - grpc_test_init(argc, argv); - empty_test(); - basic_test(); - lookup_by_key_test(); - invalid_test(); - copy_test(); - replace_value_test(); - replace_flags_test(); - delete_tag_test(); - add_tag_test(); - replace_add_delete_test(); - encode_decode_test(); - return 0; -} diff --git a/test/core/census/intrusive_hash_map_test.cc b/test/core/census/intrusive_hash_map_test.cc deleted file mode 100644 index 0826b55c63..0000000000 --- a/test/core/census/intrusive_hash_map_test.cc +++ /dev/null @@ -1,284 +0,0 @@ -/* - * - * Copyright 2017 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/ext/census/intrusive_hash_map.h" - -#include -#include -#include "test/core/util/test_config.h" - -#include -#include -#include -#include - -/* The initial size of an intrusive hash map will be 2 to this power. */ -static const uint32_t kInitialLog2Size = 4; - -/* Simple object used for testing intrusive_hash_map. */ -typedef struct object { uint64_t val; } object; - -/* Helper function to allocate and initialize object. */ -static __inline object *make_new_object(uint64_t val) { - object *obj = (object *)gpr_malloc(sizeof(object)); - obj->val = val; - return obj; -} - -/* Wrapper struct for object. */ -typedef struct ptr_item { - INTRUSIVE_HASH_MAP_HEADER; - object *obj; -} ptr_item; - -/* Helper function that creates a new hash map item. It is up to the user to - * free the item that was allocated. */ -static __inline ptr_item *make_ptr_item(uint64_t key, uint64_t value) { - ptr_item *new_item = (ptr_item *)gpr_malloc(sizeof(ptr_item)); - new_item->IHM_key = key; - new_item->IHM_hash_link = NULL; - new_item->obj = make_new_object(value); - return new_item; -} - -/* Helper function to deallocate ptr_item. */ -static void free_ptr_item(void *ptr) { gpr_free(((ptr_item *)ptr)->obj); } - -/* Simple string object used for testing intrusive_hash_map. */ -typedef struct string_item { - INTRUSIVE_HASH_MAP_HEADER; - // User data. - char buf[32]; - uint16_t len; -} string_item; - -/* Helper function to allocate and initialize string object. */ -static string_item *make_string_item(uint64_t key, const char *buf, - uint16_t len) { - string_item *item = (string_item *)gpr_malloc(sizeof(string_item)); - item->IHM_key = key; - item->IHM_hash_link = NULL; - item->len = len; - memcpy(item->buf, buf, sizeof(char) * len); - return item; -} - -/* Helper function for comparing two string objects. */ -static bool compare_string_item(const string_item *A, const string_item *B) { - if (A->IHM_key != B->IHM_key || A->len != B->len) - return false; - else { - for (int i = 0; i < A->len; ++i) { - if (A->buf[i] != B->buf[i]) return false; - } - } - - return true; -} - -void test_empty() { - intrusive_hash_map hash_map; - intrusive_hash_map_init(&hash_map, kInitialLog2Size); - GPR_ASSERT(0 == intrusive_hash_map_size(&hash_map)); - GPR_ASSERT(intrusive_hash_map_empty(&hash_map)); - intrusive_hash_map_free(&hash_map, NULL); -} - -void test_single_item() { - intrusive_hash_map hash_map; - intrusive_hash_map_init(&hash_map, kInitialLog2Size); - - ptr_item *new_item = make_ptr_item(10, 20); - bool ok = intrusive_hash_map_insert(&hash_map, (hm_item *)new_item); - GPR_ASSERT(ok); - - ptr_item *item1 = - (ptr_item *)intrusive_hash_map_find(&hash_map, (uint64_t)10); - GPR_ASSERT(item1->obj->val == 20); - GPR_ASSERT(item1 == new_item); - - ptr_item *item2 = - (ptr_item *)intrusive_hash_map_erase(&hash_map, (uint64_t)10); - GPR_ASSERT(item2 == new_item); - - gpr_free(new_item->obj); - gpr_free(new_item); - GPR_ASSERT(0 == intrusive_hash_map_size(&hash_map)); - intrusive_hash_map_free(&hash_map, &free_ptr_item); -} - -void test_two_items() { - intrusive_hash_map hash_map; - intrusive_hash_map_init(&hash_map, kInitialLog2Size); - - string_item *new_item1 = make_string_item(10, "test1", 5); - bool ok = intrusive_hash_map_insert(&hash_map, (hm_item *)new_item1); - GPR_ASSERT(ok); - string_item *new_item2 = make_string_item(20, "test2", 5); - ok = intrusive_hash_map_insert(&hash_map, (hm_item *)new_item2); - GPR_ASSERT(ok); - - string_item *item1 = - (string_item *)intrusive_hash_map_find(&hash_map, (uint64_t)10); - GPR_ASSERT(compare_string_item(new_item1, item1)); - GPR_ASSERT(item1 == new_item1); - string_item *item2 = - (string_item *)intrusive_hash_map_find(&hash_map, (uint64_t)20); - GPR_ASSERT(compare_string_item(new_item2, item2)); - GPR_ASSERT(item2 == new_item2); - - item1 = (string_item *)intrusive_hash_map_erase(&hash_map, (uint64_t)10); - GPR_ASSERT(item1 == new_item1); - item2 = (string_item *)intrusive_hash_map_erase(&hash_map, (uint64_t)20); - GPR_ASSERT(item2 == new_item2); - - gpr_free(new_item1); - gpr_free(new_item2); - GPR_ASSERT(0 == intrusive_hash_map_size(&hash_map)); - intrusive_hash_map_free(&hash_map, NULL); -} - -// Test resetting and clearing the hash map. -void test_reset_clear() { - intrusive_hash_map hash_map; - intrusive_hash_map_init(&hash_map, kInitialLog2Size); - - // Add some data to the hash_map. - for (uint64_t i = 0; i < 3; ++i) { - intrusive_hash_map_insert(&hash_map, (hm_item *)make_ptr_item(i, i)); - } - GPR_ASSERT(3 == intrusive_hash_map_size(&hash_map)); - - // Test find. - for (uint64_t i = 0; i < 3; ++i) { - ptr_item *item = (ptr_item *)intrusive_hash_map_find(&hash_map, i); - GPR_ASSERT(item != NULL); - GPR_ASSERT(item->IHM_key == i && item->obj->val == i); - } - - intrusive_hash_map_clear(&hash_map, &free_ptr_item); - GPR_ASSERT(intrusive_hash_map_empty(&hash_map)); - intrusive_hash_map_free(&hash_map, &free_ptr_item); -} - -// Check that the hash_map contains every key between [min_value, max_value] -// (inclusive). -void check_hash_map_values(intrusive_hash_map *hash_map, uint64_t min_value, - uint64_t max_value) { - GPR_ASSERT(intrusive_hash_map_size(hash_map) == max_value - min_value + 1); - - for (uint64_t i = min_value; i <= max_value; ++i) { - ptr_item *item = (ptr_item *)intrusive_hash_map_find(hash_map, i); - GPR_ASSERT(item != NULL); - GPR_ASSERT(item->obj->val == i); - } -} - -// Add many items and cause the hash_map to extend. -void test_extend() { - intrusive_hash_map hash_map; - intrusive_hash_map_init(&hash_map, kInitialLog2Size); - - const uint64_t kNumValues = (1 << 16); - - for (uint64_t i = 0; i < kNumValues; ++i) { - ptr_item *item = make_ptr_item(i, i); - bool ok = intrusive_hash_map_insert(&hash_map, (hm_item *)item); - GPR_ASSERT(ok); - if (i % 1000 == 0) { - check_hash_map_values(&hash_map, 0, i); - } - } - - for (uint64_t i = 0; i < kNumValues; ++i) { - ptr_item *item = (ptr_item *)intrusive_hash_map_find(&hash_map, i); - GPR_ASSERT(item != NULL); - GPR_ASSERT(item->IHM_key == i && item->obj->val == i); - ptr_item *item2 = (ptr_item *)intrusive_hash_map_erase(&hash_map, i); - GPR_ASSERT(item == item2); - gpr_free(item->obj); - gpr_free(item); - } - - GPR_ASSERT(intrusive_hash_map_empty(&hash_map)); - intrusive_hash_map_free(&hash_map, &free_ptr_item); -} - -void test_stress() { - intrusive_hash_map hash_map; - intrusive_hash_map_init(&hash_map, kInitialLog2Size); - size_t n = 0; - - // Randomly add and insert entries 1000000 times. - for (uint64_t i = 0; i < 1000000; ++i) { - int op = rand() & 0x1; - - switch (op) { - // Case 0 is insertion of entry. - case 0: { - uint64_t key = (uint64_t)(rand() % 10000); - ptr_item *item = make_ptr_item(key, key); - bool ok = intrusive_hash_map_insert(&hash_map, (hm_item *)item); - if (ok) { - n++; - } else { - gpr_free(item->obj); - gpr_free(item); - } - break; - } - // Case 1 is removal of entry. - case 1: { - uint64_t key = (uint64_t)(rand() % 10000); - ptr_item *item = (ptr_item *)intrusive_hash_map_find(&hash_map, key); - if (item != NULL) { - n--; - GPR_ASSERT(key == item->obj->val); - ptr_item *item2 = - (ptr_item *)intrusive_hash_map_erase(&hash_map, key); - GPR_ASSERT(item == item2); - gpr_free(item->obj); - gpr_free(item); - } - break; - } - } - } - // Check size - GPR_ASSERT(n == intrusive_hash_map_size(&hash_map)); - - // Clean the hash_map up. - intrusive_hash_map_clear(&hash_map, &free_ptr_item); - GPR_ASSERT(intrusive_hash_map_empty(&hash_map)); - intrusive_hash_map_free(&hash_map, &free_ptr_item); -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - gpr_time_init(); - srand((unsigned)gpr_now(GPR_CLOCK_REALTIME).tv_nsec); - - test_empty(); - test_single_item(); - test_two_items(); - test_reset_clear(); - test_extend(); - test_stress(); - - return 0; -} diff --git a/test/core/census/mlog_test.cc b/test/core/census/mlog_test.cc deleted file mode 100644 index 968fd91da4..0000000000 --- a/test/core/census/mlog_test.cc +++ /dev/null @@ -1,574 +0,0 @@ -/* - * - * Copyright 2015 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/ext/census/mlog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "test/core/util/test_config.h" - -// Change this to non-zero if you want more output. -#define VERBOSE 0 - -// Log size to use for all tests. -#define LOG_SIZE_IN_MB 1 -#define LOG_SIZE_IN_BYTES (LOG_SIZE_IN_MB << 20) - -// Fills in 'record' of size 'size'. Each byte in record is filled in with the -// same value. The value is extracted from 'record' pointer. -static void write_record(char* record, size_t size) { - char data = (char)((uintptr_t)record % 255); - memset(record, data, size); -} - -// Reads fixed size records. Returns the number of records read in -// 'num_records'. -static void read_records(size_t record_size, const char* buffer, - size_t buffer_size, int* num_records) { - GPR_ASSERT(buffer_size >= record_size); - GPR_ASSERT(buffer_size % record_size == 0); - *num_records = (int)(buffer_size / record_size); - for (int i = 0; i < *num_records; ++i) { - const char* record = buffer + (record_size * (size_t)i); - char data = (char)((uintptr_t)record % 255); - for (size_t j = 0; j < record_size; ++j) { - GPR_ASSERT(data == record[j]); - } - } -} - -// Tries to write the specified number of records. Stops when the log gets -// full. Returns the number of records written. Spins for random -// number of times, up to 'max_spin_count', between writes. -static int write_records_to_log(int writer_id, size_t record_size, - int num_records, int max_spin_count) { - int counter = 0; - for (int i = 0; i < num_records; ++i) { - int spin_count = max_spin_count ? rand() % max_spin_count : 0; - if (VERBOSE && (counter++ == num_records / 10)) { - printf(" Writer %d: %d out of %d written\n", writer_id, i, num_records); - counter = 0; - } - char* record = (char*)(census_log_start_write(record_size)); - if (record == NULL) { - return i; - } - write_record(record, record_size); - census_log_end_write(record, record_size); - for (int j = 0; j < spin_count; ++j) { - GPR_ASSERT(j >= 0); - } - } - return num_records; -} - -// Performs a single read iteration. Returns the number of records read. -static int perform_read_iteration(size_t record_size) { - const void* read_buffer = NULL; - size_t bytes_available; - int records_read = 0; - census_log_init_reader(); - while ((read_buffer = census_log_read_next(&bytes_available))) { - int num_records = 0; - read_records(record_size, (const char*)read_buffer, bytes_available, - &num_records); - records_read += num_records; - } - return records_read; -} - -// Asserts that the log is empty. -static void assert_log_empty(void) { - census_log_init_reader(); - size_t bytes_available; - GPR_ASSERT(census_log_read_next(&bytes_available) == NULL); -} - -// Fills the log and verifies data. If 'no fragmentation' is true, records -// are sized such that CENSUS_LOG_2_MAX_RECORD_SIZE is a multiple of record -// size. If not a circular log, verifies that the number of records written -// match the number of records read. -static void fill_log(size_t log_size, int no_fragmentation, int circular_log) { - size_t size; - if (no_fragmentation) { - int log2size = rand() % (CENSUS_LOG_2_MAX_RECORD_SIZE + 1); - size = ((size_t)1 << log2size); - } else { - while (1) { - size = 1 + ((size_t)rand() % CENSUS_LOG_MAX_RECORD_SIZE); - if (CENSUS_LOG_MAX_RECORD_SIZE % size) { - break; - } - } - } - int records_written = - write_records_to_log(0 /* writer id */, size, - (int)((log_size / size) * 2), 0 /* spin count */); - int records_read = perform_read_iteration(size); - if (!circular_log) { - GPR_ASSERT(records_written == records_read); - } - assert_log_empty(); -} - -// Structure to pass args to writer_thread -typedef struct writer_thread_args { - // Index of this thread in the writers vector. - int index; - // Record size. - size_t record_size; - // Number of records to write. - int num_records; - // Used to signal when writer is complete - gpr_cv* done; - gpr_mu* mu; - int* count; -} writer_thread_args; - -// Writes the given number of records of random size (up to kMaxRecordSize) and -// random data to the specified log. -static void writer_thread(void* arg) { - writer_thread_args* args = (writer_thread_args*)arg; - // Maximum number of times to spin between writes. - static const int MAX_SPIN_COUNT = 50; - int records_written = 0; - if (VERBOSE) { - printf(" Writer %d starting\n", args->index); - } - while (records_written < args->num_records) { - records_written += write_records_to_log(args->index, args->record_size, - args->num_records - records_written, - MAX_SPIN_COUNT); - if (records_written < args->num_records) { - // Ran out of log space. Sleep for a bit and let the reader catch up. - // This should never happen for circular logs. - if (VERBOSE) { - printf( - " Writer %d stalled due to out-of-space: %d out of %d " - "written\n", - args->index, records_written, args->num_records); - } - gpr_sleep_until(grpc_timeout_milliseconds_to_deadline(10)); - } - } - // Done. Decrement count and signal. - gpr_mu_lock(args->mu); - (*args->count)--; - gpr_cv_signal(args->done); - if (VERBOSE) { - printf(" Writer %d done\n", args->index); - } - gpr_mu_unlock(args->mu); -} - -// struct to pass args to reader_thread -typedef struct reader_thread_args { - // Record size. - size_t record_size; - // Interval between read iterations. - int read_iteration_interval_in_msec; - // Total number of records. - int total_records; - // Signalled when reader should stop. - gpr_cv stop; - int stop_flag; - // Used to signal when reader has finished - gpr_cv* done; - gpr_mu* mu; - int running; -} reader_thread_args; - -// Reads and verifies the specified number of records. Reader can also be -// stopped via gpr_cv_signal(&args->stop). Sleeps for 'read_interval_in_msec' -// between read iterations. -static void reader_thread(void* arg) { - reader_thread_args* args = (reader_thread_args*)arg; - if (VERBOSE) { - printf(" Reader starting\n"); - } - gpr_timespec interval = gpr_time_from_micros( - args->read_iteration_interval_in_msec * 1000, GPR_TIMESPAN); - gpr_mu_lock(args->mu); - int records_read = 0; - int num_iterations = 0; - int counter = 0; - while (!args->stop_flag && records_read < args->total_records) { - gpr_cv_wait(&args->stop, args->mu, interval); - if (!args->stop_flag) { - records_read += perform_read_iteration(args->record_size); - GPR_ASSERT(records_read <= args->total_records); - if (VERBOSE && (counter++ == 100000)) { - printf(" Reader: %d out of %d read\n", records_read, - args->total_records); - counter = 0; - } - ++num_iterations; - } - } - // Done - args->running = 0; - gpr_cv_signal(args->done); - if (VERBOSE) { - printf(" Reader: records: %d, iterations: %d\n", records_read, - num_iterations); - } - gpr_mu_unlock(args->mu); -} - -// Creates NUM_WRITERS writers where each writer writes NUM_RECORDS_PER_WRITER -// records. Also, starts a reader that iterates over and reads blocks every -// READ_ITERATION_INTERVAL_IN_MSEC. -// Number of writers. -#define NUM_WRITERS 5 -static void multiple_writers_single_reader(int circular_log) { - // Sleep interval between read iterations. - static const int READ_ITERATION_INTERVAL_IN_MSEC = 10; - // Maximum record size. - static const size_t MAX_RECORD_SIZE = 20; - // Number of records written by each writer. This is sized such that we - // will write through the entire log ~10 times. - const int NUM_RECORDS_PER_WRITER = - (int)((10 * census_log_remaining_space()) / (MAX_RECORD_SIZE / 2)) / - NUM_WRITERS; - size_t record_size = ((size_t)rand() % MAX_RECORD_SIZE) + 1; - // Create and start writers. - writer_thread_args writers[NUM_WRITERS]; - int writers_count = NUM_WRITERS; - gpr_cv writers_done; - gpr_mu writers_mu; // protects writers_done and writers_count - gpr_cv_init(&writers_done); - gpr_mu_init(&writers_mu); - gpr_thd_id id; - for (int i = 0; i < NUM_WRITERS; ++i) { - writers[i].index = i; - writers[i].record_size = record_size; - writers[i].num_records = NUM_RECORDS_PER_WRITER; - writers[i].done = &writers_done; - writers[i].count = &writers_count; - writers[i].mu = &writers_mu; - gpr_thd_new(&id, &writer_thread, &writers[i], NULL); - } - // Start reader. - gpr_cv reader_done; - gpr_mu reader_mu; // protects reader_done and reader.running - reader_thread_args reader; - reader.record_size = record_size; - reader.read_iteration_interval_in_msec = READ_ITERATION_INTERVAL_IN_MSEC; - reader.total_records = NUM_WRITERS * NUM_RECORDS_PER_WRITER; - reader.stop_flag = 0; - gpr_cv_init(&reader.stop); - gpr_cv_init(&reader_done); - reader.done = &reader_done; - gpr_mu_init(&reader_mu); - reader.mu = &reader_mu; - reader.running = 1; - gpr_thd_new(&id, &reader_thread, &reader, NULL); - // Wait for writers to finish. - gpr_mu_lock(&writers_mu); - while (writers_count != 0) { - gpr_cv_wait(&writers_done, &writers_mu, gpr_inf_future(GPR_CLOCK_REALTIME)); - } - gpr_mu_unlock(&writers_mu); - gpr_mu_destroy(&writers_mu); - gpr_cv_destroy(&writers_done); - gpr_mu_lock(&reader_mu); - if (circular_log) { - // Stop reader. - reader.stop_flag = 1; - gpr_cv_signal(&reader.stop); - } - // wait for reader to finish - while (reader.running) { - gpr_cv_wait(&reader_done, &reader_mu, gpr_inf_future(GPR_CLOCK_REALTIME)); - } - if (circular_log) { - // Assert that there were no out-of-space errors. - GPR_ASSERT(0 == census_log_out_of_space_count()); - } - gpr_mu_unlock(&reader_mu); - gpr_mu_destroy(&reader_mu); - gpr_cv_destroy(&reader_done); - if (VERBOSE) { - printf(" Reader: finished\n"); - } -} - -static void setup_test(int circular_log) { - census_log_initialize(LOG_SIZE_IN_MB, circular_log); - // GPR_ASSERT(census_log_remaining_space() == LOG_SIZE_IN_BYTES); -} - -// Attempts to create a record of invalid size (size > -// CENSUS_LOG_MAX_RECORD_SIZE). -void test_invalid_record_size(void) { - static const size_t INVALID_SIZE = CENSUS_LOG_MAX_RECORD_SIZE + 1; - static const size_t VALID_SIZE = 1; - printf("Starting test: invalid record size\n"); - setup_test(0); - void* record = census_log_start_write(INVALID_SIZE); - GPR_ASSERT(record == NULL); - // Now try writing a valid record. - record = census_log_start_write(VALID_SIZE); - GPR_ASSERT(record != NULL); - census_log_end_write(record, VALID_SIZE); - // Verifies that available space went down by one block. In theory, this - // check can fail if the thread is context switched to a new CPU during the - // start_write execution (multiple blocks get allocated), but this has not - // been observed in practice. - // GPR_ASSERT(LOG_SIZE_IN_BYTES - CENSUS_LOG_MAX_RECORD_SIZE == - // census_log_remaining_space()); - census_log_shutdown(); -} - -// Tests end_write() with a different size than what was specified in -// start_write(). -void test_end_write_with_different_size(void) { - static const size_t START_WRITE_SIZE = 10; - static const size_t END_WRITE_SIZE = 7; - printf("Starting test: end write with different size\n"); - setup_test(0); - void* record_written = census_log_start_write(START_WRITE_SIZE); - GPR_ASSERT(record_written != NULL); - census_log_end_write(record_written, END_WRITE_SIZE); - census_log_init_reader(); - size_t bytes_available; - const void* record_read = census_log_read_next(&bytes_available); - GPR_ASSERT(record_written == record_read); - GPR_ASSERT(END_WRITE_SIZE == bytes_available); - assert_log_empty(); - census_log_shutdown(); -} - -// Verifies that pending records are not available via read_next(). -void test_read_pending_record(void) { - static const size_t PR_RECORD_SIZE = 1024; - printf("Starting test: read pending record\n"); - setup_test(0); - // Start a write. - void* record_written = census_log_start_write(PR_RECORD_SIZE); - GPR_ASSERT(record_written != NULL); - // As write is pending, read should fail. - census_log_init_reader(); - size_t bytes_available; - const void* record_read = census_log_read_next(&bytes_available); - GPR_ASSERT(record_read == NULL); - // A read followed by end_write() should succeed. - census_log_end_write(record_written, PR_RECORD_SIZE); - census_log_init_reader(); - record_read = census_log_read_next(&bytes_available); - GPR_ASSERT(record_written == record_read); - GPR_ASSERT(PR_RECORD_SIZE == bytes_available); - assert_log_empty(); - census_log_shutdown(); -} - -// Tries reading beyond pending write. -void test_read_beyond_pending_record(void) { - printf("Starting test: read beyond pending record\n"); - setup_test(0); - // Start a write. - const size_t incomplete_record_size = 10; - void* incomplete_record = census_log_start_write(incomplete_record_size); - GPR_ASSERT(incomplete_record != NULL); - const size_t complete_record_size = 20; - void* complete_record = census_log_start_write(complete_record_size); - GPR_ASSERT(complete_record != NULL); - GPR_ASSERT(complete_record != incomplete_record); - census_log_end_write(complete_record, complete_record_size); - // Now iterate over blocks to read completed records. - census_log_init_reader(); - size_t bytes_available; - const void* record_read = census_log_read_next(&bytes_available); - GPR_ASSERT(complete_record == record_read); - GPR_ASSERT(complete_record_size == bytes_available); - // Complete first record. - census_log_end_write(incomplete_record, incomplete_record_size); - // Have read past the incomplete record, so read_next() should return NULL. - // NB: this test also assumes our thread did not get switched to a different - // CPU between the two start_write calls - record_read = census_log_read_next(&bytes_available); - GPR_ASSERT(record_read == NULL); - // Reset reader to get the newly completed record. - census_log_init_reader(); - record_read = census_log_read_next(&bytes_available); - GPR_ASSERT(incomplete_record == record_read); - GPR_ASSERT(incomplete_record_size == bytes_available); - assert_log_empty(); - census_log_shutdown(); -} - -// Tests scenario where block being read is detached from a core and put on the -// dirty list. -void test_detached_while_reading(void) { - printf("Starting test: detached while reading\n"); - setup_test(0); - // Start a write. - static const size_t DWR_RECORD_SIZE = 10; - void* record_written = census_log_start_write(DWR_RECORD_SIZE); - GPR_ASSERT(record_written != NULL); - census_log_end_write(record_written, DWR_RECORD_SIZE); - // Read this record. - census_log_init_reader(); - size_t bytes_available; - const void* record_read = census_log_read_next(&bytes_available); - GPR_ASSERT(record_read != NULL); - GPR_ASSERT(DWR_RECORD_SIZE == bytes_available); - // Now fill the log. This will move the block being read from core-local - // array to the dirty list. - while ((record_written = census_log_start_write(DWR_RECORD_SIZE))) { - census_log_end_write(record_written, DWR_RECORD_SIZE); - } - - // In this iteration, read_next() should only traverse blocks in the - // core-local array. Therefore, we expect at most gpr_cpu_num_cores() more - // blocks. As log is full, if read_next() is traversing the dirty list, we - // will get more than gpr_cpu_num_cores() blocks. - int block_read = 0; - while ((record_read = census_log_read_next(&bytes_available))) { - ++block_read; - GPR_ASSERT(block_read <= (int)gpr_cpu_num_cores()); - } - census_log_shutdown(); -} - -// Fills non-circular log with records sized such that size is a multiple of -// CENSUS_LOG_MAX_RECORD_SIZE (no per-block fragmentation). -void test_fill_log_no_fragmentation(void) { - printf("Starting test: fill log no fragmentation\n"); - const int circular = 0; - setup_test(circular); - fill_log(LOG_SIZE_IN_BYTES, 1 /* no fragmentation */, circular); - census_log_shutdown(); -} - -// Fills circular log with records sized such that size is a multiple of -// CENSUS_LOG_MAX_RECORD_SIZE (no per-block fragmentation). -void test_fill_circular_log_no_fragmentation(void) { - printf("Starting test: fill circular log no fragmentation\n"); - const int circular = 1; - setup_test(circular); - fill_log(LOG_SIZE_IN_BYTES, 1 /* no fragmentation */, circular); - census_log_shutdown(); -} - -// Fills non-circular log with records that may straddle end of a block. -void test_fill_log_with_straddling_records(void) { - printf("Starting test: fill log with straddling records\n"); - const int circular = 0; - setup_test(circular); - fill_log(LOG_SIZE_IN_BYTES, 0 /* block straddling records */, circular); - census_log_shutdown(); -} - -// Fills circular log with records that may straddle end of a block. -void test_fill_circular_log_with_straddling_records(void) { - printf("Starting test: fill circular log with straddling records\n"); - const int circular = 1; - setup_test(circular); - fill_log(LOG_SIZE_IN_BYTES, 0 /* block straddling records */, circular); - census_log_shutdown(); -} - -// Tests scenario where multiple writers and a single reader are using a log -// that is configured to discard old records. -void test_multiple_writers_circular_log(void) { - printf("Starting test: multiple writers circular log\n"); - const int circular = 1; - setup_test(circular); - multiple_writers_single_reader(circular); - census_log_shutdown(); -} - -// Tests scenario where multiple writers and a single reader are using a log -// that is configured to discard old records. -void test_multiple_writers(void) { - printf("Starting test: multiple writers\n"); - const int circular = 0; - setup_test(circular); - multiple_writers_single_reader(circular); - census_log_shutdown(); -} - -// Repeat the straddling records and multiple writers tests with a small log. -void test_small_log(void) { - printf("Starting test: small log\n"); - const int circular = 0; - census_log_initialize(0, circular); - size_t log_size = census_log_remaining_space(); - GPR_ASSERT(log_size > 0); - fill_log(log_size, 0, circular); - census_log_shutdown(); - census_log_initialize(0, circular); - multiple_writers_single_reader(circular); - census_log_shutdown(); -} - -void test_performance(void) { - for (size_t write_size = 1; write_size < CENSUS_LOG_MAX_RECORD_SIZE; - write_size *= 2) { - setup_test(0); - gpr_timespec start_time = gpr_now(GPR_CLOCK_REALTIME); - int nrecords = 0; - while (1) { - void* record = census_log_start_write(write_size); - if (record == NULL) { - break; - } - census_log_end_write(record, write_size); - nrecords++; - } - gpr_timespec write_time = - gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start_time); - double write_time_micro = - (double)write_time.tv_sec * 1000000 + (double)write_time.tv_nsec / 1000; - census_log_shutdown(); - printf( - "Wrote %d %d byte records in %.3g microseconds: %g records/us " - "(%g ns/record), %g gigabytes/s\n", - nrecords, (int)write_size, write_time_micro, - nrecords / write_time_micro, 1000 * write_time_micro / nrecords, - (double)((int)write_size * nrecords) / write_time_micro / 1000); - } -} - -int main(int argc, char** argv) { - grpc_test_init(argc, argv); - gpr_time_init(); - srand((unsigned)gpr_now(GPR_CLOCK_REALTIME).tv_nsec); - test_invalid_record_size(); - test_end_write_with_different_size(); - test_read_pending_record(); - test_read_beyond_pending_record(); - test_detached_while_reading(); - test_fill_log_no_fragmentation(); - test_fill_circular_log_no_fragmentation(); - test_fill_log_with_straddling_records(); - test_fill_circular_log_with_straddling_records(); - test_small_log(); - test_multiple_writers(); - test_multiple_writers_circular_log(); - test_performance(); - return 0; -} diff --git a/test/core/census/resource_test.cc b/test/core/census/resource_test.cc deleted file mode 100644 index 48fc43e45b..0000000000 --- a/test/core/census/resource_test.cc +++ /dev/null @@ -1,154 +0,0 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include "src/core/ext/census/resource.h" -#include -#include -#include -#include -#include -#include -#include -#include "src/core/ext/census/base_resources.h" -#include "test/core/util/test_config.h" - -// Test all the functionality for dealing with Resources. - -// Just startup and shutdown resources subsystem. -static void test_enable_disable() { - initialize_resources(); - shutdown_resources(); -} - -// A blank/empty initialization should not work. -static void test_empty_definition() { - initialize_resources(); - int32_t rid = census_define_resource(NULL, 0); - GPR_ASSERT(rid == -1); - uint8_t buffer[50] = {0}; - rid = census_define_resource(buffer, 50); - GPR_ASSERT(rid == -1); - shutdown_resources(); -} - -// Given a file name, read raw proto and define the resource included within. -// Returns resource id from census_define_resource(). -static int32_t define_resource_from_file(const char *file) { -#define BUF_SIZE 512 - uint8_t buffer[BUF_SIZE]; - FILE *input = fopen(file, "rb"); - GPR_ASSERT(input != NULL); - size_t nbytes = fread(buffer, 1, BUF_SIZE, input); - GPR_ASSERT(nbytes != 0 && nbytes < BUF_SIZE && feof(input) && !ferror(input)); - int32_t rid = census_define_resource(buffer, nbytes); - GPR_ASSERT(fclose(input) == 0); - return rid; -} - -// Test definition of a single resource, using a proto read from a file. The -// `succeed` parameter indicates whether we expect the definition to succeed or -// fail. `name` is used to check that the returned resource can be looked up by -// name. -static void test_define_single_resource(const char *file, const char *name, - bool succeed) { - gpr_log(GPR_INFO, "Test defining resource \"%s\"\n", name); - initialize_resources(); - int32_t rid = define_resource_from_file(file); - if (succeed) { - GPR_ASSERT(rid >= 0); - int32_t rid2 = census_resource_id(name); - GPR_ASSERT(rid == rid2); - } else { - GPR_ASSERT(rid < 0); - } - shutdown_resources(); -} - -// Try deleting various resources (both those that exist and those that don't). -static void test_delete_resource(const char *minimal_good, const char *full) { - initialize_resources(); - // Try deleting resource before any are defined. - census_delete_resource(0); - // Create and check a couple of resources. - int32_t rid1 = define_resource_from_file(minimal_good); - int32_t rid2 = define_resource_from_file(full); - GPR_ASSERT(rid1 >= 0 && rid2 >= 0 && rid1 != rid2); - int32_t rid3 = census_resource_id("minimal_good"); - int32_t rid4 = census_resource_id("full_resource"); - GPR_ASSERT(rid1 == rid3 && rid2 == rid4); - // Try deleting non-existant resources. - census_delete_resource(-1); - census_delete_resource(rid1 + rid2 + 1); - census_delete_resource(10000000); - // Delete one of the previously defined resources and check for deletion. - census_delete_resource(rid1); - rid3 = census_resource_id("minimal_good"); - GPR_ASSERT(rid3 < 0); - // Check that re-adding works. - rid1 = define_resource_from_file(minimal_good); - GPR_ASSERT(rid1 >= 0); - rid3 = census_resource_id("minimal_good"); - GPR_ASSERT(rid1 == rid3); - shutdown_resources(); -} - -// Test define base resources. -static void test_base_resources() { - initialize_resources(); - define_base_resources(); - int32_t rid1 = census_resource_id("client_rpc_latency"); - int32_t rid2 = census_resource_id("server_rpc_latency"); - GPR_ASSERT(rid1 >= 0 && rid2 >= 0 && rid1 != rid2); - shutdown_resources(); -} - -int main(int argc, char **argv) { - const char *resource_empty_name_pb, *resource_full_pb, - *resource_minimal_good_pb, *resource_no_name_pb, - *resource_no_numerator_pb, *resource_no_unit_pb; - if (argc == 7) { - resource_empty_name_pb = argv[1]; - resource_full_pb = argv[2]; - resource_minimal_good_pb = argv[3]; - resource_no_name_pb = argv[4]; - resource_no_numerator_pb = argv[5]; - resource_no_unit_pb = argv[6]; - } else { - GPR_ASSERT(argc == 1); - resource_empty_name_pb = "test/core/census/data/resource_empty_name.pb"; - resource_full_pb = "test/core/census/data/resource_full.pb"; - resource_minimal_good_pb = "test/core/census/data/resource_minimal_good.pb"; - resource_no_name_pb = "test/core/census/data/resource_no_name.pb"; - resource_no_numerator_pb = "test/core/census/data/resource_no_numerator.pb"; - resource_no_unit_pb = "test/core/census/data/resource_no_unit.pb"; - } - grpc_test_init(argc, argv); - test_enable_disable(); - test_empty_definition(); - test_define_single_resource(resource_minimal_good_pb, "minimal_good", true); - test_define_single_resource(resource_full_pb, "full_resource", true); - test_define_single_resource(resource_no_name_pb, "resource_no_name", false); - test_define_single_resource(resource_no_numerator_pb, "resource_no_numerator", - false); - test_define_single_resource(resource_no_unit_pb, "resource_no_unit", false); - test_define_single_resource(resource_empty_name_pb, "resource_empty_name", - false); - test_delete_resource(resource_minimal_good_pb, resource_full_pb); - test_base_resources(); - return 0; -} diff --git a/test/core/census/trace_context_test.cc b/test/core/census/trace_context_test.cc deleted file mode 100644 index 6eb831a85e..0000000000 --- a/test/core/census/trace_context_test.cc +++ /dev/null @@ -1,215 +0,0 @@ -/* - * - * Copyright 2016 gRPC authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include "src/core/ext/census/base_resources.h" -#include "src/core/ext/census/resource.h" -#include "test/core/util/test_config.h" - -#include "src/core/ext/census/gen/trace_context.pb.h" -#include "src/core/ext/census/trace_context.h" -#include "third_party/nanopb/pb_decode.h" -#include "third_party/nanopb/pb_encode.h" - -#define BUF_SIZE 256 - -/* Encodes a TraceContext structure (ctxt1) to a buffer, and then decodes it -to a second TraceContext (ctxt2). Validates that the resulting TraceContext -has a span_id, trace_id, and that the values are equal to those in initial -TraceContext. On success, returns true. If encode_trace_context returns 0, -decode_trace_context fails, or the resulting TraceContext is missing a trace_id -or span_id, it will return false. */ -bool validate_encode_decode_context(google_trace_TraceContext *ctxt1, - uint8_t *buffer, size_t buf_size) { - google_trace_TraceContext ctxt2 = google_trace_TraceContext_init_zero; - size_t msg_length; - - msg_length = encode_trace_context(ctxt1, buffer, buf_size); - if (msg_length == 0) { - return false; - } - - if (!decode_trace_context(&ctxt2, buffer, msg_length)) { - return false; - } - - if (!ctxt2.has_trace_id_hi || !ctxt2.has_trace_id_lo || !ctxt2.has_span_id) { - return false; - } - - GPR_ASSERT(ctxt1->trace_id_hi == ctxt2.trace_id_hi && - ctxt1->trace_id_lo == ctxt2.trace_id_lo && - ctxt1->span_id == ctxt2.span_id && - ctxt1->has_span_options == ctxt2.has_span_options && - (ctxt1->has_span_options - ? ctxt1->span_options == ctxt2.span_options - : true)); - - return true; -} - -/* Decodes a proto-encoded TraceContext from a buffer. If decode_trace_context -fails or the resulting TraceContext is missing a trace_id or span_id it will -return false, otherwise returns true. */ -bool validate_decode_context(google_trace_TraceContext *ctxt, uint8_t *buffer, - size_t msg_length) { - // Validate the decoding of a context written to buffer. - if (!decode_trace_context(ctxt, buffer, msg_length)) { - return false; - } - - if (!ctxt->has_trace_id_hi || !ctxt->has_trace_id_lo || !ctxt->has_span_id) { - return false; - } - - return true; -} - -/* Read an encoded trace context from a file. Validates that the decoding -gives the expected result (succeed). */ -static void read_and_validate_context_from_file(google_trace_TraceContext *ctxt, - const char *file, - const bool succeed) { - uint8_t buffer[BUF_SIZE]; - FILE *input = fopen(file, "rb"); - GPR_ASSERT(input != NULL); - size_t nbytes = fread(buffer, 1, BUF_SIZE, input); - GPR_ASSERT(nbytes <= BUF_SIZE && feof(input) && !ferror(input)); - bool res = validate_decode_context(ctxt, buffer, nbytes); - GPR_ASSERT(res == succeed); - GPR_ASSERT(fclose(input) == 0); -} - -// Test full proto-buffer. -static void test_full() { - google_trace_TraceContext ctxt = google_trace_TraceContext_init_zero; - read_and_validate_context_from_file( - &ctxt, "test/core/census/data/context_full.pb", true); -} - -// Test empty proto-buffer. -static void test_empty() { - google_trace_TraceContext ctxt = google_trace_TraceContext_init_zero; - read_and_validate_context_from_file( - &ctxt, "test/core/census/data/context_empty.pb", false); -} - -// Test proto-buffer with only trace_id. -static void test_trace_only() { - google_trace_TraceContext ctxt = google_trace_TraceContext_init_zero; - read_and_validate_context_from_file( - &ctxt, "test/core/census/data/context_trace_only.pb", false); -} - -// Test proto-buffer with only span_id. -static void test_span_only() { - google_trace_TraceContext ctxt = google_trace_TraceContext_init_zero; - read_and_validate_context_from_file( - &ctxt, "test/core/census/data/context_span_only.pb", false); -} - -// Test proto-buffer without span_options value. -static void test_no_span_options() { - google_trace_TraceContext ctxt = google_trace_TraceContext_init_zero; - read_and_validate_context_from_file( - &ctxt, "test/core/census/data/context_no_span_options.pb", true); - GPR_ASSERT(ctxt.has_span_options == false && ctxt.span_options == 0); -} - -static void test_encode_decode() { - uint8_t buffer[BUF_SIZE] = {0}; - - google_trace_TraceContext ctxt1 = google_trace_TraceContext_init_zero; - ctxt1.has_trace_id_hi = true; - ctxt1.has_trace_id_lo = true; - ctxt1.trace_id_lo = 1; - ctxt1.trace_id_hi = 2; - ctxt1.has_span_id = true; - ctxt1.span_id = 3; - validate_encode_decode_context(&ctxt1, buffer, sizeof(buffer)); - - // Missing trace_id. This should fail. - google_trace_TraceContext ctxt2 = google_trace_TraceContext_init_zero; - ctxt2.has_trace_id_hi = false; - ctxt2.has_trace_id_lo = false; - ctxt2.has_span_id = true; - validate_encode_decode_context(&ctxt2, buffer, sizeof(buffer)); -} - -// Test a corrupted proto-buffer. This should fail. -static void test_corrupt() { - uint8_t buffer[BUF_SIZE] = {0}; - google_trace_TraceContext ctxt1 = google_trace_TraceContext_init_zero; - size_t msg_length; - - ctxt1.has_trace_id_hi = true; - ctxt1.has_trace_id_lo = true; - ctxt1.trace_id_lo = 1; - ctxt1.trace_id_hi = 2; - ctxt1.has_span_id = true; - ctxt1.span_id = 3; - ctxt1.has_span_options = true; - ctxt1.span_options = SPAN_OPTIONS_IS_SAMPLED; - msg_length = encode_trace_context(&ctxt1, buffer, sizeof(buffer)); - - /* Corrupt some bytes. 255 (0xFF) should be illegal for the first byte of the - proto encoded object. */ - buffer[0] = 255; - - bool res = validate_decode_context(&ctxt1, buffer, msg_length); - GPR_ASSERT(res == false); -} - -static void test_buffer_size() { - // This buffer is too small. This should fail. - uint8_t buffer[16] = {0}; - google_trace_TraceContext ctxt1 = google_trace_TraceContext_init_zero; - size_t msg_length; - - ctxt1.has_trace_id_hi = true; - ctxt1.has_trace_id_lo = true; - ctxt1.trace_id_lo = 1; - ctxt1.trace_id_hi = 2; - ctxt1.has_span_id = true; - ctxt1.span_id = 3; - ctxt1.has_span_options = true; - ctxt1.span_options = SPAN_OPTIONS_IS_SAMPLED; - msg_length = encode_trace_context(&ctxt1, buffer, sizeof(buffer)); - - GPR_ASSERT(msg_length == 0); -} - -int main(int argc, char **argv) { - grpc_test_init(argc, argv); - test_full(); - test_empty(); - test_trace_only(); - test_span_only(); - test_encode_decode(); - test_corrupt(); - test_no_span_options(); - test_buffer_size(); - - return 0; -} -- cgit v1.2.3