aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-08 07:44:54 -0700
committerGravatar Craig Tiller <craig.tiller@gmail.com>2015-07-08 07:44:54 -0700
commit98d60fcb9adbf3379ddf3595f5a5de8289415f92 (patch)
treeae9101c565f64fcbcb4eb8cd7b5d3e3bdb5eb720 /test
parentd9b6fcfee4cb986f148762a4a7d0794de9b3ba62 (diff)
parent3b685b744818ec73580aff961f85c22b11e61ab0 (diff)
Merge github.com:grpc/grpc into hosts-need-names-too
Diffstat (limited to 'test')
-rw-r--r--test/build/openssl-npn.c45
-rw-r--r--test/core/bad_client/bad_client.c4
-rw-r--r--test/core/security/print_google_default_creds_token.c7
-rw-r--r--test/core/support/slice_test.c1
-rw-r--r--test/core/support/string_test.c51
-rw-r--r--test/core/transport/chttp2/bin_encoder_test.c15
-rw-r--r--test/core/transport/chttp2/stream_encoder_test.c8
-rw-r--r--test/core/tsi/transport_security_test.c8
8 files changed, 100 insertions, 39 deletions
diff --git a/test/build/openssl-npn.c b/test/build/openssl-npn.c
new file mode 100644
index 0000000000..90ae8ef940
--- /dev/null
+++ b/test/build/openssl-npn.c
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+/* This is just a compilation test, to see if we have a version of OpenSSL with
+ NPN support installed. It's not meant to be run, and all of the values and
+ function calls there are non-sensical. The code is only meant to test the
+ presence of symbols, and we're expecting a compilation failure otherwise. */
+
+#include <stdlib.h>
+#include <openssl/ssl.h>
+
+int main() {
+ SSL_get0_next_proto_negotiated(NULL, NULL, NULL);
+ return OPENSSL_NPN_UNSUPPORTED;
+}
diff --git a/test/core/bad_client/bad_client.c b/test/core/bad_client/bad_client.c
index 8ce666dcde..b050227b61 100644
--- a/test/core/bad_client/bad_client.c
+++ b/test/core/bad_client/bad_client.c
@@ -86,8 +86,8 @@ void grpc_run_bad_client_test(grpc_bad_client_server_side_validator validator,
gpr_slice slice =
gpr_slice_from_copied_buffer(client_payload, client_payload_length);
- hex =
- gpr_hexdump(client_payload, client_payload_length, GPR_HEXDUMP_PLAINTEXT);
+ hex = gpr_dump(client_payload, client_payload_length,
+ GPR_DUMP_HEX | GPR_DUMP_ASCII);
/* Add a debug log */
gpr_log(GPR_INFO, "TEST: %s", hex);
diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c
index a0da5b2d93..73283c2fbd 100644
--- a/test/core/security/print_google_default_creds_token.c
+++ b/test/core/security/print_google_default_creds_token.c
@@ -35,6 +35,7 @@
#include <string.h>
#include "src/core/security/credentials.h"
+#include "src/core/support/string.h"
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
@@ -56,9 +57,11 @@ static void on_metadata_response(void *user_data,
if (status == GRPC_CREDENTIALS_ERROR) {
fprintf(stderr, "Fetching token failed.\n");
} else {
+ char *token;
GPR_ASSERT(num_md == 1);
- printf("\nGot token: %s\n\n",
- (const char *)GPR_SLICE_START_PTR(md_elems[0].value));
+ token = gpr_dump_slice(md_elems[0].value, GPR_DUMP_ASCII);
+ printf("\nGot token: %s\n\n", token);
+ gpr_free(token);
}
gpr_mu_lock(GRPC_POLLSET_MU(&sync->pollset));
sync->is_done = 1;
diff --git a/test/core/support/slice_test.c b/test/core/support/slice_test.c
index 63dedea50f..3ca87427dd 100644
--- a/test/core/support/slice_test.c
+++ b/test/core/support/slice_test.c
@@ -35,6 +35,7 @@
#include <string.h>
+#include <grpc/support/alloc.h>
#include <grpc/support/log.h>
#include "test/core/util/test_config.h"
diff --git a/test/core/support/string_test.c b/test/core/support/string_test.c
index b59082eecf..f04e72ac2b 100644
--- a/test/core/support/string_test.c
+++ b/test/core/support/string_test.c
@@ -58,21 +58,49 @@ static void test_strdup(void) {
GPR_ASSERT(NULL == gpr_strdup(NULL));
}
-static void expect_hexdump(const char *buf, size_t len, gpr_uint32 flags,
- const char *result) {
- char *got = gpr_hexdump(buf, len, flags);
+static void expect_dump(const char *buf, size_t len, gpr_uint32 flags,
+ const char *result) {
+ char *got = gpr_dump(buf, len, flags);
GPR_ASSERT(0 == strcmp(got, result));
gpr_free(got);
}
-static void test_hexdump(void) {
- LOG_TEST_NAME("test_hexdump");
- expect_hexdump("\x01", 1, 0, "01");
- expect_hexdump("\x01", 1, GPR_HEXDUMP_PLAINTEXT, "01 '.'");
- expect_hexdump("\x01\x02", 2, 0, "01 02");
- expect_hexdump("\x01\x23\x45\x67\x89\xab\xcd\xef", 8, 0,
+static void test_dump(void) {
+ LOG_TEST_NAME("test_dump");
+ expect_dump("\x01", 1, GPR_DUMP_HEX, "01");
+ expect_dump("\x01", 1, GPR_DUMP_HEX | GPR_DUMP_ASCII, "01 '.'");
+ expect_dump("\x01\x02", 2, GPR_DUMP_HEX, "01 02");
+ expect_dump("\x01\x23\x45\x67\x89\xab\xcd\xef", 8, GPR_DUMP_HEX,
"01 23 45 67 89 ab cd ef");
- expect_hexdump("ab", 2, GPR_HEXDUMP_PLAINTEXT, "61 62 'ab'");
+ expect_dump("ab", 2, GPR_DUMP_HEX | GPR_DUMP_ASCII, "61 62 'ab'");
+}
+
+static void expect_slice_dump(gpr_slice slice, gpr_uint32 flags,
+ const char *result) {
+ char *got = gpr_dump_slice(slice, flags);
+ GPR_ASSERT(0 == strcmp(got, result));
+ gpr_free(got);
+ gpr_slice_unref(slice);
+}
+
+static void test_dump_slice(void) {
+ static const char *text = "HELLO WORLD!";
+ static const char *long_text =
+ "It was a bright cold day in April, and the clocks were striking "
+ "thirteen. Winston Smith, his chin nuzzled into his breast in an effort "
+ "to escape the vile wind, slipped quickly through the glass doors of "
+ "Victory Mansions, though not quickly enough to prevent a swirl of "
+ "gritty dust from entering along with him.";
+
+ LOG_TEST_NAME("test_dump_slice");
+
+ expect_slice_dump(gpr_slice_from_copied_string(text), GPR_DUMP_ASCII, text);
+ expect_slice_dump(gpr_slice_from_copied_string(long_text), GPR_DUMP_ASCII,
+ long_text);
+ expect_slice_dump(gpr_slice_from_copied_buffer("\x01", 1), GPR_DUMP_HEX,
+ "01");
+ expect_slice_dump(gpr_slice_from_copied_buffer("\x01", 1),
+ GPR_DUMP_HEX | GPR_DUMP_ASCII, "01 '.'");
}
static void test_pu32_fail(const char *s) {
@@ -148,7 +176,8 @@ static void test_asprintf(void) {
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
test_strdup();
- test_hexdump();
+ test_dump();
+ test_dump_slice();
test_parse_uint32();
test_asprintf();
return 0;
diff --git a/test/core/transport/chttp2/bin_encoder_test.c b/test/core/transport/chttp2/bin_encoder_test.c
index 983eaf5a0d..1ffd8ed3cb 100644
--- a/test/core/transport/chttp2/bin_encoder_test.c
+++ b/test/core/transport/chttp2/bin_encoder_test.c
@@ -44,10 +44,8 @@ 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_hexdump((const char *)GPR_SLICE_START_PTR(slice),
- GPR_SLICE_LENGTH(slice), GPR_HEXDUMP_PLAINTEXT);
- char *he = gpr_hexdump((const char *)GPR_SLICE_START_PTR(expected),
- GPR_SLICE_LENGTH(expected), GPR_HEXDUMP_PLAINTEXT);
+ 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);
@@ -83,12 +81,9 @@ static void expect_combined_equiv(const char *s, size_t len, int line) {
gpr_slice expect = grpc_chttp2_huffman_compress(base64);
gpr_slice got = grpc_chttp2_base64_encode_and_huffman_compress(input);
if (0 != gpr_slice_cmp(expect, got)) {
- char *t = gpr_hexdump((const char *)GPR_SLICE_START_PTR(input),
- GPR_SLICE_LENGTH(input), GPR_HEXDUMP_PLAINTEXT);
- char *e = gpr_hexdump((const char *)GPR_SLICE_START_PTR(expect),
- GPR_SLICE_LENGTH(expect), GPR_HEXDUMP_PLAINTEXT);
- char *g = gpr_hexdump((const char *)GPR_SLICE_START_PTR(got),
- GPR_SLICE_LENGTH(got), GPR_HEXDUMP_PLAINTEXT);
+ 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_free(t);
gpr_free(e);
diff --git a/test/core/transport/chttp2/stream_encoder_test.c b/test/core/transport/chttp2/stream_encoder_test.c
index bf70d43e78..6f2ea274fe 100644
--- a/test/core/transport/chttp2/stream_encoder_test.c
+++ b/test/core/transport/chttp2/stream_encoder_test.c
@@ -85,12 +85,8 @@ static void verify_sopb(size_t window_available, int eof,
grpc_sopb_destroy(&encops);
if (0 != gpr_slice_cmp(merged, expect)) {
- char *expect_str =
- gpr_hexdump((char *)GPR_SLICE_START_PTR(expect),
- GPR_SLICE_LENGTH(expect), GPR_HEXDUMP_PLAINTEXT);
- char *got_str =
- gpr_hexdump((char *)GPR_SLICE_START_PTR(merged),
- GPR_SLICE_LENGTH(merged), GPR_HEXDUMP_PLAINTEXT);
+ char *expect_str = gpr_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII);
+ char *got_str = gpr_dump_slice(merged, GPR_DUMP_HEX | GPR_DUMP_ASCII);
gpr_log(GPR_ERROR, "mismatched output for %s", expected);
gpr_log(GPR_ERROR, "EXPECT: %s", expect_str);
gpr_log(GPR_ERROR, "GOT: %s", got_str);
diff --git a/test/core/tsi/transport_security_test.c b/test/core/tsi/transport_security_test.c
index bba6744194..bec3866166 100644
--- a/test/core/tsi/transport_security_test.c
+++ b/test/core/tsi/transport_security_test.c
@@ -46,9 +46,6 @@
#include "src/core/tsi/ssl_transport_security.h"
#include "test/core/util/test_config.h"
-/* Currently points to 1.0.2a. */
-#define GRPC_MIN_OPENSSL_VERSION_NUMBER 0x1000201fL
-
typedef struct {
/* 1 if success, 0 if failure. */
int expected;
@@ -299,13 +296,8 @@ static void test_peer_matches_name(void) {
}
}
-static void test_openssl_version(void) {
- GPR_ASSERT(OPENSSL_VERSION_NUMBER >= GRPC_MIN_OPENSSL_VERSION_NUMBER);
-}
-
int main(int argc, char **argv) {
grpc_test_init(argc, argv);
test_peer_matches_name();
- test_openssl_version();
return 0;
}