tools/testing/selftests/filesystems/openat2/emptypath_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/openat2/emptypath_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/openat2/emptypath_test.c- Extension
.c- Size
- 1604 bytes
- Lines
- 78
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
Dependency Surface
fcntl.hunistd.herrno.hstring.hsys/stat.hkselftest_harness.h
Detected Declarations
function ASSERT_GE
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
#define _GNU_SOURCE
#define __SANE_USERSPACE_TYPES__
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include "kselftest_harness.h"
#ifndef O_EMPTYPATH
#define O_EMPTYPATH (1 << 26)
#endif
#define EMPTYPATH_TEST_FILE "/tmp/emptypath_test"
FIXTURE(emptypath) {
int opath_fd;
};
FIXTURE_SETUP(emptypath)
{
int fd;
self->opath_fd = -1;
fd = open(EMPTYPATH_TEST_FILE, O_CREAT | O_WRONLY, S_IRWXU);
ASSERT_GE(fd, 0) {
TH_LOG("create %s: %s", EMPTYPATH_TEST_FILE, strerror(errno));
}
close(fd);
self->opath_fd = open(EMPTYPATH_TEST_FILE, O_PATH);
ASSERT_GE(self->opath_fd, 0) {
TH_LOG("open %s O_PATH: %s", EMPTYPATH_TEST_FILE, strerror(errno));
}
}
FIXTURE_TEARDOWN(emptypath)
{
if (self->opath_fd >= 0)
close(self->opath_fd);
unlink(EMPTYPATH_TEST_FILE);
}
/* An empty path is rejected with ENOENT unless O_EMPTYPATH is set. */
TEST_F(emptypath, without_flag_returns_enoent)
{
int fd = openat(self->opath_fd, "", O_RDONLY);
if (fd >= 0)
close(fd);
ASSERT_LT(fd, 0) {
TH_LOG("empty path without O_EMPTYPATH unexpectedly succeeded");
}
EXPECT_EQ(errno, ENOENT) {
TH_LOG("expected ENOENT, got %s", strerror(errno));
}
}
/* O_EMPTYPATH reopens the O_PATH fd through an empty path. */
TEST_F(emptypath, reopens_opath_fd)
{
int fd = openat(self->opath_fd, "", O_RDONLY | O_EMPTYPATH);
if (fd < 0 && errno == EINVAL)
SKIP(return, "O_EMPTYPATH not supported");
ASSERT_GE(fd, 0) {
TH_LOG("O_EMPTYPATH failed: %s", strerror(errno));
}
close(fd);
}
TEST_HARNESS_MAIN
Annotation
- Immediate include surface: `fcntl.h`, `unistd.h`, `errno.h`, `string.h`, `sys/stat.h`, `kselftest_harness.h`.
- Detected declarations: `function ASSERT_GE`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.