Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F156945591
D50486.id156411.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D50486.id156411.diff
View Options
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
@@ -15,6 +15,9 @@
ATF_TESTS_C+= getentropy_test
ATF_TESTS_C+= getmntinfo_test
ATF_TESTS_C+= glob2_test
+.if ${COMPILER_FEATURES:Mblocks}
+ATF_TESTS_C+= glob_blocks_test
+.endif
ATF_TESTS_C+= makecontext_test
ATF_TESTS_C+= popen_test
ATF_TESTS_C+= posix_spawn_test
@@ -97,7 +100,7 @@
TESTS_SUBDIRS+= posix_spawn
# Tests that require blocks support
-.for t in fts_blocks_test
+.for t in fts_blocks_test glob_blocks_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,8 @@
*/
#include <sys/param.h>
+#include <sys/stat.h>
+
#include <errno.h>
#include <fcntl.h>
#include <glob.h>
@@ -36,6 +38,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 +106,64 @@
}
}
+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");
+}
+
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);
return (atf_no_error());
}
diff --git a/lib/libc/tests/gen/glob_blocks_test.c b/lib/libc/tests/gen/glob_blocks_test.c
new file mode 100644
--- /dev/null
+++ b/lib/libc/tests/gen/glob_blocks_test.c
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2025 Klara, Inc.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <glob.h>
+
+#include <atf-c.h>
+
+static int glob_callback_invoked;
+
+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");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+ ATF_TP_ADD_TC(tp, glob_b_callback_test);
+ return (atf_no_error());
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, May 18, 1:32 PM (9 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33250408
Default Alt Text
D50486.id156411.diff (4 KB)
Attached To
Mode
D50486: glob: Add tests for error callback functions and blocks
Attached
Detach File
Event Timeline
Log In to Comment