From patchwork Thu Jul 14 12:46:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1656429 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=1xm95Zth; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qnjoGv1q; dkim-atps=neutral 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=) 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LkDkm09LJz9sB4 for ; Thu, 14 Jul 2022 22:46:22 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DE3DD3CA96D for ; Thu, 14 Jul 2022 14:46:18 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (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 AA6FF3CA93F for ; Thu, 14 Jul 2022 14:46:16 +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-6.smtp.seeweb.it (Postfix) with ESMTPS id DA44D1401149 for ; Thu, 14 Jul 2022 14:46:15 +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 379221F926 for ; Thu, 14 Jul 2022 12:46:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657802775; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yXD4i1wyXTdT9ErIYfO3dS+XtIMudOdMmtHis7v2oHM=; b=1xm95Zth2GPVgXVp1ESTFKLodSIbnWpbP6PbRm4NOKj9ZlYrLiGwXt7pTrN/97CBfCh4+C SrbLMSZT/Y2iU8mRtLlVqA60xJH6a+9tYRbUz2aAo2We43JeGWlrf4Yj385IBMSWDcnIVT fFvjEXovIFBo1/Ei0PpWJe+gI7GTf3k= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657802775; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=yXD4i1wyXTdT9ErIYfO3dS+XtIMudOdMmtHis7v2oHM=; b=qnjoGv1qs3b6aqGIPO4TkWCnYQvlBus2uyszaoIG1hde2sdtw9xrKi4+/RQjnD7yJggLiP 8HLggIIBrHaG0nCg== 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 A653913A61 for ; Thu, 14 Jul 2022 12:46:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id PkulGRYQ0GLMBAAAMHmgww (envelope-from ) for ; Thu, 14 Jul 2022 12:46:14 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Thu, 14 Jul 2022 18:16:11 +0530 Message-Id: <20220714124611.9772-1-akumar@suse.de> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2] open06.c: convert to new LTP API 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" Signed-off-by: Avinesh Kumar --- testcases/kernel/syscalls/open/open06.c | 94 +++++-------------------- 1 file changed, 19 insertions(+), 75 deletions(-) diff --git a/testcases/kernel/syscalls/open/open06.c b/testcases/kernel/syscalls/open/open06.c index 6c774ce84..a3c3bcb89 100644 --- a/testcases/kernel/syscalls/open/open06.c +++ b/testcases/kernel/syscalls/open/open06.c @@ -1,90 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + /* - * * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) 2022 SUSE LLC Avinesh Kumar */ -/* - * DESCRIPTION - * Testcase to check open(2) sets errno to ENXIO correctly. +/*\ + * [Description] * - * ALGORITHM - * Create a named pipe using mknod(2). Attempt to - * open(2) the pipe for writing. The open(2) should - * fail with ENXIO. + * Verify that open(2) fails with ENXIO when + * O_NONBLOCK | O_WRONLY is set, the named file is a FIFO, + * and no process has the FIFO open for reading. */ -#include -#include -#include -#include -#include -#include "test.h" - -char *TCID = "open06"; -int TST_TOTAL = 1; - -static void setup(void); -static void cleanup(void); - -static char fname[100] = "fifo"; - -int main(int ac, char **av) -{ - int lc; - tst_parse_opts(ac, av, NULL, NULL); +#include "tst_test.h" - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - TEST(open(fname, O_NONBLOCK | O_WRONLY)); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "open(2) succeeded unexpectedly"); - continue; - } - - if (TEST_ERRNO != ENXIO) - tst_resm(TFAIL, "Expected ENXIO got %d", TEST_ERRNO); - else - tst_resm(TPASS, "call returned expected ENXIO error"); - } - - cleanup(); - tst_exit(); -} +#define TEMP_FIFO "tmpfile" static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - sprintf(fname, "%s.%d", fname, getpid()); - - if (mknod(fname, S_IFIFO | 0644, 0) == -1) - tst_brkm(TBROK, cleanup, "mknod FAILED"); + SAFE_MKFIFO(TEMP_FIFO, 0644); } -static void cleanup(void) +static void run(void) { - unlink(fname); - - tst_rmdir(); + TST_EXP_FAIL2(open(TEMP_FIFO, O_NONBLOCK | O_WRONLY), ENXIO); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_tmpdir = 1 +};