summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2008-10-01 23:04:37 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2008-10-01 23:04:37 +0000
commit442e27cc541945204777251780922d4ee1e46708 (patch)
treec5d29cecff0b796385ae2e4f3e5e91338335f36c /regress
parent3e694e55a5d271b025e26e1fb8815dc686bf0816 (diff)
Regress driver for glob(3). Needs more tests.
Diffstat (limited to 'regress')
-rw-r--r--regress/lib/libc/glob/Makefile13
-rw-r--r--regress/lib/libc/glob/files47
-rw-r--r--regress/lib/libc/glob/globtest.c123
-rw-r--r--regress/lib/libc/glob/globtest.in61
4 files changed, 244 insertions, 0 deletions
diff --git a/regress/lib/libc/glob/Makefile b/regress/lib/libc/glob/Makefile
new file mode 100644
index 00000000000..4a3731a9709
--- /dev/null
+++ b/regress/lib/libc/glob/Makefile
@@ -0,0 +1,13 @@
+# $OpenBSD: Makefile,v 1.1 2008/10/01 23:04:36 millert Exp $
+
+PROG= globtest
+
+run-regress-${PROG}:
+ mkdir -p `sed 's@/[^/]*$$@@' ${.CURDIR}/files | sort -u`
+ touch `cat files`
+ ./${PROG} ${.CURDIR}/${PROG}.in
+
+clean:
+ rm -rf fake ${PROG} ${OBJS} *.core
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libc/glob/files b/regress/lib/libc/glob/files
new file mode 100644
index 00000000000..c5e92aacd55
--- /dev/null
+++ b/regress/lib/libc/glob/files
@@ -0,0 +1,47 @@
+fake/bin/[
+fake/bin/cat
+fake/bin/chgrp
+fake/bin/chio
+fake/bin/chmod
+fake/bin/cksum
+fake/bin/cp
+fake/bin/cpio
+fake/bin/csh
+fake/bin/date
+fake/bin/dd
+fake/bin/df
+fake/bin/domainname
+fake/bin/echo
+fake/bin/ed
+fake/bin/eject
+fake/bin/expr
+fake/bin/hostname
+fake/bin/kill
+fake/bin/ksh
+fake/bin/ln
+fake/bin/ls
+fake/bin/md5
+fake/bin/mkdir
+fake/bin/mt
+fake/bin/mv
+fake/bin/pax
+fake/bin/ps
+fake/bin/pwd
+fake/bin/rcp
+fake/bin/rksh
+fake/bin/rm
+fake/bin/rmail
+fake/bin/rmd160
+fake/bin/rmdir
+fake/bin/sh
+fake/bin/sha1
+fake/bin/sha256
+fake/bin/sha384
+fake/bin/sha512
+fake/bin/sleep
+fake/bin/stty
+fake/bin/sum
+fake/bin/sync
+fake/bin/systrace
+fake/bin/tar
+fake/bin/test
diff --git a/regress/lib/libc/glob/globtest.c b/regress/lib/libc/glob/globtest.c
new file mode 100644
index 00000000000..f8f93573c65
--- /dev/null
+++ b/regress/lib/libc/glob/globtest.c
@@ -0,0 +1,123 @@
+/* $OpenBSD: globtest.c,v 1.1 2008/10/01 23:04:36 millert Exp $ */
+
+/*
+ * Public domain, 2008, Todd C. Miller <Todd.Miller@courtesan.com>
+ */
+
+#include <err.h>
+#include <glob.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define MAX_RESULTS 256
+
+struct gl_entry {
+ int flags;
+ int nresults;
+ char pattern[1024];
+ char *results[MAX_RESULTS];
+};
+
+int test_glob(struct gl_entry *);
+
+int
+main(int argc, char **argv)
+{
+ FILE *fp = stdin;
+ char *buf, *cp, *want, *got, *last;
+ const char *errstr;
+ int errors = 0, i, lineno;
+ struct gl_entry entry;
+ size_t len;
+
+ if (argc > 1) {
+ if ((fp = fopen(argv[1], "r")) == NULL)
+ err(1, "%s", argv[1]);
+ }
+
+ /*
+ * Read in test file, which is formatted thusly:
+ *
+ * [pattern] <flags>
+ * result1
+ * result2
+ * result3
+ * ...
+ *
+ */
+ lineno = 0;
+ memset(&entry, 0, sizeof(entry));
+ while ((buf = fgetln(fp, &len)) != NULL) {
+ lineno++;
+ if (buf[len - 1] != '\n')
+ errx(1, "missing newline at EOF");
+ buf[--len] = '\0';
+ if (len == 0)
+ continue; /* blank line */
+
+ if (buf[0] == '[') {
+ /* check previous pattern */
+ if (entry.pattern[0])
+ errors += test_glob(&entry);
+
+ /* start new entry */
+ if ((cp = strrchr(buf + 1, ']')) == NULL)
+ errx(1, "invalid entry on line %d", lineno);
+ len = cp - buf - 1;
+ if (len >= sizeof(entry.pattern))
+ errx(1, "pattern too big on line %d", lineno);
+ memcpy(entry.pattern, buf + 1, len);
+ entry.pattern[len] = '\0';
+
+ buf = cp + 2;
+ if (*buf++ != '<')
+ errx(1, "invalid entry on line %d", lineno);
+ if ((cp = strchr(buf, '>')) == NULL)
+ errx(1, "invalid entry on line %d", lineno);
+ entry.flags = (int)strtol(buf, &cp, 0);
+ if (*cp != '>' || entry.flags < 0 || entry.flags > 0x2000)
+ errx(1, "invalid flags: %s", buf);
+ entry.nresults = 0;
+ continue;
+ }
+ if (!entry.pattern[0])
+ errx(1, "missing entry on line %d", lineno);
+
+ if (entry.nresults + 1 > MAX_RESULTS) {
+ errx(1, "too many results for %s, max %d",
+ entry.pattern, MAX_RESULTS);
+ }
+ entry.results[entry.nresults++] = strdup(buf);
+ }
+ if (entry.pattern[0])
+ errors += test_glob(&entry); /* test last pattern */
+ exit(errors);
+}
+
+int test_glob(struct gl_entry *entry)
+{
+ glob_t gl;
+ int i;
+
+ if (glob(entry->pattern, entry->flags, NULL, &gl) != 0)
+ errx(1, "glob failed: %s", entry->pattern);
+
+ if (gl.gl_matchc != entry->nresults)
+ goto mismatch;
+
+ for (i = 0; i < gl.gl_matchc; i++) {
+ if (strcmp(gl.gl_pathv[i], entry->results[i]) != 0)
+ goto mismatch;
+ free(entry->results[i]);
+ }
+ return (0);
+mismatch:
+ warnx("mismatch for pattern %s, flags 0x%x", entry->pattern,
+ entry->flags);
+ while (i < gl.gl_matchc) {
+ free(entry->results[i++]);
+ }
+ return (0);
+ return (1);
+}
diff --git a/regress/lib/libc/glob/globtest.in b/regress/lib/libc/glob/globtest.in
new file mode 100644
index 00000000000..461411c2d36
--- /dev/null
+++ b/regress/lib/libc/glob/globtest.in
@@ -0,0 +1,61 @@
+[fake/bin/[[:alpha:]]*] <0x0>
+fake/bin/cat
+fake/bin/chgrp
+fake/bin/chio
+fake/bin/chmod
+fake/bin/cksum
+fake/bin/cp
+fake/bin/cpio
+fake/bin/csh
+fake/bin/date
+fake/bin/dd
+fake/bin/df
+fake/bin/domainname
+fake/bin/echo
+fake/bin/ed
+fake/bin/eject
+fake/bin/expr
+fake/bin/hostname
+fake/bin/kill
+fake/bin/ksh
+fake/bin/ln
+fake/bin/ls
+fake/bin/md5
+fake/bin/mkdir
+fake/bin/mt
+fake/bin/mv
+fake/bin/pax
+fake/bin/ps
+fake/bin/pwd
+fake/bin/rcp
+fake/bin/rksh
+fake/bin/rm
+fake/bin/rmail
+fake/bin/rmd160
+fake/bin/rmdir
+fake/bin/sh
+fake/bin/sha1
+fake/bin/sha256
+fake/bin/sha384
+fake/bin/sha512
+fake/bin/sleep
+fake/bin/stty
+fake/bin/sum
+fake/bin/sync
+fake/bin/systrace
+fake/bin/tar
+fake/bin/test
+
+[fake/bin/rm{,dir,ail}] <0x80>
+fake/bin/rm
+fake/bin/rmdir
+fake/bin/rmail
+
+[fake/bin/sha[[:digit:]]] <0x0>
+fake/bin/sha1
+
+[fake/bin/sha[[:digit:]]*] <0x0>
+fake/bin/sha1
+fake/bin/sha256
+fake/bin/sha384
+fake/bin/sha512