From patchwork Fri Jan 28 08:44:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1585565 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=BtMjVMoy; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=NOlE0a09; 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 (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JlWGY39Rdz9t25 for ; Fri, 28 Jan 2022 19:44:19 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 75E2A3C9741 for ; Fri, 28 Jan 2022 09:44:15 +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]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 3A4F63C7FEC for ; Fri, 28 Jan 2022 09:44:13 +0100 (CET) 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-5.smtp.seeweb.it (Postfix) with ESMTPS id 5729460098C for ; Fri, 28 Jan 2022 09:44:12 +0100 (CET) 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 4A9771F385; Fri, 28 Jan 2022 08:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1643359451; 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=Ayw3yhdjK6/A0Wdor9rXYCHxjAfhV3yryfmVbgr183k=; b=BtMjVMoyAIfB7MlkxZvnm0jG1158qjkC9tYWmwdhkHR0FeXh41D93ANestpGaL2a00bih4 2H0jviKmbQnY+mhAqzuGRlQRlZo6e93/+mxWFiGhz+2gZgk/PieeB4mMMBzvx5a/3KuuEW dCRoKaPygkVpSnJjjAb2DIRUncyj9sY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1643359451; 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=Ayw3yhdjK6/A0Wdor9rXYCHxjAfhV3yryfmVbgr183k=; b=NOlE0a09p/EY9GzxohdxW5KDhURUco94mACYk/9Fx5w4i7MWEoqFTVX+ffVo7/gcu8BUMS CJBdojKoOecSR8CA== 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 22475139D0; Fri, 28 Jan 2022 08:44:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 7s1kBtus82GmYwAAMHmgww (envelope-from ); Fri, 28 Jan 2022 08:44:11 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Fri, 28 Jan 2022 09:44:09 +0100 Message-Id: <20220128084409.21708-1-andrea.cervesato@suse.de> X-Mailer: git-send-email 2.34.1 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.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-5.smtp.seeweb.it Subject: [LTP] [PATCH v1] Refactoring setpgid03.c 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" Removed TST_CHECKPOINT_INIT and replaced it with the .needs_checkpoints LTP test feature. Simplified source code. Signed-off-by: Andrea Cervesato --- testcases/kernel/syscalls/setpgid/setpgid03.c | 183 ++++++------------ .../kernel/syscalls/setpgid/setpgid03_child.c | 28 +-- 2 files changed, 61 insertions(+), 150 deletions(-) diff --git a/testcases/kernel/syscalls/setpgid/setpgid03.c b/testcases/kernel/syscalls/setpgid/setpgid03.c index 51e0eeb24..6972d6099 100644 --- a/testcases/kernel/syscalls/setpgid/setpgid03.c +++ b/testcases/kernel/syscalls/setpgid/setpgid03.c @@ -1,24 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2001 * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. * Copyright (c) 2014 Cyril Hrubis - * - * 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) 2021 SUSE LLC Andrea Cervesato */ -/* +/*\ + * [Description] + * * Test to check the error and trivial conditions in setpgid system call * * EPERM - The calling process, process specified by pid and the target @@ -28,136 +18,73 @@ * has performed exec() */ -#include -#include -#include -#include -#include -#include -#include #include -#include "test.h" +#include +#include "tst_test.h" #define TEST_APP "setpgid03_child" -char *TCID = "setpgid03"; -int TST_TOTAL = 1; - -static void do_child(void); -static void setup(void); -static void cleanup(void); +static void do_child(void) +{ + SAFE_SETSID(); + TST_CHECKPOINT_WAKE_AND_WAIT(0); +} -int main(int ac, char **av) +static void run(void) { - int child_pid; + pid_t child_pid; int status; - int rval; - int lc; - - tst_parse_opts(ac, av, NULL, NULL); -#ifdef UCLINUX - maybe_run_child(&do_child, ""); -#endif - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* Child is in new session we are not alowed to change pgid */ - if ((child_pid = FORK_OR_VFORK()) == -1) - tst_brkm(TBROK, cleanup, "fork() failed"); - - if (child_pid == 0) { -#ifdef UCLINUX - if (self_exec(av[0], "") < 0) - tst_brkm(TBROK, cleanup, "self_exec failed"); -#else - do_child(); -#endif - } - - TST_SAFE_CHECKPOINT_WAIT(cleanup, 0); - rval = setpgid(child_pid, getppid()); - if (rval == -1 && errno == EPERM) { - tst_resm(TPASS, "setpgid failed with EPERM"); - } else { - tst_resm(TFAIL, - "retval %d, errno %d, expected errno %d", - rval, errno, EPERM); - } - TST_SAFE_CHECKPOINT_WAKE(cleanup, 0); - - if (wait(&status) < 0) - tst_resm(TFAIL | TERRNO, "wait() for child 1 failed"); - - if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) - tst_resm(TFAIL, "child 1 failed with status %d", - WEXITSTATUS(status)); - - /* Child after exec() we are no longer allowed to set pgid */ - if ((child_pid = FORK_OR_VFORK()) == -1) - tst_resm(TFAIL, "Fork failed"); - - if (child_pid == 0) { - if (execlp(TEST_APP, TEST_APP, NULL) < 0) - perror("exec failed"); - - exit(127); - } - - TST_SAFE_CHECKPOINT_WAIT(cleanup, 0); - rval = setpgid(child_pid, getppid()); - if (rval == -1 && errno == EACCES) { - tst_resm(TPASS, "setpgid failed with EACCES"); - } else { - tst_resm(TFAIL, - "retval %d, errno %d, expected errno %d", - rval, errno, EACCES); - } - TST_SAFE_CHECKPOINT_WAKE(cleanup, 0); - - if (wait(&status) < 0) - tst_resm(TFAIL | TERRNO, "wait() for child 2 failed"); - - if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) - tst_resm(TFAIL, "child 2 failed with status %d", - WEXITSTATUS(status)); + + child_pid = SAFE_FORK(); + if (!child_pid) { + do_child(); + return; } - cleanup(); - tst_exit(); -} + TST_CHECKPOINT_WAIT(0); -static void do_child(void) -{ - if (setsid() < 0) { - printf("CHILD: setsid() failed, errno: %d\n", errno); - exit(2); - } + TEST(setpgid(child_pid, getppid())); + if (TST_RET == -1 && TST_ERR == EPERM) + tst_res(TPASS, "setpgid failed with EPERM"); + else + tst_res(TFAIL, "retval %ld, errno %s, expected EPERM", TST_RET, + tst_strerrno(TST_ERR)); - TST_SAFE_CHECKPOINT_WAKE(NULL, 0); + TST_CHECKPOINT_WAKE(0); - TST_SAFE_CHECKPOINT_WAIT(NULL, 0); + if (wait(&status) < 0) + tst_res(TFAIL, "wait() for child 1 failed"); - exit(0); -} + if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) + tst_res(TFAIL, "child 1 failed with status %d", + WEXITSTATUS(status)); -static void setup(void) -{ - tst_sig(FORK, DEF_HANDLER, cleanup); + /* child after exec() we are no longer allowed to set pgid */ + child_pid = SAFE_FORK(); + if (!child_pid) + SAFE_EXECLP(TEST_APP, TEST_APP, NULL); - tst_tmpdir(); + TST_CHECKPOINT_WAIT(0); - TST_CHECKPOINT_INIT(tst_rmdir); + TEST(setpgid(child_pid, getppid())); + if (TST_RET == -1 && TST_ERR == EACCES) + tst_res(TPASS, "setpgid failed with EACCES"); + else + tst_res(TFAIL, "retval %ld, errno %s, expected EACCES", TST_RET, + tst_strerrno(TST_ERR)); - umask(0); + TST_CHECKPOINT_WAKE(0); - TEST_PAUSE; -} + if (wait(&status) < 0) + tst_res(TFAIL, "wait() for child 2 failed"); -static void cleanup(void) -{ - tst_rmdir(); + if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) + tst_res(TFAIL, "child 2 failed with status %d", + WEXITSTATUS(status)); } + +static struct tst_test test = { + .test_all = run, + .forks_child = 1, + .needs_checkpoints = 1, +}; diff --git a/testcases/kernel/syscalls/setpgid/setpgid03_child.c b/testcases/kernel/syscalls/setpgid/setpgid03_child.c index 2657422a6..fdb22f24d 100644 --- a/testcases/kernel/syscalls/setpgid/setpgid03_child.c +++ b/testcases/kernel/syscalls/setpgid/setpgid03_child.c @@ -1,32 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. - * - * 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 would 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 the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (C) 2021 SUSE LLC Andrea Cervesato */ -#include "test.h" - -char *TCID = "setpgid03_child"; - +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" int main(void) { - TST_CHECKPOINT_INIT(NULL); - - TST_SAFE_CHECKPOINT_WAKE(NULL, 0); - TST_SAFE_CHECKPOINT_WAIT(NULL, 0); + tst_reinit(); + TST_CHECKPOINT_WAKE_AND_WAIT(0); return 0; }