From 440ff25a446d028b864136cc92f0469572b7d187 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Sun, 22 Jun 2014 14:30:52 +0000 Subject: Add a skeleton regress for crypto/bio, which currently only covers BIO_get_port() and fails since the current code believes that "-1" is a valid port. --- src/regress/lib/libcrypto/Makefile | 3 +- src/regress/lib/libcrypto/bio/Makefile | 9 ++++ src/regress/lib/libcrypto/bio/biotest.c | 83 +++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/regress/lib/libcrypto/bio/Makefile create mode 100644 src/regress/lib/libcrypto/bio/biotest.c (limited to 'src') diff --git a/src/regress/lib/libcrypto/Makefile b/src/regress/lib/libcrypto/Makefile index d9bd92f637..19cb9ab4ad 100644 --- a/src/regress/lib/libcrypto/Makefile +++ b/src/regress/lib/libcrypto/Makefile @@ -1,10 +1,11 @@ -# $OpenBSD: Makefile,v 1.13 2014/06/22 14:28:07 jsing Exp $ +# $OpenBSD: Makefile,v 1.14 2014/06/22 14:30:52 jsing Exp $ SUBDIR= \ aead \ aeswrap \ base64 \ bf \ + bio \ bn \ cast \ chacha \ diff --git a/src/regress/lib/libcrypto/bio/Makefile b/src/regress/lib/libcrypto/bio/Makefile new file mode 100644 index 0000000000..9955cd4b8f --- /dev/null +++ b/src/regress/lib/libcrypto/bio/Makefile @@ -0,0 +1,9 @@ +# $OpenBSD: Makefile,v 1.1 2014/06/22 14:30:52 jsing Exp $ + +PROG= biotest +LDADD= -lcrypto +DPADD= ${LIBCRYPTO} +WARNINGS= Yes +CFLAGS+= -Werror + +.include diff --git a/src/regress/lib/libcrypto/bio/biotest.c b/src/regress/lib/libcrypto/bio/biotest.c new file mode 100644 index 0000000000..3639cb1f36 --- /dev/null +++ b/src/regress/lib/libcrypto/bio/biotest.c @@ -0,0 +1,83 @@ +/* $OpenBSD: biotest.c,v 1.1 2014/06/22 14:30:52 jsing Exp $ */ +/* + * Copyright (c) 2014 Joel Sing + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include +#include + +struct bio_get_port_test { + char *input; + unsigned short port; + int ret; +}; + +struct bio_get_port_test bio_get_port_tests[] = { + {NULL, 0, 0}, + {"", 0, 0}, + {"-1", 0, 0}, + {"0", 0, 1}, + {"1", 1, 1}, + {"12345", 12345, 1}, + {"65535", 65535, 1}, + {"65536", 0, 0}, + {"999999999999", 0, 0}, + {"xyzzy", 0, 0}, + {"https", 443, 1}, + {"imaps", 993, 1}, + {"telnet", 23, 1}, +}; + +#define N_BIO_GET_PORT_TESTS \ + (sizeof(bio_get_port_tests) / sizeof(*bio_get_port_tests)) + +static int +do_bio_get_port_tests(void) +{ + struct bio_get_port_test *bgpt; + unsigned short port; + int failed = 0; + size_t i; + int ret; + + for (i = 0; i < N_BIO_GET_PORT_TESTS; i++) { + bgpt = &bio_get_port_tests[i]; + port = 0; + + ret = BIO_get_port(bgpt->input, &port); + if (ret != bgpt->ret) { + fprintf(stderr, "FAIL: test %zi (\"%s\") %s, want %s\n", + i, bgpt->input, ret ? "success" : "failure", + bgpt->ret ? "success" : "failure"); + failed = 1; + continue; + } + if (ret && port != bgpt->port) { + fprintf(stderr, "FAIL: test %zi (\"%s\") returned port " + "%u != %u\n", i, bgpt->input, port, bgpt->port); + failed = 1; + } + } + + return failed; +} + +int +main(int argc, char **argv) +{ + return do_bio_get_port_tests(); +} -- cgit v1.2.3-55-g6feb