From patchwork Tue Jul 18 09:25:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avinesh Kumar X-Patchwork-Id: 1809109 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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: legolas.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=0UD8Txcq; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=bcPEJb0A; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4R4tqD2CnCz20FK for ; Tue, 18 Jul 2023 19:25:59 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 80F6A3CB2BC for ; Tue, 18 Jul 2023 11:25:56 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (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 A586A3C0222 for ; Tue, 18 Jul 2023 11:25:54 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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-7.smtp.seeweb.it (Postfix) with ESMTPS id 8FAAE200A13 for ; Tue, 18 Jul 2023 11:25:53 +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-out1.suse.de (Postfix) with ESMTPS id DFBB521873 for ; Tue, 18 Jul 2023 09:25:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1689672352; 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=OjCi51HMj+imci+GikXXdswbydRvKkrLt6LZNxSJ+iI=; b=0UD8TxcqVWED75FiwHDfQBza/pP30TMUdifSopLSdUd2Qdb0mAJr75JIW+bST9Q9ojOsQX Gzs3HNXUxR2bRevawGwBxx4XOQeliLVI0nivuhiGgYtnQhOwsW80+Rb+TLEfQAAGWiOkF4 u73kQaxMqA+xq+VvQGzkcQ+ZGWJ3BRI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1689672352; 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=OjCi51HMj+imci+GikXXdswbydRvKkrLt6LZNxSJ+iI=; b=bcPEJb0ABXNEtHQkqT2AAIja/xCZ0ttHN559JWM1QupOUiSytio7cpE2KDZl3dMz9qpqGz xIeFMyBAR6S6aoDw== 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 91DDB134B0 for ; Tue, 18 Jul 2023 09:25:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Lb7cGqBatmSZYgAAMHmgww (envelope-from ) for ; Tue, 18 Jul 2023 09:25:52 +0000 From: Avinesh Kumar To: ltp@lists.linux.it Date: Tue, 18 Jul 2023 14:55:48 +0530 Message-ID: <20230718092550.11611-1-akumar@suse.de> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 1.0.1 at in-7.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 shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2] syscalls/pipe06: Rewrite the test using 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/pipe/pipe06.c | 137 +++++++----------------- 1 file changed, 37 insertions(+), 100 deletions(-) diff --git a/testcases/kernel/syscalls/pipe/pipe06.c b/testcases/kernel/syscalls/pipe/pipe06.c index d83765632..99e72f3c8 100644 --- a/testcases/kernel/syscalls/pipe/pipe06.c +++ b/testcases/kernel/syscalls/pipe/pipe06.c @@ -1,119 +1,56 @@ +// 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) International Business Machines Corp., 2001 + * 07/2001 Ported by Wayne Boyer + * Copyright (c) 2023 SUSE LLC Avinesh Kumar */ -/* - * NAME - * pipe06.c - * - * DESCRIPTION - * Check what happens when the system runs out of pipes. - * - * ALGORITHM - * Issue enough pipe calls to run the system out of pipes. - * Check that we get EMFILE. +/*\ + * [Description] * - * USAGE: - * pipe06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * RESTRICTIONS - * None + * Verify that, pipe(2) syscall fails with errno EMFILE when + * limit on the number of open file descriptors has been reached. */ -#include -#include -#include "test.h" -char *TCID = "pipe06"; -int TST_TOTAL = 1; +#include "tst_test.h" +#include -int pipe_ret, pipes[2]; -void setup(void); -void cleanup(void); +static int fds[2]; +static int *opened_fds, num_opened_fds; -int main(int ac, char **av) +static void setup(void) { - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - /* reset tst_count in case we are looping */ - tst_count = 0; + int max_fds; - TEST(pipe(pipes)); + max_fds = getdtablesize(); + tst_res(TINFO, "getdtablesize() = %d", max_fds); + opened_fds = SAFE_MALLOC(max_fds * sizeof(int)); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - } - - if (TEST_ERRNO != EMFILE) { - tst_resm(TFAIL | TTERRNO, "pipe failed unexpectedly"); - } else { - tst_resm(TPASS, "failed with EMFILE"); - } - - } - cleanup(); - tst_exit(); + do { + SAFE_PIPE(fds); + opened_fds[num_opened_fds++] = fds[0]; + opened_fds[num_opened_fds++] = fds[1]; + } while (fds[1] < max_fds - 2); + tst_res(TINFO, "Number of fds opened by pipe calls: %d", num_opened_fds); } -/* - * setup() - performs all ONE TIME setup for this test. - */ -void setup(void) +static void run(void) { - int i, numb_fds; - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - numb_fds = getdtablesize(); - - for (i = 0; i < numb_fds; i++) { - pipe_ret = pipe(pipes); - if (pipe_ret < 0) { - if (errno != EMFILE) { - tst_brkm(TBROK | TTERRNO, cleanup, - "didn't get EMFILE"); - } - break; - } - } + TST_EXP_FAIL(pipe(fds), EMFILE); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void cleanup(void) { + for (int i = 0; i < num_opened_fds; i++) + SAFE_CLOSE(opened_fds[i]); + + if (opened_fds) + free(opened_fds); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run +};