From patchwork Thu Apr 5 14:01:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895400 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=suse.cz 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 40H4Lk36gJz9s2B for ; Fri, 6 Apr 2018 00:03:58 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0C2BF3E78D7 for ; Thu, 5 Apr 2018 16:03:55 +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 219DB3E76BA for ; Thu, 5 Apr 2018 16:03:36 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 68DCB1401B80 for ; Thu, 5 Apr 2018 16:03:35 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E42B9AD45 for ; Thu, 5 Apr 2018 14:03:34 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:01:54 +0200 Message-Id: <20180405140154.6218-9-chrubis@suse.cz> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180405140154.6218-1-chrubis@suse.cz> References: <20180405140154.6218-1-chrubis@suse.cz> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_PASS,T_RP_MATCHES_RCVD autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Subject: [LTP] [RFC PATCH 8/8] syscalls/fchmod06: Convert to the new library 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" + Make use of .needs_rofs Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/fchmod/fchmod06.c | 189 +++++++++------------------- 1 file changed, 56 insertions(+), 133 deletions(-) diff --git a/testcases/kernel/syscalls/fchmod/fchmod06.c b/testcases/kernel/syscalls/fchmod/fchmod06.c index a5c6d911c..b5240086e 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod06.c +++ b/testcases/kernel/syscalls/fchmod/fchmod06.c @@ -1,23 +1,22 @@ /* + * Copyright (c) International Business Machines Corp., 2001 + * Author: Wayne Boyer + * Copyright (c) 2018 Cyril Hrubis * - * Copyright (c) International Business Machines Corp., 2001 - * Author: Wayne Boyer + * 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. * - * 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 + * 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 that fchmod() fails and sets the proper errno values. */ @@ -25,152 +24,76 @@ #ifndef _GNU_SOURCE # define _GNU_SOURCE #endif - -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include +#include #include -#include +#include "tst_test.h" -#include "test.h" -#include "safe_macros.h" +#define MNT_POINT "mntpoint" static int fd1; static int fd2; static int fd3; -static const char *device; -static int mount_flag; -static struct test_case_t { - char *name; +static struct tcase { int *fd; int mode; int exp_errno; -} test_cases[] = { - {"EPERM", &fd1, 0644, EPERM}, - {"EBADF", &fd2, 0644, EBADF}, - {"EROFS", &fd3, 0644, EROFS}, +} tcases[] = { + {&fd1, 0644, EPERM}, + {&fd2, 0644, EBADF}, + {&fd3, 0644, EROFS}, }; -char *TCID = "fchmod06"; -int TST_TOTAL = ARRAY_SIZE(test_cases); - -static void setup(void); -static void cleanup(void); - -int main(int ac, char **av) +static void verify_fchmod(unsigned int i) { - int lc; - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); + struct tcase *tc = &tcases[i]; - for (lc = 0; TEST_LOOPING(lc); lc++) { + TEST(fchmod(*tc->fd, tc->mode)); - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { - - TEST(fchmod(*test_cases[i].fd, test_cases[i].mode)); - - if (TEST_RETURN == -1) { - if (TEST_ERRNO == test_cases[i].exp_errno) { - tst_resm(TPASS | TTERRNO, - "fchmod: test %s success", - test_cases[i].name); - } else { - tst_resm(TFAIL | TTERRNO, - "fchmod: test %s FAILED with " - "unexpect errno: %d", - test_cases[i].name, - TEST_ERRNO); - } - } else { - tst_resm(TFAIL, - "fchmod: test %s success unexpectly", - test_cases[i].name); - } - } + if (TEST_RETURN != -1) { + tst_res(TFAIL, "fchmod() passed unexpectedly (%li)", + TEST_RETURN); + return; + } + if (TEST_ERRNO == tcases[i].exp_errno) { + tst_res(TPASS | TTERRNO, "fchmod() failed expectedly"); + return; } - cleanup(); - tst_exit(); + tst_res(TFAIL | TTERRNO, + "fchmod() failed unexpectedly, expected %i - %s", + TEST_ERRNO, tst_strerrno(TEST_ERRNO)); } static void setup(void) { - struct passwd *ltpuser; - const char *fs_type; - - tst_sig(FORK, DEF_HANDLER, cleanup); - - tst_require_root(); - - TEST_PAUSE; - - tst_tmpdir(); - - fs_type = tst_dev_fs_type(); - device = tst_acquire_device(cleanup); + struct passwd *ltpuser = SAFE_GETPWNAM("nobody"); - if (!device) - tst_brkm(TCONF, cleanup, "Failed to obtain block device"); + fd3 = SAFE_OPEN(MNT_POINT"/file", O_RDONLY); + fd1 = SAFE_OPEN("tfile_1", O_RDWR | O_CREAT, 0666); + fd2 = SAFE_OPEN("tfile_2", O_RDWR | O_CREAT, 0666); + SAFE_CLOSE(fd2); - tst_mkfs(cleanup, device, fs_type, NULL, NULL); - - SAFE_MKDIR(cleanup, "mntpoint", 0755); - - SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, 0, NULL); - mount_flag = 1; - - /* Create a file in the file system, then remount it as read-only */ - SAFE_TOUCH(cleanup, "mntpoint/tfile_3", 0644, NULL); - - SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, - MS_REMOUNT | MS_RDONLY, NULL); - - fd3 = SAFE_OPEN(cleanup, "mntpoint/tfile_3", O_RDONLY); - - fd1 = SAFE_OPEN(cleanup, "tfile_1", O_RDWR | O_CREAT, 0666); - - fd2 = SAFE_OPEN(cleanup, "tfile_2", O_RDWR | O_CREAT, 0666); - - SAFE_CLOSE(cleanup, fd2); - - ltpuser = SAFE_GETPWNAM(cleanup, "nobody"); - - SAFE_SETEUID(cleanup, ltpuser->pw_uid); + SAFE_SETEUID(ltpuser->pw_uid); } static void cleanup(void) { - if (seteuid(0)) - tst_resm(TWARN | TERRNO, "seteuid(0) failed"); - - if (fd1 > 0 && close(fd1)) - tst_resm(TWARN | TERRNO, "close(fd1) failed"); - - if (fd3 > 0 && close(fd3)) - tst_resm(TWARN | TERRNO, "close(fd1) failed"); - - if (mount_flag && tst_umount("mntpoint") < 0) { - tst_brkm(TBROK | TERRNO, NULL, - "umount device:%s failed", device); - } - - if (device) - tst_release_device(device); + if (fd1 > 0) + SAFE_CLOSE(fd1); - tst_rmdir(); + if (fd3 > 0) + SAFE_CLOSE(fd3); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test = verify_fchmod, + .tcnt = ARRAY_SIZE(tcases), + .needs_root = 1, + .needs_rofs = 1, + .mntpoint = MNT_POINT, +};