mirror of https://github.com/openssl/openssl.git
test/bioprinttest.c: check the output against libc's one as well
Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org> Reviewed-by: Saša Nedvědický <sashan@openssl.org> Reviewed-by: Neil Horman <nhorman@openssl.org> (Merged from https://github.com/openssl/openssl/pull/28177)
This commit is contained in:
parent
f5bb94918f
commit
8d8a8aac53
|
@ -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,31 +239,58 @@ 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);
|
||||
} 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)
|
||||
printf(" },\n");
|
||||
|
|
Loading…
Reference in New Issue