From patchwork Thu Feb 1 12:57:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Doucha X-Patchwork-Id: 1893925 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=iJLbla0I; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Is/RUNmK; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=iJLbla0I; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Is/RUNmK; dkim-atps=neutral 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=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TQf7l3qJsz23g7 for ; Thu, 1 Feb 2024 23:57:22 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3F7A83CF8E0 for ; Thu, 1 Feb 2024 13:57:20 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 7CC363CC96F for ; Thu, 1 Feb 2024 13:57:16 +0100 (CET) Authentication-Results: in-3.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.cz (client-ip=195.135.223.130; helo=smtp-out1.suse.de; envelope-from=mdoucha@suse.cz; receiver=lists.linux.it) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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-3.smtp.seeweb.it (Postfix) with ESMTPS id 7D0A11A04343 for ; Thu, 1 Feb 2024 13:57:14 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 583F621FA0 for ; Thu, 1 Feb 2024 12:57:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1706792234; 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=quxIrh1tyAx9ITJ3SJo14NnRyIIMLc7KgZTAplulWmE=; b=iJLbla0IhxoqJ8tiDFzkbc6HVbE1RYA7bRLaTtNZT8GOCQZs+5jXY/H4gGmju5dehsD0xw scOeuhGj1tfZsJ9khojWzyLnkNnIJjMmhgbqPKWQT18bp5Uy0eBed24g/vQdrZvTWFUEdd a2f8aDMxIMO0g989CRgByfJJJeovDt8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1706792234; 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=quxIrh1tyAx9ITJ3SJo14NnRyIIMLc7KgZTAplulWmE=; b=Is/RUNmKPc73WcnbHPoTHL7UonQOhWP9WqESj8Of+c0Y78w1ZXc7rNONLDFXojT7LpGhu0 pMHuOrJFa2jtUVBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1706792234; 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=quxIrh1tyAx9ITJ3SJo14NnRyIIMLc7KgZTAplulWmE=; b=iJLbla0IhxoqJ8tiDFzkbc6HVbE1RYA7bRLaTtNZT8GOCQZs+5jXY/H4gGmju5dehsD0xw scOeuhGj1tfZsJ9khojWzyLnkNnIJjMmhgbqPKWQT18bp5Uy0eBed24g/vQdrZvTWFUEdd a2f8aDMxIMO0g989CRgByfJJJeovDt8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1706792234; 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=quxIrh1tyAx9ITJ3SJo14NnRyIIMLc7KgZTAplulWmE=; b=Is/RUNmKPc73WcnbHPoTHL7UonQOhWP9WqESj8Of+c0Y78w1ZXc7rNONLDFXojT7LpGhu0 pMHuOrJFa2jtUVBw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 482C2139B1 for ; Thu, 1 Feb 2024 12:57:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id TpQwESqVu2WCPQAAD6G6ig (envelope-from ) for ; Thu, 01 Feb 2024 12:57:14 +0000 From: Martin Doucha To: ltp@lists.linux.it Date: Thu, 1 Feb 2024 13:57:10 +0100 Message-ID: <20240201125713.1811-1-mdoucha@suse.cz> X-Mailer: git-send-email 2.42.1 MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [10.00 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; FROM_HAS_DN(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[ltp@lists.linux.it]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; TO_DN_NONE(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: 10.00 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-3.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-3.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2] waitpid04: Convert to new 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" Convert waitpid() error state checks to new API, fix bugs in the original test and add ESRCH subtest. Signed-off-by: Martin Doucha --- Changes since v1: - Fix include - Use TST_EXP_FAIL2() testcases/kernel/syscalls/waitpid/waitpid04.c | 161 +++--------------- 1 file changed, 28 insertions(+), 133 deletions(-) diff --git a/testcases/kernel/syscalls/waitpid/waitpid04.c b/testcases/kernel/syscalls/waitpid/waitpid04.c index abf94eed1..7cd050e72 100644 --- a/testcases/kernel/syscalls/waitpid/waitpid04.c +++ b/testcases/kernel/syscalls/waitpid/waitpid04.c @@ -1,144 +1,39 @@ +// 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 + * Copyright (c) 2024 SUSE LLC */ -/* - * NAME - * waitpid04.c - * - * DESCRIPTION - * test to check the error conditions in waitpid sys call - * - * USAGE: - * waitpid04 [-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. +/*\ + * [Description] * - * History - * 07/2001 John George - * -Ported - * - * Restrictions - * NONE + * Test to check the error conditions in waitpid() syscall. */ -#include -#include +#include #include -#include -#include "test.h" - -static void setup(void); -static void cleanup(void); - -char *TCID = "waitpid04"; -int TST_TOTAL = 1; - -#define INVAL_FLAG -1 - -static int flag, condition_number; - -int main(int ac, char **av) +#include "tst_test.h" + +static struct testcase { + pid_t pid; + int flags; + int err; +} testcase_list[] = { + {-1, 0, ECHILD}, /* Wait for any child when none exist */ + {1, 0, ECHILD}, /* Wait for non-child process */ + {-1, -1, EINVAL}, /* Invalid flags */ + {INT_MIN, 0, ESRCH}, /* Wait for invalid process group */ +}; + +void run(unsigned int n) { - int pid, status, ret; + const struct testcase *tc = testcase_list + n; - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - /* check for looping state if -i option is given */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - ret = waitpid(pid, &status, WNOHANG); - flag = 0; - condition_number = 1; - if (ret != -1) { - tst_resm(TFAIL, "condition %d test failed", - condition_number); - } else { - if (errno != ECHILD) { - tst_resm(TFAIL, "waitpid() set invalid " - "errno, expected ECHILD, got: %d", - errno); - } else { - tst_resm(TPASS, "condition %d test passed", - condition_number); - } - } - condition_number++; - - if (FORK_OR_VFORK() == 0) - exit(0); - - pid = 1; - ret = waitpid(pid, &status, WUNTRACED); - flag = 0; - if (ret != -1) { - tst_resm(TFAIL, "condition %d test failed", - condition_number); - } else { - if (errno != ECHILD) { - tst_resm(TFAIL, "waitpid() set invalid " - "errno, expected ECHILD, got: %d", - errno); - } else { - tst_resm(TPASS, "condition %d test passed", - condition_number); - } - } - condition_number++; - - /* Option is Inval = INVAL_FLAG */ - ret = waitpid(pid, &status, INVAL_FLAG); - flag = 0; - if (ret != -1) { - tst_resm(TFAIL, "condition %d test failed", - condition_number); - } else { - if (errno != EINVAL) { - tst_resm(TFAIL, "waitpid() set invalid " - "errno, expected EINVAL, got: %d", - errno); - } else { - tst_resm(TPASS, "condition %d test passed", - condition_number); - } - } - condition_number++; - } - - cleanup(); - tst_exit(); -} - -static void setup(void) -{ - TEST_PAUSE; + TST_EXP_FAIL2(waitpid(tc->pid, NULL, tc->flags), tc->err, + "waipid(%d, NULL, 0x%x)", tc->pid, tc->flags); } -static void cleanup(void) -{ -} +static struct tst_test test = { + .test = run, + .tcnt = ARRAY_SIZE(testcase_list) +};