From patchwork Fri Mar 30 10:56:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinhui Huang X-Patchwork-Id: 893217 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40CJTp5J2Vz9s1r for ; Fri, 30 Mar 2018 21:57:02 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id EBD023E6B56 for ; Fri, 30 Mar 2018 12:56:59 +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]) by picard.linux.it (Postfix) with ESMTP id 5CC573E6B1E for ; Fri, 30 Mar 2018 12:56:58 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 2C63C1400066 for ; Fri, 30 Mar 2018 12:56:54 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38350036" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Mar 2018 18:56:45 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 8E8A5486A78C for ; Fri, 30 Mar 2018 18:56:47 +0800 (CST) Received: from localhost.localdomain (10.167.220.196) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 30 Mar 2018 18:56:45 +0800 From: Jinhui Huang To: Date: Fri, 30 Mar 2018 18:56:42 +0800 Message-ID: <1522407404-6877-1-git-send-email-huangjh.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.196] X-yoursite-MailScanner-ID: 8E8A5486A78C.AEAA9 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: huangjh.jy@cn.fujitsu.com X-Spam-Status: No, score=-0.0 required=7.0 tests=T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 1/3] syscalls/fchmod.h: Move common macros to fchmod.h X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 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: Jinhui Huang Acked-by: Petr Vorel --- testcases/kernel/syscalls/fchmod/fchmod.h | 26 ++++++++++++++++++++++++++ testcases/kernel/syscalls/fchmod/fchmod02.c | 7 +------ testcases/kernel/syscalls/fchmod/fchmod03.c | 5 +---- testcases/kernel/syscalls/fchmod/fchmod04.c | 8 +------- testcases/kernel/syscalls/fchmod/fchmod05.c | 15 +++++++-------- testcases/kernel/syscalls/fchmod/fchmod07.c | 4 +--- 6 files changed, 37 insertions(+), 28 deletions(-) create mode 100644 testcases/kernel/syscalls/fchmod/fchmod.h diff --git a/testcases/kernel/syscalls/fchmod/fchmod.h b/testcases/kernel/syscalls/fchmod/fchmod.h new file mode 100644 index 0000000..e52850d --- /dev/null +++ b/testcases/kernel/syscalls/fchmod/fchmod.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved. + * Author: Jinhui huang + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * alone with this program. + */ + +#ifndef FCHMOD_H +#define FCHMOD_H + +#define FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) +#define DIR_MODE (S_IRWXU | S_IRWXG | S_IRWXO) +#define PERMS 01777 +#define TESTFILE "testfile" +#define TESTDIR "testdir" + +#endif /* FCHMOD_H */ diff --git a/testcases/kernel/syscalls/fchmod/fchmod02.c b/testcases/kernel/syscalls/fchmod/fchmod02.c index ea2bdb4..aa3bab3 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod02.c +++ b/testcases/kernel/syscalls/fchmod/fchmod02.c @@ -82,15 +82,10 @@ #include "test.h" #include "safe_macros.h" +#include "fchmod.h" #define LTPUSER "nobody" #define LTPGRP "users" -#define FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH -#define PERMS 01777 /* - * Mode permissions of test file with sticky - * bit set. - */ -#define TESTFILE "testfile" int fd; /* file descriptor variable */ char *TCID = "fchmod02"; diff --git a/testcases/kernel/syscalls/fchmod/fchmod03.c b/testcases/kernel/syscalls/fchmod/fchmod03.c index 8d35bc1..a5824f3 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod03.c +++ b/testcases/kernel/syscalls/fchmod/fchmod03.c @@ -81,10 +81,7 @@ #include "test.h" #include "safe_macros.h" - -#define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) -#define PERMS 01777 -#define TESTFILE "testfile" +#include "fchmod.h" int fd; /* file descriptor for test file */ char *TCID = "fchmod03"; diff --git a/testcases/kernel/syscalls/fchmod/fchmod04.c b/testcases/kernel/syscalls/fchmod/fchmod04.c index 27e3bdc..befaadb 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod04.c +++ b/testcases/kernel/syscalls/fchmod/fchmod04.c @@ -81,13 +81,7 @@ #include "test.h" #include "safe_macros.h" - -#define DIR_MODE S_IRWXU | S_IRWXG | S_IRWXO -#define PERMS 01777 /* - * Mode permissions of test directory with - * sticky bit set. - */ -#define TESTDIR "testdir_4" +#include "fchmod.h" int fd; /* file descriptor for test directory */ char *TCID = "fchmod04"; diff --git a/testcases/kernel/syscalls/fchmod/fchmod05.c b/testcases/kernel/syscalls/fchmod/fchmod05.c index cdd3d07..0ab2023 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod05.c +++ b/testcases/kernel/syscalls/fchmod/fchmod05.c @@ -88,10 +88,9 @@ #include "test.h" #include "safe_macros.h" +#include "fchmod.h" -#define MODE_RWX (S_IRWXU | S_IRWXG | S_IRWXO) -#define PERMS 043777 -#define TESTDIR "testdir" +#define PERMS_GID 043777 int fd; /* file descriptor for test directory */ char *TCID = "fchmod05"; @@ -119,7 +118,7 @@ int main(int ac, char **av) * to set setgid bit on TESTDIR. */ - TEST(fchmod(fd, PERMS)); + TEST(fchmod(fd, PERMS_GID)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "fchmod(%d, %#o) Failed, errno=%d : %s", @@ -136,14 +135,14 @@ int main(int ac, char **av) TESTDIR, TEST_ERRNO); } dir_mode = stat_buf.st_mode; - if ((PERMS & ~S_ISGID) != dir_mode) { + if ((PERMS_GID & ~S_ISGID) != dir_mode) { tst_resm(TFAIL, "%s: Incorrect modes 0%03o, " "Expected 0%03o", - TESTDIR, dir_mode, PERMS & ~S_ISGID); + TESTDIR, dir_mode, PERMS_GID & ~S_ISGID); } else { tst_resm(TPASS, "Functionality of fchmod(%d, " "%#o) successful", fd, - PERMS & ~S_ISGID); + PERMS_GID & ~S_ISGID); } } @@ -188,7 +187,7 @@ void setup(void) * mode permissions and change the gid of test directory to that of * guest user. */ - SAFE_MKDIR(cleanup, TESTDIR, MODE_RWX); + SAFE_MKDIR(cleanup, TESTDIR, DIR_MODE); if (setgroups(1, &nobody_u->pw_gid) == -1) tst_brkm(TBROK, cleanup, diff --git a/testcases/kernel/syscalls/fchmod/fchmod07.c b/testcases/kernel/syscalls/fchmod/fchmod07.c index 6973555..d7fe41f 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod07.c +++ b/testcases/kernel/syscalls/fchmod/fchmod07.c @@ -75,9 +75,7 @@ #include "test.h" #include "safe_macros.h" - -#define FILE_MODE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH -#define TESTFILE "testfile" +#include "fchmod.h" int fd; /* file descriptor for testfile */ char *TCID = "fchmod07"; From patchwork Fri Mar 30 10:56:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinhui Huang X-Patchwork-Id: 893219 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; 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=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40CJV05Krtz9sCv for ; Fri, 30 Mar 2018 21:57:12 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D1A9E3E6B9B for ; Fri, 30 Mar 2018 12:57:09 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 4A1DB3E6B1E for ; Fri, 30 Mar 2018 12:57:08 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 7869E1002894 for ; Fri, 30 Mar 2018 12:56:59 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38350038" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Mar 2018 18:56:51 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 44E3C486A78C for ; Fri, 30 Mar 2018 18:56:48 +0800 (CST) Received: from localhost.localdomain (10.167.220.196) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 30 Mar 2018 18:56:46 +0800 From: Jinhui Huang To: Date: Fri, 30 Mar 2018 18:56:43 +0800 Message-ID: <1522407404-6877-2-git-send-email-huangjh.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1522407404-6877-1-git-send-email-huangjh.jy@cn.fujitsu.com> References: <1522407404-6877-1-git-send-email-huangjh.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.196] X-yoursite-MailScanner-ID: 44E3C486A78C.AE935 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: huangjh.jy@cn.fujitsu.com X-Spam-Status: No, score=-0.0 required=7.0 tests=T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 2/3] syscalls/fchmod01.c: Convert to new API && merge fchmod07 into fchmod01 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 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: Jinhui Huang --- runtest/ltplite | 1 - runtest/stress.part3 | 1 - runtest/syscalls | 1 - testcases/kernel/syscalls/.gitignore | 1 - testcases/kernel/syscalls/fchmod/fchmod01.c | 182 ++++++-------------------- testcases/kernel/syscalls/fchmod/fchmod07.c | 192 ---------------------------- 6 files changed, 41 insertions(+), 337 deletions(-) delete mode 100644 testcases/kernel/syscalls/fchmod/fchmod07.c diff --git a/runtest/ltplite b/runtest/ltplite index 15dc0c2..dd8dc96 100644 --- a/runtest/ltplite +++ b/runtest/ltplite @@ -191,7 +191,6 @@ fchmod03 fchmod03 fchmod04 fchmod04 fchmod05 fchmod05 fchmod06 fchmod06 -fchmod07 fchmod07 fchown01 fchown01 fchown02 fchown02 diff --git a/runtest/stress.part3 b/runtest/stress.part3 index 2a7747c..9eeae83 100644 --- a/runtest/stress.part3 +++ b/runtest/stress.part3 @@ -132,7 +132,6 @@ fchmod03 fchmod03 fchmod04 fchmod04 fchmod05 fchmod05 fchmod06 fchmod06 -fchmod07 fchmod07 fchown01 fchown01 fchown02 fchown02 diff --git a/runtest/syscalls b/runtest/syscalls index 76ab082..83bd90b 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -184,7 +184,6 @@ fchmod03 fchmod03 fchmod04 fchmod04 fchmod05 fchmod05 fchmod06 fchmod06 -fchmod07 fchmod07 #fchmodat test cases fchmodat01 fchmodat01 diff --git a/testcases/kernel/syscalls/.gitignore b/testcases/kernel/syscalls/.gitignore index eea606e..41ca097 100644 --- a/testcases/kernel/syscalls/.gitignore +++ b/testcases/kernel/syscalls/.gitignore @@ -153,7 +153,6 @@ /fchmod/fchmod04 /fchmod/fchmod05 /fchmod/fchmod06 -/fchmod/fchmod07 /fchmodat/fchmodat01 /fchown/fchown01 /fchown/fchown01_16 diff --git a/testcases/kernel/syscalls/fchmod/fchmod01.c b/testcases/kernel/syscalls/fchmod/fchmod01.c index dd4a28c..062290c 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod01.c +++ b/testcases/kernel/syscalls/fchmod/fchmod01.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. + * Author: Wayne Boyer and William Roske * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as @@ -15,167 +16,66 @@ * otherwise, applies only to this software file. Patent licenses, if * any, provided herein do not apply to combinations of this program with * other software, or any other product whatsoever. - * - * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, - * Mountain View, CA 94043, or: - * - * http://www.sgi.com - * - * For further information regarding this notice, see: - * - * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ - * */ -/* $Id: fchmod01.c,v 1.6 2009/10/26 14:55:46 subrata_modak Exp $ */ -/********************************************************** - * - * OS Test - Silicon Graphics, Inc. - * - * TEST IDENTIFIER : fchmod01 - * - * PARENT DOCUMENT : usctpl01 - * - * TEST CASE TOTAL : 1 - * - * WALL CLOCK TIME : 1 - * - * CPU TYPES : ALL - * - * AUTHOR : William Roske - * - * CO-PILOT : Dave Fenner - * - * DATE STARTED : 03/30/92 - * - * INITIAL RELEASE : UNICOS 7.0 - * - * TEST CASES - * - * 1.) fchmod(2) returns...(See Description) - * - * INPUT SPECIFICATIONS - * The standard options for system call tests are accepted. - * (See the parse_opts(3) man page). - * - * OUTPUT SPECIFICATIONS - *$ - * DURATION - * Terminates - with frequency and infinite modes. - * - * SIGNALS - * Uses SIGUSR1 to pause before test if option set. - * (See the parse_opts(3) man page). - * - * RESOURCES - * None - * - * ENVIRONMENTAL NEEDS - * No run-time environmental needs. - * - * SPECIAL PROCEDURAL REQUIREMENTS - * None - * - * INTERCASE DEPENDENCIES - * None - * - * DETAILED DESCRIPTION - * This is a Phase I test for the fchmod(2) system call. It is intended - * to provide a limited exposure of the system call, for now. It - * should/will be extended when full functional tests are written for - * fchmod(2). - * - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, Issue a PASS message. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * - * - *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/ +/* + * Test Description: + * fchmod() will succeed to change the mode permissions of a file specified + * by file descriptor. + */ #include -#include #include +#include #include -#include -#include -#include "test.h" - -void setup(); -void cleanup(); -char *TCID = "fchmod01"; -int TST_TOTAL = 1; +#include "tst_test.h" +#include "fchmod.h" -char fname[255]; -int fd; -char *buf = "davef"; +static int fd; +static int Modes[] = { 0, 07, 070, 0700, 0777, 02777, 04777, 06777 }; -int main(int ac, char **av) +static void verify_fchmod(void) { - int lc; + struct stat stat_buf; + int ind; + mode_t file_mode, mode; - tst_parse_opts(ac, av, NULL, NULL); + for (ind = 0; ind < 8; ind++) { + mode = (mode_t)Modes[ind]; - setup(); + TEST(fchmod(fd, mode)); + if (TEST_RETURN == -1) + tst_res(TFAIL | TTERRNO, "fchmod() failed unexpectly"); - for (lc = 0; TEST_LOOPING(lc); lc++) { + SAFE_FSTAT(fd, &stat_buf); + file_mode = stat_buf.st_mode; - tst_count = 0; - - TEST(fchmod(fd, 0700)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL | TTERRNO, - "fchmod(%s, 0700) failed", fname); + if ((file_mode & ~S_IFREG) != mode) { + tst_res(TFAIL, + "%s: Incorrect modes 0%03o, Expected 0%03o", + TESTFILE, file_mode & ~S_IFREG, mode); } else { - tst_resm(TPASS, "fchmod(%s, 0700) returned %ld", - fname, TEST_RETURN); + tst_res(TPASS, + "Functionality of fchmod(%d, %#o) successful", + fd, mode); } - } - - cleanup(); - tst_exit(); } -void setup(void) +static void setup(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - sprintf(fname, "tfile_%d", getpid()); - if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "open failed"); - else if (write(fd, buf, strlen(buf)) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "write failed"); + fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, FILE_MODE); } -/*************************************************************** - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - ***************************************************************/ -void cleanup(void) +static void cleanup(void) { - if (close(fd) == -1) - tst_brkm(TWARN | TERRNO, cleanup, "close failed"); - - tst_rmdir(); - + if (fd > 0) + SAFE_CLOSE(fd); } + +static struct tst_test test = { + .test_all = verify_fchmod, + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +}; diff --git a/testcases/kernel/syscalls/fchmod/fchmod07.c b/testcases/kernel/syscalls/fchmod/fchmod07.c deleted file mode 100644 index d7fe41f..0000000 --- a/testcases/kernel/syscalls/fchmod/fchmod07.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * - * 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 - */ - -/* - * Test Name: fchmod07 - * - * Test Description: - * Verify that, fchmod(2) succeeds when used to change the mode permissions - * of a file specified by file descriptor. - * - * Expected Result: - * fchmod(2) should return 0 and the mode permissions set on file should match - * the specified mode. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * fchmod07 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -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. - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" -#include "fchmod.h" - -int fd; /* file descriptor for testfile */ -char *TCID = "fchmod07"; -int TST_TOTAL = 8; /* Total number of test conditions */ - -mode_t Modes[] = { 0, 07, 070, 0700, 0777, 02777, 04777, 06777 }; - -void setup(); /* setup function for the test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) -{ - struct stat stat_buf; /* stat(2) struct contents */ - int lc; - int ind; /* counter variable for chmod(2) tests */ - mode_t mode; /* file mode permission */ - - TST_TOTAL = sizeof(Modes) / sizeof(int); - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - for (ind = 0; ind < TST_TOTAL; ind++) { - mode = Modes[ind]; - - /* - * Call fchmod(2) with different mode permission - * bits to set it for "testfile". - */ - TEST(fchmod(fd, mode)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "fchmod(%d, %#o) Failed, " - "errno=%d : %s", fd, mode, TEST_ERRNO, - strerror(TEST_ERRNO)); - continue; - } - /* - * Get the testfile information using - * fstat(2). - */ - if (fstat(fd, &stat_buf) < 0) { - tst_brkm(TFAIL, cleanup, - "fstat(2) of " - "%s failed, errno:%d", - TESTFILE, TEST_ERRNO); - } - stat_buf.st_mode &= ~S_IFREG; - - /* - * Check for expected mode permissions - * on testfile. - */ - if (stat_buf.st_mode == mode) { - tst_resm(TPASS, - "Functionality of " - "fchmod(%d, %#o) successful", - fd, mode); - } else { - tst_resm(TFAIL, "%s: Incorrect modes " - "0%03o, Expected 0%03o", - TESTFILE, stat_buf.st_mode, - mode); - } - } - } - - cleanup(); - tst_exit(); -} - -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and change directory to it. - * Create a test file under temporary directory. - */ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) { - tst_brkm(TBROK, cleanup, - "open(%s, O_RDWR|O_CREAT, %o) Failed, errno=%d : %s", - TESTFILE, FILE_MODE, errno, strerror(errno)); - } -} - -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Close the testfile created in the setup. - * Remove the test directory and testfile created in the setup. - */ -void cleanup(void) -{ - - /* Close the TESTFILE opened in the setup() */ - SAFE_CLOSE(NULL, fd); - - tst_rmdir(); - -} From patchwork Fri Mar 30 10:56:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jinhui Huang X-Patchwork-Id: 893218 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; 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=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40CJTs3dVdz9s1r for ; Fri, 30 Mar 2018 21:57:05 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E553A3E6C25 for ; Fri, 30 Mar 2018 12:57:02 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id D9A8E3E6B1E for ; Fri, 30 Mar 2018 12:56:58 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 5C13B1002891 for ; Fri, 30 Mar 2018 12:56:56 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="38350037" Received: from bogon (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 30 Mar 2018 18:56:51 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id 30BCC48AE76C for ; Fri, 30 Mar 2018 18:56:49 +0800 (CST) Received: from localhost.localdomain (10.167.220.196) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 30 Mar 2018 18:56:47 +0800 From: Jinhui Huang To: Date: Fri, 30 Mar 2018 18:56:44 +0800 Message-ID: <1522407404-6877-3-git-send-email-huangjh.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1522407404-6877-1-git-send-email-huangjh.jy@cn.fujitsu.com> References: <1522407404-6877-1-git-send-email-huangjh.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.196] X-yoursite-MailScanner-ID: 30BCC48AE76C.A17C1 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: huangjh.jy@cn.fujitsu.com X-Spam-Status: No, score=-0.0 required=7.0 tests=T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 3/3] syscalls/fchmod02.c: Cleanup && convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 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: Jinhui Huang Acked-by: Petr Vorel --- testcases/kernel/syscalls/fchmod/fchmod02.c | 227 +++++++--------------------- 1 file changed, 53 insertions(+), 174 deletions(-) diff --git a/testcases/kernel/syscalls/fchmod/fchmod02.c b/testcases/kernel/syscalls/fchmod/fchmod02.c index aa3bab3..3a7deaa 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod02.c +++ b/testcases/kernel/syscalls/fchmod/fchmod02.c @@ -1,27 +1,19 @@ /* + * Copyright (c) International Business Machines Corp., 2001 * - * 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 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 + * 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. */ - /* - * Test Name: fchmod02 - * * Test Description: - * Verify that, fchmod(2) will succeed to change the mode of a file/directory + * Verify that, fchmod() will succeed to change the mode of a file/directory * set the sticky bit on it if invoked by root (uid = 0) process with * the following constraints, * - the process is not the owner of the file/directory. @@ -31,182 +23,69 @@ * Expected Result: * fchmod() should return value 0 on success and succeeds to set sticky bit * on the specified file. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * Log the errno and Issue a FAIL message. - * Otherwise, - * Verify the Functionality of system call - * if successful, - * Issue Functionality-Pass message. - * Otherwise, - * Issue Functionality-Fail message. - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory created. - * - * Usage: - * fchmod02 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -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: - * This test should be run by 'super-user' (root) only. - * */ -#include #include #include -#include -#include -#include -#include -#include +#include #include +#include +#include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "fchmod.h" #define LTPUSER "nobody" #define LTPGRP "users" -int fd; /* file descriptor variable */ -char *TCID = "fchmod02"; -int TST_TOTAL = 1; +static int fd; -void setup(); /* Main setup function for the test */ -void cleanup(); /* Main cleanup function for the test */ - -int main(int ac, char **av) +static void verify_fchmod(void) { - struct stat stat_buf; /* stat(2) struct contents */ - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Call fchmod(2) with specified mode argument - * (sticky-bit set) on testfile. - */ - TEST(fchmod(fd, PERMS)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "fchmod(%d, %#o) Failed, errno=%d : %s", - fd, PERMS, TEST_ERRNO, strerror(TEST_ERRNO)); - continue; - } - /* - * Get the testfile information using - * fstat(2). - */ - if (fstat(fd, &stat_buf) < 0) { - tst_brkm(TFAIL, cleanup, "fstat(2) of %s " - "failed, errno:%d", TESTFILE, - TEST_ERRNO); - } - - /* Check for expected mode permissions */ - if ((stat_buf.st_mode & PERMS) == PERMS) { - tst_resm(TPASS, "Functionality of fchmod(%d, " - "%#o) Successful", fd, PERMS); - } else { - tst_resm(TFAIL, "%s: Incorrect modes 0%03o, " - "Expected 0%03o", TESTFILE, - stat_buf.st_mode, PERMS); - } + struct stat stat_buf; + mode_t file_mode; + + TEST(fchmod(fd, PERMS)); + if (TEST_RETURN == -1) + tst_res(TFAIL | TTERRNO, "fchmod() failed unexpectly"); + + SAFE_FSTAT(fd, &stat_buf); + file_mode = stat_buf.st_mode; + + if ((file_mode & ~S_IFREG) != PERMS) { + tst_res(TFAIL, "%s: Incorrect modes 0%03o, Expected 0%03o", + TESTFILE, file_mode, PERMS); + } else { + tst_res(TPASS, "Functionality of fchmod(%d, %#o) Successful", + fd, PERMS); } - - cleanup(); - tst_exit(); } -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and change directory to it. - * Create a test file under temporary directory. - * Change the ownership of test file to that of "ltpuser1" user. - */ -void setup(void) +static void setup(void) { - struct passwd *ltpuser; /* password struct for ltpuser1 */ - struct group *ltpgroup; /* group struct for ltpuser1 */ - gid_t group1_gid; /* user and process group id's */ - uid_t user1_uid; - - tst_require_root(); - - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - /* Get the uid of guest user - ltpuser1 */ - if ((ltpuser = getpwnam(LTPUSER)) == NULL) { - tst_brkm(TBROK, cleanup, "%s not in /etc/passwd", LTPUSER); - } - user1_uid = ltpuser->pw_uid; + struct passwd *ltpuser; + struct group *ltpgroup; - /* Get the group id of guest user - ltpuser1 */ - if ((ltpgroup = getgrnam(LTPGRP)) == NULL) { - tst_brkm(TBROK, cleanup, "%s not in /etc/group", LTPGRP); - } - group1_gid = ltpgroup->gr_gid; - - /* - * Create a test file under temporary directory with specified - * mode permissios and set the ownership of the test file to the - * uid/gid of guest user user1. - */ - if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) { - tst_brkm(TBROK, cleanup, - "open(%s, O_RDWR|O_CREAT, %#o) Failed, errno=%d : %s", - TESTFILE, FILE_MODE, errno, strerror(errno)); - } + ltpuser = SAFE_GETPWNAM(LTPUSER); + ltpgroup = getgrnam(LTPGRP); + if (ltpgroup == NULL) + tst_brk(TBROK, "%s not in /etc/group", LTPGRP); - SAFE_CHOWN(cleanup, TESTFILE, user1_uid, group1_gid); - - /* Set the effective gid of the process to that of user */ - SAFE_SETGID(cleanup, group1_gid); + fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, FILE_MODE); + SAFE_CHOWN(TESTFILE, ltpuser->pw_uid, ltpgroup->gr_gid); + SAFE_SETGID(ltpgroup->gr_gid); } -/* - * void - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Close the testfile created in the setup. - * Remove the test directory and testfile created in the setup. - */ -void cleanup(void) +static void cleanup(void) { - - /* Close the testfile created in the setup() */ - SAFE_CLOSE(NULL, fd); - - tst_rmdir(); - + if (fd > 0) + SAFE_CLOSE(fd); } + +static struct tst_test test = { + .test_all = verify_fchmod, + .needs_root = 1, + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, +};