2 * Copyright (c) 2017 Dell EMC Isilon
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
43 * Derived from Russ Cox' pathological case test program used for the
44 * https://research.swtch.com/glob article.
46 ATF_TC_WITHOUT_HEAD(glob_pathological_test);
47 ATF_TC_BODY(glob_pathological_test, tc)
49 struct timespec t, t2;
51 const char *longname = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
52 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
53 char pattern[1000], *p;
55 unsigned i, j, k, mul;
58 fd = open(longname, O_CREAT | O_RDWR, 0666);
62 * Test up to 100 a* groups. Exponential implementations typically go
65 for (i = 0; i < 100; i++) {
67 * Create a*...b pattern with i 'a*' groups.
70 for (k = 0; k < i; k++) {
77 clock_gettime(CLOCK_REALTIME, &t);
78 for (j = 0; j < mul; j++) {
79 memset(&g, 0, sizeof g);
80 rc = glob(pattern, 0, 0, &g);
81 if (rc == GLOB_NOSPACE || rc == GLOB_ABORTED) {
82 ATF_REQUIRE_MSG(rc == GLOB_NOMATCH,
83 "an unexpected error occurred: "
84 "rc=%d errno=%d", rc, errno);
88 ATF_CHECK_MSG(rc == GLOB_NOMATCH,
89 "A bogus match occurred: '%s' ~ '%s'", pattern,
93 clock_gettime(CLOCK_REALTIME, &t2);
95 t2.tv_sec -= t.tv_sec;
96 t2.tv_nsec -= t.tv_nsec;
97 dt = t2.tv_sec + (double)t2.tv_nsec/1e9;
100 ATF_CHECK_MSG(dt < 1, "glob(3) took far too long: %d %.9f", i,
111 ATF_TP_ADD_TC(tp, glob_pathological_test);
113 return (atf_no_error());