tools/testing/selftests/net/epoll_busy_poll.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/epoll_busy_poll.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/epoll_busy_poll.c
Extension
.c
Size
7962 bytes
Lines
321
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct epoll_params {
	uint32_t busy_poll_usecs;
	uint16_t busy_poll_budget;
	uint8_t prefer_busy_poll;

	/* pad the struct to a multiple of 64bits */
	uint8_t __pad;
};

#define EPOLL_IOC_TYPE 0x8A
#define EPIOCSPARAMS _IOW(EPOLL_IOC_TYPE, 0x01, struct epoll_params)
#define EPIOCGPARAMS _IOR(EPOLL_IOC_TYPE, 0x02, struct epoll_params)
#endif

FIXTURE(invalid_fd)
{
	int invalid_fd;
	struct epoll_params params;
};

FIXTURE_SETUP(invalid_fd)
{
	int ret;

	ret = socket(AF_UNIX, SOCK_DGRAM, 0);
	EXPECT_NE(-1, ret)
		TH_LOG("error creating unix socket");

	self->invalid_fd = ret;
}

FIXTURE_TEARDOWN(invalid_fd)
{
	int ret;

	ret = close(self->invalid_fd);
	EXPECT_EQ(0, ret);
}

TEST_F(invalid_fd, test_invalid_fd)
{
	int ret;

	ret = ioctl(self->invalid_fd, EPIOCGPARAMS, &self->params);

	EXPECT_EQ(-1, ret)
		TH_LOG("EPIOCGPARAMS on invalid epoll FD should error");

	EXPECT_EQ(ENOTTY, errno)
		TH_LOG("EPIOCGPARAMS on invalid epoll FD should set errno to ENOTTY");

	memset(&self->params, 0, sizeof(struct epoll_params));

	ret = ioctl(self->invalid_fd, EPIOCSPARAMS, &self->params);

	EXPECT_EQ(-1, ret)
		TH_LOG("EPIOCSPARAMS on invalid epoll FD should error");

	EXPECT_EQ(ENOTTY, errno)
		TH_LOG("EPIOCSPARAMS on invalid epoll FD should set errno to ENOTTY");
}

FIXTURE(epoll_busy_poll)
{
	int fd;
	struct epoll_params params;
	struct epoll_params *invalid_params;
	cap_t caps;
};

FIXTURE_SETUP(epoll_busy_poll)
{
	int ret;

	ret = epoll_create1(0);
	EXPECT_NE(-1, ret)
		TH_LOG("epoll_create1 failed?");

	self->fd = ret;

	self->caps = cap_get_proc();
	EXPECT_NE(NULL, self->caps);
}

FIXTURE_TEARDOWN(epoll_busy_poll)
{
	int ret;

	ret = close(self->fd);
	EXPECT_EQ(0, ret);

Annotation

Implementation Notes