summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2006-02-19 22:50:20 +1100
committerDarren Tucker <dtucker@zip.com.au>2006-02-19 22:50:20 +1100
commit4881c371cef5e3c1065d7dfa314fffc3a5ab0256 (patch)
treeaad34a5efc70e601b688ae83c7ebdfd01792297d
parentbf209f590108a12a9758dcfcdf4297a3d593ce87 (diff)
- (dtucker) [Makefile.in configure.ac, added openbsd-compat/regress/]
Add first attempt at regress tests for compat library. ok djm@
-rw-r--r--ChangeLog6
-rw-r--r--Makefile.in5
-rw-r--r--configure.ac6
-rw-r--r--openbsd-compat/regress/Makefile.in39
-rw-r--r--openbsd-compat/regress/snprintftest.c72
-rw-r--r--openbsd-compat/regress/strduptest.c42
-rw-r--r--openbsd-compat/regress/strtonumtest.c66
7 files changed, 231 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index fd1d9d2b..67369376 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+20060219
+ - (dtucker) [Makefile.in configure.ac, added openbsd-compat/regress/]
+ Add first attempt at regress tests for compat library. ok djm@
+
20060214
- (tim) [buildpkg.sh.in] Make the names consistent.
s/pkg_post_make_install_fixes.sh/pkg-post-make-install-fixes.sh/ OK dtucker@
@@ -3859,4 +3863,4 @@
- (djm) Trim deprecated options from INSTALL. Mention UsePAM
- (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
-$Id: ChangeLog,v 1.4129 2006/02/13 20:46:44 tim Exp $
+$Id: ChangeLog,v 1.4130 2006/02/19 11:50:20 dtucker Exp $
diff --git a/Makefile.in b/Makefile.in
index af881c52..1baffb4d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,4 @@
-# $Id: Makefile.in,v 1.274 2006/01/01 08:47:05 djm Exp $
+# $Id: Makefile.in,v 1.275 2006/02/19 11:50:20 dtucker Exp $
# uncomment if you run a non bourne compatable shell. Ie. csh
#SHELL = @SH@
@@ -410,6 +410,9 @@ tests: $(TARGETS)
EXEEXT="$(EXEEXT)" \
$@
+compat-tests: $(LIBCOMPAT)
+ (cd openbsd-compat/regress && $(MAKE))
+
regressclean:
if [ -f regress/Makefile ] && [ -r regress/Makefile ]; then \
(cd regress && $(MAKE) clean) \
diff --git a/configure.ac b/configure.ac
index 7fcca216..c4feaf75 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
-# $Id: configure.ac,v 1.329 2006/02/12 02:37:48 tim Exp $
+# $Id: configure.ac,v 1.330 2006/02/19 11:50:20 dtucker Exp $
#
# Copyright (c) 1999-2004 Damien Miller
#
@@ -15,7 +15,7 @@
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org)
-AC_REVISION($Revision: 1.329 $)
+AC_REVISION($Revision: 1.330 $)
AC_CONFIG_SRCDIR([ssh.c])
AC_CONFIG_HEADER(config.h)
@@ -3729,7 +3729,7 @@ CFLAGS="$CFLAGS $werror_flags"
AC_EXEEXT
AC_CONFIG_FILES([Makefile buildpkg.sh opensshd.init openbsd-compat/Makefile \
- scard/Makefile ssh_prng_cmds survey.sh])
+ openbsd-compat/regress/Makefile scard/Makefile ssh_prng_cmds survey.sh])
AC_OUTPUT
# Print summary of options
diff --git a/openbsd-compat/regress/Makefile.in b/openbsd-compat/regress/Makefile.in
new file mode 100644
index 00000000..51383a77
--- /dev/null
+++ b/openbsd-compat/regress/Makefile.in
@@ -0,0 +1,39 @@
+# $Id: Makefile.in,v 1.1 2006/02/19 11:50:20 dtucker Exp $
+
+sysconfdir=@sysconfdir@
+piddir=@piddir@
+srcdir=@srcdir@
+top_srcdir=@top_srcdir@
+
+VPATH=@srcdir@
+CC=@CC@
+LD=@LD@
+CFLAGS=@CFLAGS@
+CPPFLAGS=-I. -I.. -I$(srcdir) -I$(srcdir)/.. @CPPFLAGS@ @DEFS@
+LIBS=@LIBS@
+LDFLAGS=-L.. -lopenbsd-compat @LDFLAGS@
+
+LIBCOMPAT=../libopenbsd-compat.a
+TESTPROGS=strtonumtest strduptest snprintftest
+
+all: t-exec ${OTHERTESTS}
+
+t-exec: $(TESTPROGS)
+ @echo running compat regress tests
+ @for TEST in ""$?; do \
+ echo "run test $${TEST}" ... 1>&2; \
+ ./$${TEST} || exit $$? ; \
+ done
+ @echo finished compat regress tests
+
+strtonumtest: strtonumtest.c $(LIBCOMPAT)
+ $(CC) $(CFLAGS) $(CPPFLAGS) -o strtonumtest $< $(LDFLAGS)
+
+strduptest: strduptest.c $(LIBCOMPAT)
+ $(CC) $(CFLAGS) $(CPPFLAGS) -o strduptest $< $(LDFLAGS)
+
+clean:
+ rm -f *.o *.a core $(TESTPROGS) valid.out
+
+distclean: clean
+ rm -f Makefile *~
diff --git a/openbsd-compat/regress/snprintftest.c b/openbsd-compat/regress/snprintftest.c
new file mode 100644
index 00000000..e25bf223
--- /dev/null
+++ b/openbsd-compat/regress/snprintftest.c
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2005 Darren Tucker
+ * Copyright (c) 2005 Damien Miller
+ *
+ * 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.
+ */
+
+#define BUFSZ 2048
+
+#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+
+static int failed = 0;
+
+static void
+fail(const char *m)
+{
+ fprintf(stderr, "%s", m);
+ failed = 1;
+}
+
+int x_snprintf(char *str, size_t count, const char *fmt, ...)
+{
+ size_t ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = vsnprintf(str, count, fmt, ap);
+ va_end(ap);
+ return ret;
+}
+
+int
+main(void)
+{
+ char b[5];
+ char *src;
+
+ snprintf(b,5,"123456789");
+ if (b[4] != '\0')
+ fail("snprintf does not correctly terminate long strings");
+
+ /* check for read overrun on unterminated string */
+ if ((src = malloc(BUFSZ)) == NULL) {
+ fail("malloc failed");
+ } else {
+ memset(src, 'a', BUFSZ);
+ snprintf(b, sizeof(b), "%.*s", 1, src);
+ if (strcmp(b, "a") != 0)
+ fail("failed with length limit '%%.s'");
+ }
+
+ /* check that snprintf and vsnprintf return sane values */
+ if (snprintf(b, 1, "%s %d", "hello", 12345) != 11)
+ fail("snprintf does not return required length");
+ if (x_snprintf(b, 1, "%s %d", "hello", 12345) != 11)
+ fail("vsnprintf does not return required length");
+
+ return failed;
+}
diff --git a/openbsd-compat/regress/strduptest.c b/openbsd-compat/regress/strduptest.c
new file mode 100644
index 00000000..664a48ef
--- /dev/null
+++ b/openbsd-compat/regress/strduptest.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2005 Darren Tucker
+ *
+ * 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.
+ */
+
+static int fail = 0;
+
+void
+test(const char *a)
+{
+ char *b;
+
+ b = strdup(a);
+ if (b == 0) {
+ fail = 1;
+ return;
+ }
+ if (strcmp(a, b) != 0)
+ fail = 1;
+ free(b);
+}
+
+int
+main(void)
+{
+ test("");
+ test("a");
+ test("\0");
+ test("abcdefghijklmnopqrstuvwxyz");
+ return fail;
+}
diff --git a/openbsd-compat/regress/strtonumtest.c b/openbsd-compat/regress/strtonumtest.c
new file mode 100644
index 00000000..cb858512
--- /dev/null
+++ b/openbsd-compat/regress/strtonumtest.c
@@ -0,0 +1,66 @@
+/* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */
+/*
+ * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net>
+ *
+ * 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.
+ */
+
+/* OPENBSD ORIGINAL: regress/lib/libc/strtonum/strtonumtest.c */
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int fail;
+
+void
+test(const char *p, long long lb, long long ub, int ok)
+{
+ long long val;
+ const char *q;
+
+ val = strtonum(p, lb, ub, &q);
+ if (ok && q != NULL) {
+ fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub);
+ fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q);
+ fail = 1;
+ } else if (!ok && q == NULL) {
+ fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val);
+ fprintf(stderr, "NUMBER ACCEPTED\n");
+ fail = 1;
+ }
+}
+
+int main(int argc, char *argv[])
+{
+ test("1", 0, 10, 1);
+ test("0", -2, 5, 1);
+ test("0", 2, 5, 0);
+ test("0", 2, LLONG_MAX, 0);
+ test("-2", 0, LLONG_MAX, 0);
+ test("0", -5, LLONG_MAX, 1);
+ test("-3", -3, LLONG_MAX, 1);
+ test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1);
+ test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1);
+ test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0);
+ test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0);
+ test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0);
+ test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0);
+ test("-2", 10, -1, 0);
+ test("-2", -10, -1, 1);
+ test("-20", -10, -1, 0);
+ test("20", -10, -1, 0);
+
+ return (fail);
+}
+