diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/bio/biotest.c | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/bio/biotest.c b/src/regress/lib/libcrypto/bio/biotest.c index 442c64e93b..d31e51e454 100644 --- a/src/regress/lib/libcrypto/bio/biotest.c +++ b/src/regress/lib/libcrypto/bio/biotest.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: biotest.c,v 1.7 2022/02/17 18:51:58 jsing Exp $ */ | 1 | /* $OpenBSD: biotest.c,v 1.8 2022/02/19 16:00:57 jsing Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014, 2022 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014, 2022 Joel Sing <jsing@openbsd.org> |
| 4 | * | 4 | * |
| @@ -274,6 +274,76 @@ bio_mem_test(void) | |||
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | static int | 276 | static int |
| 277 | bio_mem_small_io_test(void) | ||
| 278 | { | ||
| 279 | uint8_t buf[2]; | ||
| 280 | int i, j, ret; | ||
| 281 | BIO *bio; | ||
| 282 | int failed = 1; | ||
| 283 | |||
| 284 | memset(buf, 0xdb, sizeof(buf)); | ||
| 285 | |||
| 286 | if ((bio = BIO_new(BIO_s_mem())) == NULL) { | ||
| 287 | fprintf(stderr, "FAIL: BIO_new() returned NULL\n"); | ||
| 288 | goto failure; | ||
| 289 | } | ||
| 290 | |||
| 291 | for (i = 0; i < 100; i++) { | ||
| 292 | if (!BIO_reset(bio)) { | ||
| 293 | fprintf(stderr, "FAIL: BIO_reset() failed\n"); | ||
| 294 | goto failure; | ||
| 295 | } | ||
| 296 | for (j = 0; j < 25000; j++) { | ||
| 297 | ret = BIO_write(bio, buf, sizeof(buf)); | ||
| 298 | if (ret != sizeof(buf)) { | ||
| 299 | fprintf(stderr, "FAIL: BIO_write() = %d, " | ||
| 300 | "want %zu\n", ret, sizeof(buf)); | ||
| 301 | goto failure; | ||
| 302 | } | ||
| 303 | } | ||
| 304 | for (j = 0; j < 25000; j++) { | ||
| 305 | ret = BIO_read(bio, buf, sizeof(buf)); | ||
| 306 | if (ret != sizeof(buf)) { | ||
| 307 | fprintf(stderr, "FAIL: BIO_read() = %d, " | ||
| 308 | "want %zu\n", ret, sizeof(buf)); | ||
| 309 | goto failure; | ||
| 310 | } | ||
| 311 | ret = BIO_write(bio, buf, sizeof(buf)); | ||
| 312 | if (ret != sizeof(buf)) { | ||
| 313 | fprintf(stderr, "FAIL: BIO_write() = %d, " | ||
| 314 | "want %zu\n", ret, sizeof(buf)); | ||
| 315 | goto failure; | ||
| 316 | } | ||
| 317 | } | ||
| 318 | for (j = 0; j < 25000; j++) { | ||
| 319 | ret = BIO_read(bio, buf, sizeof(buf)); | ||
| 320 | if (ret != sizeof(buf)) { | ||
| 321 | fprintf(stderr, "FAIL: BIO_read() = %d, " | ||
| 322 | "want %zu\n", ret, sizeof(buf)); | ||
| 323 | goto failure; | ||
| 324 | } | ||
| 325 | } | ||
| 326 | if (!BIO_eof(bio)) { | ||
| 327 | fprintf(stderr, "FAIL: BIO not EOF\n"); | ||
| 328 | goto failure; | ||
| 329 | } | ||
| 330 | } | ||
| 331 | |||
| 332 | if (buf[0] != 0xdb || buf[1] != 0xdb) { | ||
| 333 | fprintf(stderr, "FAIL: buf = {0x%x, 0x%x}, want {0xdb, 0xdb}\n", | ||
| 334 | buf[0], buf[1]); | ||
| 335 | goto failure; | ||
| 336 | } | ||
| 337 | |||
| 338 | failed = 0; | ||
| 339 | |||
| 340 | failure: | ||
| 341 | BIO_free(bio); | ||
| 342 | |||
| 343 | return failed; | ||
| 344 | } | ||
| 345 | |||
| 346 | static int | ||
| 277 | bio_mem_readonly_test(void) | 347 | bio_mem_readonly_test(void) |
| 278 | { | 348 | { |
| 279 | uint8_t *data = NULL; | 349 | uint8_t *data = NULL; |
| @@ -389,6 +459,7 @@ do_bio_mem_tests(void) | |||
| 389 | int failed = 0; | 459 | int failed = 0; |
| 390 | 460 | ||
| 391 | failed |= bio_mem_test(); | 461 | failed |= bio_mem_test(); |
| 462 | failed |= bio_mem_small_io_test(); | ||
| 392 | failed |= bio_mem_readonly_test(); | 463 | failed |= bio_mem_readonly_test(); |
| 393 | 464 | ||
| 394 | return failed; | 465 | return failed; |
