aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/core/bad_client/tests/simple_request.c30
-rw-r--r--test/core/compression/algorithm_test.c104
-rw-r--r--test/core/compression/compression_test.c72
-rw-r--r--test/core/compression/message_compress_test.c76
-rw-r--r--test/core/iomgr/sockaddr_utils_test.c24
-rw-r--r--test/core/iomgr/socket_utils_test.c62
-rw-r--r--test/core/iomgr/tcp_client_posix_test.c5
-rw-r--r--test/core/iomgr/workqueue_test.c36
-rw-r--r--test/core/support/sync_test.c2
-rw-r--r--test/core/support/thd_test.c14
-rw-r--r--test/core/support/time_test.c4
-rw-r--r--test/core/surface/lame_client_test.c38
-rw-r--r--test/core/surface/server_test.c68
13 files changed, 521 insertions, 14 deletions
diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c
index 5cddafc0b5..b3cd556421 100644
--- a/test/core/bad_client/tests/simple_request.c
+++ b/test/core/bad_client/tests/simple_request.c
@@ -99,6 +99,14 @@ static void verifier(grpc_server *server, grpc_completion_queue *cq) {
cq_verifier_destroy(cqv);
}
+static void failure_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);
@@ -115,6 +123,28 @@ int main(int argc, char **argv) {
/* push a data frame with bad flags */
GRPC_RUN_BAD_CLIENT_TEST(verifier,
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,
+ 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,
+ 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,
+ 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,
+ PFX_STR "\x00\x00\x04\x07\x00\x00\x00\x00\x00", 0);
+ /* disconnect before sending goaway */
+ GRPC_RUN_BAD_CLIENT_TEST(failure_verifier,
+ 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,
+ 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,
+ PFX_STR "\x00\x00\x00\x03\x10\x00\x00\x00\x01", 0);
return 0;
}
diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c
new file mode 100644
index 0000000000..7de7e11a94
--- /dev/null
+++ b/test/core/compression/algorithm_test.c
@@ -0,0 +1,104 @@
+/*
+ *
+ * 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 "src/core/compression/algorithm_metadata.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include <grpc/support/useful.h>
+
+#include "src/core/transport/static_metadata.h"
+#include "test/core/util/test_config.h"
+
+static void test_algorithm_mesh(void) {
+ int i;
+
+ gpr_log(GPR_DEBUG, "test_algorithm_mesh");
+
+ for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
+ char *name;
+ grpc_compression_algorithm parsed;
+ grpc_mdstr *mdstr;
+ grpc_mdelem *mdelem;
+ GPR_ASSERT(
+ grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name));
+ GPR_ASSERT(grpc_compression_algorithm_parse(name, strlen(name), &parsed));
+ GPR_ASSERT((int)parsed == i);
+ mdstr = grpc_mdstr_from_string(name);
+ GPR_ASSERT(mdstr == grpc_compression_algorithm_mdstr(parsed));
+ GPR_ASSERT(parsed == grpc_compression_algorithm_from_mdstr(mdstr));
+ mdelem = grpc_compression_encoding_mdelem(parsed);
+ GPR_ASSERT(mdelem->value == mdstr);
+ GPR_ASSERT(mdelem->key == GRPC_MDSTR_GRPC_ENCODING);
+ GRPC_MDSTR_UNREF(mdstr);
+ GRPC_MDELEM_UNREF(mdelem);
+ }
+
+ /* test failure */
+ GPR_ASSERT(NULL ==
+ grpc_compression_encoding_mdelem(GRPC_COMPRESS_ALGORITHMS_COUNT));
+}
+
+static void test_algorithm_failure(void) {
+ grpc_mdstr *mdstr;
+
+ gpr_log(GPR_DEBUG, "test_algorithm_failure");
+
+ GPR_ASSERT(grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT,
+ NULL) == 0);
+ GPR_ASSERT(grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT + 1,
+ NULL) == 0);
+ mdstr = grpc_mdstr_from_string("this-is-an-invalid-algorithm");
+ GPR_ASSERT(grpc_compression_algorithm_from_mdstr(mdstr) ==
+ GRPC_COMPRESS_ALGORITHMS_COUNT);
+ GPR_ASSERT(grpc_compression_algorithm_mdstr(GRPC_COMPRESS_ALGORITHMS_COUNT) ==
+ NULL);
+ GPR_ASSERT(grpc_compression_algorithm_mdstr(GRPC_COMPRESS_ALGORITHMS_COUNT +
+ 1) == NULL);
+ GRPC_MDSTR_UNREF(mdstr);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+
+ test_algorithm_mesh();
+ test_algorithm_failure();
+
+ grpc_shutdown();
+
+ return 0;
+}
diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c
index 35fadc00c0..78266357c4 100644
--- a/test/core/compression/compression_test.c
+++ b/test/core/compression/compression_test.c
@@ -53,9 +53,8 @@ static void test_compression_algorithm_parse(void) {
for (i = 0; i < GPR_ARRAY_SIZE(valid_names); i++) {
const char *valid_name = valid_names[i];
grpc_compression_algorithm algorithm;
- int success;
- success = grpc_compression_algorithm_parse(valid_name, strlen(valid_name),
- &algorithm);
+ const int success = grpc_compression_algorithm_parse(
+ valid_name, strlen(valid_name), &algorithm);
GPR_ASSERT(success != 0);
GPR_ASSERT(algorithm == valid_algorithms[i]);
}
@@ -71,9 +70,76 @@ static void test_compression_algorithm_parse(void) {
}
}
+static void test_compression_algorithm_name(void) {
+ int success;
+ char *name;
+ size_t i;
+ const char *valid_names[] = {"identity", "gzip", "deflate"};
+ const grpc_compression_algorithm valid_algorithms[] = {
+ GRPC_COMPRESS_NONE, GRPC_COMPRESS_GZIP, GRPC_COMPRESS_DEFLATE};
+
+ gpr_log(GPR_DEBUG, "test_compression_algorithm_name");
+
+ for (i = 0; i < GPR_ARRAY_SIZE(valid_algorithms); i++) {
+ success = grpc_compression_algorithm_name(valid_algorithms[i], &name);
+ GPR_ASSERT(success != 0);
+ GPR_ASSERT(strcmp(name, valid_names[i]) == 0);
+ }
+
+ success =
+ grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT, &name);
+ GPR_ASSERT(success == 0);
+ /* the value of "name" is undefined upon failure */
+}
+
+
+static void test_compression_algorithm_for_level(void) {
+ size_t i;
+ grpc_compression_level levels[] = {
+ GRPC_COMPRESS_LEVEL_NONE, GRPC_COMPRESS_LEVEL_LOW,
+ GRPC_COMPRESS_LEVEL_MED, GRPC_COMPRESS_LEVEL_HIGH};
+ grpc_compression_algorithm algorithms[] = {GRPC_COMPRESS_NONE,
+ GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_DEFLATE, GRPC_COMPRESS_DEFLATE};
+ gpr_log(GPR_DEBUG, "test_compression_algorithm_for_level");
+
+ for (i = 0; i < GPR_ARRAY_SIZE(levels); i++) {
+ GPR_ASSERT(algorithms[i] ==
+ grpc_compression_algorithm_for_level(levels[i]));
+ }
+}
+
+static void test_compression_enable_disable_algorithm(void) {
+ grpc_compression_options options;
+ grpc_compression_algorithm algorithm;
+
+ gpr_log(GPR_DEBUG, "test_compression_enable_disable_algorithm");
+
+ grpc_compression_options_init(&options);
+ for (algorithm = GRPC_COMPRESS_NONE; algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
+ /* all algorithms are enabled by default */
+ GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options,
+ algorithm) != 0);
+ }
+ /* disable one by one */
+ for (algorithm = GRPC_COMPRESS_NONE; algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
+ grpc_compression_options_disable_algorithm(&options, algorithm);
+ GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options,
+ algorithm) == 0);
+ }
+ /* re-enable one by one */
+ for (algorithm = GRPC_COMPRESS_NONE; algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT; algorithm++) {
+ grpc_compression_options_enable_algorithm(&options, algorithm);
+ GPR_ASSERT(grpc_compression_options_is_algorithm_enabled(&options,
+ algorithm) != 0);
+ }
+}
+
int main(int argc, char **argv) {
grpc_init();
test_compression_algorithm_parse();
+ test_compression_algorithm_name();
+ test_compression_algorithm_for_level();
+ test_compression_enable_disable_algorithm();
grpc_shutdown();
return 0;
diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c
index 70359a3f69..bd454099ce 100644
--- a/test/core/compression/message_compress_test.c
+++ b/test/core/compression/message_compress_test.c
@@ -148,26 +148,87 @@ static gpr_slice create_test_value(test_value id) {
return gpr_slice_from_copied_string("bad value");
}
-static void test_bad_data(void) {
+static void test_tiny_data_compress(void) {
gpr_slice_buffer input;
gpr_slice_buffer output;
grpc_compression_algorithm i;
gpr_slice_buffer_init(&input);
gpr_slice_buffer_init(&output);
- gpr_slice_buffer_add(&input, gpr_slice_from_copied_string(
- "this is not valid compressed input"));
+ gpr_slice_buffer_add(&input, create_test_value(ONE_A));
for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) {
if (i == GRPC_COMPRESS_NONE) continue;
- GPR_ASSERT(0 == grpc_msg_decompress(i, &input, &output));
- GPR_ASSERT(0 == output.count);
+ GPR_ASSERT(0 == grpc_msg_compress(i, &input, &output));
+ GPR_ASSERT(1 == output.count);
}
gpr_slice_buffer_destroy(&input);
gpr_slice_buffer_destroy(&output);
}
+static void test_bad_decompression_data_crc(void) {
+ gpr_slice_buffer input;
+ gpr_slice_buffer corrupted;
+ gpr_slice_buffer output;
+ size_t idx;
+ const gpr_uint32 bad = 0xdeadbeef;
+
+ gpr_slice_buffer_init(&input);
+ gpr_slice_buffer_init(&corrupted);
+ gpr_slice_buffer_init(&output);
+ gpr_slice_buffer_add(&input, create_test_value(ONE_MB_A));
+
+ /* compress it */
+ grpc_msg_compress(GRPC_COMPRESS_GZIP, &input, &corrupted);
+ /* corrupt the output by smashing the CRC */
+ GPR_ASSERT(corrupted.count > 1);
+ GPR_ASSERT(GPR_SLICE_LENGTH(corrupted.slices[1]) > 8);
+ idx = GPR_SLICE_LENGTH(corrupted.slices[1]) - 8;
+ memcpy(GPR_SLICE_START_PTR(corrupted.slices[1]) + idx, &bad, 4);
+
+ /* try (and fail) to decompress the corrupted compresed buffer */
+ GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_GZIP, &corrupted, &output));
+
+ gpr_slice_buffer_destroy(&input);
+ gpr_slice_buffer_destroy(&corrupted);
+ gpr_slice_buffer_destroy(&output);
+}
+
+static void test_bad_decompression_data_trailing_garbage(void) {
+ gpr_slice_buffer input;
+ gpr_slice_buffer output;
+
+ gpr_slice_buffer_init(&input);
+ gpr_slice_buffer_init(&output);
+ /* append 0x99 to the end of an otherwise valid stream */
+ gpr_slice_buffer_add(
+ &input, gpr_slice_from_copied_buffer(
+ "\x78\xda\x63\x60\x60\x60\x00\x00\x00\x04\x00\x01\x99", 13));
+
+ /* try (and fail) to decompress the invalid compresed buffer */
+ GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output));
+
+ gpr_slice_buffer_destroy(&input);
+ gpr_slice_buffer_destroy(&output);
+}
+
+static void test_bad_decompression_data_stream(void) {
+ gpr_slice_buffer input;
+ gpr_slice_buffer output;
+
+ gpr_slice_buffer_init(&input);
+ gpr_slice_buffer_init(&output);
+ gpr_slice_buffer_add(&input,
+ gpr_slice_from_copied_buffer("\x78\xda\xff\xff", 4));
+
+ /* try (and fail) to decompress the invalid compresed buffer */
+ GPR_ASSERT(0 == grpc_msg_decompress(GRPC_COMPRESS_DEFLATE, &input, &output));
+
+ gpr_slice_buffer_destroy(&input);
+ gpr_slice_buffer_destroy(&output);
+}
+
static void test_bad_compression_algorithm(void) {
gpr_slice_buffer input;
gpr_slice_buffer output;
@@ -234,7 +295,10 @@ int main(int argc, char **argv) {
}
}
- test_bad_data();
+ test_tiny_data_compress();
+ test_bad_decompression_data_crc();
+ test_bad_decompression_data_stream();
+ test_bad_decompression_data_trailing_garbage();
test_bad_compression_algorithm();
test_bad_decompression_algorithm();
grpc_shutdown();
diff --git a/test/core/iomgr/sockaddr_utils_test.c b/test/core/iomgr/sockaddr_utils_test.c
index 5009a641ea..2596095bc9 100644
--- a/test/core/iomgr/sockaddr_utils_test.c
+++ b/test/core/iomgr/sockaddr_utils_test.c
@@ -236,6 +236,29 @@ static void test_sockaddr_to_string(void) {
GPR_ASSERT(errno == 0x7EADBEEF);
}
+static void test_sockaddr_set_get_port(void) {
+ struct sockaddr_in input4;
+ struct sockaddr_in6 input6;
+ struct sockaddr dummy;
+
+ gpr_log(GPR_DEBUG, "test_sockaddr_set_get_port");
+
+ input4 = make_addr4(kIPv4, sizeof(kIPv4));
+ GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input4) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr*)&input4, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input4) == 54321);
+
+ input6 = make_addr6(kIPv6, sizeof(kIPv6));
+ GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input6) == 12345);
+ GPR_ASSERT(grpc_sockaddr_set_port((struct sockaddr*)&input6, 54321));
+ GPR_ASSERT(grpc_sockaddr_get_port((struct sockaddr*)&input6) == 54321);
+
+ memset(&dummy, 0, sizeof(dummy));
+ dummy.sa_family = 123;
+ GPR_ASSERT(grpc_sockaddr_get_port(&dummy) == 0);
+ GPR_ASSERT(grpc_sockaddr_set_port(&dummy, 1234) == 0);
+}
+
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
@@ -243,6 +266,7 @@ int main(int argc, char **argv) {
test_sockaddr_to_v4mapped();
test_sockaddr_is_wildcard();
test_sockaddr_to_string();
+ test_sockaddr_set_get_port();
return 0;
}
diff --git a/test/core/iomgr/socket_utils_test.c b/test/core/iomgr/socket_utils_test.c
new file mode 100644
index 0000000000..58c3fbc0ae
--- /dev/null
+++ b/test/core/iomgr/socket_utils_test.c
@@ -0,0 +1,62 @@
+/*
+ *
+ * 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 <grpc/support/port_platform.h>
+#include "src/core/iomgr/socket_utils_posix.h"
+
+#include <errno.h>
+#include <string.h>
+
+#include <grpc/support/log.h>
+#include "test/core/util/test_config.h"
+
+int main(int argc, char **argv) {
+ int sock;
+ grpc_test_init(argc, argv);
+
+ sock = socket(PF_INET, SOCK_STREAM, 0);
+ GPR_ASSERT(sock > 0);
+
+ GPR_ASSERT(grpc_set_socket_nonblocking(sock, 1));
+ GPR_ASSERT(grpc_set_socket_nonblocking(sock, 0));
+ GPR_ASSERT(grpc_set_socket_cloexec(sock, 1));
+ GPR_ASSERT(grpc_set_socket_cloexec(sock, 0));
+ GPR_ASSERT(grpc_set_socket_reuse_addr(sock, 1));
+ GPR_ASSERT(grpc_set_socket_reuse_addr(sock, 0));
+ GPR_ASSERT(grpc_set_socket_low_latency(sock, 1));
+ GPR_ASSERT(grpc_set_socket_low_latency(sock, 0));
+
+ close(sock);
+
+ return 0;
+}
diff --git a/test/core/iomgr/tcp_client_posix_test.c b/test/core/iomgr/tcp_client_posix_test.c
index a61cccdb02..833ceace54 100644
--- a/test/core/iomgr/tcp_client_posix_test.c
+++ b/test/core/iomgr/tcp_client_posix_test.c
@@ -234,8 +234,9 @@ void test_times_out(void) {
if (gpr_time_cmp(now, finish_time) > 0) {
break;
}
- gpr_log(GPR_DEBUG, "now=%d.%09d connect_deadline=%d.%09d", now.tv_sec,
- now.tv_nsec, connect_deadline.tv_sec, connect_deadline.tv_nsec);
+ gpr_log(GPR_DEBUG, "now=%lld.%09d connect_deadline=%lld.%09d",
+ (long long)now.tv_sec, (int)now.tv_nsec,
+ (long long)connect_deadline.tv_sec, (int)connect_deadline.tv_nsec);
if (is_after_deadline && gpr_time_cmp(now, restart_verifying_time) <= 0) {
/* allow some slack before insisting that things be done */
} else {
diff --git a/test/core/iomgr/workqueue_test.c b/test/core/iomgr/workqueue_test.c
index 90f7ba7a83..d1f9dabc57 100644
--- a/test/core/iomgr/workqueue_test.c
+++ b/test/core/iomgr/workqueue_test.c
@@ -48,6 +48,15 @@ static void must_succeed(grpc_exec_ctx *exec_ctx, void *p, int success) {
gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
}
+static void test_ref_unref(void) {
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx);
+ GRPC_WORKQUEUE_REF(wq, "test");
+ GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "test");
+ GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "destroy");
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
static void test_add_closure(void) {
grpc_closure c;
int done = 0;
@@ -72,6 +81,31 @@ static void test_add_closure(void) {
grpc_exec_ctx_finish(&exec_ctx);
}
+static void test_flush(void) {
+ grpc_closure c;
+ int done = 0;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_workqueue *wq = grpc_workqueue_create(&exec_ctx);
+ gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5);
+ grpc_pollset_worker worker;
+ grpc_closure_init(&c, must_succeed, &done);
+
+ grpc_exec_ctx_enqueue(&exec_ctx, &c, 1);
+ grpc_workqueue_flush(&exec_ctx, wq);
+ grpc_workqueue_add_to_pollset(&exec_ctx, wq, &g_pollset);
+
+ gpr_mu_lock(GRPC_POLLSET_MU(&g_pollset));
+ GPR_ASSERT(!done);
+ grpc_pollset_work(&exec_ctx, &g_pollset, &worker,
+ gpr_now(deadline.clock_type), deadline);
+ gpr_mu_unlock(GRPC_POLLSET_MU(&g_pollset));
+ grpc_exec_ctx_finish(&exec_ctx);
+ GPR_ASSERT(done);
+
+ GRPC_WORKQUEUE_UNREF(&exec_ctx, wq, "destroy");
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
static void destroy_pollset(grpc_exec_ctx *exec_ctx, void *p, int success) {
grpc_pollset_destroy(p);
}
@@ -83,7 +117,9 @@ int main(int argc, char **argv) {
grpc_init();
grpc_pollset_init(&g_pollset);
+ test_ref_unref();
test_add_closure();
+ test_flush();
grpc_closure_init(&destroyed, destroy_pollset, &g_pollset);
grpc_pollset_shutdown(&exec_ctx, &g_pollset, &destroyed);
diff --git a/test/core/support/sync_test.c b/test/core/support/sync_test.c
index 6bc5f792e5..e538af93f2 100644
--- a/test/core/support/sync_test.c
+++ b/test/core/support/sync_test.c
@@ -272,7 +272,7 @@ static void test(const char *name, void (*body)(void *m),
test_destroy(m);
}
time_taken = gpr_time_sub(gpr_now(GPR_CLOCK_REALTIME), start);
- fprintf(stderr, " done %ld.%09d s\n", (long)time_taken.tv_sec,
+ fprintf(stderr, " done %lld.%09d s\n", (long long)time_taken.tv_sec,
(int)time_taken.tv_nsec);
}
diff --git a/test/core/support/thd_test.c b/test/core/support/thd_test.c
index faba33c5e8..f7807d280a 100644
--- a/test/core/support/thd_test.c
+++ b/test/core/support/thd_test.c
@@ -62,6 +62,19 @@ static void thd_body(void *v) {
static void thd_body_joinable(void *v) {}
+/* Test thread options work as expected */
+static void test_options(void) {
+ gpr_thd_options options = gpr_thd_options_default();
+ GPR_ASSERT(!gpr_thd_options_is_joinable(&options));
+ GPR_ASSERT(gpr_thd_options_is_detached(&options));
+ gpr_thd_options_set_joinable(&options);
+ GPR_ASSERT(gpr_thd_options_is_joinable(&options));
+ GPR_ASSERT(!gpr_thd_options_is_detached(&options));
+ gpr_thd_options_set_detached(&options);
+ GPR_ASSERT(!gpr_thd_options_is_joinable(&options));
+ GPR_ASSERT(gpr_thd_options_is_detached(&options));
+}
+
/* Test that we can create a number of threads and wait for them. */
static void test(void) {
int i;
@@ -96,6 +109,7 @@ static void test(void) {
int main(int argc, char *argv[]) {
grpc_test_init(argc, argv);
+ test_options();
test();
return 0;
}
diff --git a/test/core/support/time_test.c b/test/core/support/time_test.c
index ce35edd83c..b921052e7b 100644
--- a/test/core/support/time_test.c
+++ b/test/core/support/time_test.c
@@ -98,7 +98,7 @@ static void test_values(void) {
fprintf(stderr, "far future ");
i_to_s(x.tv_sec, 16, 16, &to_fp, stderr);
fprintf(stderr, "\n");
- GPR_ASSERT(x.tv_sec >= INT_MAX);
+ GPR_ASSERT(x.tv_sec == INT64_MAX);
fprintf(stderr, "far future ");
ts_to_s(x, &to_fp, stderr);
fprintf(stderr, "\n");
@@ -107,7 +107,7 @@ static void test_values(void) {
fprintf(stderr, "far past ");
i_to_s(x.tv_sec, 16, 16, &to_fp, stderr);
fprintf(stderr, "\n");
- GPR_ASSERT(x.tv_sec <= INT_MIN);
+ GPR_ASSERT(x.tv_sec == INT64_MIN);
fprintf(stderr, "far past ");
ts_to_s(x, &to_fp, stderr);
fprintf(stderr, "\n");
diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c
index 971055e6fd..1b1955fa0e 100644
--- a/test/core/surface/lame_client_test.c
+++ b/test/core/surface/lame_client_test.c
@@ -36,11 +36,47 @@
#include <grpc/grpc.h>
#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
+#include "src/core/channel/channel_stack.h"
+#include "src/core/iomgr/closure.h"
+#include "src/core/surface/channel.h"
+#include "src/core/transport/transport.h"
#include "test/core/end2end/cq_verifier.h"
#include "test/core/util/test_config.h"
+grpc_closure transport_op_cb;
+
static void *tag(gpr_intptr x) { return (void *)x; }
+void verify_connectivity(grpc_exec_ctx *exec_ctx, void *arg, int success) {
+ grpc_transport_op* op = arg;
+ GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE == *op->connectivity_state);
+ GPR_ASSERT(success);
+}
+
+void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, int success) { }
+
+void test_transport_op(grpc_channel *channel) {
+ grpc_transport_op op;
+ grpc_channel_element *elem;
+ grpc_connectivity_state state = GRPC_CHANNEL_IDLE;
+ grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+
+ memset(&op, 0, sizeof(op));
+ grpc_closure_init(&transport_op_cb, verify_connectivity, &op);
+
+ op.on_connectivity_state_change = &transport_op_cb;
+ op.connectivity_state = &state;
+ elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
+ elem->filter->start_transport_op(&exec_ctx, elem, &op);
+ grpc_exec_ctx_finish(&exec_ctx);
+
+ memset(&op, 0, sizeof(op));
+ grpc_closure_init(&transport_op_cb, do_nothing, NULL);
+ op.on_consumed = &transport_op_cb;
+ elem->filter->start_transport_op(&exec_ctx, elem, &op);
+ grpc_exec_ctx_finish(&exec_ctx);
+}
+
int main(int argc, char **argv) {
grpc_channel *chan;
grpc_call *call;
@@ -66,6 +102,8 @@ int main(int argc, char **argv) {
"lampoon:national", GRPC_STATUS_UNKNOWN, "Rpc sent on a lame channel.");
GPR_ASSERT(chan);
+ test_transport_op(chan);
+
GPR_ASSERT(GRPC_CHANNEL_FATAL_FAILURE ==
grpc_channel_check_connectivity_state(chan, 0));
diff --git a/test/core/surface/server_test.c b/test/core/surface/server_test.c
new file mode 100644
index 0000000000..f180bcdaa1
--- /dev/null
+++ b/test/core/surface/server_test.c
@@ -0,0 +1,68 @@
+/*
+ *
+ * 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 <grpc/grpc.h>
+#include <grpc/support/log.h>
+#include "test/core/util/test_config.h"
+
+void test_register_method_fail(void) {
+ grpc_server *server = grpc_server_create(NULL, NULL);
+ void *method;
+ void *method_old;
+ method = grpc_server_register_method(server, NULL, NULL);
+ GPR_ASSERT(method == NULL);
+ method_old = grpc_server_register_method(server, "m", "h");
+ GPR_ASSERT(method_old != NULL);
+ method = grpc_server_register_method(server, "m", "h");
+ GPR_ASSERT(method == NULL);
+ grpc_server_destroy(server);
+}
+
+void test_request_call_on_no_server_cq(void) {
+ grpc_completion_queue *cc = grpc_completion_queue_create(NULL);
+ GPR_ASSERT(GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE ==
+ grpc_server_request_call(NULL, NULL, NULL, NULL, cc, cc, NULL));
+ GPR_ASSERT(GRPC_CALL_ERROR_NOT_SERVER_COMPLETION_QUEUE ==
+ grpc_server_request_registered_call(NULL, NULL, NULL, NULL, NULL,
+ NULL, cc, cc, NULL));
+ grpc_completion_queue_destroy(cc);
+}
+
+int main(int argc, char **argv) {
+ grpc_test_init(argc, argv);
+ grpc_init();
+ test_register_method_fail();
+ test_request_call_on_no_server_cq();
+ grpc_shutdown();
+ return 0;
+}