From patchwork Tue Jan 12 13:29:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1425233 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DFWc60g9wz9t2D for ; Wed, 13 Jan 2021 00:28:21 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A027A3C5DD0 for ; Tue, 12 Jan 2021 14:28:18 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 740DD3C26DF for ; Tue, 12 Jan 2021 14:28:15 +0100 (CET) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id E1B79600E5F for ; Tue, 12 Jan 2021 14:28:14 +0100 (CET) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2789EABC4 for ; Tue, 12 Jan 2021 13:28:14 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Tue, 12 Jan 2021 14:29:11 +0100 Message-Id: <20210112132911.4031-1-chrubis@suse.cz> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH] syscalls: epoll_pwait01: Work around a race 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" There was a race that would manifest on slower machines. The call to epoll_pwait() could time out before the child has chance to run, and that would cause the signal to be sent to the parent when it was already sleeping in wait(). Ideally the whole test should be rewritten into new library and fixed properly, however as we are just before a release this is an attempt for a minimal fix. The logic in the test is changed so that: - epoll_wait() sleeps indefinitely - the child: - waits for the parent to get asleep - sends the signal - sleeps - writes to the pipe This causes the child to actually run, while the parent is blocked in the epoll_wait(), which greatly increases the changes of the signal arriving at the right time. Fixes: #765 Signed-off-by: Cyril Hrubis Reviewed-by: Petr Vorel Reviewed-by: Li Wang --- testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c index ed05da8fe..1f08112ad 100644 --- a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c +++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c @@ -121,8 +121,8 @@ static void verify_sigmask(void) return; } - if (TEST_RETURN != 0) { - tst_resm(TFAIL, "epoll_pwait() returned %li, expected 0", + if (TEST_RETURN != 1) { + tst_resm(TFAIL, "epoll_pwait() returned %li, expected 1", TEST_RETURN); return; } @@ -153,6 +153,7 @@ static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) static void do_test(sigset_t *sigmask) { pid_t cpid; + char b; cpid = tst_fork(); if (cpid < 0) @@ -161,13 +162,15 @@ static void do_test(sigset_t *sigmask) if (cpid == 0) do_child(); - TEST(epoll_pwait(epfd, &epevs, 1, 100, sigmask)); + TEST(epoll_pwait(epfd, &epevs, 1, -1, sigmask)); if (sigmask != NULL) verify_sigmask(); else verify_nonsigmask(); + SAFE_READ(cleanup, 1, fds[0], &b, 1); + tst_record_childstatus(cleanup, cpid); } @@ -179,6 +182,8 @@ static void do_child(void) } SAFE_KILL(cleanup, getppid(), SIGUSR1); + usleep(10000); + SAFE_WRITE(cleanup, 1, fds[1], "w", 1); cleanup(); tst_exit();