tools/testing/selftests/filesystems/eventfd/eventfd_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/eventfd/eventfd_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/filesystems/eventfd/eventfd_test.c- Extension
.c- Size
- 6295 bytes
- Lines
- 312
- 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
errno.hfcntl.hasm/unistd.hlinux/time_types.hunistd.hassert.hsignal.hpthread.hsys/epoll.hsys/eventfd.hkselftest_harness.h
Detected Declarations
struct errorfunction error_setfunction sys_eventfd2function trim_newlinefunction verify_fdinfofunction writefunction readfunction readfunction read
Annotated Snippet
struct error {
int code;
char msg[512];
};
static int error_set(struct error *err, int code, const char *fmt, ...)
{
va_list args;
int r;
if (code == 0 || !err || err->code != 0)
return code;
err->code = code;
va_start(args, fmt);
r = vsnprintf(err->msg, sizeof(err->msg), fmt, args);
assert((size_t)r < sizeof(err->msg));
va_end(args);
return code;
}
static inline int sys_eventfd2(unsigned int count, int flags)
{
return syscall(__NR_eventfd2, count, flags);
}
TEST(eventfd_check_flag_rdwr)
{
int fd, flags;
fd = sys_eventfd2(0, 0);
ASSERT_GE(fd, 0);
flags = fcntl(fd, F_GETFL);
// The kernel automatically adds the O_RDWR flag.
EXPECT_EQ(flags, O_RDWR);
close(fd);
}
TEST(eventfd_check_flag_cloexec)
{
int fd, flags;
fd = sys_eventfd2(0, EFD_CLOEXEC);
ASSERT_GE(fd, 0);
flags = fcntl(fd, F_GETFD);
ASSERT_GT(flags, -1);
EXPECT_EQ(flags, FD_CLOEXEC);
close(fd);
}
TEST(eventfd_check_flag_nonblock)
{
int fd, flags;
fd = sys_eventfd2(0, EFD_NONBLOCK);
ASSERT_GE(fd, 0);
flags = fcntl(fd, F_GETFL);
ASSERT_GT(flags, -1);
EXPECT_EQ(flags & EFD_NONBLOCK, EFD_NONBLOCK);
EXPECT_EQ(flags & O_RDWR, O_RDWR);
close(fd);
}
TEST(eventfd_check_flag_cloexec_and_nonblock)
{
int fd, flags;
fd = sys_eventfd2(0, EFD_CLOEXEC|EFD_NONBLOCK);
ASSERT_GE(fd, 0);
flags = fcntl(fd, F_GETFL);
ASSERT_GT(flags, -1);
EXPECT_EQ(flags & EFD_NONBLOCK, EFD_NONBLOCK);
EXPECT_EQ(flags & O_RDWR, O_RDWR);
flags = fcntl(fd, F_GETFD);
ASSERT_GT(flags, -1);
EXPECT_EQ(flags, FD_CLOEXEC);
close(fd);
}
static inline void trim_newline(char *str)
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `asm/unistd.h`, `linux/time_types.h`, `unistd.h`, `assert.h`, `signal.h`, `pthread.h`.
- Detected declarations: `struct error`, `function error_set`, `function sys_eventfd2`, `function trim_newline`, `function verify_fdinfo`, `function write`, `function read`, `function read`, `function read`.
- 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.