diff options
| author | otto <> | 2011-11-05 15:01:37 +0000 |
|---|---|---|
| committer | otto <> | 2011-11-05 15:01:37 +0000 |
| commit | cbb7c977911d2a2fb6f022e9ea3ca5f6d151e18d (patch) | |
| tree | 21777a89c50586abcce4f27c2267ab78372729b2 /src | |
| parent | 4f2b2d66516d0921a9838ac6675d575147a8adca (diff) | |
| download | openbsd-cbb7c977911d2a2fb6f022e9ea3ca5f6d151e18d.tar.gz openbsd-cbb7c977911d2a2fb6f022e9ea3ca5f6d151e18d.tar.bz2 openbsd-cbb7c977911d2a2fb6f022e9ea3ca5f6d151e18d.zip | |
add exhaust test from netbsd
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libc/regex/Makefile | 6 | ||||
| -rw-r--r-- | src/regress/lib/libc/regex/t_exhaust.c | 184 |
2 files changed, 188 insertions, 2 deletions
diff --git a/src/regress/lib/libc/regex/Makefile b/src/regress/lib/libc/regex/Makefile index 271debb5d3..bfa2dff375 100644 --- a/src/regress/lib/libc/regex/Makefile +++ b/src/regress/lib/libc/regex/Makefile | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.6 2004/08/13 14:54:12 millert Exp $ | 1 | # $OpenBSD: Makefile,v 1.7 2011/11/05 15:01:37 otto Exp $ |
| 2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ | 2 | # $NetBSD: Makefile,v 1.2 1995/02/16 19:38:45 cgd Exp $ |
| 3 | 3 | ||
| 4 | PROG= re | 4 | PROG= re |
| @@ -9,7 +9,7 @@ CFLAGS+= -I${.CURDIR}/../../../../lib/libc/regex -DREDEBUG -DPOSIX_MISTAKE | |||
| 9 | 9 | ||
| 10 | TESTS= ${.CURDIR}/tests | 10 | TESTS= ${.CURDIR}/tests |
| 11 | 11 | ||
| 12 | REGRESS_TARGETS=do-reg do-reg-long do-reg-backref | 12 | REGRESS_TARGETS=do-reg do-reg-long do-reg-backref do-t_exhaust |
| 13 | 13 | ||
| 14 | do-reg: ${PROG} | 14 | do-reg: ${PROG} |
| 15 | ./re < ${TESTS} | 15 | ./re < ${TESTS} |
| @@ -17,5 +17,7 @@ do-reg-long: ${PROG} | |||
| 17 | ./re -el < ${TESTS} | 17 | ./re -el < ${TESTS} |
| 18 | do-reg-backref: ${PROG} | 18 | do-reg-backref: ${PROG} |
| 19 | ./re -er < ${TESTS} | 19 | ./re -er < ${TESTS} |
| 20 | do-t_exhaust: t_exhaust | ||
| 21 | ./t_exhaust | ||
| 20 | 22 | ||
| 21 | .include <bsd.regress.mk> | 23 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libc/regex/t_exhaust.c b/src/regress/lib/libc/regex/t_exhaust.c new file mode 100644 index 0000000000..870dae64fa --- /dev/null +++ b/src/regress/lib/libc/regex/t_exhaust.c | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | /* $OpenBSD: t_exhaust.c,v 1.1 2011/11/05 15:01:37 otto Exp $ */ | ||
| 2 | /* $NetBSD: t_exhaust.c,v 1.2 2011/10/21 00:41:34 christos Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 2011 The NetBSD Foundation, Inc. | ||
| 6 | * All rights reserved. | ||
| 7 | * | ||
| 8 | * This code is derived from software contributed to The NetBSD Foundation | ||
| 9 | * by Christos Zoulas. | ||
| 10 | * | ||
| 11 | * Redistribution and use in source and binary forms, with or without | ||
| 12 | * modification, are permitted provided that the following conditions | ||
| 13 | * are met: | ||
| 14 | * 1. Redistributions of source code must retain the above copyright | ||
| 15 | * notice, this list of conditions and the following disclaimer. | ||
| 16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 17 | * notice, this list of conditions and the following disclaimer in the | ||
| 18 | * documentation and/or other materials provided with the distribution. | ||
| 19 | * 3. All advertising materials mentioning features or use of this software | ||
| 20 | * must display the following acknowledgement: | ||
| 21 | * This product includes software developed by the NetBSD | ||
| 22 | * Foundation, Inc. and its contributors. | ||
| 23 | * 4. Neither the name of The NetBSD Foundation nor the names of its | ||
| 24 | * contributors may be used to endorse or promote products derived | ||
| 25 | * from this software without specific prior written permission. | ||
| 26 | * | ||
| 27 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
| 28 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
| 29 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 30 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
| 31 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 32 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 33 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 34 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 35 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 36 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 37 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include <sys/cdefs.h> | ||
| 41 | |||
| 42 | #include <stdio.h> | ||
| 43 | #include <regex.h> | ||
| 44 | #include <string.h> | ||
| 45 | #include <stdlib.h> | ||
| 46 | #include <err.h> | ||
| 47 | //#include <atf-c.h> | ||
| 48 | |||
| 49 | |||
| 50 | static char * | ||
| 51 | mkstr(const char *str, size_t len) | ||
| 52 | { | ||
| 53 | size_t i, slen = strlen(str); | ||
| 54 | char *p = malloc(slen * len + 1); | ||
| 55 | if (p == NULL) | ||
| 56 | err(1, "malloc"); | ||
| 57 | for (i = 0; i < len; i++) | ||
| 58 | strlcpy(&p[i * slen], str, slen * len + 1 - (i * slen)); | ||
| 59 | return p; | ||
| 60 | } | ||
| 61 | |||
| 62 | static char * | ||
| 63 | concat(const char *d, const char *s) | ||
| 64 | { | ||
| 65 | size_t dlen = strlen(d); | ||
| 66 | size_t slen = strlen(s); | ||
| 67 | char *p = malloc(dlen + slen + 1); | ||
| 68 | strlcpy(p, d, dlen + slen + 1); | ||
| 69 | strlcat(p, s, dlen + slen + 1); | ||
| 70 | return p; | ||
| 71 | } | ||
| 72 | |||
| 73 | static char * | ||
| 74 | p0(size_t len) | ||
| 75 | { | ||
| 76 | char *d, *s1, *s2; | ||
| 77 | s1 = mkstr("\\(", len); | ||
| 78 | s2 = concat(s1, ")"); | ||
| 79 | free(s1); | ||
| 80 | d = concat("(", s2); | ||
| 81 | free(s2); | ||
| 82 | return d; | ||
| 83 | } | ||
| 84 | |||
| 85 | static char * | ||
| 86 | p1(size_t len) | ||
| 87 | { | ||
| 88 | char *d, *s1, *s2, *s3; | ||
| 89 | s1 = mkstr("\\(", 60); | ||
| 90 | s2 = mkstr("(.*)", len); | ||
| 91 | s3 = concat(s1, s2); | ||
| 92 | free(s2); | ||
| 93 | free(s1); | ||
| 94 | s1 = concat(s3, ")"); | ||
| 95 | free(s3); | ||
| 96 | d = concat("(", s1); | ||
| 97 | free(s1); | ||
| 98 | return d; | ||
| 99 | } | ||
| 100 | |||
| 101 | static char * | ||
| 102 | ps(const char *m, const char *s, size_t len) | ||
| 103 | { | ||
| 104 | char *d, *s1, *s2, *s3; | ||
| 105 | s1 = mkstr(m, len); | ||
| 106 | s2 = mkstr(s, len); | ||
| 107 | s3 = concat(s1, s2); | ||
| 108 | free(s2); | ||
| 109 | free(s1); | ||
| 110 | d = concat("(.?)", s3); | ||
| 111 | free(s3); | ||
| 112 | return d; | ||
| 113 | } | ||
| 114 | |||
| 115 | static char * | ||
| 116 | p2(size_t len) | ||
| 117 | { | ||
| 118 | return ps("((.*){0,255}", ")", len); | ||
| 119 | } | ||
| 120 | |||
| 121 | static char * | ||
| 122 | p3(size_t len) | ||
| 123 | { | ||
| 124 | return ps("(.\\{0,}", ")", len); | ||
| 125 | } | ||
| 126 | |||
| 127 | static char * | ||
| 128 | p4(size_t len) | ||
| 129 | { | ||
| 130 | return ps("((.*){1,255}", ")", len); | ||
| 131 | } | ||
| 132 | |||
| 133 | static char * | ||
| 134 | p5(size_t len) | ||
| 135 | { | ||
| 136 | return ps("(", "){1,100}", len); | ||
| 137 | } | ||
| 138 | |||
| 139 | static char * | ||
| 140 | p6(size_t len) | ||
| 141 | { | ||
| 142 | char *d, *s1, *s2; | ||
| 143 | s1 = mkstr("(?:(.*)|", len); | ||
| 144 | s2 = concat(s1, "(.*)"); | ||
| 145 | free(s1); | ||
| 146 | s1 = mkstr(")", len); | ||
| 147 | d = concat(s2, s1); | ||
| 148 | free(s1); | ||
| 149 | free(s2); | ||
| 150 | return d; | ||
| 151 | } | ||
| 152 | |||
| 153 | static char *(*patterns[])(size_t) = { | ||
| 154 | p0, | ||
| 155 | p1, | ||
| 156 | p2, | ||
| 157 | p3, | ||
| 158 | p4, | ||
| 159 | p5, | ||
| 160 | p6, | ||
| 161 | }; | ||
| 162 | |||
| 163 | |||
| 164 | main() | ||
| 165 | { | ||
| 166 | regex_t re; | ||
| 167 | int e; | ||
| 168 | size_t i; | ||
| 169 | |||
| 170 | for (i = 0; i < sizeof(patterns) / sizeof(patterns[0]); i++) { | ||
| 171 | char *d = (*patterns[i])(9999); | ||
| 172 | e = regcomp(&re, d, i == 6 ? REG_BASIC : REG_EXTENDED); | ||
| 173 | free(d); | ||
| 174 | if (e) { | ||
| 175 | if (e != REG_ESPACE) | ||
| 176 | printf("regcomp returned %d for pattern %zu", e, i); | ||
| 177 | continue; | ||
| 178 | } | ||
| 179 | (void)regexec(&re, "aaaaaaaa", 0, NULL, 0); | ||
| 180 | regfree(&re); | ||
| 181 | } | ||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | |||
