summaryrefslogtreecommitdiff
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 fd1d9d2ba..67369376f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
120060219
2 - (dtucker) [Makefile.in configure.ac, added openbsd-compat/regress/]
3 Add first attempt at regress tests for compat library. ok djm@
4
120060214 520060214
2 - (tim) [buildpkg.sh.in] Make the names consistent. 6 - (tim) [buildpkg.sh.in] Make the names consistent.
3 s/pkg_post_make_install_fixes.sh/pkg-post-make-install-fixes.sh/ OK dtucker@ 7 s/pkg_post_make_install_fixes.sh/pkg-post-make-install-fixes.sh/ OK dtucker@
@@ -3859,4 +3863,4 @@
3859 - (djm) Trim deprecated options from INSTALL. Mention UsePAM 3863 - (djm) Trim deprecated options from INSTALL. Mention UsePAM
3860 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu 3864 - (djm) Fix quote handling in sftp; Patch from admorten AT umich.edu
3861 3865
3862$Id: ChangeLog,v 1.4129 2006/02/13 20:46:44 tim Exp $ 3866$Id: ChangeLog,v 1.4130 2006/02/19 11:50:20 dtucker Exp $
diff --git a/Makefile.in b/Makefile.in
index af881c521..1baffb4df 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1,4 +1,4 @@
1# $Id: Makefile.in,v 1.274 2006/01/01 08:47:05 djm Exp $ 1# $Id: Makefile.in,v 1.275 2006/02/19 11:50:20 dtucker Exp $
2 2
3# uncomment if you run a non bourne compatable shell. Ie. csh 3# uncomment if you run a non bourne compatable shell. Ie. csh
4#SHELL = @SH@ 4#SHELL = @SH@
@@ -410,6 +410,9 @@ tests: $(TARGETS)
410 EXEEXT="$(EXEEXT)" \ 410 EXEEXT="$(EXEEXT)" \
411 $@ 411 $@
412 412
413compat-tests: $(LIBCOMPAT)
414 (cd openbsd-compat/regress && $(MAKE))
415
413regressclean: 416regressclean:
414 if [ -f regress/Makefile ] && [ -r regress/Makefile ]; then \ 417 if [ -f regress/Makefile ] && [ -r regress/Makefile ]; then \
415 (cd regress && $(MAKE) clean) \ 418 (cd regress && $(MAKE) clean) \
diff --git a/configure.ac b/configure.ac
index 7fcca216a..c4feaf752 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,4 +1,4 @@
1# $Id: configure.ac,v 1.329 2006/02/12 02:37:48 tim Exp $ 1# $Id: configure.ac,v 1.330 2006/02/19 11:50:20 dtucker Exp $
2# 2#
3# Copyright (c) 1999-2004 Damien Miller 3# Copyright (c) 1999-2004 Damien Miller
4# 4#
@@ -15,7 +15,7 @@
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 16
17AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org) 17AC_INIT(OpenSSH, Portable, openssh-unix-dev@mindrot.org)
18AC_REVISION($Revision: 1.329 $) 18AC_REVISION($Revision: 1.330 $)
19AC_CONFIG_SRCDIR([ssh.c]) 19AC_CONFIG_SRCDIR([ssh.c])
20 20
21AC_CONFIG_HEADER(config.h) 21AC_CONFIG_HEADER(config.h)
@@ -3729,7 +3729,7 @@ CFLAGS="$CFLAGS $werror_flags"
3729 3729
3730AC_EXEEXT 3730AC_EXEEXT
3731AC_CONFIG_FILES([Makefile buildpkg.sh opensshd.init openbsd-compat/Makefile \ 3731AC_CONFIG_FILES([Makefile buildpkg.sh opensshd.init openbsd-compat/Makefile \
3732 scard/Makefile ssh_prng_cmds survey.sh]) 3732 openbsd-compat/regress/Makefile scard/Makefile ssh_prng_cmds survey.sh])
3733AC_OUTPUT 3733AC_OUTPUT
3734 3734
3735# Print summary of options 3735# Print summary of options
diff --git a/openbsd-compat/regress/Makefile.in b/openbsd-compat/regress/Makefile.in
new file mode 100644
index 000000000..51383a777
--- /dev/null
+++ b/openbsd-compat/regress/Makefile.in
@@ -0,0 +1,39 @@
1# $Id: Makefile.in,v 1.1 2006/02/19 11:50:20 dtucker Exp $
2
3sysconfdir=@sysconfdir@
4piddir=@piddir@
5srcdir=@srcdir@
6top_srcdir=@top_srcdir@
7
8VPATH=@srcdir@
9CC=@CC@
10LD=@LD@
11CFLAGS=@CFLAGS@
12CPPFLAGS=-I. -I.. -I$(srcdir) -I$(srcdir)/.. @CPPFLAGS@ @DEFS@
13LIBS=@LIBS@
14LDFLAGS=-L.. -lopenbsd-compat @LDFLAGS@
15
16LIBCOMPAT=../libopenbsd-compat.a
17TESTPROGS=strtonumtest strduptest snprintftest
18
19all: t-exec ${OTHERTESTS}
20
21t-exec: $(TESTPROGS)
22 @echo running compat regress tests
23 @for TEST in ""$?; do \
24 echo "run test $${TEST}" ... 1>&2; \
25 ./$${TEST} || exit $$? ; \
26 done
27 @echo finished compat regress tests
28
29strtonumtest: strtonumtest.c $(LIBCOMPAT)
30 $(CC) $(CFLAGS) $(CPPFLAGS) -o strtonumtest $< $(LDFLAGS)
31
32strduptest: strduptest.c $(LIBCOMPAT)
33 $(CC) $(CFLAGS) $(CPPFLAGS) -o strduptest $< $(LDFLAGS)
34
35clean:
36 rm -f *.o *.a core $(TESTPROGS) valid.out
37
38distclean: clean
39 rm -f Makefile *~
diff --git a/openbsd-compat/regress/snprintftest.c b/openbsd-compat/regress/snprintftest.c
new file mode 100644
index 000000000..e25bf223f
--- /dev/null
+++ b/openbsd-compat/regress/snprintftest.c
@@ -0,0 +1,72 @@
1/*
2 * Copyright (c) 2005 Darren Tucker
3 * Copyright (c) 2005 Damien Miller
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#define BUFSZ 2048
19
20#include <sys/types.h>
21#include <stdlib.h>
22#include <stdio.h>
23#include <stdarg.h>
24
25static int failed = 0;
26
27static void
28fail(const char *m)
29{
30 fprintf(stderr, "%s", m);
31 failed = 1;
32}
33
34int x_snprintf(char *str, size_t count, const char *fmt, ...)
35{
36 size_t ret;
37 va_list ap;
38
39 va_start(ap, fmt);
40 ret = vsnprintf(str, count, fmt, ap);
41 va_end(ap);
42 return ret;
43}
44
45int
46main(void)
47{
48 char b[5];
49 char *src;
50
51 snprintf(b,5,"123456789");
52 if (b[4] != '\0')
53 fail("snprintf does not correctly terminate long strings");
54
55 /* check for read overrun on unterminated string */
56 if ((src = malloc(BUFSZ)) == NULL) {
57 fail("malloc failed");
58 } else {
59 memset(src, 'a', BUFSZ);
60 snprintf(b, sizeof(b), "%.*s", 1, src);
61 if (strcmp(b, "a") != 0)
62 fail("failed with length limit '%%.s'");
63 }
64
65 /* check that snprintf and vsnprintf return sane values */
66 if (snprintf(b, 1, "%s %d", "hello", 12345) != 11)
67 fail("snprintf does not return required length");
68 if (x_snprintf(b, 1, "%s %d", "hello", 12345) != 11)
69 fail("vsnprintf does not return required length");
70
71 return failed;
72}
diff --git a/openbsd-compat/regress/strduptest.c b/openbsd-compat/regress/strduptest.c
new file mode 100644
index 000000000..664a48ef4
--- /dev/null
+++ b/openbsd-compat/regress/strduptest.c
@@ -0,0 +1,42 @@
1/*
2 * Copyright (c) 2005 Darren Tucker
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17static int fail = 0;
18
19void
20test(const char *a)
21{
22 char *b;
23
24 b = strdup(a);
25 if (b == 0) {
26 fail = 1;
27 return;
28 }
29 if (strcmp(a, b) != 0)
30 fail = 1;
31 free(b);
32}
33
34int
35main(void)
36{
37 test("");
38 test("a");
39 test("\0");
40 test("abcdefghijklmnopqrstuvwxyz");
41 return fail;
42}
diff --git a/openbsd-compat/regress/strtonumtest.c b/openbsd-compat/regress/strtonumtest.c
new file mode 100644
index 000000000..cb8585129
--- /dev/null
+++ b/openbsd-compat/regress/strtonumtest.c
@@ -0,0 +1,66 @@
1/* $OpenBSD: strtonumtest.c,v 1.1 2004/08/03 20:38:36 otto Exp $ */
2/*
3 * Copyright (c) 2004 Otto Moerbeek <otto@drijf.net>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18/* OPENBSD ORIGINAL: regress/lib/libc/strtonum/strtonumtest.c */
19
20#include <limits.h>
21#include <stdio.h>
22#include <stdlib.h>
23
24int fail;
25
26void
27test(const char *p, long long lb, long long ub, int ok)
28{
29 long long val;
30 const char *q;
31
32 val = strtonum(p, lb, ub, &q);
33 if (ok && q != NULL) {
34 fprintf(stderr, "%s [%lld-%lld] ", p, lb, ub);
35 fprintf(stderr, "NUMBER NOT ACCEPTED %s\n", q);
36 fail = 1;
37 } else if (!ok && q == NULL) {
38 fprintf(stderr, "%s [%lld-%lld] %lld ", p, lb, ub, val);
39 fprintf(stderr, "NUMBER ACCEPTED\n");
40 fail = 1;
41 }
42}
43
44int main(int argc, char *argv[])
45{
46 test("1", 0, 10, 1);
47 test("0", -2, 5, 1);
48 test("0", 2, 5, 0);
49 test("0", 2, LLONG_MAX, 0);
50 test("-2", 0, LLONG_MAX, 0);
51 test("0", -5, LLONG_MAX, 1);
52 test("-3", -3, LLONG_MAX, 1);
53 test("-9223372036854775808", LLONG_MIN, LLONG_MAX, 1);
54 test("9223372036854775807", LLONG_MIN, LLONG_MAX, 1);
55 test("-9223372036854775809", LLONG_MIN, LLONG_MAX, 0);
56 test("9223372036854775808", LLONG_MIN, LLONG_MAX, 0);
57 test("1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0);
58 test("-1000000000000000000000000", LLONG_MIN, LLONG_MAX, 0);
59 test("-2", 10, -1, 0);
60 test("-2", -10, -1, 1);
61 test("-20", -10, -1, 0);
62 test("20", -10, -1, 0);
63
64 return (fail);
65}
66