diff options
Diffstat (limited to 'test/core/bad_client')
-rw-r--r-- | test/core/bad_client/BUILD | 34 | ||||
-rw-r--r-- | test/core/bad_client/bad_client.c | 31 | ||||
-rwxr-xr-x | test/core/bad_client/generate_tests.bzl | 68 | ||||
-rw-r--r-- | test/core/bad_client/tests/badreq.c | 2 | ||||
-rw-r--r-- | test/core/bad_client/tests/connection_prefix.c | 2 | ||||
-rw-r--r-- | test/core/bad_client/tests/headers.c | 2 | ||||
-rw-r--r-- | test/core/bad_client/tests/initial_settings_frame.c | 2 | ||||
-rw-r--r-- | test/core/bad_client/tests/large_metadata.c | 59 | ||||
-rw-r--r-- | test/core/bad_client/tests/simple_request.c | 6 | ||||
-rw-r--r-- | test/core/bad_client/tests/unknown_frame.c | 2 | ||||
-rw-r--r-- | test/core/bad_client/tests/window_overflow.c | 2 |
11 files changed, 157 insertions, 53 deletions
diff --git a/test/core/bad_client/BUILD b/test/core/bad_client/BUILD new file mode 100644 index 0000000000..6b06955efe --- /dev/null +++ b/test/core/bad_client/BUILD @@ -0,0 +1,34 @@ +# Copyright 2016, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +licenses(["notice"]) # 3-clause BSD + +load(":generate_tests.bzl", "grpc_bad_client_tests") + +grpc_bad_client_tests() diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c index 07fcd995d7..fdedfe284e 100644 --- a/test/core/bad_client/bad_client.c +++ b/test/core/bad_client/bad_client.c @@ -33,15 +33,18 @@ #include "test/core/bad_client/bad_client.h" +#include <stdio.h> + #include <grpc/support/alloc.h> #include <grpc/support/string_util.h> #include <grpc/support/sync.h> #include <grpc/support/thd.h> -#include <stdio.h> + #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/channel/http_server_filter.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" @@ -117,7 +120,7 @@ void grpc_run_bad_client_test( grpc_resource_quota *resource_quota = grpc_resource_quota_create("bad_client_test"); sfd = grpc_iomgr_create_endpoint_pair("fixture", resource_quota, 65536); - grpc_resource_quota_internal_unref(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); /* Create server, completion events */ a.server = grpc_server_create(NULL, NULL); @@ -148,7 +151,8 @@ void grpc_run_bad_client_test( grpc_slice_buffer_init(&outgoing); grpc_slice_buffer_add(&outgoing, slice); - grpc_closure_init(&done_write_closure, done_write, &a); + 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); @@ -156,16 +160,17 @@ void grpc_run_bad_client_test( /* Await completion */ GPR_ASSERT( - gpr_event_wait(&a.done_write, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))); + 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_endpoint_shutdown(&exec_ctx, sfd.client, + GRPC_ERROR_CREATE("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))); + GPR_ASSERT(gpr_event_wait(&a.done_thd, grpc_timeout_seconds_to_deadline(5))); if (sfd.client != NULL) { // Validate client stream, if requested. @@ -175,26 +180,28 @@ void grpc_run_bad_client_test( grpc_slice_buffer_init(&args.incoming); gpr_event_init(&args.read_done); grpc_closure read_done_closure; - grpc_closure_init(&read_done_closure, read_done, &args); + grpc_closure_init(&read_done_closure, read_done, &args, + grpc_schedule_on_exec_ctx); grpc_endpoint_read(&exec_ctx, sfd.client, &args.incoming, &read_done_closure); grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT( - gpr_event_wait(&args.read_done, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5))); - grpc_slice_buffer_destroy(&args.incoming); + gpr_event_wait(&args.read_done, grpc_timeout_seconds_to_deadline(5))); + grpc_slice_buffer_destroy_internal(&exec_ctx, &args.incoming); } // Shutdown. - grpc_endpoint_shutdown(&exec_ctx, sfd.client); + grpc_endpoint_shutdown(&exec_ctx, sfd.client, + GRPC_ERROR_CREATE("Test Shutdown")); grpc_endpoint_destroy(&exec_ctx, sfd.client); grpc_exec_ctx_finish(&exec_ctx); } grpc_server_shutdown_and_notify(a.server, a.cq, NULL); GPR_ASSERT(grpc_completion_queue_pluck( - a.cq, NULL, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(1), NULL) + a.cq, NULL, grpc_timeout_seconds_to_deadline(1), NULL) .type == GRPC_OP_COMPLETE); grpc_server_destroy(a.server); grpc_completion_queue_destroy(a.cq); - grpc_slice_buffer_destroy(&outgoing); + grpc_slice_buffer_destroy_internal(&exec_ctx, &outgoing); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); diff --git a/test/core/bad_client/generate_tests.bzl b/test/core/bad_client/generate_tests.bzl new file mode 100755 index 0000000000..694ddeeab6 --- /dev/null +++ b/test/core/bad_client/generate_tests.bzl @@ -0,0 +1,68 @@ +#!/usr/bin/env python2.7 +# Copyright 2015, Google Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +"""Generates the appropriate build.json data for all the bad_client tests.""" + + +def test_options(): + return struct() + + +# maps test names to options +BAD_CLIENT_TESTS = { + 'badreq': test_options(), + 'connection_prefix': test_options(), + 'headers': test_options(), + 'initial_settings_frame': test_options(), + 'head_of_line_blocking': test_options(), + 'large_metadata': test_options(), + 'server_registered_method': test_options(), + 'simple_request': test_options(), + 'window_overflow': test_options(), + 'unknown_frame': test_options(), +} + +def grpc_bad_client_tests(): + native.cc_library( + name = 'bad_client_test', + srcs = ['bad_client.c'], + 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(): + native.cc_test( + name = '%s_bad_client_test' % t, + srcs = ['tests/%s.c' % 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 index 5d9ffef3f2..7b22f880ab 100644 --- a/test/core/bad_client/tests/badreq.c +++ b/test/core/bad_client/tests/badreq.c @@ -46,7 +46,7 @@ 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_MILLIS_TO_DEADLINE(20), NULL) + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) .type == GRPC_QUEUE_TIMEOUT); } } diff --git a/test/core/bad_client/tests/connection_prefix.c b/test/core/bad_client/tests/connection_prefix.c index bc5ed2e393..42787ab90d 100644 --- a/test/core/bad_client/tests/connection_prefix.c +++ b/test/core/bad_client/tests/connection_prefix.c @@ -38,7 +38,7 @@ 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_MILLIS_TO_DEADLINE(20), NULL) + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) .type == GRPC_QUEUE_TIMEOUT); } } diff --git a/test/core/bad_client/tests/headers.c b/test/core/bad_client/tests/headers.c index f872e5006a..ab47821760 100644 --- a/test/core/bad_client/tests/headers.c +++ b/test/core/bad_client/tests/headers.c @@ -42,7 +42,7 @@ 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_MILLIS_TO_DEADLINE(20), NULL) + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) .type == GRPC_QUEUE_TIMEOUT); } } diff --git a/test/core/bad_client/tests/initial_settings_frame.c b/test/core/bad_client/tests/initial_settings_frame.c index b84b67a7e5..890efd8924 100644 --- a/test/core/bad_client/tests/initial_settings_frame.c +++ b/test/core/bad_client/tests/initial_settings_frame.c @@ -41,7 +41,7 @@ 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_MILLIS_TO_DEADLINE(20), NULL) + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) .type == GRPC_QUEUE_TIMEOUT); } } diff --git a/test/core/bad_client/tests/large_metadata.c b/test/core/bad_client/tests/large_metadata.c index 9c804e78c1..f672776a9f 100644 --- a/test/core/bad_client/tests/large_metadata.c +++ b/test/core/bad_client/tests/large_metadata.c @@ -126,8 +126,8 @@ static void server_verifier(grpc_server *server, grpc_completion_queue *cq, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); + 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); @@ -153,16 +153,14 @@ static void server_verifier_sends_too_much_metadata(grpc_server *server, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); + 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 = 16 * 1024; grpc_metadata meta; - meta.key = "key"; - meta.value = gpr_malloc(metadata_value_size + 1); - memset((char *)meta.value, 'a', metadata_value_size); - ((char *)meta.value)[metadata_value_size] = 0; - meta.value_length = metadata_value_size; + 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)); @@ -176,7 +174,7 @@ static void server_verifier_sends_too_much_metadata(grpc_server *server, CQ_EXPECT_COMPLETION(cqv, tag(102), 0); // Operation fails. cq_verify(cqv); - gpr_free((char *)meta.value); + grpc_slice_unref(meta.value); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); grpc_call_destroy(s); @@ -190,29 +188,26 @@ static void client_validator(grpc_slice_buffer *incoming) { 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]; - // Construct expected frame. - grpc_slice expected = grpc_slice_malloc(13); - uint8_t *p = GRPC_SLICE_START_PTR(expected); - // Length. - *p++ = 0; - *p++ = 0; - *p++ = 4; - // Frame type (RST_STREAM). - *p++ = 3; - // Flags. - *p++ = 0; + const uint8_t *p = GRPC_SLICE_START_PTR(last_frame); + // Length = 4 + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 4); + // Frame type (RST_STREAM) + GPR_ASSERT(*p++ == 3); + // Flags + GPR_ASSERT(*p++ == 0); // Stream ID. - *p++ = 0; - *p++ = 0; - *p++ = 0; - *p++ = 1; - // Payload (error code). - *p++ = 0; - *p++ = 0; - *p++ = 0; - *p++ = 11; - // Compare actual and expected. - GPR_ASSERT(grpc_slice_cmp(last_frame, expected) == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 1); + // Payload (error code) + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p == 0 || *p == 11); + grpc_slice_buffer_destroy(&last_frame_buffer); } diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c index c08aa40a0a..608b849d41 100644 --- a/test/core/bad_client/tests/simple_request.c +++ b/test/core/bad_client/tests/simple_request.c @@ -117,8 +117,8 @@ static void verifier(grpc_server *server, grpc_completion_queue *cq, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); + 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); @@ -130,7 +130,7 @@ 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_MILLIS_TO_DEADLINE(20), NULL) + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) .type == GRPC_QUEUE_TIMEOUT); } } diff --git a/test/core/bad_client/tests/unknown_frame.c b/test/core/bad_client/tests/unknown_frame.c index 4f483d21f2..1d04699422 100644 --- a/test/core/bad_client/tests/unknown_frame.c +++ b/test/core/bad_client/tests/unknown_frame.c @@ -42,7 +42,7 @@ 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_MILLIS_TO_DEADLINE(20), NULL) + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) .type == GRPC_QUEUE_TIMEOUT); } } diff --git a/test/core/bad_client/tests/window_overflow.c b/test/core/bad_client/tests/window_overflow.c index 0d17dbe448..7db85906f9 100644 --- a/test/core/bad_client/tests/window_overflow.c +++ b/test/core/bad_client/tests/window_overflow.c @@ -61,7 +61,7 @@ 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_MILLIS_TO_DEADLINE(20), NULL) + cq, grpc_timeout_milliseconds_to_deadline(20), NULL) .type == GRPC_QUEUE_TIMEOUT); } } |