1e1051a39Sopenharmony_ci/* 2e1051a39Sopenharmony_ci * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. 3e1051a39Sopenharmony_ci * 4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License"). You may not use 5e1051a39Sopenharmony_ci * this file except in compliance with the License. You can obtain a copy 6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at 7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html 8e1051a39Sopenharmony_ci */ 9e1051a39Sopenharmony_ci 10e1051a39Sopenharmony_ci#define TESTUTIL_NO_size_t_COMPARISON 11e1051a39Sopenharmony_ci 12e1051a39Sopenharmony_ci#include <stdio.h> 13e1051a39Sopenharmony_ci#include <string.h> 14e1051a39Sopenharmony_ci#include <openssl/bio.h> 15e1051a39Sopenharmony_ci#include "internal/numbers.h" 16e1051a39Sopenharmony_ci#include "testutil.h" 17e1051a39Sopenharmony_ci#include "testutil/output.h" 18e1051a39Sopenharmony_ci 19e1051a39Sopenharmony_ci#define nelem(x) (int)(sizeof(x) / sizeof((x)[0])) 20e1051a39Sopenharmony_ci 21e1051a39Sopenharmony_cistatic int justprint = 0; 22e1051a39Sopenharmony_ci 23e1051a39Sopenharmony_cistatic char *fpexpected[][10][5] = { 24e1051a39Sopenharmony_ci { 25e1051a39Sopenharmony_ci /* 00 */ { "0.0000e+00", "0.0000", "0", "0.0000E+00", "0" }, 26e1051a39Sopenharmony_ci /* 01 */ { "6.7000e-01", "0.6700", "0.67", "6.7000E-01", "0.67" }, 27e1051a39Sopenharmony_ci /* 02 */ { "6.6667e-01", "0.6667", "0.6667", "6.6667E-01", "0.6667" }, 28e1051a39Sopenharmony_ci /* 03 */ { "6.6667e-04", "0.0007", "0.0006667", "6.6667E-04", "0.0006667" }, 29e1051a39Sopenharmony_ci /* 04 */ { "6.6667e-05", "0.0001", "6.667e-05", "6.6667E-05", "6.667E-05" }, 30e1051a39Sopenharmony_ci /* 05 */ { "6.6667e+00", "6.6667", "6.667", "6.6667E+00", "6.667" }, 31e1051a39Sopenharmony_ci /* 06 */ { "6.6667e+01", "66.6667", "66.67", "6.6667E+01", "66.67" }, 32e1051a39Sopenharmony_ci /* 07 */ { "6.6667e+02", "666.6667", "666.7", "6.6667E+02", "666.7" }, 33e1051a39Sopenharmony_ci /* 08 */ { "6.6667e+03", "6666.6667", "6667", "6.6667E+03", "6667" }, 34e1051a39Sopenharmony_ci /* 09 */ { "6.6667e+04", "66666.6667", "6.667e+04", "6.6667E+04", "6.667E+04" }, 35e1051a39Sopenharmony_ci }, 36e1051a39Sopenharmony_ci { 37e1051a39Sopenharmony_ci /* 10 */ { "0.00000e+00", "0.00000", "0", "0.00000E+00", "0" }, 38e1051a39Sopenharmony_ci /* 11 */ { "6.70000e-01", "0.67000", "0.67", "6.70000E-01", "0.67" }, 39e1051a39Sopenharmony_ci /* 12 */ { "6.66667e-01", "0.66667", "0.66667", "6.66667E-01", "0.66667" }, 40e1051a39Sopenharmony_ci /* 13 */ { "6.66667e-04", "0.00067", "0.00066667", "6.66667E-04", "0.00066667" }, 41e1051a39Sopenharmony_ci /* 14 */ { "6.66667e-05", "0.00007", "6.6667e-05", "6.66667E-05", "6.6667E-05" }, 42e1051a39Sopenharmony_ci /* 15 */ { "6.66667e+00", "6.66667", "6.6667", "6.66667E+00", "6.6667" }, 43e1051a39Sopenharmony_ci /* 16 */ { "6.66667e+01", "66.66667", "66.667", "6.66667E+01", "66.667" }, 44e1051a39Sopenharmony_ci /* 17 */ { "6.66667e+02", "666.66667", "666.67", "6.66667E+02", "666.67" }, 45e1051a39Sopenharmony_ci /* 18 */ { "6.66667e+03", "6666.66667", "6666.7", "6.66667E+03", "6666.7" }, 46e1051a39Sopenharmony_ci /* 19 */ { "6.66667e+04", "66666.66667", "66667", "6.66667E+04", "66667" }, 47e1051a39Sopenharmony_ci }, 48e1051a39Sopenharmony_ci { 49e1051a39Sopenharmony_ci /* 20 */ { " 0.0000e+00", " 0.0000", " 0", " 0.0000E+00", " 0" }, 50e1051a39Sopenharmony_ci /* 21 */ { " 6.7000e-01", " 0.6700", " 0.67", " 6.7000E-01", " 0.67" }, 51e1051a39Sopenharmony_ci /* 22 */ { " 6.6667e-01", " 0.6667", " 0.6667", " 6.6667E-01", " 0.6667" }, 52e1051a39Sopenharmony_ci /* 23 */ { " 6.6667e-04", " 0.0007", " 0.0006667", " 6.6667E-04", " 0.0006667" }, 53e1051a39Sopenharmony_ci /* 24 */ { " 6.6667e-05", " 0.0001", " 6.667e-05", " 6.6667E-05", " 6.667E-05" }, 54e1051a39Sopenharmony_ci /* 25 */ { " 6.6667e+00", " 6.6667", " 6.667", " 6.6667E+00", " 6.667" }, 55e1051a39Sopenharmony_ci /* 26 */ { " 6.6667e+01", " 66.6667", " 66.67", " 6.6667E+01", " 66.67" }, 56e1051a39Sopenharmony_ci /* 27 */ { " 6.6667e+02", " 666.6667", " 666.7", " 6.6667E+02", " 666.7" }, 57e1051a39Sopenharmony_ci /* 28 */ { " 6.6667e+03", " 6666.6667", " 6667", " 6.6667E+03", " 6667" }, 58e1051a39Sopenharmony_ci /* 29 */ { " 6.6667e+04", " 66666.6667", " 6.667e+04", " 6.6667E+04", " 6.667E+04" }, 59e1051a39Sopenharmony_ci }, 60e1051a39Sopenharmony_ci { 61e1051a39Sopenharmony_ci /* 30 */ { " 0.00000e+00", " 0.00000", " 0", " 0.00000E+00", " 0" }, 62e1051a39Sopenharmony_ci /* 31 */ { " 6.70000e-01", " 0.67000", " 0.67", " 6.70000E-01", " 0.67" }, 63e1051a39Sopenharmony_ci /* 32 */ { " 6.66667e-01", " 0.66667", " 0.66667", " 6.66667E-01", " 0.66667" }, 64e1051a39Sopenharmony_ci /* 33 */ { " 6.66667e-04", " 0.00067", " 0.00066667", " 6.66667E-04", " 0.00066667" }, 65e1051a39Sopenharmony_ci /* 34 */ { " 6.66667e-05", " 0.00007", " 6.6667e-05", " 6.66667E-05", " 6.6667E-05" }, 66e1051a39Sopenharmony_ci /* 35 */ { " 6.66667e+00", " 6.66667", " 6.6667", " 6.66667E+00", " 6.6667" }, 67e1051a39Sopenharmony_ci /* 36 */ { " 6.66667e+01", " 66.66667", " 66.667", " 6.66667E+01", " 66.667" }, 68e1051a39Sopenharmony_ci /* 37 */ { " 6.66667e+02", " 666.66667", " 666.67", " 6.66667E+02", " 666.67" }, 69e1051a39Sopenharmony_ci /* 38 */ { " 6.66667e+03", " 6666.66667", " 6666.7", " 6.66667E+03", " 6666.7" }, 70e1051a39Sopenharmony_ci /* 39 */ { " 6.66667e+04", " 66666.66667", " 66667", " 6.66667E+04", " 66667" }, 71e1051a39Sopenharmony_ci }, 72e1051a39Sopenharmony_ci { 73e1051a39Sopenharmony_ci /* 40 */ { "0e+00", "0", "0", "0E+00", "0" }, 74e1051a39Sopenharmony_ci /* 41 */ { "7e-01", "1", "0.7", "7E-01", "0.7" }, 75e1051a39Sopenharmony_ci /* 42 */ { "7e-01", "1", "0.7", "7E-01", "0.7" }, 76e1051a39Sopenharmony_ci /* 43 */ { "7e-04", "0", "0.0007", "7E-04", "0.0007" }, 77e1051a39Sopenharmony_ci /* 44 */ { "7e-05", "0", "7e-05", "7E-05", "7E-05" }, 78e1051a39Sopenharmony_ci /* 45 */ { "7e+00", "7", "7", "7E+00", "7" }, 79e1051a39Sopenharmony_ci /* 46 */ { "7e+01", "67", "7e+01", "7E+01", "7E+01" }, 80e1051a39Sopenharmony_ci /* 47 */ { "7e+02", "667", "7e+02", "7E+02", "7E+02" }, 81e1051a39Sopenharmony_ci /* 48 */ { "7e+03", "6667", "7e+03", "7E+03", "7E+03" }, 82e1051a39Sopenharmony_ci /* 49 */ { "7e+04", "66667", "7e+04", "7E+04", "7E+04" }, 83e1051a39Sopenharmony_ci }, 84e1051a39Sopenharmony_ci { 85e1051a39Sopenharmony_ci /* 50 */ { "0.000000e+00", "0.000000", "0", "0.000000E+00", "0" }, 86e1051a39Sopenharmony_ci /* 51 */ { "6.700000e-01", "0.670000", "0.67", "6.700000E-01", "0.67" }, 87e1051a39Sopenharmony_ci /* 52 */ { "6.666667e-01", "0.666667", "0.666667", "6.666667E-01", "0.666667" }, 88e1051a39Sopenharmony_ci /* 53 */ { "6.666667e-04", "0.000667", "0.000666667", "6.666667E-04", "0.000666667" }, 89e1051a39Sopenharmony_ci /* 54 */ { "6.666667e-05", "0.000067", "6.66667e-05", "6.666667E-05", "6.66667E-05" }, 90e1051a39Sopenharmony_ci /* 55 */ { "6.666667e+00", "6.666667", "6.66667", "6.666667E+00", "6.66667" }, 91e1051a39Sopenharmony_ci /* 56 */ { "6.666667e+01", "66.666667", "66.6667", "6.666667E+01", "66.6667" }, 92e1051a39Sopenharmony_ci /* 57 */ { "6.666667e+02", "666.666667", "666.667", "6.666667E+02", "666.667" }, 93e1051a39Sopenharmony_ci /* 58 */ { "6.666667e+03", "6666.666667", "6666.67", "6.666667E+03", "6666.67" }, 94e1051a39Sopenharmony_ci /* 59 */ { "6.666667e+04", "66666.666667", "66666.7", "6.666667E+04", "66666.7" }, 95e1051a39Sopenharmony_ci }, 96e1051a39Sopenharmony_ci { 97e1051a39Sopenharmony_ci /* 60 */ { "0.0000e+00", "000.0000", "00000000", "0.0000E+00", "00000000" }, 98e1051a39Sopenharmony_ci /* 61 */ { "6.7000e-01", "000.6700", "00000.67", "6.7000E-01", "00000.67" }, 99e1051a39Sopenharmony_ci /* 62 */ { "6.6667e-01", "000.6667", "000.6667", "6.6667E-01", "000.6667" }, 100e1051a39Sopenharmony_ci /* 63 */ { "6.6667e-04", "000.0007", "0.0006667", "6.6667E-04", "0.0006667" }, 101e1051a39Sopenharmony_ci /* 64 */ { "6.6667e-05", "000.0001", "6.667e-05", "6.6667E-05", "6.667E-05" }, 102e1051a39Sopenharmony_ci /* 65 */ { "6.6667e+00", "006.6667", "0006.667", "6.6667E+00", "0006.667" }, 103e1051a39Sopenharmony_ci /* 66 */ { "6.6667e+01", "066.6667", "00066.67", "6.6667E+01", "00066.67" }, 104e1051a39Sopenharmony_ci /* 67 */ { "6.6667e+02", "666.6667", "000666.7", "6.6667E+02", "000666.7" }, 105e1051a39Sopenharmony_ci /* 68 */ { "6.6667e+03", "6666.6667", "00006667", "6.6667E+03", "00006667" }, 106e1051a39Sopenharmony_ci /* 69 */ { "6.6667e+04", "66666.6667", "6.667e+04", "6.6667E+04", "6.667E+04" }, 107e1051a39Sopenharmony_ci }, 108e1051a39Sopenharmony_ci}; 109e1051a39Sopenharmony_ci 110e1051a39Sopenharmony_citypedef struct z_data_st { 111e1051a39Sopenharmony_ci size_t value; 112e1051a39Sopenharmony_ci const char *format; 113e1051a39Sopenharmony_ci const char *expected; 114e1051a39Sopenharmony_ci} z_data; 115e1051a39Sopenharmony_ci 116e1051a39Sopenharmony_cistatic z_data zu_data[] = { 117e1051a39Sopenharmony_ci { SIZE_MAX, "%zu", (sizeof(size_t) == 4 ? "4294967295" 118e1051a39Sopenharmony_ci : sizeof(size_t) == 8 ? "18446744073709551615" 119e1051a39Sopenharmony_ci : "") }, 120e1051a39Sopenharmony_ci /* 121e1051a39Sopenharmony_ci * in 2-complement, the unsigned number divided by two plus one becomes the 122e1051a39Sopenharmony_ci * smallest possible negative signed number of the corresponding type 123e1051a39Sopenharmony_ci */ 124e1051a39Sopenharmony_ci { SIZE_MAX / 2 + 1, "%zi", (sizeof(size_t) == 4 ? "-2147483648" 125e1051a39Sopenharmony_ci : sizeof(size_t) == 8 ? "-9223372036854775808" 126e1051a39Sopenharmony_ci : "") }, 127e1051a39Sopenharmony_ci { 0, "%zu", "0" }, 128e1051a39Sopenharmony_ci { 0, "%zi", "0" }, 129e1051a39Sopenharmony_ci}; 130e1051a39Sopenharmony_ci 131e1051a39Sopenharmony_cistatic int test_zu(int i) 132e1051a39Sopenharmony_ci{ 133e1051a39Sopenharmony_ci char bio_buf[80]; 134e1051a39Sopenharmony_ci const z_data *data = &zu_data[i]; 135e1051a39Sopenharmony_ci 136e1051a39Sopenharmony_ci BIO_snprintf(bio_buf, sizeof(bio_buf) - 1, data->format, data->value); 137e1051a39Sopenharmony_ci if (!TEST_str_eq(bio_buf, data->expected)) 138e1051a39Sopenharmony_ci return 0; 139e1051a39Sopenharmony_ci return 1; 140e1051a39Sopenharmony_ci} 141e1051a39Sopenharmony_ci 142e1051a39Sopenharmony_citypedef struct j_data_st { 143e1051a39Sopenharmony_ci uint64_t value; 144e1051a39Sopenharmony_ci const char *format; 145e1051a39Sopenharmony_ci const char *expected; 146e1051a39Sopenharmony_ci} j_data; 147e1051a39Sopenharmony_ci 148e1051a39Sopenharmony_cistatic j_data jf_data[] = { 149e1051a39Sopenharmony_ci { 0xffffffffffffffffULL, "%ju", "18446744073709551615" }, 150e1051a39Sopenharmony_ci { 0xffffffffffffffffULL, "%jx", "ffffffffffffffff" }, 151e1051a39Sopenharmony_ci { 0x8000000000000000ULL, "%ju", "9223372036854775808" }, 152e1051a39Sopenharmony_ci /* 153e1051a39Sopenharmony_ci * These tests imply two's-complement, but it's the only binary 154e1051a39Sopenharmony_ci * representation we support, see test/sanitytest.c... 155e1051a39Sopenharmony_ci */ 156e1051a39Sopenharmony_ci { 0x8000000000000000ULL, "%ji", "-9223372036854775808" }, 157e1051a39Sopenharmony_ci}; 158e1051a39Sopenharmony_ci 159e1051a39Sopenharmony_cistatic int test_j(int i) 160e1051a39Sopenharmony_ci{ 161e1051a39Sopenharmony_ci const j_data *data = &jf_data[i]; 162e1051a39Sopenharmony_ci char bio_buf[80]; 163e1051a39Sopenharmony_ci 164e1051a39Sopenharmony_ci BIO_snprintf(bio_buf, sizeof(bio_buf) - 1, data->format, data->value); 165e1051a39Sopenharmony_ci if (!TEST_str_eq(bio_buf, data->expected)) 166e1051a39Sopenharmony_ci return 0; 167e1051a39Sopenharmony_ci return 1; 168e1051a39Sopenharmony_ci} 169e1051a39Sopenharmony_ci 170e1051a39Sopenharmony_ci 171e1051a39Sopenharmony_ci/* Precision and width. */ 172e1051a39Sopenharmony_citypedef struct pw_st { 173e1051a39Sopenharmony_ci int p; 174e1051a39Sopenharmony_ci const char *w; 175e1051a39Sopenharmony_ci} pw; 176e1051a39Sopenharmony_ci 177e1051a39Sopenharmony_cistatic pw pw_params[] = { 178e1051a39Sopenharmony_ci { 4, "" }, 179e1051a39Sopenharmony_ci { 5, "" }, 180e1051a39Sopenharmony_ci { 4, "12" }, 181e1051a39Sopenharmony_ci { 5, "12" }, 182e1051a39Sopenharmony_ci { 0, "" }, 183e1051a39Sopenharmony_ci { -1, "" }, 184e1051a39Sopenharmony_ci { 4, "08" } 185e1051a39Sopenharmony_ci}; 186e1051a39Sopenharmony_ci 187e1051a39Sopenharmony_cistatic int dofptest(int test, int sub, double val, const char *width, int prec) 188e1051a39Sopenharmony_ci{ 189e1051a39Sopenharmony_ci static const char *fspecs[] = { 190e1051a39Sopenharmony_ci "e", "f", "g", "E", "G" 191e1051a39Sopenharmony_ci }; 192e1051a39Sopenharmony_ci char format[80], result[80]; 193e1051a39Sopenharmony_ci int ret = 1, i; 194e1051a39Sopenharmony_ci 195e1051a39Sopenharmony_ci for (i = 0; i < nelem(fspecs); i++) { 196e1051a39Sopenharmony_ci const char *fspec = fspecs[i]; 197e1051a39Sopenharmony_ci 198e1051a39Sopenharmony_ci if (prec >= 0) 199e1051a39Sopenharmony_ci BIO_snprintf(format, sizeof(format), "%%%s.%d%s", width, prec, 200e1051a39Sopenharmony_ci fspec); 201e1051a39Sopenharmony_ci else 202e1051a39Sopenharmony_ci BIO_snprintf(format, sizeof(format), "%%%s%s", width, fspec); 203e1051a39Sopenharmony_ci BIO_snprintf(result, sizeof(result), format, val); 204e1051a39Sopenharmony_ci 205e1051a39Sopenharmony_ci if (justprint) { 206e1051a39Sopenharmony_ci if (i == 0) 207e1051a39Sopenharmony_ci printf(" /* %d%d */ { \"%s\"", test, sub, result); 208e1051a39Sopenharmony_ci else 209e1051a39Sopenharmony_ci printf(", \"%s\"", result); 210e1051a39Sopenharmony_ci } else if (!TEST_str_eq(fpexpected[test][sub][i], result)) { 211e1051a39Sopenharmony_ci TEST_info("test %d format=|%s| exp=|%s|, ret=|%s|", 212e1051a39Sopenharmony_ci test, format, fpexpected[test][sub][i], result); 213e1051a39Sopenharmony_ci ret = 0; 214e1051a39Sopenharmony_ci } 215e1051a39Sopenharmony_ci } 216e1051a39Sopenharmony_ci if (justprint) 217e1051a39Sopenharmony_ci printf(" },\n"); 218e1051a39Sopenharmony_ci return ret; 219e1051a39Sopenharmony_ci} 220e1051a39Sopenharmony_ci 221e1051a39Sopenharmony_cistatic int test_fp(int i) 222e1051a39Sopenharmony_ci{ 223e1051a39Sopenharmony_ci int t = 0, r; 224e1051a39Sopenharmony_ci const double frac = 2.0 / 3.0; 225e1051a39Sopenharmony_ci const pw *pwp = &pw_params[i]; 226e1051a39Sopenharmony_ci 227e1051a39Sopenharmony_ci if (justprint) 228e1051a39Sopenharmony_ci printf(" {\n"); 229e1051a39Sopenharmony_ci r = TEST_true(dofptest(i, t++, 0.0, pwp->w, pwp->p)) 230e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, 0.67, pwp->w, pwp->p)) 231e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, frac, pwp->w, pwp->p)) 232e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, frac / 1000, pwp->w, pwp->p)) 233e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, frac / 10000, pwp->w, pwp->p)) 234e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, 6.0 + frac, pwp->w, pwp->p)) 235e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, 66.0 + frac, pwp->w, pwp->p)) 236e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, 666.0 + frac, pwp->w, pwp->p)) 237e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, 6666.0 + frac, pwp->w, pwp->p)) 238e1051a39Sopenharmony_ci && TEST_true(dofptest(i, t++, 66666.0 + frac, pwp->w, pwp->p)); 239e1051a39Sopenharmony_ci if (justprint) 240e1051a39Sopenharmony_ci printf(" },\n"); 241e1051a39Sopenharmony_ci return r; 242e1051a39Sopenharmony_ci} 243e1051a39Sopenharmony_ci 244e1051a39Sopenharmony_cistatic int test_big(void) 245e1051a39Sopenharmony_ci{ 246e1051a39Sopenharmony_ci char buf[80]; 247e1051a39Sopenharmony_ci 248e1051a39Sopenharmony_ci /* Test excessively big number. Should fail */ 249e1051a39Sopenharmony_ci if (!TEST_int_eq(BIO_snprintf(buf, sizeof(buf), 250e1051a39Sopenharmony_ci "%f\n", 2 * (double)ULONG_MAX), -1)) 251e1051a39Sopenharmony_ci return 0; 252e1051a39Sopenharmony_ci 253e1051a39Sopenharmony_ci return 1; 254e1051a39Sopenharmony_ci} 255e1051a39Sopenharmony_ci 256e1051a39Sopenharmony_citypedef enum OPTION_choice { 257e1051a39Sopenharmony_ci OPT_ERR = -1, 258e1051a39Sopenharmony_ci OPT_EOF = 0, 259e1051a39Sopenharmony_ci OPT_PRINT, 260e1051a39Sopenharmony_ci OPT_TEST_ENUM 261e1051a39Sopenharmony_ci} OPTION_CHOICE; 262e1051a39Sopenharmony_ci 263e1051a39Sopenharmony_ciconst OPTIONS *test_get_options(void) 264e1051a39Sopenharmony_ci{ 265e1051a39Sopenharmony_ci static const OPTIONS options[] = { 266e1051a39Sopenharmony_ci OPT_TEST_OPTIONS_DEFAULT_USAGE, 267e1051a39Sopenharmony_ci { "expected", OPT_PRINT, '-', "Output values" }, 268e1051a39Sopenharmony_ci { NULL } 269e1051a39Sopenharmony_ci }; 270e1051a39Sopenharmony_ci return options; 271e1051a39Sopenharmony_ci} 272e1051a39Sopenharmony_ci 273e1051a39Sopenharmony_ciint setup_tests(void) 274e1051a39Sopenharmony_ci{ 275e1051a39Sopenharmony_ci OPTION_CHOICE o; 276e1051a39Sopenharmony_ci 277e1051a39Sopenharmony_ci while ((o = opt_next()) != OPT_EOF) { 278e1051a39Sopenharmony_ci switch (o) { 279e1051a39Sopenharmony_ci case OPT_PRINT: 280e1051a39Sopenharmony_ci justprint = 1; 281e1051a39Sopenharmony_ci break; 282e1051a39Sopenharmony_ci case OPT_TEST_CASES: 283e1051a39Sopenharmony_ci break; 284e1051a39Sopenharmony_ci default: 285e1051a39Sopenharmony_ci return 0; 286e1051a39Sopenharmony_ci } 287e1051a39Sopenharmony_ci } 288e1051a39Sopenharmony_ci 289e1051a39Sopenharmony_ci ADD_TEST(test_big); 290e1051a39Sopenharmony_ci ADD_ALL_TESTS(test_fp, nelem(pw_params)); 291e1051a39Sopenharmony_ci ADD_ALL_TESTS(test_zu, nelem(zu_data)); 292e1051a39Sopenharmony_ci ADD_ALL_TESTS(test_j, nelem(jf_data)); 293e1051a39Sopenharmony_ci return 1; 294e1051a39Sopenharmony_ci} 295e1051a39Sopenharmony_ci 296e1051a39Sopenharmony_ci/* 297e1051a39Sopenharmony_ci * Replace testutil output routines. We do this to eliminate possible sources 298e1051a39Sopenharmony_ci * of BIO error 299e1051a39Sopenharmony_ci */ 300e1051a39Sopenharmony_ciBIO *bio_out = NULL; 301e1051a39Sopenharmony_ciBIO *bio_err = NULL; 302e1051a39Sopenharmony_ci 303e1051a39Sopenharmony_cistatic int tap_level = 0; 304e1051a39Sopenharmony_ci 305e1051a39Sopenharmony_civoid test_open_streams(void) 306e1051a39Sopenharmony_ci{ 307e1051a39Sopenharmony_ci} 308e1051a39Sopenharmony_ci 309e1051a39Sopenharmony_civoid test_adjust_streams_tap_level(int level) 310e1051a39Sopenharmony_ci{ 311e1051a39Sopenharmony_ci tap_level = level; 312e1051a39Sopenharmony_ci} 313e1051a39Sopenharmony_ci 314e1051a39Sopenharmony_civoid test_close_streams(void) 315e1051a39Sopenharmony_ci{ 316e1051a39Sopenharmony_ci} 317e1051a39Sopenharmony_ci 318e1051a39Sopenharmony_ci/* 319e1051a39Sopenharmony_ci * This works out as long as caller doesn't use any "fancy" formats. 320e1051a39Sopenharmony_ci * But we are caller's caller, and test_str_eq is the only one called, 321e1051a39Sopenharmony_ci * and it uses only "%s", which is not "fancy"... 322e1051a39Sopenharmony_ci */ 323e1051a39Sopenharmony_ciint test_vprintf_stdout(const char *fmt, va_list ap) 324e1051a39Sopenharmony_ci{ 325e1051a39Sopenharmony_ci return fprintf(stdout, "%*s# ", tap_level, "") + vfprintf(stdout, fmt, ap); 326e1051a39Sopenharmony_ci} 327e1051a39Sopenharmony_ci 328e1051a39Sopenharmony_ciint test_vprintf_stderr(const char *fmt, va_list ap) 329e1051a39Sopenharmony_ci{ 330e1051a39Sopenharmony_ci return fprintf(stderr, "%*s# ", tap_level, "") + vfprintf(stderr, fmt, ap); 331e1051a39Sopenharmony_ci} 332e1051a39Sopenharmony_ci 333e1051a39Sopenharmony_ciint test_flush_stdout(void) 334e1051a39Sopenharmony_ci{ 335e1051a39Sopenharmony_ci return fflush(stdout); 336e1051a39Sopenharmony_ci} 337e1051a39Sopenharmony_ci 338e1051a39Sopenharmony_ciint test_flush_stderr(void) 339e1051a39Sopenharmony_ci{ 340e1051a39Sopenharmony_ci return fflush(stderr); 341e1051a39Sopenharmony_ci} 342e1051a39Sopenharmony_ci 343e1051a39Sopenharmony_ciint test_vprintf_tapout(const char *fmt, va_list ap) 344e1051a39Sopenharmony_ci{ 345e1051a39Sopenharmony_ci return fprintf(stdout, "%*s", tap_level, "") + vfprintf(stdout, fmt, ap); 346e1051a39Sopenharmony_ci} 347e1051a39Sopenharmony_ci 348e1051a39Sopenharmony_ciint test_vprintf_taperr(const char *fmt, va_list ap) 349e1051a39Sopenharmony_ci{ 350e1051a39Sopenharmony_ci return fprintf(stderr, "%*s", tap_level, "") + vfprintf(stderr, fmt, ap); 351e1051a39Sopenharmony_ci} 352e1051a39Sopenharmony_ci 353e1051a39Sopenharmony_ciint test_flush_tapout(void) 354e1051a39Sopenharmony_ci{ 355e1051a39Sopenharmony_ci return fflush(stdout); 356e1051a39Sopenharmony_ci} 357e1051a39Sopenharmony_ci 358e1051a39Sopenharmony_ciint test_flush_taperr(void) 359e1051a39Sopenharmony_ci{ 360e1051a39Sopenharmony_ci return fflush(stderr); 361e1051a39Sopenharmony_ci} 362e1051a39Sopenharmony_ci 363