diff options
author | Craig Tiller <ctiller@google.com> | 2015-12-08 15:27:55 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-12-08 15:27:55 -0800 |
commit | a83cc5e9b4eba9509a40f9c3d5fddcee5e7ea599 (patch) | |
tree | c41945f149b7bcc49fda943eeda342dfc8de2df2 /test | |
parent | d391b560ece42fd3cae93df5551dbd2a42785535 (diff) | |
parent | 248904afadfc8eb987d51abbb7f8ea216f548891 (diff) |
Merge github.com:grpc/grpc into partial-send-header
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 | 16 | ||||
-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 | ||||
-rw-r--r-- | test/core/surface/completion_queue_test.c | 14 | ||||
-rw-r--r-- | test/core/surface/init_test.c | 6 |
7 files changed, 138 insertions, 31 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 036a33ccb7..39ce7838de 100644 --- a/test/core/bad_client/tests/headers.c +++ b/test/core/bad_client/tests/headers.c @@ -126,24 +126,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 @@ -268,5 +268,11 @@ int main(int argc, char **argv) { "\x00\x00\x00\x09\x04\x00\x00\x00\x01", 0); + /* an invalid header found with fuzzing */ + GRPC_RUN_BAD_CLIENT_TEST(verifier, + PFX_STR + "\x00\x00\x00\x01\x39\x67\xed\x1d\x64", + GRPC_BAD_CLIENT_DISCONNECT); + return 0; } 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; } diff --git a/test/core/surface/completion_queue_test.c b/test/core/surface/completion_queue_test.c index e3fc789788..7a5cf30506 100644 --- a/test/core/surface/completion_queue_test.c +++ b/test/core/surface/completion_queue_test.c @@ -175,6 +175,19 @@ static void test_pluck(void) { grpc_exec_ctx_finish(&exec_ctx); } +static void test_pluck_after_shutdown(void) { + grpc_event ev; + grpc_completion_queue *cc; + + LOG_TEST("test_pluck_after_shutdown"); + cc = grpc_completion_queue_create(NULL); + grpc_completion_queue_shutdown(cc); + ev = grpc_completion_queue_pluck(cc, NULL, gpr_inf_future(GPR_CLOCK_REALTIME), + NULL); + GPR_ASSERT(ev.type == GRPC_QUEUE_SHUTDOWN); + grpc_completion_queue_destroy(cc); +} + #define TEST_THREAD_EVENTS 10000 typedef struct test_thread_options { @@ -343,6 +356,7 @@ int main(int argc, char **argv) { test_shutdown_then_next_with_timeout(); test_cq_end_op(); test_pluck(); + test_pluck_after_shutdown(); test_threading(1, 1); test_threading(1, 10); test_threading(10, 1); diff --git a/test/core/surface/init_test.c b/test/core/surface/init_test.c index c8791965bf..d4451e4567 100644 --- a/test/core/surface/init_test.c +++ b/test/core/surface/init_test.c @@ -47,7 +47,7 @@ static void test(int rounds) { } } -static void test_mixed() { +static void test_mixed(void) { grpc_init(); grpc_init(); grpc_shutdown(); @@ -56,8 +56,8 @@ static void test_mixed() { grpc_shutdown(); } -static void plugin_init() { g_flag = 1; } -static void plugin_destroy() { g_flag = 2; } +static void plugin_init(void) { g_flag = 1; } +static void plugin_destroy(void) { g_flag = 2; } static void test_plugin() { grpc_register_plugin(plugin_init, plugin_destroy); |