diff --git a/test/bioprinttest.c b/test/bioprinttest.c index 38e6b403ca..543f39806c 100644 --- a/test/bioprinttest.c +++ b/test/bioprinttest.c @@ -137,13 +137,33 @@ static const z_data zu_data[] = { static int test_zu(int i) { char bio_buf[80]; + char std_buf[80]; const z_data *data = &zu_data[i]; + const int exp_ret = (int) strlen(data->expected); + int bio_ret; + int std_ret; memset(bio_buf, '@', sizeof(bio_buf)); + memset(std_buf, '#', sizeof(std_buf)); - BIO_snprintf(bio_buf, sizeof(bio_buf), data->format, data->value); - if (!TEST_str_eq(bio_buf, data->expected)) + bio_ret = BIO_snprintf(bio_buf, sizeof(bio_buf), data->format, data->value); + std_ret = snprintf(std_buf, sizeof(std_buf), data->format, data->value); + if (!TEST_str_eq(bio_buf, data->expected) + + !TEST_int_eq(bio_ret, exp_ret)) return 0; + + /* + * We treat the unexpected discrepancies with libc results as notable, + * but not fatal. + */ + if (!TEST_str_eq(bio_buf, std_buf) + + !TEST_int_eq(bio_ret, std_ret)) { + TEST_note("Format: \"%s\"", data->format); +#if defined(OPENSSL_STRICT_LIBC_PRINTF_CHECK) + return 0; +#endif + } + return 1; } @@ -168,12 +188,32 @@ static int test_j(int i) { const j_data *data = &jf_data[i]; char bio_buf[80]; + char std_buf[80]; + const int exp_ret = (int) strlen(data->expected); + int bio_ret; + int std_ret; memset(bio_buf, '@', sizeof(bio_buf)); + memset(std_buf, '#', sizeof(std_buf)); - BIO_snprintf(bio_buf, sizeof(bio_buf), data->format, data->value); - if (!TEST_str_eq(bio_buf, data->expected)) + bio_ret = BIO_snprintf(bio_buf, sizeof(bio_buf), data->format, data->value); + std_ret = snprintf(std_buf, sizeof(std_buf), data->format, data->value); + if (!TEST_str_eq(bio_buf, data->expected) + + !TEST_int_eq(bio_ret, exp_ret)) return 0; + + /* + * We treat the unexpected discrepancies with libc results as notable, + * but not fatal. + */ + if (!TEST_str_eq(bio_buf, std_buf) + + !TEST_int_eq(bio_ret, std_ret)) { + TEST_note("Format: \"%s\"", data->format); +#if defined(OPENSSL_STRICT_LIBC_PRINTF_CHECK) + return 0; +#endif + } + return 1; } @@ -199,30 +239,57 @@ static int dofptest(int test, int sub, double val, const char *width, int prec) static const char *fspecs[] = { "e", "f", "g", "E", "G" }; - char format[80], result[80]; + char format[80], result[80], std_result[80]; int ret = 1, i; + int exp_ret; + int bio_ret; + int std_ret; for (i = 0; i < (int)OSSL_NELEM(fspecs); i++) { const char *fspec = fspecs[i]; memset(result, '@', sizeof(result)); + memset(std_result, '#', sizeof(std_result)); if (prec >= 0) BIO_snprintf(format, sizeof(format), "%%%s.%d%s", width, prec, fspec); else BIO_snprintf(format, sizeof(format), "%%%s%s", width, fspec); - BIO_snprintf(result, sizeof(result), format, val); + + exp_ret = (int) strlen(fpexpected[test][sub][i]); + bio_ret = BIO_snprintf(result, sizeof(result), format, val); + std_ret = snprintf(std_result, sizeof(std_result), format, val); if (justprint) { if (i == 0) printf(" /* %d.%02d */ { \"%s\"", test, sub, result); else printf(", \"%s\"", result); - } else if (!TEST_str_eq(fpexpected[test][sub][i], result)) { - TEST_info("test %d format=|%s| exp=|%s|, ret=|%s|", - test, format, fpexpected[test][sub][i], result); - ret = 0; + } else { + if (!TEST_str_eq(fpexpected[test][sub][i], result) + + !TEST_int_eq(bio_ret, exp_ret)) { + TEST_info("test %d format=|%s| exp=|%s|, ret=|%s|" + ", stdlib_ret=|%s|", + test, format, fpexpected[test][sub][i], result, + std_result); + ret = 0; + } + + /* + * We treat the unexpected discrepancies with libc results as notable, + * but not fatal. + */ + if (!TEST_str_eq(result, std_result) + + !TEST_int_eq(bio_ret, std_ret)) { + TEST_info("test %d format=|%s| exp=|%s|, ret=|%s|" + ", stdlib_ret=|%s|", + test, format, fpexpected[test][sub][i], result, + std_result); +#if defined(OPENSSL_STRICT_LIBC_PRINTF_CHECK) + ret = 0; +#endif + } } } if (justprint)