From patchwork Thu Apr 5 14:01:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895401 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 40H4Lp2kdfz9ryk for ; Fri, 6 Apr 2018 00:04:02 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 61B573E792C for ; Thu, 5 Apr 2018 16:03:57 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id 9E8C63E76B2 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-5.smtp.seeweb.it (Postfix) with ESMTPS id AE2DC6012DD for ; Thu, 5 Apr 2018 16:03:32 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 51154AD97 for ; Thu, 5 Apr 2018 14:03:32 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:01:47 +0200 Message-Id: <20180405140154.6218-2-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-5.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-5.smtp.seeweb.it Subject: [LTP] [RFC PATCH 1/8] lib/tst_test.c: mntpoint implies tmpdir 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" If mntpoint is set in the test structure we create a directory hence it should set needs_tmpdir flag so that we are sure we create directory in the right place. Signed-off-by: Cyril Hrubis --- lib/tst_test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/tst_test.c b/lib/tst_test.c index 8be13327c..5e10460b0 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -743,6 +743,9 @@ static void do_setup(int argc, char *argv[]) if (tst_test->all_filesystems) tst_test->needs_device = 1; + if (tst_test->mntpoint) + tst_test->needs_tmpdir = 1; + setup_ipc(); if (needs_tmpdir() && !tst_tmpdir_created()) From patchwork Thu Apr 5 14:01:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895396 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=suse.cz 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 40H4LM2x2kz9s0y for ; Fri, 6 Apr 2018 00:03:39 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 079B43E76B6 for ; Thu, 5 Apr 2018 16:03:36 +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 [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id 3044B3E7309 for ; Thu, 5 Apr 2018 16:03:33 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id 1F648201414 for ; Thu, 5 Apr 2018 16:03:33 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C52A9AD9C for ; Thu, 5 Apr 2018 14:03:32 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:01:48 +0200 Message-Id: <20180405140154.6218-3-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-7.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-7.smtp.seeweb.it Subject: [LTP] [RFC PATCH 2/8] lib/tst_test: Populate the read-only fs 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" Populate the read only filesystem with a file and a directory. This is needed for a testing syscalls such as unlink() or rmdir() for EROFS error. Signed-off-by: Cyril Hrubis Tested-by: Petr Vorel --- lib/tst_test.c | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/tst_test.c b/lib/tst_test.c index 5e10460b0..3b9014487 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -695,6 +695,32 @@ static void assert_test_fn(void) tst_brk(TBROK, "You can define tcnt only for test()"); } +static int prepare_and_mount_ro_fs(const char *dev, + const char *mntpoint, + const char *fs_type) +{ + char buf[PATH_MAX]; + + if (mount(dev, mntpoint, fs_type, 0, NULL)) { + tst_res(TINFO | TERRNO, "Can't mount %s at %s (%s)", + dev, mntpoint, fs_type); + return 1; + } + + mntpoint_mounted = 1; + + snprintf(buf, sizeof(buf), "%s/dir/", mntpoint); + SAFE_MKDIR(buf, 0777); + + snprintf(buf, sizeof(buf), "%s/file", mntpoint); + SAFE_FILE_PRINTF(buf, "file content"); + SAFE_CHMOD(buf, 0777); + + SAFE_MOUNT(dev, mntpoint, fs_type, MS_REMOUNT | MS_RDONLY, NULL); + + return 0; +} + static void prepare_device(void) { if (tst_test->format_device) { @@ -702,6 +728,12 @@ static void prepare_device(void) tst_test->dev_extra_opt); } + if (tst_test->needs_rofs) { + prepare_and_mount_ro_fs(tdev.dev, tst_test->mntpoint, + tdev.fs_type); + return; + } + if (tst_test->mount_device) { SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type, tst_test->mnt_flags, tst_test->mnt_data); @@ -761,18 +793,13 @@ static void do_setup(int argc, char *argv[]) if (tst_test->needs_rofs) { /* If we failed to mount read-only tmpfs. Fallback to - * using a device with empty read-only filesystem. + * using a device with read-only filesystem. */ - if (mount(NULL, tst_test->mntpoint, "tmpfs", MS_RDONLY, NULL)) { - tst_res(TINFO | TERRNO, "Can't mount tmpfs read-only" - " at %s, setting up a device instead\n", - tst_test->mntpoint); - tst_test->mount_device = 1; + if (prepare_and_mount_ro_fs(NULL, tst_test->mntpoint, "tmpfs")) { + tst_res(TINFO, "Can't mount tmpfs read-only, " + "falling back to block device..."); tst_test->needs_device = 1; tst_test->format_device = 1; - tst_test->mnt_flags = MS_RDONLY; - } else { - mntpoint_mounted = 1; } } From patchwork Thu Apr 5 14:01:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895403 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=suse.cz 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 40H4M049Sqz9ryk for ; Fri, 6 Apr 2018 00:04:12 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D4A443E7A04 for ; Thu, 5 Apr 2018 16:04:01 +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 7F0053E76DC for ; Thu, 5 Apr 2018 16:03:39 +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-4.smtp.seeweb.it (Postfix) with ESMTPS id 7B5231001994 for ; Thu, 5 Apr 2018 16:03:33 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 2AB20AE46 for ; Thu, 5 Apr 2018 14:03:33 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:01:49 +0200 Message-Id: <20180405140154.6218-4-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-4.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-4.smtp.seeweb.it Subject: [LTP] [RFC PATCH 3/8] syscalls/chmod06: Rewrite 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/chmod/chmod06.c | 166 +++++++++--------------------- 1 file changed, 49 insertions(+), 117 deletions(-) diff --git a/testcases/kernel/syscalls/chmod/chmod06.c b/testcases/kernel/syscalls/chmod/chmod06.c index acd653f7d..ad0a3615b 100644 --- a/testcases/kernel/syscalls/chmod/chmod06.c +++ b/testcases/kernel/syscalls/chmod/chmod06.c @@ -1,7 +1,7 @@ /* * Copyright (c) International Business Machines Corp., 2001 * 07/2001 Ported by Wayne Boyer - * Copyright (c) 2014 Cyril Hrubis + * Copyright (c) 2014-2018 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 @@ -37,27 +37,9 @@ * 6) chmod(2) returns -1 and sets errno to ENOENT if the specified file * does not exists. */ - -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" +#include +#include "tst_test.h" #define MODE_RWX (S_IRWXU|S_IRWXG|S_IRWXO) #define FILE_MODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) @@ -73,14 +55,12 @@ static char long_path[PATH_MAX + 2]; -static const char *device; -static int mount_flag; static uid_t nobody_uid; static void set_root(void); static void set_nobody(void); -struct test_case_t { +static struct tcase { char *pathname; mode_t mode; int exp_errno; @@ -90,7 +70,7 @@ struct test_case_t { {TEST_FILE1, FILE_MODE, EPERM, set_nobody, set_root}, {TEST_FILE2, FILE_MODE, EACCES, set_nobody, set_root}, {(char *)-1, FILE_MODE, EFAULT, NULL, NULL}, - {(char *)-2, FILE_MODE, EFAULT, NULL, NULL}, + {NULL, FILE_MODE, EFAULT, NULL, NULL}, {long_path, FILE_MODE, ENAMETOOLONG, NULL, NULL}, {"", FILE_MODE, ENOENT, NULL, NULL}, {TEST_FILE3, FILE_MODE, ENOTDIR, NULL, NULL}, @@ -98,109 +78,62 @@ struct test_case_t { {TEST_FILE4, FILE_MODE, ELOOP, NULL, NULL}, }; -char *TCID = "chmod06"; -int TST_TOTAL = ARRAY_SIZE(tc); - -static char *bad_addr = 0; +static char *bad_addr; -static void setup(void); -static void cleanup(void); - -int main(int ac, char **av) +void run(unsigned int i) { - int lc; - int i; - - tst_parse_opts(ac, av, NULL, NULL); + if (tc[i].setup) + tc[i].setup(); - setup(); + TEST(chmod(tc[i].pathname, tc[i].mode)); - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) { - - if (tc[i].setup) - tc[i].setup(); - - TEST(chmod(tc[i].pathname, tc[i].mode)); - - if (tc[i].cleanup) - tc[i].cleanup(); - - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "chmod succeeded unexpectedly"); - continue; - } - - if (TEST_ERRNO == tc[i].exp_errno) - tst_resm(TPASS | TTERRNO, - "chmod failed as expected"); - else - tst_resm(TFAIL | TTERRNO, - "chmod failed unexpectedly; " - "expected %d - %s", - tc[i].exp_errno, - tst_strerrno(tc[i].exp_errno)); - } + if (tc[i].cleanup) + tc[i].cleanup(); + if (TEST_RETURN != -1) { + tst_res(TFAIL, "chmod succeeded unexpectedly"); + return; } - cleanup(); - tst_exit(); + if (TEST_ERRNO == tc[i].exp_errno) { + tst_res(TPASS | TTERRNO, "chmod failed as expected"); + } else { + tst_res(TFAIL | TTERRNO, "chmod failed unexpectedly; " + "expected %d - %s", tc[i].exp_errno, + tst_strerrno(tc[i].exp_errno)); + } } void set_root(void) { - SAFE_SETEUID(cleanup, 0); + SAFE_SETEUID(0); } void set_nobody(void) { - SAFE_SETEUID(cleanup, nobody_uid); + SAFE_SETEUID(nobody_uid); } void setup(void) { struct passwd *nobody; - const char *fs_type; - - tst_sig(FORK, DEF_HANDLER, cleanup); + unsigned int i; - tst_require_root(); - - TEST_PAUSE; - - nobody = SAFE_GETPWNAM(NULL, "nobody"); + nobody = SAFE_GETPWNAM("nobody"); nobody_uid = nobody->pw_uid; - bad_addr = SAFE_MMAP(NULL, 0, 1, PROT_NONE, - MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0); - tc[3].pathname = bad_addr; - - tst_tmpdir(); - - fs_type = tst_dev_fs_type(); - device = tst_acquire_device(cleanup); + bad_addr = SAFE_MMAP(0, 1, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); - if (!device) - tst_brkm(TCONF, cleanup, "Failed to obtain block device"); - - SAFE_TOUCH(cleanup, TEST_FILE1, 0666, NULL); - SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX); - SAFE_TOUCH(cleanup, TEST_FILE2, 0666, NULL); - SAFE_CHMOD(cleanup, DIR_TEMP, FILE_MODE); - SAFE_TOUCH(cleanup, "t_file", MODE_RWX, NULL); - - tst_mkfs(cleanup, device, fs_type, NULL, NULL); - - SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE); + for (i = 0; i < ARRAY_SIZE(tc); i++) { + if (!tc[i].pathname) + tc[i].pathname = bad_addr; + } - /* - * mount a read-only file system for test EROFS - */ - SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, MS_RDONLY, NULL); - mount_flag = 1; + SAFE_TOUCH(TEST_FILE1, 0666, NULL); + SAFE_MKDIR(DIR_TEMP, MODE_RWX); + SAFE_TOUCH(TEST_FILE2, 0666, NULL); + SAFE_CHMOD(DIR_TEMP, FILE_MODE); + SAFE_TOUCH("t_file", MODE_RWX, NULL); memset(long_path, 'a', PATH_MAX+1); @@ -208,22 +141,21 @@ void setup(void) * create two symbolic links who point to each other for * test ELOOP. */ - SAFE_SYMLINK(cleanup, "test_file4", "test_file5"); - SAFE_SYMLINK(cleanup, "test_file5", "test_file4"); + SAFE_SYMLINK("test_file4", "test_file5"); + SAFE_SYMLINK("test_file5", "test_file4"); } static void cleanup(void) { - if (chmod(DIR_TEMP, MODE_RWX) == -1) - tst_resm(TBROK | TERRNO, "chmod(%s) failed", DIR_TEMP); - - if (mount_flag && tst_umount(MNT_POINT) < 0) { - tst_brkm(TBROK | TERRNO, NULL, - "umount device:%s failed", device); - } - - if (device) - tst_release_device(device); - - tst_rmdir(); + SAFE_CHMOD(DIR_TEMP, MODE_RWX); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test = run, + .tcnt = ARRAY_SIZE(tc), + .needs_root = 1, + .needs_rofs = 1, + .mntpoint = MNT_POINT, +}; From patchwork Thu Apr 5 14:01:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895397 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=suse.cz 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 40H4LS382Dz9s0y for ; Fri, 6 Apr 2018 00:03:44 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E17383E7701 for ; Thu, 5 Apr 2018 16:03:41 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id 642A13E730A for ; Thu, 5 Apr 2018 16:03:34 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id D00666002EC for ; Thu, 5 Apr 2018 16:03:33 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 7E003AE57 for ; Thu, 5 Apr 2018 14:03:33 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:01:50 +0200 Message-Id: <20180405140154.6218-5-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-2.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-2.smtp.seeweb.it Subject: [LTP] [RFC PATCH 4/8] syscalls/rmdir02: Make use of .needs_rofs 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" Signed-off-by: Cyril Hrubis --- testcases/kernel/syscalls/rmdir/rmdir02.c | 83 +++++++++++-------------------- 1 file changed, 29 insertions(+), 54 deletions(-) diff --git a/testcases/kernel/syscalls/rmdir/rmdir02.c b/testcases/kernel/syscalls/rmdir/rmdir02.c index 55123c727..d7cec8d4e 100644 --- a/testcases/kernel/syscalls/rmdir/rmdir02.c +++ b/testcases/kernel/syscalls/rmdir/rmdir02.c @@ -14,41 +14,21 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - /* * Description: - * 1) create a directory tstdir1, create a file under it. - * call rmdir(tstdir1), verify the return value is -1 - * and the errno is ENOTEMPTY. - * 2) create a directory with long path, call rmdir(tstdir1), - * verify the return value is -1 and the errno is ENAMETOOLONG. - * 3) pass a pathname containing non-exist directory component - * to rmdir(), verify the return value is -1 and the errno - * is ENOENT. - * 4) pass a pathname containing a file component to rmdir(), - * verify the return value is -1 and the errno is ENOTDIR. - * 5) attempt to pass an invalid pathname with an address - * pointing outside the address space of the process, as the - * argument to rmdir(), verify the return value is -1 and - * the errno is EFAULT. - * 6) pass a pathname with too many symbolic links to rmdir(), - * verify the return value is -1 and the errno is ELOOP. - * 7) pass a pathname which refers to a directory on a read-only - * file system to rmdir(), verify the return value is -1 and - * the errno is EROFS. - * 8) pass a pathname which is currently used as a mount point - * to rmdir(), verify the return value is -1 and the errno is - * EBUSY. - * 9) pass a pathname which points to the current directory(.) - * to rmdir(), verify the return value is -1 and the errno is - * EINVAL. + * 1) attempt to rmdir() non-empty directory -> ENOTEMPTY + * 2) attempt to rmdir() directory with long path name -> ENAMETOOLONG + * 3) attempt to rmdir() non-existing directory -> ENOENT + * 4) attempt to rmdir() a file -> ENOTDIR + * 5) attempt to rmdir() invalid pointer -> EFAULT + * 6) attempt to rmdir() symlink loop -> ELOOP + * 7) attempt to rmdir() dir on RO mounted FS -> EROFS + * 8) attempt to rmdir() mount point -> EBUSY + * 9) attempt to rmdir() current directory "." -> EINVAL */ #include -#include -#include -#include -#include + #include "tst_test.h" #define DIR_MODE (S_IRWXU | S_IRWXG | S_IRWXO) @@ -58,11 +38,10 @@ #define TESTDIR2 "nosuchdir/testdir2" #define TESTDIR3 "testfile2/testdir3" #define TESTDIR4 "/loopdir" -#define MNTPOINT "mntpoint" -#define TESTDIR5 "mntpoint/testdir5" +#define MNT_POINT "mntpoint" +#define TESTDIR5 "mntpoint/dir" #define TESTFILE "testdir/testfile" #define TESTFILE2 "testfile2" -#define CURRENTDIR "." static char longpathname[PATH_MAX + 2]; static char looppathname[sizeof(TESTDIR4) * 43] = "."; @@ -78,17 +57,14 @@ static struct testcase { {NULL, EFAULT}, {looppathname, ELOOP}, {TESTDIR5, EROFS}, - {MNTPOINT, EBUSY}, - {CURRENTDIR, EINVAL}, + {MNT_POINT, EBUSY}, + {".", EINVAL} }; static void setup(void) { unsigned int i; - SAFE_MKDIR(TESTDIR5, DIR_MODE); - SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, - MS_REMOUNT | MS_RDONLY, NULL); SAFE_MKDIR(TESTDIR, DIR_MODE); SAFE_TOUCH(TESTFILE, FILE_MODE, NULL); @@ -97,16 +73,15 @@ static void setup(void) SAFE_TOUCH(TESTFILE2, FILE_MODE, NULL); for (i = 0; i < ARRAY_SIZE(tcases); i++) { - if (tcases[i].exp_errno == EFAULT) { + if (!tcases[i].dir) tcases[i].dir = tst_get_bad_addr(NULL); - } } /* - * NOTE: the ELOOP test is written based on that the - * consecutive symlinks limit in kernel is hardwire - * to 40. - */ + * NOTE: the ELOOP test is written based on that the + * consecutive symlinks limit in kernel is hardwired + * to 40. + */ SAFE_MKDIR("loopdir", DIR_MODE); SAFE_SYMLINK("../loopdir", "loopdir/loopdir"); for (i = 0; i < 43; i++) @@ -118,18 +93,21 @@ static void verify_rmdir(unsigned int n) struct testcase *tc = &tcases[n]; TEST(rmdir(tc->dir)); + if (TEST_RETURN != -1) { - tst_res(TFAIL, "rmdir() succeeded unexpectedly"); + tst_res(TFAIL, "rmdir() succeeded unexpectedly (%li)", + TEST_RETURN); return; } if (TEST_ERRNO == tc->exp_errno) { tst_res(TPASS | TTERRNO, "rmdir() failed as expected"); - } else { - tst_res(TFAIL | TTERRNO, - "rmdir() failed unexpectedly; expected: %d, got ", - tc->exp_errno); + return; } + + tst_res(TFAIL | TTERRNO, + "rmdir() failed unexpectedly; expected: %d - %s", + tc->exp_errno, tst_strerrno(tc->exp_errno)); } static struct tst_test test = { @@ -137,9 +115,6 @@ static struct tst_test test = { .tcnt = ARRAY_SIZE(tcases), .test = verify_rmdir, .needs_root = 1, - .needs_tmpdir = 1, - .mntpoint = MNTPOINT, - .mount_device = 1, - + .needs_rofs = 1, + .mntpoint = MNT_POINT, }; - From patchwork Thu Apr 5 14:01:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895398 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 40H4LY5Y75z9ryk for ; Fri, 6 Apr 2018 00:03:49 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 033D93E76B4 for ; Thu, 5 Apr 2018 16:03:46 +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 [217.194.8.7]) by picard.linux.it (Postfix) with ESMTP id B45163E7309 for ; Thu, 5 Apr 2018 16:03:34 +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-7.smtp.seeweb.it (Postfix) with ESMTPS id 56B8420140F for ; Thu, 5 Apr 2018 16:03:34 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D3FD1AE71 for ; Thu, 5 Apr 2018 14:03:33 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Thu, 5 Apr 2018 16:01:51 +0200 Message-Id: <20180405140154.6218-6-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-7.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-7.smtp.seeweb.it Subject: [LTP] [RFC PATCH 5/8] syscalls/mkdirat02: Rewrite 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/mkdirat/mkdirat02.c | 137 +++++++------------------- 1 file changed, 34 insertions(+), 103 deletions(-) diff --git a/testcases/kernel/syscalls/mkdirat/mkdirat02.c b/testcases/kernel/syscalls/mkdirat/mkdirat02.c index 9dcf37fb1..b2f86efa8 100644 --- a/testcases/kernel/syscalls/mkdirat/mkdirat02.c +++ b/testcases/kernel/syscalls/mkdirat/mkdirat02.c @@ -21,142 +21,73 @@ */ #define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "lapi/mkdirat.h" -static void setup(void); -static void cleanup(void); - -#define TEST_FILE1 "mntpoint/test_file1" +#define MNT_POINT "mntpoint" +#define TEST_DIR "mntpoint/test_dir" #define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ S_IXGRP|S_IROTH|S_IXOTH) -char *TCID = "mkdirat02"; - static int dir_fd; static int cur_fd = AT_FDCWD; -static char test_file2[PATH_MAX] = "."; -static const char *device; -static int mount_flag_dir; -static int mount_flag_cur; +static char test_dir[PATH_MAX] = "."; -static struct test_case_t { +static struct tcase { int *dirfd; char *pathname; int exp_errno; -} TC[] = { - {&dir_fd, TEST_FILE1, EROFS}, - {&cur_fd, TEST_FILE1, EROFS}, - {&dir_fd, test_file2, ELOOP}, - {&cur_fd, test_file2, ELOOP}, +} tcases[] = { + {&dir_fd, TEST_DIR, EROFS}, + {&cur_fd, TEST_DIR, EROFS}, + {&dir_fd, test_dir, ELOOP}, + {&cur_fd, test_dir, ELOOP}, }; -int TST_TOTAL = ARRAY_SIZE(TC); -static void mkdirat_verify(const struct test_case_t *); - -int main(int ac, char **av) -{ - int lc; - int i; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - for (i = 0; i < TST_TOTAL; i++) - mkdirat_verify(&TC[i]); - } - - cleanup(); - tst_exit(); -} - static void setup(void) { - int i; - const char *fs_type; - - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; + unsigned int i; - tst_tmpdir(); + dir_fd = SAFE_OPEN(".", O_DIRECTORY); - fs_type = tst_dev_fs_type(); - device = tst_acquire_device(cleanup); + SAFE_MKDIR("test_eloop", DIR_MODE); + SAFE_SYMLINK("../test_eloop", "test_eloop/test_eloop"); - if (!device) - tst_brkm(TCONF, cleanup, "Failed to acquire device"); - - SAFE_MKDIR(cleanup, "test_dir", DIR_MODE); - dir_fd = SAFE_OPEN(cleanup, "test_dir", O_DIRECTORY); - - SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE); - SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop"); - - SAFE_MKDIR(cleanup, "test_dir/test_eloop", DIR_MODE); - SAFE_SYMLINK(cleanup, "../test_eloop", - "test_dir/test_eloop/test_eloop"); /* * NOTE: the ELOOP test is written based on that the consecutive * symlinks limits in kernel is hardwired to 40. */ for (i = 0; i < 43; i++) - strcat(test_file2, "/test_eloop"); - - tst_mkfs(cleanup, device, fs_type, NULL, NULL); - - SAFE_MKDIR(cleanup, "test_dir/mntpoint", DIR_MODE); - SAFE_MOUNT(cleanup, device, "test_dir/mntpoint", fs_type, MS_RDONLY, - NULL); - mount_flag_dir = 1; - - SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE); - SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, MS_RDONLY, NULL); - mount_flag_cur = 1; + strcat(test_dir, "/test_eloop"); } -static void mkdirat_verify(const struct test_case_t *test) +static void mkdirat_verify(unsigned int i) { + struct tcase *test = &tcases[i]; + TEST(mkdirat(*test->dirfd, test->pathname, 0777)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "mkdirat() returned %ld, expected -1, errno=%d", - TEST_RETURN, test->exp_errno); + tst_res(TFAIL, "mkdirat() succeeded unexpectedly (%li)", + TEST_RETURN); return; } if (TEST_ERRNO == test->exp_errno) { - tst_resm(TPASS | TTERRNO, "mkdirat() failed as expected"); - } else { - tst_resm(TFAIL | TTERRNO, - "mkdirat() failed unexpectedly; expected: %d - %s", - test->exp_errno, strerror(test->exp_errno)); + tst_res(TPASS | TTERRNO, "mkdirat() failed as expected"); + return; } -} - -static void cleanup(void) -{ - if (mount_flag_dir && tst_umount("mntpoint") < 0) - tst_resm(TWARN | TERRNO, "umount device:%s failed", device); - - if (mount_flag_cur && tst_umount("test_dir/mntpoint") < 0) - tst_resm(TWARN | TERRNO, "umount device:%s failed", device); - if (device) - tst_release_device(device); - - tst_rmdir(); + tst_res(TFAIL | TTERRNO, + "mkdirat() failed unexpectedly; expected: %d - %s", + test->exp_errno, tst_strerrno(test->exp_errno)); } + +static struct tst_test test = { + .setup = setup, + .test = mkdirat_verify, + .tcnt = ARRAY_SIZE(tcases), + .needs_root = 1, + .needs_rofs = 1, + .mntpoint = MNT_POINT, +}; From patchwork Thu Apr 5 14:01:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895399 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=suse.cz 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 40H4Lf5k70z9ryk for ; Fri, 6 Apr 2018 00:03:54 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2CDFF3E76FE for ; Thu, 5 Apr 2018 16:03:52 +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 [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id EEA1B3E730A for ; Thu, 5 Apr 2018 16:03:34 +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 8E60F1401B95 for ; Thu, 5 Apr 2018 16:03:34 +0200 (CEST) Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3D843AD45 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:52 +0200 Message-Id: <20180405140154.6218-7-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 6/8] syscalls/link08: Rewrite 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/link/link08.c | 115 +++++++------------------------- 1 file changed, 25 insertions(+), 90 deletions(-) diff --git a/testcases/kernel/syscalls/link/link08.c b/testcases/kernel/syscalls/link/link08.c index 8cb72d1df..986d5552e 100644 --- a/testcases/kernel/syscalls/link/link08.c +++ b/testcases/kernel/syscalls/link/link08.c @@ -15,7 +15,6 @@ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * */ /* * Test Description: @@ -32,134 +31,70 @@ * 4. link() fails with -1 return value and sets errno to ELOOP * if too many symbolic links were encountered in resolving path. */ - -#include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #define DIR_MODE (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \ S_IXGRP|S_IROTH|S_IXOTH) #define MNT_POINT "mntpoint" #define TEST_FILE "testfile" #define TEST_FILE1 "testfile1" -#define TEST_FILE2 "mntpoint/testfile3" +#define TEST_FILE2 "mntpoint/file" #define TEST_FILE3 "mntpoint/testfile4" static char test_file4[PATH_MAX] = "."; static void setup(void); -static void cleanup(void); - -static const char *device; -static int mount_flag; -static struct test_case_t { +static struct tcase { char *oldpath; char *newpath; int exp_errno; -} test_cases[] = { +} tcases[] = { {TEST_FILE1, TEST_FILE, EPERM}, {TEST_FILE2, TEST_FILE, EXDEV}, {TEST_FILE2, TEST_FILE3, EROFS}, {test_file4, TEST_FILE, ELOOP}, }; -static void link_verify(const struct test_case_t *); - -char *TCID = "link08"; -int TST_TOTAL = ARRAY_SIZE(test_cases); - -int main(int ac, char **av) +static void link_verify(unsigned int i) { - int i, lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); + struct tcase *tc = &tcases[i]; - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - for (i = 0; i < TST_TOTAL; i++) - link_verify(&test_cases[i]); - } - - cleanup(); - tst_exit(); - -} - -static void link_verify(const struct test_case_t *tc) -{ TEST(link(tc->oldpath, tc->newpath)); if (TEST_RETURN != -1) { - tst_resm(TFAIL, "link succeeded unexpectedly"); + tst_res(TFAIL, "link() succeeded unexpectedly (%li)", + TEST_RETURN); return; } if (TEST_ERRNO == tc->exp_errno) { - tst_resm(TPASS | TTERRNO, "link failed as expected"); - } else { - tst_resm(TFAIL | TTERRNO, - "link failed unexpectedly; expected: %d - %s", - tc->exp_errno, strerror(tc->exp_errno)); + tst_res(TPASS | TTERRNO, "link() failed as expected"); + return; } -} + tst_res(TFAIL | TTERRNO, + "link() failed unexpectedly; expected: %d - %s", + tc->exp_errno, tst_strerrno(tc->exp_errno)); +} static void setup(void) { int i; - const char *fs_type; - - tst_require_root(); - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - fs_type = tst_dev_fs_type(); - device = tst_acquire_device(cleanup); - - if (!device) - tst_brkm(TCONF, cleanup, "Failed to acquire device"); - SAFE_MKDIR(cleanup, TEST_FILE1, DIR_MODE); + SAFE_MKDIR(TEST_FILE1, DIR_MODE); - SAFE_MKDIR(cleanup, "test_eloop", DIR_MODE); - SAFE_SYMLINK(cleanup, "../test_eloop", "test_eloop/test_eloop"); + SAFE_MKDIR("test_eloop", DIR_MODE); + SAFE_SYMLINK("../test_eloop", "test_eloop/test_eloop"); for (i = 0; i < 43; i++) strcat(test_file4, "/test_eloop"); - - tst_mkfs(cleanup, device, fs_type, NULL, NULL); - SAFE_MKDIR(cleanup, MNT_POINT, DIR_MODE); - SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, 0, NULL); - mount_flag = 1; - - SAFE_TOUCH(cleanup, TEST_FILE2, 0644, NULL); - SAFE_MOUNT(cleanup, device, MNT_POINT, fs_type, - MS_REMOUNT | MS_RDONLY, NULL); } -static void cleanup(void) -{ - if (mount_flag && tst_umount(MNT_POINT) < 0) - tst_resm(TWARN | TERRNO, "umount device:%s failed", device); - - if (device) - tst_release_device(device); - - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test = link_verify, + .tcnt = ARRAY_SIZE(tcases), + .needs_root = 1, + .needs_rofs = 1, + .mntpoint = MNT_POINT, +}; From patchwork Thu Apr 5 14:01:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 895402 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=suse.cz 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 40H4Lt2mcqz9ryk for ; Fri, 6 Apr 2018 00:04:06 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8B58D3E799B for ; Thu, 5 Apr 2018 16:03:59 +0200 (CEST) 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 [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id 337EB3E76D8 for ; Thu, 5 Apr 2018 16:03:37 +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-5.smtp.seeweb.it (Postfix) with ESMTPS id E59D16013DA for ; Thu, 5 Apr 2018 16:03:34 +0200 (CEST) Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 87DEAAD9C 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:53 +0200 Message-Id: <20180405140154.6218-8-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-5.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-5.smtp.seeweb.it Subject: [LTP] [RFC PATCH 7/8] syscalls/utimes01: Rewrite 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/utimes/utimes01.c | 131 +++++----------------------- 1 file changed, 24 insertions(+), 107 deletions(-) diff --git a/testcases/kernel/syscalls/utimes/utimes01.c b/testcases/kernel/syscalls/utimes/utimes01.c index c79bd092c..b67543b09 100644 --- a/testcases/kernel/syscalls/utimes/utimes01.c +++ b/testcases/kernel/syscalls/utimes/utimes01.c @@ -36,45 +36,28 @@ */ #include -#include -#include -#include #include -#include -#include -#include -#include -#include #include -#include - -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "lapi/syscalls.h" -#define MNTPOINT "mntpoint" +#define MNT_POINT "mntpoint" #define TESTFILE1 "testfile1" #define TESTFILE2 "testfile2" -#define TESTFILE3 "mntpoint/testfile" +#define TESTFILE3 "mntpoint/file" #define FILE_MODE (S_IRWXU | S_IRGRP | S_IXGRP | \ S_IROTH | S_IXOTH) #define DIR_MODE (S_IRWXU | S_IRWXG | S_IRWXO) -#define LTPUSER1 "nobody" -#define LTPUSER2 "bin" - -static const char *device; -static int mount_flag; - static struct timeval a_tv[2] = { {0, 0}, {1000, 0} }; static struct timeval m_tv[2] = { {1000, 0}, {0, 0} }; static struct timeval tv[2] = { {1000, 0}, {2000, 0} }; -static struct test_case_t { +static struct tcase { char *pathname; struct timeval *times; int exp_errno; -} test_cases[] = { +} tcases[] = { { TESTFILE1, a_tv, 0 }, { TESTFILE1, m_tv, 0 }, { TESTFILE2, NULL, EACCES }, @@ -84,83 +67,23 @@ static struct test_case_t { { TESTFILE3, tv, EROFS }, }; -static void setup(void); -static void cleanup(void); -static void utimes_verify(const struct test_case_t *); - -char *TCID = "utimes01"; -int TST_TOTAL = ARRAY_SIZE(test_cases); - -int main(int ac, char **av) -{ - int i, lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - tst_count = 0; - - for (i = 0; i < TST_TOTAL; i++) - utimes_verify(&test_cases[i]); - } - - cleanup(); - tst_exit(); -} - static void setup(void) { - struct passwd *ltpuser; - const char *fs_type; - - tst_require_root(); + struct passwd *ltpuser = SAFE_GETPWNAM("nobody"); - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - fs_type = tst_dev_fs_type(); - device = tst_acquire_device(cleanup); - - if (!device) - tst_brkm(TCONF, cleanup, "Failed to obtain block device"); - - SAFE_TOUCH(cleanup, TESTFILE1, FILE_MODE, NULL); - ltpuser = SAFE_GETPWNAM(cleanup, LTPUSER1); - SAFE_CHOWN(cleanup, TESTFILE1, ltpuser->pw_uid, - ltpuser->pw_gid); - - SAFE_TOUCH(cleanup, TESTFILE2, FILE_MODE, NULL); - ltpuser = SAFE_GETPWNAM(cleanup, LTPUSER2); - SAFE_CHOWN(cleanup, TESTFILE2, ltpuser->pw_uid, - ltpuser->pw_gid); - - tst_mkfs(cleanup, device, fs_type, NULL, NULL); - SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE); - SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL); - mount_flag = 1; - SAFE_TOUCH(cleanup, TESTFILE3, FILE_MODE, NULL); - ltpuser = SAFE_GETPWNAM(cleanup, LTPUSER1); - SAFE_CHOWN(cleanup, TESTFILE3, ltpuser->pw_uid, - ltpuser->pw_gid); - SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, MS_REMOUNT | MS_RDONLY, - NULL); - - ltpuser = SAFE_GETPWNAM(cleanup, LTPUSER1); - SAFE_SETEUID(cleanup, ltpuser->pw_uid); + SAFE_TOUCH(TESTFILE2, FILE_MODE, NULL); + SAFE_SETEUID(ltpuser->pw_uid); + SAFE_TOUCH(TESTFILE1, FILE_MODE, NULL); } -static void utimes_verify(const struct test_case_t *tc) +static void utimes_verify(unsigned int i) { struct stat st; struct timeval tmp_tv[2]; + struct tcase *tc = &tcases[i]; if (tc->exp_errno == 0) { - SAFE_STAT(cleanup, tc->pathname, &st); + SAFE_STAT(tc->pathname, &st); tmp_tv[0].tv_sec = st.st_atime; tmp_tv[0].tv_usec = 0; @@ -171,28 +94,22 @@ static void utimes_verify(const struct test_case_t *tc) TEST(utimes(tc->pathname, tc->times)); if (TEST_ERRNO == tc->exp_errno) { - tst_resm(TPASS | TTERRNO, "utimes() worked as expected"); + tst_res(TPASS | TTERRNO, "utimes() worked as expected"); } else { - tst_resm(TFAIL | TTERRNO, + tst_res(TFAIL | TTERRNO, "utimes() failed unexpectedly; expected: %d - %s", - tc->exp_errno, strerror(tc->exp_errno)); + tc->exp_errno, tst_strerrno(tc->exp_errno)); } if (TEST_ERRNO == 0 && utimes(tc->pathname, tmp_tv) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "utimes() failed."); + tst_brk(TBROK | TERRNO, "utimes() failed."); } -static void cleanup(void) -{ - if (seteuid(0) == -1) - tst_resm(TWARN | TERRNO, "seteuid(0) failed"); - - if (mount_flag && tst_umount(MNTPOINT) == -1) - tst_resm(TWARN | TERRNO, "umount %s failed", MNTPOINT); - - - if (device) - tst_release_device(device); - - tst_rmdir(); -} +static struct tst_test test = { + .setup = setup, + .test = utimes_verify, + .tcnt = ARRAY_SIZE(tcases), + .needs_root = 1, + .needs_rofs = 1, + .mntpoint = MNT_POINT, +}; 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, +};