From nobody Fri May 22 17:39:14 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4gMXZv6wqhz6fJTp for ; Fri, 22 May 2026 17:39:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gMXZv5xYQz47V3 for ; Fri, 22 May 2026 17:39:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1779471559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZdKUEkoRPoeSw+ukh0kYmGgl4f90iKL4l2aHR5fE2hQ=; b=RRrkCci79Vg6GDWr7HgFnZpMG/F6sfkNoDn8sVlvUcx3hw9G7Pz426D1ozmjemM/plvchB L2qY/iEmKjbpZ5DXeYi8ORUsKdLPSY3EymhsXjQZIPhsahjHZnG3fWFzRferg518eeVcbC lTxLZ0/fGI0jx0IgbNZX3JNforOtGt3m9bjTwQ5Uhd/jLEZyiW+QyaIQXdHdvET1rzf5W2 N3YTXVWq9PP2+qC9yW90nndYItVU5WwmoHJZKQAI4Qc/wxm8DqD8oXonNPJv/SoTD7q71V FimTJiGSzxPHy6Lg48wI2vZOHvU+YfrwV24FWiyusuaiQC48PoWZKVrspt45+w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1779471559; a=rsa-sha256; cv=none; b=j/7VWRLU512tVsrOUZqUhP0I17BiXARJ3m/HnvCYkBR9hHejH8kuoL7B0oZ6WQ0oNHzVvV 72kq7m9ldgyjLDT2FqwFFdW9s5i4sCaZIJ/5jYIHyPQbLwl69vqd+YJZGh0zun+Voo1Ia5 Kg6bqQkxlUXLlzdsFSHVOiAmBrQA0210dufCRjQpbWxjzz8yvjPaiAKpTtg4vN0d1aVG21 J6tFI9ZlfUnEzePJxCRNz6fW5IeDjowGv0UfZ/8x5Xd98Kx5D0dGxxj9uSh7HUnFsODSSZ 1drxieW7tmIN/ou9CTw2WsjCmHKpKM52ph/HVrbqy9pbiH2IYOID48TbL4jSDA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1779471559; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZdKUEkoRPoeSw+ukh0kYmGgl4f90iKL4l2aHR5fE2hQ=; b=ZN5CROUka+Psu/C9XNWh3JJSZN3fmuIvLWbj/b/8MhGbBBvvwyh77cioboO7boSYMPlxVz lNWQEd/d0xAQ0N9ARCQSpnVBCDt2xZU3MZxNnJYY8EMjU6EPoqUGEliEgGe3NvV0fnB/5o HK5O6gUWYEsm6Tk89OwrhKVJv0oMPtWQnAviT6Z/u/CpHt/NJfk8aUrOotm5rF8uKwekG0 LfUcWOk1WvtSIsaXAs0BYzOa7NJr0+DwzCHGdv8yCf+GKOJbEU1y7dPmW8y8Ur8G93+xhM xN+Gjvrdn2S8VZD4JP+Zvq8ldtA7/qhJFEsUpMIuw+yz2K9NL+CQFYNsBfEe4A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gMXZv5Cv4zWTw for ; Fri, 22 May 2026 17:39:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 37423 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 22 May 2026 17:39:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Cc: Jitendra Bhati From: Alan Somers Subject: git: 113c262b2ad1 - main - lib/libc/tests/gen: add fts_open() error and edge case tests List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 113c262b2ad157790e19188bf298b7205bd1887b Auto-Submitted: auto-generated Date: Fri, 22 May 2026 17:39:14 +0000 Message-Id: <6a1094c2.37423.3db33e3e@gitrepo.freebsd.org> The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=113c262b2ad157790e19188bf298b7205bd1887b commit 113c262b2ad157790e19188bf298b7205bd1887b Author: Jitendra Bhati AuthorDate: 2026-05-21 01:40:13 +0000 Commit: Alan Somers CommitDate: 2026-05-22 17:38:21 +0000 lib/libc/tests/gen: add fts_open() error and edge case tests Add ATF test cases covering fts_open() error conditions and edge cases: - invalid option bits (outside FTS_OPTIONMASK) yield EINVAL - empty argv yields EINVAL - empty path string yields FTS_NS with ENOENT - nonexistent path yields FTS_NS, not open failure - trailing slash does not crash (SVN r49851 regression) - unreadable directory yields FTS_D then FTS_DNR, never FTS_DP - multiple root paths are all visited left to right Sponsored by: Google LLC (GSoC 2026) Reviewed by: asomers MFC after: 1 week Pull Request: https://github.com/freebsd/freebsd-src/pull/2217 --- lib/libc/tests/gen/Makefile | 1 + lib/libc/tests/gen/fts_open_test.c | 230 +++++++++++++++++++++++++++++++++++++ 2 files changed, 231 insertions(+) diff --git a/lib/libc/tests/gen/Makefile b/lib/libc/tests/gen/Makefile index 054b1b426b3d..9c1c1cb75bcf 100644 --- a/lib/libc/tests/gen/Makefile +++ b/lib/libc/tests/gen/Makefile @@ -11,6 +11,7 @@ ATF_TESTS_C+= fpclassify2_test ATF_TESTS_C+= fts_blocks_test .endif ATF_TESTS_C+= fts_misc_test +ATF_TESTS_C+= fts_open_test ATF_TESTS_C+= fts_options_test ATF_TESTS_C+= ftw_test ATF_TESTS_C+= getentropy_test diff --git a/lib/libc/tests/gen/fts_open_test.c b/lib/libc/tests/gen/fts_open_test.c new file mode 100644 index 000000000000..e6120b09006b --- /dev/null +++ b/lib/libc/tests/gen/fts_open_test.c @@ -0,0 +1,230 @@ +/* + * Copyright (c) 2026 Jitendra Bhati + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +/* + * Tests for fts_open() error conditions and edge cases. + */ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "fts_test.h" + +/* + * Option bits outside FTS_OPTIONMASK must fail with EINVAL. + */ +ATF_TC(invalid_options); +ATF_TC_HEAD(invalid_options, tc) +{ + atf_tc_set_md_var(tc, "descr", + "fts_open with out-of-mask option bits fails with EINVAL"); +} +ATF_TC_BODY(invalid_options, tc) +{ + char *paths[] = { ".", NULL }; + + ATF_REQUIRE_ERRNO(EINVAL, fts_open(paths, 0x10000, NULL) == NULL); +} + +/* + * Empty argv (NULL as first element) must fail with EINVAL. + */ +ATF_TC(empty_argv); +ATF_TC_HEAD(empty_argv, tc) +{ + atf_tc_set_md_var(tc, "descr", + "fts_open with NULL first argv element fails with EINVAL"); +} +ATF_TC_BODY(empty_argv, tc) +{ + char *paths[] = { NULL }; + + ATF_REQUIRE_ERRNO(EINVAL, + fts_open(paths, FTS_PHYSICAL, NULL) == NULL); +} + +/* + * An empty string in argv is a valid path but stat("") fails with ENOENT. + * fts_open() succeeds; the resulting FTSENT has fts_info == FTS_NS and + * fts_errno == ENOENT. + */ +ATF_TC(empty_path_string); +ATF_TC_HEAD(empty_path_string, tc) +{ + atf_tc_set_md_var(tc, "descr", + "empty string in argv produces FTS_NS entry"); +} +ATF_TC_BODY(empty_path_string, tc) +{ + char *paths[] = { "", NULL }; + FTS *fts; + FTSENT *ent; + + ATF_REQUIRE((fts = fts_open(paths, FTS_PHYSICAL, NULL)) != NULL); + + ent = fts_read(fts); + ATF_REQUIRE(ent != NULL); + ATF_CHECK_EQ(FTS_NS, ent->fts_info); + ATF_CHECK_EQ(ENOENT, ent->fts_errno); + + fts_close(fts); +} + +/* + * A nonexistent path produces an FTS_NS entry rather than causing + * fts_open() itself to fail. fts_open() does not validate whether + * paths exist. errno must be 0 after the traversal ends normally. + */ +ATF_TC(nonexistent_path); +ATF_TC_HEAD(nonexistent_path, tc) +{ + atf_tc_set_md_var(tc, "descr", + "nonexistent path produces FTS_NS entry, not fts_open failure"); +} +ATF_TC_BODY(nonexistent_path, tc) +{ + char *paths[] = { "this-path-does-not-exist", NULL }; + FTS *fts; + FTSENT *ent; + + ATF_REQUIRE((fts = fts_open(paths, FTS_PHYSICAL, NULL)) != NULL); + + ent = fts_read(fts); + ATF_REQUIRE(ent != NULL); + ATF_CHECK_EQ(FTS_NS, ent->fts_info); + ATF_CHECK_EQ(ENOENT, ent->fts_errno); + + /* + * Next fts_read must return NULL with errno == 0 — + * end-of-traversal, not an error. + */ + errno = 1; /* sentinel — fts_read must clear this */ + ATF_CHECK_EQ(NULL, fts_read(fts)); + ATF_CHECK_EQ(0, errno); + + ATF_REQUIRE_EQ_MSG(0, fts_close(fts), "fts_close(): %m"); +} + +/* + * A path with a trailing slash must not crash and must traverse the + * directory normally. This is a regression test for SVN r49851. + */ +ATF_TC(trailing_slash); +ATF_TC_HEAD(trailing_slash, tc) +{ + atf_tc_set_md_var(tc, "descr", + "trailing slash on root path must not crash (SVN r49851)"); +} +ATF_TC_BODY(trailing_slash, tc) +{ + char *paths[] = { "dir/", NULL }; + FTS *fts; + FTSENT *ent; + int seen_dir, seen_file; + + ATF_REQUIRE_EQ(0, mkdir("dir", 0755)); + ATF_REQUIRE_EQ(0, close(creat("dir/file", 0644))); + + ATF_REQUIRE((fts = fts_open(paths, FTS_PHYSICAL, NULL)) != NULL); + + seen_dir = 0; + seen_file = 0; + while ((ent = fts_read(fts)) != NULL) { + if (ent->fts_info == FTS_D || ent->fts_info == FTS_DP) + seen_dir = 1; + if (ent->fts_info == FTS_F) + seen_file = 1; + } + + ATF_CHECK_EQ_MSG(0, errno, + "fts_read loop should end with errno 0, not %d", errno); + ATF_CHECK_MSG(seen_dir != 0, "directory was never visited"); + ATF_CHECK_MSG(seen_file != 0, "file inside dir was never visited"); + + ATF_REQUIRE_EQ_MSG(0, fts_close(fts), "fts_close(): %m"); +} + +/* + * An unreadable directory must produce FTS_D then FTS_DNR. It must NOT + * produce FTS_DP because fts never successfully entered it. + * + * Requires an unprivileged user because root ignores directory permissions. + */ +ATF_TC(unreadable_dir); +ATF_TC_HEAD(unreadable_dir, tc) +{ + atf_tc_set_md_var(tc, "descr", + "unreadable directory yields FTS_D then FTS_DNR, never FTS_DP"); + atf_tc_set_md_var(tc, "require.user", "unprivileged"); +} +ATF_TC_BODY(unreadable_dir, tc) +{ + ATF_REQUIRE_EQ(0, mkdir("unr", 0000)); + fts_test(tc, &(struct fts_testcase){ + (char *[]){ "unr", NULL }, + FTS_PHYSICAL, + (struct fts_expect[]){ + { FTS_D, "unr", "unr" }, + { FTS_DNR, "unr", "unr" }, + { 0 } + }, + }); +} + +/* + * Multiple root paths must all be visited left-to-right, each tree + * traversed completely before moving to the next root. + */ +ATF_TC(multiple_roots); +ATF_TC_HEAD(multiple_roots, tc) +{ + atf_tc_set_md_var(tc, "descr", + "fts_open visits multiple root paths left-to-right"); +} +ATF_TC_BODY(multiple_roots, tc) +{ + ATF_REQUIRE_EQ(0, mkdir("a", 0755)); + ATF_REQUIRE_EQ(0, mkdir("b", 0755)); + ATF_REQUIRE_EQ(0, close(creat("a/x", 0644))); + ATF_REQUIRE_EQ(0, close(creat("b/y", 0644))); + + fts_test(tc, &(struct fts_testcase){ + (char *[]){ "a", "b", NULL }, + FTS_PHYSICAL, + (struct fts_expect[]){ + { FTS_D, "a", "a" }, + { FTS_F, "x", "x" }, + { FTS_DP, "a", "a" }, + { FTS_D, "b", "b" }, + { FTS_F, "y", "y" }, + { FTS_DP, "b", "b" }, + { 0 } + }, + }); +} + +ATF_TP_ADD_TCS(tp) +{ + fts_check_debug(); + ATF_TP_ADD_TC(tp, invalid_options); + ATF_TP_ADD_TC(tp, empty_argv); + ATF_TP_ADD_TC(tp, empty_path_string); + ATF_TP_ADD_TC(tp, nonexistent_path); + ATF_TP_ADD_TC(tp, trailing_slash); + ATF_TP_ADD_TC(tp, unreadable_dir); + ATF_TP_ADD_TC(tp, multiple_roots); + + return (atf_no_error()); +}