Commit 8fe3127c authored by Pauli's avatar Pauli Committed by Rich Salz
Browse files

Update tests to avoid printf to stdout/stderr when running as test cases.

parent f39a5501
Loading
Loading
Loading
Loading
+19 −27
Original line number Diff line number Diff line
@@ -712,14 +712,12 @@ static int do_print_item(const TEST_PACKAGE *package)
    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;
}
@@ -745,18 +743,16 @@ static int test_intern(const TEST_PACKAGE *package)
                                               ->encode_expectations)[pos],
                                 &test_custom_data[i], package)) {
        case -1:
            fprintf(stderr, "Failed custom encode round trip %u of %s\n",
            TEST_error("Failed custom encode round trip %u of %s",
                       i, package->name);
            ERR_print_errors_fp(stderr);
            TEST_openssl_errors();
            fail++;
            ERR_clear_error();
            break;
        case 0:
            fprintf(stderr, "Custom encode round trip %u of %s mismatch\n",
            TEST_error("Custom encode round trip %u of %s mismatch",
                       i, package->name);
            ERR_print_errors_fp(stderr);
            TEST_openssl_errors();
            fail++;
            ERR_clear_error();
            break;
        case 1:
            break;
@@ -770,18 +766,16 @@ static int test_intern(const TEST_PACKAGE *package)
                                 package->encode_expectations_elem_size,
                                 package)) {
        case -1:
            fprintf(stderr, "Failed custom decode round trip %u of %s\n",
            TEST_error("Failed custom decode round trip %u of %s",
                       i, package->name);
            ERR_print_errors_fp(stderr);
            TEST_openssl_errors();
            fail++;
            ERR_clear_error();
            break;
        case 0:
            fprintf(stderr, "Custom decode round trip %u of %s mismatch\n",
            TEST_error("Custom decode round trip %u of %s mismatch",
                       i, package->name);
            ERR_print_errors_fp(stderr);
            TEST_openssl_errors();
            fail++;
            ERR_clear_error();
            break;
        case 1:
            break;
@@ -800,14 +794,13 @@ static int test_intern(const TEST_PACKAGE *package)
                           package->encdec_data_elem_size,
                           package)) {
        case -1:
            fprintf(stderr, "Failed encode/decode round trip %u of %s\n",
            TEST_error("Failed encode/decode round trip %u of %s",
                       i, package->name);
            ERR_print_errors_fp(stderr);
            ERR_clear_error();
            TEST_openssl_errors();
            fail++;
            break;
        case 0:
            fprintf(stderr, "Encode/decode round trip %u of %s mismatch\n",
            TEST_error("Encode/decode round trip %u of %s mismatch",
                       i, package->name);
            fail++;
            break;
@@ -820,8 +813,7 @@ static int test_intern(const TEST_PACKAGE *package)
    }

    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++;
    }

+12 −11
Original line number Diff line number Diff line
/*
 * 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
@@ -40,13 +40,14 @@ static int test_tbl_standard()
        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",
        TEST_note("asn1 tbl_standard: Index %" OSSLzu ", NID %d, Name=%s",
                  i, tmp->nid, OBJ_nid2ln(tmp->nid));

    return 0;
@@ -76,16 +77,16 @@ static int test_standard_methods()
        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,
        TEST_note("asn1 standard methods: Index %" OSSLzu
                  ", pkey ID %d, Name=%s", i, (*tmp)->pkey_id,
                  OBJ_nid2sn((*tmp)->pkey_id));

    return 0;
+3 −3
Original line number Diff line number Diff line
@@ -137,14 +137,14 @@ int test_main(int argc, char *argv[])
    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;
    }
+4 −4
Original line number Diff line number Diff line
/*
 * 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
@@ -151,7 +151,7 @@ static int test_engines(void)
    }
    for (loop = 0; loop < NUMTOADD; loop++) {
        if (!TEST_true(ENGINE_add(block[loop]))) {
            printf("Adding stopped at %d, (%s,%s)",
            test_note("Adding stopped at %d, (%s,%s)",
                      loop, ENGINE_get_id(block[loop]),
                      ENGINE_get_name(block[loop]));
            goto cleanup_loop;
+4 −4
Original line number Diff line number Diff line
@@ -284,7 +284,7 @@ static int parse_bin(const char *value, unsigned char **buf, size_t *buflen)
    /* 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 */
@@ -2208,7 +2208,7 @@ static int run_test(EVP_TEST *t)
            return 0;
        }
        if (!check_test_error(t)) {
            test_openssl_errors();
            TEST_openssl_errors();
            t->s.errors++;
        }
    }
@@ -2306,7 +2306,7 @@ top:
        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;
@@ -2315,7 +2315,7 @@ top:
        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;
Loading