diff options
author | Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> | 2024-04-02 20:24:18 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2024-04-02 20:24:18 +0000 |
commit | cdb9cd95d819b7d394f63db8dd87804de5aa3e69 (patch) | |
tree | 21df5650189a18b6e92f11a618bac3deb1adf361 /testcases/kernel/syscalls/epoll_wait/epoll_wait06.c | |
parent | 26a125c969109073ae74a948b3d8e4035cda4f7c (diff) | |
parent | 74f79dc224f4a1e79829ddfa11fa9439bf561423 (diff) | |
download | ltp-cdb9cd95d819b7d394f63db8dd87804de5aa3e69.tar.gz |
Merge changes from topic "ltp-20230929-android14-tests" into android14-tests-devandroid14-tests-dev
* changes:
cgroup: Fix scanning V1 mount options
cgroup: Handle trailing new line in cgroup.controllers
compare_ltp_projects.py: Fix test sorting, adjust printing
madvise11: Allow test to skip if MADV_SOFT_OFFLINE is not supported
madvise11: Replace /etc/mtab with /proc/mounts
syscalls/process_madvise01: fix smaps scan and min_swap_avail
tst_clocks.c: Fix stack smashing on 32bit
tst_kvercmp: Handle larger kernel version numbers
getpgid01: On Android, pgid(1) is 0 instead of 1
pipe07: refactor exp_num_pipes
pipe07: close /proc/self/fd after counting fds
config.h: Compile with linux/ioprio.h to fix ioprio_set03
sched.h: Don't exclude clone_args_minimal when HAVE_STRUCT_CLONE_ARGS is set
ltp-version.h: Generate with genrule
mq_notify03: disable test because don't have mqueue
kvm: Disable kvm tests
make_parser.py: Handle as (gnu assembler) command in makefile
android_build_generator.py: Print more info when failing with compile target
LTP 20230929
Merge tag '20230929'
Diffstat (limited to 'testcases/kernel/syscalls/epoll_wait/epoll_wait06.c')
-rw-r--r-- | testcases/kernel/syscalls/epoll_wait/epoll_wait06.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait06.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait06.c new file mode 100644 index 000000000..f35e0423a --- /dev/null +++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait06.c @@ -0,0 +1,107 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2023 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com> + */ + +/*\ + * [Description] + * + * Verify that edge triggering is correctly handled by epoll, for both EPOLLIN + * and EPOLLOUT. + * + * [Algorithm] + * + * - The file descriptors for non-blocking pipe are registered on an epoll + * instance. + * - A pipe writer writes data on the write side of the pipe. + * - A call to epoll_wait() is done that will return a EPOLLIN event. + * - The pipe reader reads half of data from rfd. + * - A call to epoll_wait() should hang because there's data left to read. + * - The pipe reader reads remaining data from rfd. + * - A call to epoll_wait() should return a EPOLLOUT event. + */ + +#define _GNU_SOURCE + +#include <fcntl.h> +#include "tst_test.h" +#include "tst_epoll.h" + +static size_t write_size; +static size_t read_size; +static int fds[2]; +static int epfd; + +static void setup(void) +{ + write_size = getpagesize(); + read_size = write_size / 2; + + SAFE_PIPE2(fds, O_NONBLOCK); + + /* EPOLLOUT will be raised when buffer became empty after becoming full */ + SAFE_FCNTL(fds[1], F_SETPIPE_SZ, write_size); +} + +static void cleanup(void) +{ + if (epfd > 0) + SAFE_CLOSE(epfd); + + if (fds[0] > 0) + SAFE_CLOSE(fds[0]); + + if (fds[1] > 0) + SAFE_CLOSE(fds[1]); +} + +static void run(void) +{ + char buff[write_size]; + struct epoll_event evt_receive; + + tst_res(TINFO, "Polling on channel with EPOLLET"); + + epfd = SAFE_EPOLL_CREATE1(0); + + SAFE_EPOLL_CTL(epfd, EPOLL_CTL_ADD, fds[0], &((struct epoll_event) { + .events = EPOLLIN | EPOLLET, + .data.fd = fds[0], + })); + SAFE_EPOLL_CTL(epfd, EPOLL_CTL_ADD, fds[1], &((struct epoll_event) { + .events = EPOLLOUT | EPOLLET, + .data.fd = fds[1], + })); + + tst_res(TINFO, "Write bytes on channel: %zu bytes", write_size); + + memset(buff, 'a', write_size); + SAFE_WRITE(SAFE_WRITE_ANY, fds[1], buff, write_size); + TST_EXP_FAIL(write(fds[1], buff, write_size), EAGAIN, "write() failed"); + + TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 1, 0), 1); + TST_EXP_EQ_LI(evt_receive.data.fd, fds[0]); + TST_EXP_EQ_LI(evt_receive.events & EPOLLIN, EPOLLIN); + + tst_res(TINFO, "Read half bytes from channel: %zu bytes", read_size); + + memset(buff, 0, write_size); + SAFE_READ(1, fds[0], buff, read_size); + + TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 1, 0), 0); + + tst_res(TINFO, "Read remaining bytes from channel: %zu bytes", read_size); + + SAFE_READ(1, fds[0], buff + read_size, read_size); + TST_EXP_FAIL(read(fds[0], buff, read_size), EAGAIN, "read() failed"); + + TST_EXP_EQ_LI(SAFE_EPOLL_WAIT(epfd, &evt_receive, 1, 0), 1); + TST_EXP_EQ_LI(evt_receive.data.fd, fds[1]); + TST_EXP_EQ_LI(evt_receive.events & EPOLLOUT, EPOLLOUT); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run, +}; |