aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/core/transport
diff options
context:
space:
mode:
Diffstat (limited to 'test/core/transport')
-rw-r--r--test/core/transport/chttp2/bin_decoder_test.c144
-rw-r--r--test/core/transport/chttp2/bin_encoder_test.c3
-rw-r--r--test/core/transport/chttp2/hpack_parser_fuzzer_test.c7
-rw-r--r--test/core/transport/chttp2/hpack_parser_test.c3
-rw-r--r--test/core/transport/chttp2/hpack_table_test.c12
-rw-r--r--test/core/transport/connectivity_state_test.c29
-rw-r--r--test/core/transport/metadata_test.c5
7 files changed, 178 insertions, 25 deletions
diff --git a/test/core/transport/chttp2/bin_decoder_test.c b/test/core/transport/chttp2/bin_decoder_test.c
new file mode 100644
index 0000000000..c4e6cd332f
--- /dev/null
+++ b/test/core/transport/chttp2/bin_decoder_test.c
@@ -0,0 +1,144 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+#include "src/core/ext/transport/chttp2/transport/bin_decoder.h"
+
+#include <string.h>
+
+#include <grpc/support/alloc.h>
+#include <grpc/support/log.h>
+#include "src/core/ext/transport/chttp2/transport/bin_encoder.h"
+#include "src/core/lib/support/string.h"
+
+static int all_ok = 1;
+
+static void expect_slice_eq(gpr_slice expected, gpr_slice slice, char *debug,
+ int line) {
+ if (0 != gpr_slice_cmp(slice, expected)) {
+ char *hs = gpr_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
+ char *he = gpr_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII);
+ gpr_log(GPR_ERROR, "FAILED:%d: %s\ngot: %s\nwant: %s", line, debug, hs,
+ he);
+ gpr_free(hs);
+ gpr_free(he);
+ all_ok = 0;
+ }
+ gpr_slice_unref(expected);
+ gpr_slice_unref(slice);
+}
+
+static gpr_slice base64_encode(const char *s) {
+ gpr_slice ss = gpr_slice_from_copied_string(s);
+ gpr_slice out = grpc_chttp2_base64_encode(ss);
+ gpr_slice_unref(ss);
+ return out;
+}
+
+static gpr_slice base64_decode(const char *s) {
+ gpr_slice ss = gpr_slice_from_copied_string(s);
+ gpr_slice out = grpc_chttp2_base64_decode(ss);
+ gpr_slice_unref(ss);
+ return out;
+}
+
+static gpr_slice base64_decode_with_length(const char *s,
+ size_t output_length) {
+ gpr_slice ss = gpr_slice_from_copied_string(s);
+ gpr_slice out = grpc_chttp2_base64_decode_with_length(ss, output_length);
+ gpr_slice_unref(ss);
+ return out;
+}
+
+#define EXPECT_SLICE_EQ(expected, slice) \
+ expect_slice_eq( \
+ gpr_slice_from_copied_buffer(expected, sizeof(expected) - 1), slice, \
+ #slice, __LINE__);
+
+#define ENCODE_AND_DECODE(s) \
+ EXPECT_SLICE_EQ( \
+ s, grpc_chttp2_base64_decode_with_length(base64_encode(s), strlen(s)));
+
+int main(int argc, char **argv) {
+ /* ENCODE_AND_DECODE tests grpc_chttp2_base64_decode_with_length(), which
+ takes encoded base64 strings without pad chars, but output length is
+ required. */
+ /* Base64 test vectors from RFC 4648 */
+ ENCODE_AND_DECODE("");
+ ENCODE_AND_DECODE("f");
+ ENCODE_AND_DECODE("foo");
+ ENCODE_AND_DECODE("fo");
+ ENCODE_AND_DECODE("foob");
+ ENCODE_AND_DECODE("fooba");
+ ENCODE_AND_DECODE("foobar");
+
+ ENCODE_AND_DECODE("\xc0\xc1\xc2\xc3\xc4\xc5");
+
+ /* Base64 test vectors from RFC 4648, with pad chars */
+ /* BASE64("") = "" */
+ EXPECT_SLICE_EQ("", base64_decode(""));
+ /* BASE64("f") = "Zg==" */
+ EXPECT_SLICE_EQ("f", base64_decode("Zg=="));
+ /* BASE64("fo") = "Zm8=" */
+ EXPECT_SLICE_EQ("fo", base64_decode("Zm8="));
+ /* BASE64("foo") = "Zm9v" */
+ EXPECT_SLICE_EQ("foo", base64_decode("Zm9v"));
+ /* BASE64("foob") = "Zm9vYg==" */
+ EXPECT_SLICE_EQ("foob", base64_decode("Zm9vYg=="));
+ /* BASE64("fooba") = "Zm9vYmE=" */
+ EXPECT_SLICE_EQ("fooba", base64_decode("Zm9vYmE="));
+ /* BASE64("foobar") = "Zm9vYmFy" */
+ EXPECT_SLICE_EQ("foobar", base64_decode("Zm9vYmFy"));
+
+ EXPECT_SLICE_EQ("\xc0\xc1\xc2\xc3\xc4\xc5", base64_decode("wMHCw8TF"));
+
+ // Test illegal input length in grpc_chttp2_base64_decode
+ EXPECT_SLICE_EQ("", base64_decode("a"));
+ EXPECT_SLICE_EQ("", base64_decode("ab"));
+ EXPECT_SLICE_EQ("", base64_decode("abc"));
+
+ // Test illegal charactors in grpc_chttp2_base64_decode
+ EXPECT_SLICE_EQ("", base64_decode("Zm:v"));
+ EXPECT_SLICE_EQ("", base64_decode("Zm=v"));
+
+ // Test output_length longer than max possible output length in
+ // grpc_chttp2_base64_decode_with_length
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zg", 2));
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zm8", 3));
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zm9v", 4));
+
+ // Test illegal charactors in grpc_chttp2_base64_decode_with_length
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zm:v", 3));
+ EXPECT_SLICE_EQ("", base64_decode_with_length("Zm=v", 3));
+
+ return all_ok ? 0 : 1;
+}
diff --git a/test/core/transport/chttp2/bin_encoder_test.c b/test/core/transport/chttp2/bin_encoder_test.c
index 095861e974..08d10735a5 100644
--- a/test/core/transport/chttp2/bin_encoder_test.c
+++ b/test/core/transport/chttp2/bin_encoder_test.c
@@ -88,7 +88,8 @@ static void expect_combined_equiv(const char *s, size_t len, int line) {
char *t = gpr_dump_slice(input, GPR_DUMP_HEX | GPR_DUMP_ASCII);
char *e = gpr_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII);
char *g = gpr_dump_slice(got, GPR_DUMP_HEX | GPR_DUMP_ASCII);
- gpr_log(GPR_ERROR, "FAILED:%d:\ntest: %s\ngot: %s\nwant: %s", t, g, e);
+ gpr_log(GPR_ERROR, "FAILED:%d:\ntest: %s\ngot: %s\nwant: %s", line, t, g,
+ e);
gpr_free(t);
gpr_free(e);
gpr_free(g);
diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c
index e41eda8653..b7f68e0dd4 100644
--- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c
+++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c
@@ -40,17 +40,20 @@
#include "src/core/ext/transport/chttp2/transport/hpack_parser.h"
+bool squelch = true;
+bool leak_check = true;
+
static void onhdr(void *ud, grpc_mdelem *md) { GRPC_MDELEM_UNREF(md); }
static void dont_log(gpr_log_func_args *args) {}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
grpc_test_only_set_metadata_hash_seed(0);
- gpr_set_log_function(dont_log);
+ if (squelch) gpr_set_log_function(dont_log);
grpc_init();
grpc_chttp2_hpack_parser parser;
grpc_chttp2_hpack_parser_init(&parser);
parser.on_header = onhdr;
- grpc_chttp2_hpack_parser_parse(&parser, data, data + size);
+ GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse(&parser, data, data + size));
grpc_chttp2_hpack_parser_destroy(&parser);
grpc_shutdown();
return 0;
diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c
index 51bf48dc09..9ddceb8981 100644
--- a/test/core/transport/chttp2/hpack_parser_test.c
+++ b/test/core/transport/chttp2/hpack_parser_test.c
@@ -76,7 +76,8 @@ static void test_vector(grpc_chttp2_hpack_parser *parser,
for (i = 0; i < nslices; i++) {
GPR_ASSERT(grpc_chttp2_hpack_parser_parse(
- parser, GPR_SLICE_START_PTR(slices[i]), GPR_SLICE_END_PTR(slices[i])));
+ parser, GPR_SLICE_START_PTR(slices[i]),
+ GPR_SLICE_END_PTR(slices[i])) == GRPC_ERROR_NONE);
}
for (i = 0; i < nslices; i++) {
diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c
index 73e59f1536..75b0ef4629 100644
--- a/test/core/transport/chttp2/hpack_table_test.c
+++ b/test/core/transport/chttp2/hpack_table_test.c
@@ -139,12 +139,12 @@ static void test_many_additions(void) {
grpc_chttp2_hptbl_init(&tbl);
- for (i = 0; i < 1000000; i++) {
+ for (i = 0; i < 100000; i++) {
grpc_mdelem *elem;
gpr_asprintf(&key, "K:%d", i);
gpr_asprintf(&value, "VALUE:%d", i);
elem = grpc_mdelem_from_strings(key, value);
- GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem));
+ GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE);
GRPC_MDELEM_UNREF(elem);
assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value);
gpr_free(key);
@@ -181,13 +181,13 @@ static void test_find(void) {
grpc_chttp2_hptbl_init(&tbl);
elem = grpc_mdelem_from_strings("abc", "xyz");
- GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem));
+ GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE);
GRPC_MDELEM_UNREF(elem);
elem = grpc_mdelem_from_strings("abc", "123");
- GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem));
+ GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE);
GRPC_MDELEM_UNREF(elem);
elem = grpc_mdelem_from_strings("x", "1");
- GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem));
+ GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE);
GRPC_MDELEM_UNREF(elem);
r = find_simple(&tbl, "abc", "123");
@@ -238,7 +238,7 @@ static void test_find(void) {
for (i = 0; i < 10000; i++) {
int64_ttoa(i, buffer);
elem = grpc_mdelem_from_strings("test", buffer);
- GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem));
+ GPR_ASSERT(grpc_chttp2_hptbl_add(&tbl, elem) == GRPC_ERROR_NONE);
GRPC_MDELEM_UNREF(elem);
}
diff --git a/test/core/transport/connectivity_state_test.c b/test/core/transport/connectivity_state_test.c
index 6bb7c3b06b..1050059eff 100644
--- a/test/core/transport/connectivity_state_test.c
+++ b/test/core/transport/connectivity_state_test.c
@@ -43,14 +43,15 @@
int g_counter;
-static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
- GPR_ASSERT(success);
+static void must_succeed(grpc_exec_ctx *exec_ctx, void *arg,
+ grpc_error *error) {
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
GPR_ASSERT(arg == THE_ARG);
g_counter++;
}
-static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, bool success) {
- GPR_ASSERT(!success);
+static void must_fail(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {
+ GPR_ASSERT(error != GRPC_ERROR_NONE);
GPR_ASSERT(arg == THE_ARG);
g_counter++;
}
@@ -66,17 +67,19 @@ static void test_connectivity_state_name(void) {
GPR_ASSERT(
0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_TRANSIENT_FAILURE),
"TRANSIENT_FAILURE"));
- GPR_ASSERT(0 ==
- strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_FATAL_FAILURE),
- "FATAL_FAILURE"));
+ GPR_ASSERT(0 == strcmp(grpc_connectivity_state_name(GRPC_CHANNEL_SHUTDOWN),
+ "SHUTDOWN"));
}
static void test_check(void) {
grpc_connectivity_state_tracker tracker;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
+ grpc_error *error;
gpr_log(GPR_DEBUG, "test_check");
grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_IDLE, "xxx");
- GPR_ASSERT(grpc_connectivity_state_check(&tracker) == GRPC_CHANNEL_IDLE);
+ GPR_ASSERT(grpc_connectivity_state_check(&tracker, &error) ==
+ GRPC_CHANNEL_IDLE);
+ GPR_ASSERT(error == GRPC_ERROR_NONE);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
}
@@ -119,26 +122,26 @@ static void test_subscribe_then_destroy(void) {
GPR_ASSERT(g_counter == 0);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
+ GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN);
GPR_ASSERT(g_counter == 1);
}
static void test_subscribe_with_failure_then_destroy(void) {
grpc_connectivity_state_tracker tracker;
grpc_closure *closure = grpc_closure_create(must_fail, THE_ARG);
- grpc_connectivity_state state = GRPC_CHANNEL_FATAL_FAILURE;
+ grpc_connectivity_state state = GRPC_CHANNEL_SHUTDOWN;
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
gpr_log(GPR_DEBUG, "test_subscribe_with_failure_then_destroy");
g_counter = 0;
- grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_FATAL_FAILURE, "xxx");
+ grpc_connectivity_state_init(&tracker, GRPC_CHANNEL_SHUTDOWN, "xxx");
GPR_ASSERT(0 == grpc_connectivity_state_notify_on_state_change(
&exec_ctx, &tracker, &state, closure));
grpc_exec_ctx_flush(&exec_ctx);
- GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
+ GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN);
GPR_ASSERT(g_counter == 0);
grpc_connectivity_state_destroy(&exec_ctx, &tracker);
grpc_exec_ctx_finish(&exec_ctx);
- GPR_ASSERT(state == GRPC_CHANNEL_FATAL_FAILURE);
+ GPR_ASSERT(state == GRPC_CHANNEL_SHUTDOWN);
GPR_ASSERT(g_counter == 1);
}
diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c
index a4e9694a93..007892930c 100644
--- a/test/core/transport/metadata_test.c
+++ b/test/core/transport/metadata_test.c
@@ -166,7 +166,7 @@ static void test_things_stick_around(void) {
grpc_init();
for (i = 0; i < nstrs; i++) {
- gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", i);
+ gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i);
strs[i] = grpc_mdstr_from_string(buffer);
shuf[i] = i;
gpr_free(buffer);
@@ -188,7 +188,8 @@ static void test_things_stick_around(void) {
for (i = 0; i < nstrs; i++) {
GRPC_MDSTR_UNREF(strs[shuf[i]]);
for (j = i + 1; j < nstrs; j++) {
- gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%dx", shuf[j]);
+ gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x",
+ shuf[j]);
test = grpc_mdstr_from_string(buffer);
GPR_ASSERT(test == strs[shuf[j]]);
GRPC_MDSTR_UNREF(test);