Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 65827C433F5 for ; Fri, 7 Oct 2022 20:26:29 +0000 (UTC) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 557433CAE6F for ; Fri, 7 Oct 2022 22:26:26 +0200 (CEST) Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6343C3C0FBC for ; Fri, 7 Oct 2022 22:26:17 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id BD7B0100155F for ; Fri, 7 Oct 2022 22:26:16 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id D8B4D1F8B8; Fri, 7 Oct 2022 20:26:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1665174375; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Laa4LDZl+bg8dQaGfBGX/VdbtKkEwrzXCQh6rWxS3Gw=; b=kg+Nsm1/uFRf1qXnRpGUDctTRL8TgEIeM7JluPhJRwZO+A1jndMOcO7yEMeH/UyKAIu5cC KIyP7QQqwzWu12uwdO34WLcP4C3PJ4t6cJT6l4I8+RFDyMtqISuZ1LiaW5NbzOjBm8E1LD Q3vieRi5SlcQ/biC6cdG11FxFr8Yqwo= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9E63113A9A; Fri, 7 Oct 2022 20:26:15 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id N0CdJGeLQGO1EgAAMHmgww (envelope-from ); Fri, 07 Oct 2022 20:26:15 +0000 To: ltp@lists.linux.it Date: Fri, 7 Oct 2022 22:25:02 +0200 Message-Id: <20221007202502.21414-1-andrea.cervesato@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-4.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v1] Add epoll_ctl06 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Andrea Cervesato via ltp Reply-To: Andrea Cervesato Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.org@lists.linux.it Sender: "ltp" The epoll_ctl06 test verifies that EPOLLRDHUP event is correctly recognised by epoll. Signed-off-by: Andrea Cervesato --- .../kernel/syscalls/epoll_ctl/.gitignore | 1 + .../kernel/syscalls/epoll_ctl/epoll_ctl06.c | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c diff --git a/testcases/kernel/syscalls/epoll_ctl/.gitignore b/testcases/kernel/syscalls/epoll_ctl/.gitignore index 3e05f2e1f..9c555f41b 100644 --- a/testcases/kernel/syscalls/epoll_ctl/.gitignore +++ b/testcases/kernel/syscalls/epoll_ctl/.gitignore @@ -3,3 +3,4 @@ epoll_ctl02 epoll_ctl03 epoll_ctl04 epoll_ctl05 +epoll_ctl06 diff --git a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c new file mode 100644 index 000000000..b3cb80a36 --- /dev/null +++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl06.c @@ -0,0 +1,86 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ + +/*\ + * [Description] + * + * Verify that epoll receives EPOLLRDHUP event when we hang a reading + * half-socket we are polling on. + */ + +#include +#include +#include "tst_test.h" + +static int sockfd; +static int epfd; + +static void setup(void) +{ + sockfd = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0); +} + +static void cleanup(void) +{ + if (epfd > 0) + SAFE_CLOSE(epfd); + + if (sockfd > 0) + SAFE_CLOSE(sockfd); +} + +static void run(void) +{ + int res; + pid_t pid; + struct epoll_event evt_req; + struct epoll_event evt_rec; + + pid = SAFE_FORK(); + if (pid != 0) { + TST_CHECKPOINT_WAIT(0); + + tst_res(TINFO, "Hang reading half-socket"); + shutdown(sockfd, SHUT_RD); + + TST_CHECKPOINT_WAKE(0); + + return; + } + + epfd = epoll_create1(0); + if (epfd == -1) + tst_brk(TBROK | TERRNO, "fail to create epoll instance"); + + tst_res(TINFO, "Looking at EPOLLRDHUP events"); + + evt_req.events = EPOLLRDHUP; + res = epoll_ctl(epfd, EPOLL_CTL_ADD, sockfd, &evt_req); + if (res == -1) + tst_brk(TBROK | TERRNO, "epoll_ctl failure"); + + TST_CHECKPOINT_WAKE_AND_WAIT(0); + + res = epoll_wait(epfd, &evt_rec, 1, 2000); + if (res <= 0) { + tst_res(TFAIL | TERRNO, "epoll_wait() returned %i", res); + return; + } + + if (evt_rec.events & evt_req.events) + tst_res(TPASS, "Received EPOLLRDHUP"); + else + tst_res(TFAIL, "EPOLLRDHUP has not been received"); + + SAFE_CLOSE(epfd); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run, + .forks_child = 1, + .needs_checkpoints = 1, +}; -- 2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp