Page MenuHomeFreeBSD

D50486.id156047.diff
No OneTemporary

D50486.id156047.diff

diff --git a/lib/libc/tests/gen/Makefile b/lib/libc/tests/gen/Makefile
--- a/lib/libc/tests/gen/Makefile
+++ b/lib/libc/tests/gen/Makefile
@@ -97,7 +97,7 @@
TESTS_SUBDIRS+= posix_spawn
# Tests that require blocks support
-.for t in fts_blocks_test
+.for t in fts_blocks_test glob2_test
CFLAGS.${t}.c+= -fblocks
LIBADD.${t}+= BlocksRuntime
.endfor
diff --git a/lib/libc/tests/gen/glob2_test.c b/lib/libc/tests/gen/glob2_test.c
--- a/lib/libc/tests/gen/glob2_test.c
+++ b/lib/libc/tests/gen/glob2_test.c
@@ -25,6 +25,7 @@
*/
#include <sys/param.h>
+#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <glob.h>
@@ -36,6 +37,8 @@
#include <atf-c.h>
+static int glob_callback_invoked;
+
/*
* Derived from Russ Cox' pathological case test program used for the
* https://research.swtch.com/glob article.
@@ -102,10 +105,98 @@
}
}
+ATF_TC(glob_period);
+ATF_TC_HEAD(glob_period, tc)
+{
+ atf_tc_set_md_var(tc, "descr",
+ "Test behaviour when matching files that start with a period"
+ "(documented in the glob(3) CAVEATS section).");
+}
+ATF_TC_BODY(glob_period, tc)
+{
+ int i;
+ glob_t g;
+
+ atf_utils_create_file(".test", "");
+ glob(".", 0, NULL, &g);
+ ATF_REQUIRE_MSG(g.gl_matchc == 1,
+ "glob(3) shouldn't match files starting with a period when using '.'");
+ for (i = 0; i < g.gl_matchc; i++)
+ printf("%s\n", g.gl_pathv[i]);
+ glob(".*", 0, NULL, &g);
+ ATF_REQUIRE_MSG(g.gl_matchc == 3 && strcmp(g.gl_pathv[2], ".test") == 0,
+ "glob(3) should match files starting with a period when using '.*'");
+}
+
+static int
+errfunc(const char *path, int err)
+{
+ ATF_REQUIRE_STREQ(path, "test/");
+ ATF_REQUIRE(err == EACCES);
+ glob_callback_invoked = 1;
+ /* Suppress EACCES errors. */
+ return (0);
+}
+
+ATF_TC_WITHOUT_HEAD(glob_callback_test);
+ATF_TC_BODY(glob_callback_test, tc)
+{
+ int rv;
+ glob_t g;
+
+ glob_callback_invoked = 0;
+ ATF_REQUIRE_EQ(0, mkdir("test", 0007));
+ rv = glob("test/*", 0, errfunc, &g);
+ ATF_REQUIRE_MSG(glob_callback_invoked == 1,
+ "glob(3) failed to invoke callback function");
+ ATF_REQUIRE_MSG(rv == GLOB_NOMATCH,
+ "error callback function failed to suppress EACCES");
+
+ /* GLOB_ERR should ignore the suppressed error. */
+ rv = glob("test/*", GLOB_ERR, errfunc, &g);
+ ATF_REQUIRE_MSG(rv == GLOB_ABORTED,
+ "GLOB_ERR didn't override error callback function");
+}
+
+#ifdef __BLOCKS__
+ATF_TC_WITHOUT_HEAD(glob_b_callback_test);
+ATF_TC_BODY(glob_b_callback_test, tc)
+{
+ int rv;
+ glob_t g;
+
+ glob_callback_invoked = 0;
+ ATF_REQUIRE_EQ(0, mkdir("test", 0007));
+ int (^errblk)(const char *, int) =
+ ^(const char *path, int err) {
+ ATF_REQUIRE_STREQ(path, "test/");
+ ATF_REQUIRE(err == EACCES);
+ glob_callback_invoked = 1;
+ /* Suppress EACCES errors. */
+ return (0);
+ };
+
+ rv = glob_b("test/*", 0, errblk, &g);
+ ATF_REQUIRE_MSG(glob_callback_invoked == 1,
+ "glob(3) failed to invoke callback block");
+ ATF_REQUIRE_MSG(rv == GLOB_NOMATCH,
+ "error callback function failed to suppress EACCES");
+
+ /* GLOB_ERR should ignore the suppressed error. */
+ rv = glob_b("test/*", GLOB_ERR, errblk, &g);
+ ATF_REQUIRE_MSG(rv == GLOB_ABORTED,
+ "GLOB_ERR didn't override error callback block");
+}
+#endif
+
ATF_TP_ADD_TCS(tp)
{
ATF_TP_ADD_TC(tp, glob_pathological_test);
-
+ ATF_TP_ADD_TC(tp, glob_period);
+ ATF_TP_ADD_TC(tp, glob_callback_test);
+#ifdef __BLOCKS__
+ ATF_TP_ADD_TC(tp, glob_b_callback_test);
+#endif
return (atf_no_error());
}

File Metadata

Mime Type
text/plain
Expires
Tue, Mar 10, 12:29 PM (40 m, 51 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29492130
Default Alt Text
D50486.id156047.diff (3 KB)

Event Timeline