unsigned char buf[DATA_BUF_SIZE];
const ASN1_ITEM *i = ASN1_ITEM_ptr(package->asn1_type);
ASN1_VALUE *o = (ASN1_VALUE *)&buf;
- BIO *bio = BIO_new_fp(stdout, 0);
int ret;
OPENSSL_assert(package->encode_expectations_elem_size <= DATA_BUF_SIZE);
(void)RAND_bytes(buf, (int)package->encode_expectations_elem_size);
- ret = ASN1_item_print(bio, o, 0, i, NULL);
- BIO_free(bio);
+ ret = ASN1_item_print(bio_out, o, 0, i, NULL);
return ret;
}
->encode_expectations)[pos],
&test_custom_data[i], package)) {
case -1:
- fprintf(stderr, "Failed custom encode round trip %u of %s\n",
- i, package->name);
- ERR_print_errors_fp(stderr);
+ TEST_error("Failed custom encode round trip %u of %s",
+ i, package->name);
+ TEST_openssl_errors();
fail++;
- ERR_clear_error();
break;
case 0:
- fprintf(stderr, "Custom encode round trip %u of %s mismatch\n",
- i, package->name);
- ERR_print_errors_fp(stderr);
+ TEST_error("Custom encode round trip %u of %s mismatch",
+ i, package->name);
+ TEST_openssl_errors();
fail++;
- ERR_clear_error();
break;
case 1:
break;
package->encode_expectations_elem_size,
package)) {
case -1:
- fprintf(stderr, "Failed custom decode round trip %u of %s\n",
- i, package->name);
- ERR_print_errors_fp(stderr);
+ TEST_error("Failed custom decode round trip %u of %s",
+ i, package->name);
+ TEST_openssl_errors();
fail++;
- ERR_clear_error();
break;
case 0:
- fprintf(stderr, "Custom decode round trip %u of %s mismatch\n",
- i, package->name);
- ERR_print_errors_fp(stderr);
+ TEST_error("Custom decode round trip %u of %s mismatch",
+ i, package->name);
+ TEST_openssl_errors();
fail++;
- ERR_clear_error();
break;
case 1:
break;
package->encdec_data_elem_size,
package)) {
case -1:
- fprintf(stderr, "Failed encode/decode round trip %u of %s\n",
- i, package->name);
- ERR_print_errors_fp(stderr);
- ERR_clear_error();
+ TEST_error("Failed encode/decode round trip %u of %s",
+ i, package->name);
+ TEST_openssl_errors();
fail++;
break;
case 0:
- fprintf(stderr, "Encode/decode round trip %u of %s mismatch\n",
- i, package->name);
+ TEST_error("Encode/decode round trip %u of %s mismatch",
+ i, package->name);
fail++;
break;
case 1:
}
if (!do_print_item(package)) {
- fprintf(stderr, "Printing of %s failed\n", package->name);
- ERR_print_errors_fp(stderr);
+ TEST_error("Printing of %s failed", package->name);
fail++;
}
/*
- * Copyright 1999-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1999-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
last_nid = tmp->nid;
}
- if (last_nid != 0) {
- fprintf(stderr, "asn1 tbl_standard: Table order OK\n");
+ if (TEST_int_ne(last_nid, 0)) {
+ TEST_info("asn1 tbl_standard: Table order OK");
return 1;
}
+ TEST_error("asn1 tbl_standard: out of order");
for (tmp = tbl_standard, i = 0; i < OSSL_NELEM(tbl_standard); i++, tmp++)
- fprintf(stderr, "asn1 tbl_standard: Index %" OSSLzu ", NID %d, Name=%s\n",
- i, tmp->nid, OBJ_nid2ln(tmp->nid));
+ TEST_note("asn1 tbl_standard: Index %" OSSLzu ", NID %d, Name=%s",
+ i, tmp->nid, OBJ_nid2ln(tmp->nid));
return 0;
}
last_pkey_id = (*tmp)->pkey_id;
}
- if (last_pkey_id != 0) {
- fprintf(stderr, "asn1 standard methods: Table order OK\n");
+ if (TEST_int_ne(last_pkey_id, 0)) {
+ TEST_info("asn1 standard methods: Table order OK");
return 1;
}
- TEST_error("asn1 standard methods out of order");
+ TEST_error("asn1 standard methods: out of order");
for (tmp = standard_methods, i = 0; i < OSSL_NELEM(standard_methods);
i++, tmp++)
- fprintf(stderr, "asn1 standard methods: Index %" OSSLzu
- ", pkey ID %d, Name=%s\n", i, (*tmp)->pkey_id,
- OBJ_nid2sn((*tmp)->pkey_id));
+ TEST_note("asn1 standard methods: Index %" OSSLzu
+ ", pkey ID %d, Name=%s", i, (*tmp)->pkey_id,
+ OBJ_nid2sn((*tmp)->pkey_id));
return 0;
}
item_type = ASN1_ITEM_lookup(test_type_name);
if (item_type == NULL) {
- TEST_error("Unknown type %s\n", test_type_name);
- fprintf(stderr, "Supported types:\n");
+ TEST_error("Unknown type %s", test_type_name);
+ TEST_note("Supported types:");
for (i = 0;; i++) {
const ASN1_ITEM *it = ASN1_ITEM_get(i);
if (it == NULL)
break;
- fprintf(stderr, "\t%s\n", it->sname);
+ TEST_note("\t%s", it->sname);
}
return 1;
}
/*
- * Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
}
for (loop = 0; loop < NUMTOADD; loop++) {
if (!TEST_true(ENGINE_add(block[loop]))) {
- printf("Adding stopped at %d, (%s,%s)",
- loop, ENGINE_get_id(block[loop]),
- ENGINE_get_name(block[loop]));
+ test_note("Adding stopped at %d, (%s,%s)",
+ loop, ENGINE_get_id(block[loop]),
+ ENGINE_get_name(block[loop]));
goto cleanup_loop;
}
}
/* Otherwise assume as hex literal and convert it to binary buffer */
if (!TEST_ptr(*buf = OPENSSL_hexstr2buf(value, &len))) {
TEST_info("Can't convert %s", value);
- ERR_print_errors(bio_err);
+ TEST_openssl_errors();
return -1;
}
/* Size of input buffer means we'll never overflow */
return 0;
}
if (!check_test_error(t)) {
- test_openssl_errors();
+ TEST_openssl_errors();
t->s.errors++;
}
}
pkey = PEM_read_bio_PrivateKey(t->s.key, NULL, 0, NULL);
if (pkey == NULL && !key_unsupported()) {
TEST_info("Can't read private key %s", pp->value);
- ERR_print_errors_fp(stderr);
+ TEST_openssl_errors();
return 0;
}
klist = &private_keys;
pkey = PEM_read_bio_PUBKEY(t->s.key, NULL, 0, NULL);
if (pkey == NULL && !key_unsupported()) {
TEST_info("Can't read public key %s", pp->value);
- ERR_print_errors_fp(stderr);
+ TEST_openssl_errors();
return 0;
}
klist = &public_keys;
if (!TEST_int_eq(lh_int_num_items(h), n))
goto end;
- fprintf(stderr, "hash full statistics:\n");
- OPENSSL_LH_stats((OPENSSL_LHASH *)h, stderr);
- fprintf(stderr, "\nhash full node usage:\n");
- OPENSSL_LH_node_usage_stats((OPENSSL_LHASH *)h, stderr);
+ TEST_info("hash full statistics:");
+ OPENSSL_LH_stats_bio((OPENSSL_LHASH *)h, bio_err);
+ TEST_note("hash full node usage:");
+ OPENSSL_LH_node_usage_stats_bio((OPENSSL_LHASH *)h, bio_err);
/* delete in a different order */
for (i = 0; i < n; i++) {
OPENSSL_free(p);
}
- fprintf(stderr, "\nhash empty statistics:\n");
- OPENSSL_LH_stats((OPENSSL_LHASH *)h, stderr);
- fprintf(stderr, "\nhash empty node usage:\n");
- OPENSSL_LH_node_usage_stats((OPENSSL_LHASH *)h, stderr);
+ TEST_info("hash empty statistics:");
+ OPENSSL_LH_stats_bio((OPENSSL_LHASH *)h, bio_err);
+ TEST_note("hash empty node usage:");
+ OPENSSL_LH_node_usage_stats_bio((OPENSSL_LHASH *)h, bio_err);
testresult = 1;
end:
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
EVP_PKEY_asn1_get0_info(&pkey_id, NULL, NULL, &info, NULL, ameth);
if (info == NULL)
info = "<NO NAME>";
- fprintf(stderr, "%d : %s : %s\n", pkey_id, OBJ_nid2ln(pkey_id),
- info);
+ TEST_note("%d : %s : %s", pkey_id, OBJ_nid2ln(pkey_id), info);
}
- } else {
- fprintf(stderr, "Order OK\n");
}
-
return good;
}
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
static void print_ca_names(STACK_OF(X509_NAME) *names)
{
- BIO *err;
int i;
if (names == NULL || sk_X509_NAME_num(names) == 0) {
- fprintf(stderr, " <empty>\n");
+ TEST_note(" <empty>");
return;
}
- err = BIO_new_fp(stderr, BIO_NOCLOSE);
for (i = 0; i < sk_X509_NAME_num(names); i++) {
- X509_NAME_print_ex(err, sk_X509_NAME_value(names, i), 4,
+ X509_NAME_print_ex(bio_err, sk_X509_NAME_value(names, i), 4,
XN_FLAG_ONELINE);
- BIO_puts(err, "\n");
+ BIO_puts(bio_err, "\n");
}
- BIO_free(err);
}
static int check_ca_names(const char *name,
if (expected_names == NULL)
return 1;
if (names == NULL || sk_X509_NAME_num(names) == 0) {
- if (sk_X509_NAME_num(expected_names) == 0)
+ if (TEST_int_eq(sk_X509_NAME_num(expected_names), 0))
return 1;
goto err;
}
if (sk_X509_NAME_num(names) != sk_X509_NAME_num(expected_names))
goto err;
for (i = 0; i < sk_X509_NAME_num(names); i++) {
- if (X509_NAME_cmp(sk_X509_NAME_value(names, i),
- sk_X509_NAME_value(expected_names, i)) != 0) {
+ if (!TEST_int_eq(X509_NAME_cmp(sk_X509_NAME_value(names, i),
+ sk_X509_NAME_value(expected_names, i)),
+ 0)) {
goto err;
}
}
return 1;
- err:
- fprintf(stderr, "%s: list mismatch\nExpected Names:\n", name);
+err:
+ TEST_info("%s: list mismatch", name);
+ TEST_note("Expected Names:");
print_ca_names(expected_names);
- fprintf(stderr, "Received Names:\n");
+ TEST_note("Received Names:");
print_ca_names(names);
return 0;
}
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
for (j = 0; j < OSSL_NELEM(ssl_test_client_options); j++) {
if (strcmp(option->name, ssl_test_client_options[j].name) == 0) {
if (!ssl_test_client_options[j].parse(client, option->value)) {
- fprintf(stderr, "Bad value %s for option %s\n",
- option->value, option->name);
+ TEST_info("Bad value %s for option %s",
+ option->value, option->name);
return 0;
}
found = 1;
}
}
if (!found) {
- fprintf(stderr, "Unknown test option: %s\n", option->name);
+ TEST_info("Unknown test option: %s", option->name);
return 0;
}
}
for (j = 0; j < OSSL_NELEM(ssl_test_server_options); j++) {
if (strcmp(option->name, ssl_test_server_options[j].name) == 0) {
if (!ssl_test_server_options[j].parse(server, option->value)) {
- fprintf(stderr, "Bad value %s for option %s\n",
- option->value, option->name);
+ TEST_info("Bad value %s for option %s",
+ option->value, option->name);
return 0;
}
found = 1;
}
}
if (!found) {
- fprintf(stderr, "Unknown test option: %s\n", option->name);
+ TEST_info("Unknown test option: %s", option->name);
return 0;
}
}
option->value))
goto err;
} else if (strcmp(option->name, "server") == 0) {
- if (!parse_server_options(&ctx->extra.server, conf,
- option->value))
+ if (!TEST_true(parse_server_options(&ctx->extra.server, conf,
+ option->value)))
goto err;
} else if (strcmp(option->name, "server2") == 0) {
- if (!parse_server_options(&ctx->extra.server2, conf,
- option->value))
+ if (!TEST_true(parse_server_options(&ctx->extra.server2, conf,
+ option->value)))
goto err;
} else if (strcmp(option->name, "resume-client") == 0) {
- if (!parse_client_options(&ctx->resume_extra.client, conf,
- option->value))
+ if (!TEST_true(parse_client_options(&ctx->resume_extra.client, conf,
+ option->value)))
goto err;
} else if (strcmp(option->name, "resume-server") == 0) {
- if (!parse_server_options(&ctx->resume_extra.server, conf,
- option->value))
+ if (!TEST_true(parse_server_options(&ctx->resume_extra.server, conf,
+ option->value)))
goto err;
} else if (strcmp(option->name, "resume-server2") == 0) {
if (!parse_server_options(&ctx->resume_extra.server2, conf,
for (j = 0; j < OSSL_NELEM(ssl_test_ctx_options); j++) {
if (strcmp(option->name, ssl_test_ctx_options[j].name) == 0) {
if (!ssl_test_ctx_options[j].parse(ctx, option->value)) {
- fprintf(stderr, "Bad value %s for option %s\n",
- option->value, option->name);
+ TEST_info("Bad value %s for option %s",
+ option->value, option->name);
goto err;
}
found = 1;
}
}
if (!found) {
- fprintf(stderr, "Unknown test option: %s\n", option->name);
+ TEST_info("Unknown test option: %s", option->name);
goto err;
}
}
/*
- * Copyright 2014-2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2014-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
void test_info_c90(const char *desc, ...) PRINTF_FORMAT(1, 2);
void test_note(const char *desc, ...) PRINTF_FORMAT(1, 2);
void test_openssl_errors(void);
+void test_perror(const char *s);
/*
* The following macros provide wrapper calls to the test functions with
# endif
# define TEST_note test_note
# define TEST_openssl_errors test_openssl_errors
+# define TEST_perror test_perror
/*
* For "impossible" conditions such as malloc failures or bugs in test code,
#include "output.h"
#include "tu_local.h"
+#include <errno.h>
#include <string.h>
#include <ctype.h>
#include "../../e_os.h"
test_printf_stderr("\n");
}
+void test_perror(const char *s)
+{
+ /*
+ * Using openssl_strerror_r causes linking issues since it isn't
+ * exported from libcrypto.so
+ */
+ TEST_error("%s: %s", s, strerror(errno));
+}
+
void test_note(const char *fmt, ...)
{
if (fmt != NULL) {
void test_openssl_errors(void)
{
ERR_print_errors_cb(openssl_error_cb, NULL);
+ ERR_clear_error();
}
/*
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
seq = NULL;
}
- fprintf(stderr, "PASS: %"OSSLzu" records tested\n", ctr);
+ TEST_note("PASS: %"OSSLzu" records tested", ctr);
ret = 1;
err:
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
tmp = standard_exts;
TEST_error("Extensions out of order!");
for (i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
- fprintf(stderr, "%d : %s\n", (*tmp)->ext_nid,
- OBJ_nid2sn((*tmp)->ext_nid));
- } else {
- fprintf(stderr, "Order OK\n");
+ TEST_note("%d : %s", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
}
-
return good;
}
/*
- * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2016-2017 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL licenses, (the "License");
* you may not use this file except in compliance with the License.
for (count = 0;
!err && PEM_read_bio(fp, &name, &header, &data, &len);
- ++count) {
+ ++count) {
int trusted = strcmp(name, PEM_STRING_X509_TRUSTED) == 0;
d2i_X509_t d2i = trusted ? d2i_X509_AUX : d2i_X509;
i2d_X509_t i2d = trusted ? i2d_X509_AUX : i2d_X509;
X509 *cert = NULL;
- const unsigned char *p = data;
+ const unsigned char *p = data;
unsigned char *buf = NULL;
unsigned char *bufp;
long enclen;
- if (!trusted
+ if (!trusted
&& strcmp(name, PEM_STRING_X509) != 0
- && strcmp(name, PEM_STRING_X509_OLD) != 0) {
- fprintf(stderr, "unexpected PEM object: %s\n", name);
+ && strcmp(name, PEM_STRING_X509_OLD) != 0) {
+ TEST_error("unexpected PEM object: %s", name);
err = 1;
- goto next;
+ goto next;
}
cert = d2i(NULL, &p, len);
if (cert == NULL || (p - data) != len) {
- fprintf(stderr, "error parsing input %s\n", name);
+ TEST_error("error parsing input %s", name);
err = 1;
goto next;
}
/* Test traditional 2-pass encoding into caller allocated buffer */
enclen = i2d(cert, NULL);
if (len != enclen) {
- fprintf(stderr, "encoded length %ld of %s != input length %ld\n",
- enclen, name, len);
+ TEST_error("encoded length %ld of %s != input length %ld",
+ enclen, name, len);
err = 1;
goto next;
}
if ((buf = bufp = OPENSSL_malloc(len)) == NULL) {
- perror("malloc");
+ TEST_perror("malloc");
err = 1;
goto next;
}
enclen = i2d(cert, &bufp);
if (len != enclen) {
- fprintf(stderr, "encoded length %ld of %s != input length %ld\n",
- enclen, name, len);
+ TEST_error("encoded length %ld of %s != input length %ld",
+ enclen, name, len);
err = 1;
goto next;
}
enclen = (long) (bufp - buf);
if (enclen != len) {
- fprintf(stderr, "unexpected buffer position after encoding %s\n",
- name);
+ TEST_error("unexpected buffer position after encoding %s", name);
err = 1;
goto next;
}
if (memcmp(buf, data, len) != 0) {
- fprintf(stderr, "encoded content of %s does not match input\n",
- name);
+ TEST_error("encoded content of %s does not match input", name);
err = 1;
goto next;
}
/* Test 1-pass encoding into library allocated buffer */
enclen = i2d(cert, &buf);
if (len != enclen) {
- fprintf(stderr, "encoded length %ld of %s != input length %ld\n",
- enclen, name, len);
+ TEST_error("encoded length %ld of %s != input length %ld",
+ enclen, name, len);
err = 1;
goto next;
}
if (memcmp(buf, data, len) != 0) {
- fprintf(stderr, "encoded content of %s does not match input\n",
- name);
+ TEST_error("encoded content of %s does not match input", name);
err = 1;
goto next;
}
/* Test 1-pass encoding into library allocated buffer */
enclen = i2d(cert, &buf);
if (enclen > len) {
- fprintf(stderr, "encoded length %ld of %s > input length %ld\n",
- enclen, name, len);
+ TEST_error("encoded length %ld of %s > input length %ld",
+ enclen, name, len);
err = 1;
goto next;
}
if (memcmp(buf, data, enclen) != 0) {
- fprintf(stderr, "encoded cert content does not match input\n");
+ TEST_error("encoded cert content does not match input");
err = 1;
goto next;
}
}
- /*
- * If any of these were null, PEM_read() would have failed.
- */
+ /*
+ * If any of these were null, PEM_read() would have failed.
+ */
next:
X509_free(cert);
OPENSSL_free(buf);
- OPENSSL_free(name);
- OPENSSL_free(header);
- OPENSSL_free(data);
+ OPENSSL_free(name);
+ OPENSSL_free(header);
+ OPENSSL_free(data);
}
BIO_free(fp);