diff options
author | yang-g <yangg@google.com> | 2015-12-08 14:38:52 -0800 |
---|---|---|
committer | yang-g <yangg@google.com> | 2015-12-08 14:38:52 -0800 |
commit | bd000af27896441b34b3d1983db5ea1ec645cc43 (patch) | |
tree | df9e852991348d49497be5e5a9e2b0786861da86 /test | |
parent | 0edc362f91dea54f0b094daddc589b25b94f31bb (diff) | |
parent | 5ecd75fdf6f047f251bea8b61219687b72102a4d (diff) |
merge with head
Diffstat (limited to 'test')
-rwxr-xr-x | test/core/bad_client/gen_build_yaml.py | 3 | ||||
-rw-r--r-- | test/core/bad_client/tests/headers.c | 26 | ||||
-rw-r--r-- | test/core/bad_client/tests/unknown_frame.c | 58 | ||||
-rw-r--r-- | test/core/support/slice_test.c | 17 | ||||
-rw-r--r-- | test/core/support/sync_test.c | 55 |
5 files changed, 131 insertions, 28 deletions
diff --git a/test/core/bad_client/gen_build_yaml.py b/test/core/bad_client/gen_build_yaml.py index 86ada9896b..bdb0176ba9 100755 --- a/test/core/bad_client/gen_build_yaml.py +++ b/test/core/bad_client/gen_build_yaml.py @@ -41,8 +41,9 @@ default_test_options = TestOptions(False) # maps test names to options BAD_CLIENT_TESTS = { 'connection_prefix': default_test_options, - 'initial_settings_frame': default_test_options, 'headers': default_test_options, + 'initial_settings_frame': default_test_options, + 'unknown_frame': default_test_options, } def main(): diff --git a/test/core/bad_client/tests/headers.c b/test/core/bad_client/tests/headers.c index c16bfd623b..5547aca210 100644 --- a/test/core/bad_client/tests/headers.c +++ b/test/core/bad_client/tests/headers.c @@ -96,6 +96,22 @@ int main(int argc, char **argv) { 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" + "\x00\x00\x00", + GRPC_BAD_CLIENT_DISCONNECT); + GRPC_RUN_BAD_CLIENT_TEST(verifier, 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, PFX_STR + "\x00\x00\x05\x01\x24\x00\x00\x00\x01" "\x00\x00\x00\x00\x00", GRPC_BAD_CLIENT_DISCONNECT); @@ -106,24 +122,24 @@ int main(int argc, char **argv) { 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x7f\x7f\x01a", + "\x7f\x7f\x01""a", 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x0f\x7f\x01a", + "\x0f\x7f\x01""a", 0); GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x04\x01\x04\x00\x00\x00\x01" - "\x1f\x7f\x01a", + "\x1f\x7f\x01""a", 0); /* test nvr, not indexed in static table */ GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x01\x01a", + "\x01\x01""a", GRPC_BAD_CLIENT_DISCONNECT); GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR "\x00\x00\x03\x01\x04\x00\x00\x00\x01" - "\x11\x01a", + "\x11\x01""a", GRPC_BAD_CLIENT_DISCONNECT); /* illegal op code */ GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR diff --git a/test/core/bad_client/tests/unknown_frame.c b/test/core/bad_client/tests/unknown_frame.c new file mode 100644 index 0000000000..8ea81390c9 --- /dev/null +++ b/test/core/bad_client/tests/unknown_frame.c @@ -0,0 +1,58 @@ +/* + * + * Copyright 2015, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include "test/core/bad_client/bad_client.h" +#include "src/core/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" + +static void verifier(grpc_server *server, grpc_completion_queue *cq) { + while (grpc_server_has_open_connections(server)) { + GPR_ASSERT(grpc_completion_queue_next( + cq, GRPC_TIMEOUT_MILLIS_TO_DEADLINE(20), NULL) + .type == GRPC_QUEUE_TIMEOUT); + } +} + +int main(int argc, char **argv) { + grpc_test_init(argc, argv); + + /* test adding prioritization data */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, PFX_STR + "\x00\x00\x00\x88\x00\x00\x00\x00\x01", + GRPC_BAD_CLIENT_DISCONNECT); + + return 0; +} diff --git a/test/core/support/slice_test.c b/test/core/support/slice_test.c index 1d202f0618..9e0e22c24b 100644 --- a/test/core/support/slice_test.c +++ b/test/core/support/slice_test.c @@ -94,12 +94,27 @@ static void do_nothing_with_len_1(void *ignored, size_t len) { static void test_slice_new_with_len_returns_something_sensible(void) { gpr_uint8 x; + int num_refs = 5; /* To test adding/removing an arbitrary number of refs */ + int i; gpr_slice slice = gpr_slice_new_with_len(&x, 1, do_nothing_with_len_1); - GPR_ASSERT(slice.refcount); + GPR_ASSERT(slice.refcount); /* ref count is initialized to 1 at this point */ GPR_ASSERT(slice.data.refcounted.bytes == &x); GPR_ASSERT(slice.data.refcounted.length == 1); GPR_ASSERT(do_nothing_with_len_1_calls == 0); + + /* Add an arbitrary number of refs to the slice and remoe the refs. This is to + make sure that that the destroy callback (i.e do_nothing_with_len_1()) is + not called until the last unref operation */ + for (i = 0; i < num_refs; i++) { + gpr_slice_ref(slice); + } + for (i = 0; i < num_refs; i++) { + gpr_slice_unref(slice); + } + GPR_ASSERT(do_nothing_with_len_1_calls == 0); /* Shouldn't be called yet */ + + /* last unref */ gpr_slice_unref(slice); GPR_ASSERT(do_nothing_with_len_1_calls == 1); } diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c index 220b16b60f..6bc5f792e5 100644 --- a/test/core/support/sync_test.c +++ b/test/core/support/sync_test.c @@ -153,6 +153,7 @@ struct test { gpr_int64 counter; int thread_count; /* used to allocate thread ids */ int done; /* threads not yet completed */ + int incr_step; /* how much to increment/decrement refcount each time */ gpr_mu mu; /* protects iterations, counter, thread_count, done */ @@ -170,13 +171,14 @@ struct test { }; /* Return pointer to a new struct test. */ -static struct test *test_new(int threads, gpr_int64 iterations) { +static struct test *test_new(int threads, gpr_int64 iterations, int incr_step) { struct test *m = gpr_malloc(sizeof(*m)); m->threads = threads; m->iterations = iterations; m->counter = 0; m->thread_count = 0; m->done = threads; + m->incr_step = incr_step; gpr_mu_init(&m->mu); gpr_cv_init(&m->cv); gpr_cv_init(&m->done_cv); @@ -238,9 +240,12 @@ static void mark_thread_done(struct test *m) { /* Test several threads running (*body)(struct test *m) for increasing settings of m->iterations, until about timeout_s to 2*timeout_s seconds have elapsed. - If extra!=NULL, run (*extra)(m) in an additional thread. */ + If extra!=NULL, run (*extra)(m) in an additional thread. + incr_step controls by how much m->refcount should be incremented/decremented + (if at all) each time in the tests. + */ static void test(const char *name, void (*body)(void *m), - void (*extra)(void *m), int timeout_s) { + void (*extra)(void *m), int timeout_s, int incr_step) { gpr_int64 iterations = 1024; struct test *m; gpr_timespec start = gpr_now(GPR_CLOCK_REALTIME); @@ -251,7 +256,7 @@ static void test(const char *name, void (*body)(void *m), while (gpr_time_cmp(gpr_now(GPR_CLOCK_REALTIME), deadline) < 0) { iterations <<= 1; fprintf(stderr, " %ld", (long)iterations); - m = test_new(10, iterations); + m = test_new(10, iterations, incr_step); if (extra != NULL) { gpr_thd_id id; GPR_ASSERT(gpr_thd_new(&id, extra, m, NULL)); @@ -259,7 +264,7 @@ static void test(const char *name, void (*body)(void *m), } test_create_threads(m, body); test_wait(m); - if (m->counter != m->threads * m->iterations) { + if (m->counter != m->threads * m->iterations * m->incr_step) { fprintf(stderr, "counter %ld threads %d iterations %ld\n", (long)m->counter, m->threads, (long)m->iterations); GPR_ASSERT(0); @@ -406,14 +411,18 @@ static void statsinc(void *v /*=m*/) { mark_thread_done(m); } -/* Increment m->refcount m->iterations times, decrement m->thread_refcount - once, and if it reaches zero, set m->event to (void*)1; then mark thread as - done. */ +/* Increment m->refcount by m->incr_step for m->iterations times. Decrement + m->thread_refcount once, and if it reaches zero, set m->event to (void*)1; + then mark thread as done. */ static void refinc(void *v /*=m*/) { struct test *m = v; gpr_int64 i; for (i = 0; i != m->iterations; i++) { - gpr_ref(&m->refcount); + if (m->incr_step == 1) { + gpr_ref(&m->refcount); + } else { + gpr_refn(&m->refcount, m->incr_step); + } } if (gpr_unref(&m->thread_refcount)) { gpr_event_set(&m->event, (void *)1); @@ -421,12 +430,13 @@ static void refinc(void *v /*=m*/) { mark_thread_done(m); } -/* Wait until m->event is set to (void *)1, then decrement m->refcount - m->stats_counter m->iterations times, and ensure that the last decrement - caused the counter to reach zero, then mark thread as done. */ + +/* Wait until m->event is set to (void *)1, then decrement m->refcount by 1 + (m->threads * m->iterations * m->incr_step) times, and ensure that the last + decrement caused the counter to reach zero, then mark thread as done. */ static void refcheck(void *v /*=m*/) { struct test *m = v; - gpr_int64 n = m->iterations * m->threads; + gpr_int64 n = m->iterations * m->threads * m->incr_step; gpr_int64 i; GPR_ASSERT(gpr_event_wait(&m->event, gpr_inf_future(GPR_CLOCK_REALTIME)) == (void *)1); @@ -444,13 +454,16 @@ static void refcheck(void *v /*=m*/) { int main(int argc, char *argv[]) { grpc_test_init(argc, argv); - test("mutex", &inc, NULL, 1); - test("mutex try", &inctry, NULL, 1); - test("cv", &inc_by_turns, NULL, 1); - test("timedcv", &inc_with_1ms_delay, NULL, 1); - test("queue", &many_producers, &consumer, 10); - test("stats_counter", &statsinc, NULL, 1); - test("refcount", &refinc, &refcheck, 1); - test("timedevent", &inc_with_1ms_delay_event, NULL, 1); + test("mutex", &inc, NULL, 1, 1); + test("mutex try", &inctry, NULL, 1, 1); + test("cv", &inc_by_turns, NULL, 1, 1); + test("timedcv", &inc_with_1ms_delay, NULL, 1, 1); + test("queue", &many_producers, &consumer, 10, 1); + test("stats_counter", &statsinc, NULL, 1, 1); + test("refcount by 1", &refinc, &refcheck, 1, 1); + test("refcount by 3", &refinc, &refcheck, 1, 3); /* incr_step of 3 is an + arbitrary choice. Any + number > 1 is okay here */ + test("timedevent", &inc_with_1ms_delay_event, NULL, 1, 1); return 0; } |