tools/testing/selftests/filesystems/openat2/resolve_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/openat2/resolve_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/openat2/resolve_test.c- Extension
.c- Size
- 22738 bytes
- Lines
- 562
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
fcntl.hsched.hsys/stat.hsys/types.hsys/mount.hstdlib.hstdbool.hstring.hhelpers.hkselftest_harness.h
Detected Declarations
struct resolve_testfunction verify_resolve_testfunction EXPECT_EQ
Annotated Snippet
struct resolve_test {
const char *name;
const char *dir;
const char *path;
struct open_how how;
bool pass;
union {
int err;
const char *path;
} out;
};
/*
* Verify a single resolve test case. This must be called from within a TEST_F
* function with _metadata in scope.
*/
static void verify_resolve_test(struct __test_metadata *_metadata,
int rootfd, int hardcoded_fd,
const struct resolve_test *test)
{
struct open_how how = test->how;
int dfd, fd;
char *fdpath = NULL;
/* Auto-set O_PATH. */
if (!(how.flags & O_CREAT))
how.flags |= O_PATH;
if (test->dir)
dfd = openat(rootfd, test->dir, O_PATH | O_DIRECTORY);
else
dfd = dup(rootfd);
ASSERT_GE(dfd, 0) TH_LOG("failed to open dir '%s': %m", test->dir ?: ".");
ASSERT_EQ(dup2(dfd, hardcoded_fd), hardcoded_fd);
fd = sys_openat2(dfd, test->path, &how);
if (test->pass) {
EXPECT_GE(fd, 0) {
TH_LOG("%s: expected success, got %d (%s)",
test->name, fd, strerror(-fd));
}
if (fd >= 0) {
EXPECT_TRUE(fdequal(_metadata, fd, rootfd, test->out.path)) {
fdpath = fdreadlink(_metadata, fd);
TH_LOG("%s: wrong path '%s', expected '%s'",
test->name, fdpath,
test->out.path ?: ".");
free(fdpath);
}
}
} else {
EXPECT_EQ(test->out.err, fd) {
if (fd >= 0) {
fdpath = fdreadlink(_metadata, fd);
TH_LOG("%s: expected %d (%s), got %d['%s']",
test->name, test->out.err,
strerror(-test->out.err), fd, fdpath);
free(fdpath);
} else {
TH_LOG("%s: expected %d (%s), got %d (%s)",
test->name, test->out.err,
strerror(-test->out.err),
fd, strerror(-fd));
}
}
}
if (fd >= 0)
close(fd);
close(dfd);
}
/*
* Construct a test directory with the following structure:
*
* root/
* |-- procexe -> /proc/self/exe
* |-- procroot -> /proc/self/root
* |-- root/
* |-- mnt/ [mountpoint]
* | |-- self -> ../mnt/
* | `-- absself -> /mnt/
* |-- etc/
* | `-- passwd
* |-- creatlink -> /newfile3
* |-- reletc -> etc/
* |-- relsym -> etc/passwd
* |-- absetc -> /etc/
* |-- abssym -> /etc/passwd
Annotation
- Immediate include surface: `fcntl.h`, `sched.h`, `sys/stat.h`, `sys/types.h`, `sys/mount.h`, `stdlib.h`, `stdbool.h`, `string.h`.
- Detected declarations: `struct resolve_test`, `function verify_resolve_test`, `function EXPECT_EQ`.
- 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.