diff options
author | Craig Tiller <ctiller@google.com> | 2015-09-11 13:33:26 -0700 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-09-11 13:33:26 -0700 |
commit | 1701b093339fc124bd9c7f08eb7d8511799281ec (patch) | |
tree | 5fba7871d124fb784a87df8850daff146b48a9ae /test/core/iomgr | |
parent | 8664ca6463e8387b711f32fe283e0115e79c4c54 (diff) | |
parent | 35fea62432d7a41b5b3bc96d9af7975310553fe7 (diff) |
Merge github.com:grpc/grpc into shindig
Diffstat (limited to 'test/core/iomgr')
-rw-r--r-- | test/core/iomgr/alarm_heap_test.c | 65 | ||||
-rw-r--r-- | test/core/iomgr/endpoint_tests.c | 6 | ||||
-rw-r--r-- | test/core/iomgr/fd_posix_test.c | 5 | ||||
-rw-r--r-- | test/core/iomgr/tcp_posix_test.c | 46 | ||||
-rw-r--r-- | test/core/iomgr/udp_server_test.c | 4 |
5 files changed, 65 insertions, 61 deletions
diff --git a/test/core/iomgr/alarm_heap_test.c b/test/core/iomgr/alarm_heap_test.c index 66b6e4cb64..13bf7e43f6 100644 --- a/test/core/iomgr/alarm_heap_test.c +++ b/test/core/iomgr/alarm_heap_test.c @@ -48,9 +48,9 @@ static gpr_timespec random_deadline(void) { return ts; } -static grpc_alarm *create_test_elements(int num_elements) { +static grpc_alarm *create_test_elements(size_t num_elements) { grpc_alarm *elems = gpr_malloc(num_elements * sizeof(grpc_alarm)); - int i; + size_t i; for (i = 0; i < num_elements; i++) { elems[i].deadline = random_deadline(); } @@ -63,24 +63,25 @@ static int cmp_elem(const void *a, const void *b) { return i - j; } -static int *all_top(grpc_alarm_heap *pq, int *n) { - int *vec = NULL; - int *need_to_check_children; - int num_need_to_check_children = 0; +static size_t *all_top(grpc_alarm_heap *pq, size_t *n) { + size_t *vec = NULL; + size_t *need_to_check_children; + size_t num_need_to_check_children = 0; *n = 0; if (pq->alarm_count == 0) return vec; - need_to_check_children = gpr_malloc(pq->alarm_count * sizeof(int)); + need_to_check_children = + gpr_malloc(pq->alarm_count * sizeof(*need_to_check_children)); need_to_check_children[num_need_to_check_children++] = 0; - vec = gpr_malloc(pq->alarm_count * sizeof(int)); + vec = gpr_malloc(pq->alarm_count * sizeof(*vec)); while (num_need_to_check_children > 0) { - int ind = need_to_check_children[0]; - int leftchild, rightchild; + size_t ind = need_to_check_children[0]; + size_t leftchild, rightchild; num_need_to_check_children--; memmove(need_to_check_children, need_to_check_children + 1, - num_need_to_check_children * sizeof(int)); + num_need_to_check_children * sizeof(*need_to_check_children)); vec[(*n)++] = ind; - leftchild = 1 + 2 * ind; + leftchild = 1u + 2u * ind; if (leftchild < pq->alarm_count) { if (gpr_time_cmp(pq->alarms[leftchild]->deadline, pq->alarms[ind]->deadline) >= 0) { @@ -101,13 +102,14 @@ static int *all_top(grpc_alarm_heap *pq, int *n) { } static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq, - gpr_uint8 *inpq, int num_elements) { + gpr_uint8 *inpq, size_t num_elements) { gpr_timespec max_deadline = gpr_inf_past(GPR_CLOCK_REALTIME); - int *max_deadline_indices = gpr_malloc(num_elements * sizeof(int)); - int *top_elements; - int num_max_deadline_indices = 0; - int num_top_elements; - int i; + size_t *max_deadline_indices = + gpr_malloc(num_elements * sizeof(*max_deadline_indices)); + size_t *top_elements; + size_t num_max_deadline_indices = 0; + size_t num_top_elements; + size_t i; for (i = 0; i < num_elements; ++i) { if (inpq[i] && gpr_time_cmp(elements[i].deadline, max_deadline) >= 0) { if (gpr_time_cmp(elements[i].deadline, max_deadline) > 0) { @@ -117,7 +119,8 @@ static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq, max_deadline_indices[num_max_deadline_indices++] = elements[i].heap_index; } } - qsort(max_deadline_indices, num_max_deadline_indices, sizeof(int), cmp_elem); + qsort(max_deadline_indices, num_max_deadline_indices, + sizeof(*max_deadline_indices), cmp_elem); top_elements = all_top(pq, &num_top_elements); GPR_ASSERT(num_top_elements == num_max_deadline_indices); for (i = 0; i < num_top_elements; i++) { @@ -128,7 +131,7 @@ static void check_pq_top(grpc_alarm *elements, grpc_alarm_heap *pq, } static int contains(grpc_alarm_heap *pq, grpc_alarm *el) { - int i; + size_t i; for (i = 0; i < pq->alarm_count; i++) { if (pq->alarms[i] == el) return 1; } @@ -136,10 +139,10 @@ static int contains(grpc_alarm_heap *pq, grpc_alarm *el) { } static void check_valid(grpc_alarm_heap *pq) { - int i; + size_t i; for (i = 0; i < pq->alarm_count; ++i) { - int left_child = 1 + 2 * i; - int right_child = left_child + 1; + size_t left_child = 1u + 2u * i; + size_t right_child = left_child + 1u; if (left_child < pq->alarm_count) { GPR_ASSERT(gpr_time_cmp(pq->alarms[i]->deadline, pq->alarms[left_child]->deadline) >= 0); @@ -153,9 +156,9 @@ static void check_valid(grpc_alarm_heap *pq) { static void test1(void) { grpc_alarm_heap pq; - const int num_test_elements = 200; - const int num_test_operations = 10000; - int i; + const size_t num_test_elements = 200; + const size_t num_test_operations = 10000; + size_t i; grpc_alarm *test_elements = create_test_elements(num_test_elements); gpr_uint8 *inpq = gpr_malloc(num_test_elements); @@ -182,7 +185,7 @@ static void test1(void) { check_pq_top(test_elements, &pq, inpq, num_test_elements); for (i = 0; i < num_test_operations; ++i) { - int elem_num = rand() % num_test_elements; + size_t elem_num = (size_t)rand() % num_test_elements; grpc_alarm *el = &test_elements[elem_num]; if (!inpq[elem_num]) { /* not in pq */ GPR_ASSERT(!contains(&pq, el)); @@ -209,11 +212,11 @@ static void test1(void) { static void shrink_test(void) { grpc_alarm_heap pq; - int i; - int expected_size; + size_t i; + size_t expected_size; /* A large random number to allow for multiple shrinkages, at least 512. */ - const int num_elements = rand() % 2000 + 512; + const size_t num_elements = (size_t)rand() % 2000 + 512; grpc_alarm_heap_init(&pq); @@ -243,7 +246,7 @@ static void shrink_test(void) { 4 times the Size and not less than 2 times, but never goes below 16. */ expected_size = pq.alarm_count; while (pq.alarm_count > 0) { - const int which = rand() % pq.alarm_count; + const size_t which = (size_t)rand() % pq.alarm_count; grpc_alarm *te = pq.alarms[which]; grpc_alarm_heap_remove(&pq, te); gpr_free(te); diff --git a/test/core/iomgr/endpoint_tests.c b/test/core/iomgr/endpoint_tests.c index 27123eb216..853b9a32c2 100644 --- a/test/core/iomgr/endpoint_tests.c +++ b/test/core/iomgr/endpoint_tests.c @@ -86,7 +86,7 @@ static grpc_endpoint_test_fixture begin_test(grpc_endpoint_test_config config, static void end_test(grpc_endpoint_test_config config) { config.clean_up(); } static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, - size_t *num_blocks, int *current_data) { + size_t *num_blocks, gpr_uint8 *current_data) { size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0); gpr_slice *slices = malloc(sizeof(gpr_slice) * nslices); size_t num_bytes_left = num_bytes; @@ -102,7 +102,7 @@ static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, buf = GPR_SLICE_START_PTR(slices[i]); for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) { buf[j] = *current_data; - *current_data = (*current_data + 1) % 256; + (*current_data)++; } } GPR_ASSERT(num_bytes_left == 0); @@ -117,7 +117,7 @@ struct read_and_write_test_state { size_t current_write_size; size_t bytes_written; int current_read_data; - int current_write_data; + gpr_uint8 current_write_data; int read_done; int write_done; gpr_slice_buffer incoming; diff --git a/test/core/iomgr/fd_posix_test.c b/test/core/iomgr/fd_posix_test.c index 8bba87d61f..75959069c0 100644 --- a/test/core/iomgr/fd_posix_test.c +++ b/test/core/iomgr/fd_posix_test.c @@ -83,7 +83,8 @@ static void create_test_socket(int port, int *socket_fd, /* Use local address for test */ sin->sin_family = AF_INET; sin->sin_addr.s_addr = htonl(0x7f000001); - sin->sin_port = htons(port); + GPR_ASSERT(port >= 0 && port < 65536); + sin->sin_port = htons((gpr_uint16)port); } /* Dummy gRPC callback */ @@ -419,7 +420,7 @@ static void test_grpc_fd_change(void) { int flags; int sv[2]; char data; - int result; + ssize_t result; grpc_iomgr_closure first_closure; grpc_iomgr_closure second_closure; diff --git a/test/core/iomgr/tcp_posix_test.c b/test/core/iomgr/tcp_posix_test.c index 8acaa433bb..59c498edff 100644 --- a/test/core/iomgr/tcp_posix_test.c +++ b/test/core/iomgr/tcp_posix_test.c @@ -81,7 +81,7 @@ static ssize_t fill_socket(int fd) { int i; unsigned char buf[256]; for (i = 0; i < 256; ++i) { - buf[i] = i; + buf[i] = (gpr_uint8)i; } do { write_bytes = write(fd, buf, 256); @@ -99,13 +99,13 @@ static size_t fill_socket_partial(int fd, size_t bytes) { unsigned char *buf = malloc(bytes); unsigned i; for (i = 0; i < bytes; ++i) { - buf[i] = i % 256; + buf[i] = (gpr_uint8)(i % 256); } do { write_bytes = write(fd, buf, bytes - total_bytes); if (write_bytes > 0) { - total_bytes += write_bytes; + total_bytes += (size_t)write_bytes; } } while ((write_bytes >= 0 || errno == EINTR) && bytes > total_bytes); @@ -116,15 +116,15 @@ static size_t fill_socket_partial(int fd, size_t bytes) { struct read_socket_state { grpc_endpoint *ep; - ssize_t read_bytes; - ssize_t target_read_bytes; + size_t read_bytes; + size_t target_read_bytes; gpr_slice_buffer incoming; grpc_iomgr_closure read_cb; }; -static ssize_t count_slices(gpr_slice *slices, size_t nslices, - int *current_data) { - ssize_t num_bytes = 0; +static size_t count_slices(gpr_slice *slices, size_t nslices, + int *current_data) { + size_t num_bytes = 0; unsigned i, j; unsigned char *buf; for (i = 0; i < nslices; ++i) { @@ -140,7 +140,7 @@ static ssize_t count_slices(gpr_slice *slices, size_t nslices, static void read_cb(void *user_data, int success) { struct read_socket_state *state = (struct read_socket_state *)user_data; - ssize_t read_bytes; + size_t read_bytes; int current_data; GPR_ASSERT(success); @@ -172,11 +172,11 @@ static void read_cb(void *user_data, int success) { } /* Write to a socket, then read from it using the grpc_tcp API. */ -static void read_test(ssize_t num_bytes, ssize_t slice_size) { +static void read_test(size_t num_bytes, size_t slice_size) { int sv[2]; grpc_endpoint *ep; struct read_socket_state state; - ssize_t written_bytes; + size_t written_bytes; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); gpr_log(GPR_INFO, "Read test of size %d, slice size %d", num_bytes, @@ -222,7 +222,7 @@ static void read_test(ssize_t num_bytes, ssize_t slice_size) { /* Write to a socket until it fills up, then read from it using the grpc_tcp API. */ -static void large_read_test(ssize_t slice_size) { +static void large_read_test(size_t slice_size) { int sv[2]; grpc_endpoint *ep; struct read_socket_state state; @@ -242,7 +242,7 @@ static void large_read_test(ssize_t slice_size) { state.ep = ep; state.read_bytes = 0; - state.target_read_bytes = written_bytes; + state.target_read_bytes = (size_t)written_bytes; gpr_slice_buffer_init(&state.incoming); grpc_iomgr_closure_init(&state.read_cb, read_cb, &state); @@ -275,11 +275,11 @@ struct write_socket_state { int write_done; }; -static gpr_slice *allocate_blocks(ssize_t num_bytes, ssize_t slice_size, - size_t *num_blocks, int *current_data) { - size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1 : 0); +static gpr_slice *allocate_blocks(size_t num_bytes, size_t slice_size, + size_t *num_blocks, gpr_uint8 *current_data) { + size_t nslices = num_bytes / slice_size + (num_bytes % slice_size ? 1u : 0u); gpr_slice *slices = gpr_malloc(sizeof(gpr_slice) * nslices); - ssize_t num_bytes_left = num_bytes; + size_t num_bytes_left = num_bytes; unsigned i, j; unsigned char *buf; *num_blocks = nslices; @@ -291,7 +291,7 @@ static gpr_slice *allocate_blocks(ssize_t num_bytes, ssize_t slice_size, buf = GPR_SLICE_START_PTR(slices[i]); for (j = 0; j < GPR_SLICE_LENGTH(slices[i]); ++j) { buf[j] = *current_data; - *current_data = (*current_data + 1) % 256; + (*current_data)++; } } GPR_ASSERT(num_bytes_left == 0); @@ -334,7 +334,7 @@ void drain_socket_blocking(int fd, size_t num_bytes, size_t read_size) { GPR_ASSERT(buf[i] == current); current = (current + 1) % 256; } - bytes_left -= bytes_read; + bytes_left -= (size_t)bytes_read; if (bytes_left == 0) break; } flags = fcntl(fd, F_GETFL, 0); @@ -366,14 +366,14 @@ static ssize_t drain_socket(int fd) { /* Write to a socket using the grpc_tcp API, then drain it directly. Note that if the write does not complete immediately we need to drain the socket in parallel with the read. */ -static void write_test(ssize_t num_bytes, ssize_t slice_size) { +static void write_test(size_t num_bytes, size_t slice_size) { int sv[2]; grpc_endpoint *ep; struct write_socket_state state; ssize_t read_bytes; size_t num_blocks; gpr_slice *slices; - int current_data = 0; + gpr_uint8 current_data = 0; gpr_slice_buffer outgoing; grpc_iomgr_closure write_done_closure; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20); @@ -400,7 +400,7 @@ static void write_test(ssize_t num_bytes, ssize_t slice_size) { case GRPC_ENDPOINT_DONE: /* Write completed immediately */ read_bytes = drain_socket(sv[0]); - GPR_ASSERT(read_bytes == num_bytes); + GPR_ASSERT((size_t)read_bytes == num_bytes); break; case GRPC_ENDPOINT_PENDING: drain_socket_blocking(sv[0], num_bytes, num_bytes); @@ -426,7 +426,7 @@ static void write_test(ssize_t num_bytes, ssize_t slice_size) { } void run_tests(void) { - int i = 0; + size_t i = 0; read_test(100, 8192); read_test(10000, 8192); diff --git a/test/core/iomgr/udp_server_test.c b/test/core/iomgr/udp_server_test.c index c91752b937..c4f1896ba6 100644 --- a/test/core/iomgr/udp_server_test.c +++ b/test/core/iomgr/udp_server_test.c @@ -53,13 +53,13 @@ static void on_connect(void *arg, grpc_endpoint *udp) {} static void on_read(int fd, grpc_udp_server_cb new_transport_cb, void *cb_arg) { char read_buffer[512]; - int byte_count; + ssize_t byte_count; gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset)); byte_count = recv(fd, read_buffer, sizeof(read_buffer), 0); g_number_of_reads++; - g_number_of_bytes_read += byte_count; + g_number_of_bytes_read += (int)byte_count; grpc_pollset_kick(&g_pollset, NULL); gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset)); |