From patchwork Mon Nov 5 23:50:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Patil X-Patchwork-Id: 150230 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3231156ljp; Mon, 5 Nov 2018 15:51:03 -0800 (PST) X-Google-Smtp-Source: AJdET5cyw8uAFrDdKQ8/XXZiiD7SPF+shVt4kSTuxlXDf/pzdp8tl2Y4huTpwTnMFBEw4PR1y84h X-Received: by 2002:a17:906:d507:: with SMTP id ge7-v6mr15397140ejb.78.1541461863016; Mon, 05 Nov 2018 15:51:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541461863; cv=none; d=google.com; s=arc-20160816; b=h+/fB6s7c+RTRBoGaPpThy4VwPsQiXeQBLdqlSHptG/Ie/QdzXhPZRkooCr474aZgt hMwL6BSJeyWKl3OJBy1NvmY2ggL/ZfCk3PffU9oKO4c+VoOg1+4spVAucEvulx7yMZ2r J4kMpTa9CtCpohG9nkoFz2wVNYGoFb3YtTD764ID25SedklluLTqHEKrDnGwuIxEa8QG 8bNMpOqM8d7KrD/Z+VMu5bwyJpu7IZgLXTjs+v5/Fb8BebAQ0gwN85+Fp0EeITL7cMoU 0ZdkDtv54xzBpEk/rhX9RvYxMLrMSg3smeLaILZOVL6BoL4XE6/+Dg4BiSWJ9bsUS603 rQyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=7XrJaj25TMVlhfK7uw3moZ7HjwYFelZuXtKMltfNIZA=; b=RbXGBmDBQ7q442yKmGGqJTB8yjBLwzU4rQM5uEPgBHazwuYqDmLx7tgdWWzI36+fds DAnBlj1O95Cui2odZhGGjwwyx/tykHiPP5eaonz8QSGTIo4DsrFXr+VtvLr0P3lJfEZp Ilc0QIyLjj+nxNKpEcO7dfLxd8/qiVPuedzZRCkYmt+yQrzNk6YIrxJPX50Cg+sWEfiP K05CdmQI6GmUkOqCHfsCHFUE8NVzfGJjulGCXfidfmq+GCV3HQPY//hXTl/IkML1T6GI 5w6M5peeH0QTRwOIZqig5v9HoHNWm80ZQTRb7rcJbkjRP2Z57gTf5r1mpH1sOmS7Zci/ cPEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=Zhb6PwGi; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=REJECT sp=REJECT dis=QUARANTINE) header.from=google.com Return-Path: Received: from picard.linux.it (picard.linux.it. [2001:1418:10:5::2]) by mx.google.com with ESMTPS id q22-v6si5472319edc.335.2018.11.05.15.51.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:51:03 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) client-ip=2001:1418:10:5::2; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=Zhb6PwGi; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 2001:1418:10:5::2 as permitted sender) smtp.mailfrom="ltp-bounces+patch=linaro.org@lists.linux.it"; dmarc=fail (p=REJECT sp=REJECT dis=QUARANTINE) header.from=google.com Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 973173E78EC for ; Tue, 6 Nov 2018 00:51:02 +0100 (CET) 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 E0A4C3E78E0 for ; Tue, 6 Nov 2018 00:50:52 +0100 (CET) Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 9D0931000A00 for ; Tue, 6 Nov 2018 00:50:51 +0100 (CET) Received: by mail-pf1-x441.google.com with SMTP id f26-v6so5186920pfn.9 for ; Mon, 05 Nov 2018 15:50:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=79T+7nXc2WH47rzDgY8IEQXPwK1pDAm8oqArGisNbb0=; b=Zhb6PwGieZPep5iBdSE1TtD1y5c6R0QoKdxtovIatiey1XF+jdqfhhsCbHIdj7aSLx y7rai2xaZiTFC3i1hX7Gugd/bCzrgwq4RZCGwxgUER7M6Aanf3hcUl0TqiJy6Lmqy4Ma rCmi+XuyQUkzYF3FJRCQxmKoKivcV6Qps91rCVajidWMdclI0V71rLcN/bmoN7ptkZt/ huLN7B1WzAwsyT4TTbDBsjiTGXtI4Nd80zTuoYvi4a28vGKXdQbVrNrCrvUk979yp0iy 2sGFXsFDNCq33qthqSYKw1IXdc8pZaOWVdND0F3MFTqrrKOoYsN3pnAsy6IqHu/YwAkI KbEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=79T+7nXc2WH47rzDgY8IEQXPwK1pDAm8oqArGisNbb0=; b=HPXsBkYEmQCGB8mbsAw3oIYIfuxBYAbG0hN2Xq5CnkJuYdaYeeC7PKaWcbKrhF9/XJ 7DLt3OKp94RnSF10m8ey3/x2ZMLKp76DTPV7Gm/ChvnAxB/QTrNDZ8yhPQvKcjYe3INH rnu96xYJyreWHGP5yEatzQnCEiPWFzZ0shq5YgOJPdogyKAaqOHVdX4eRXvHzEIrBjTr 7Cwo5cD8yRq5HfaCW0BeWqBIHIFBhK9TINHJUahZ7y3rzTm4RwYL5mfExcvJv3glwcCg P3yH+Mmw5APPnmWeA8KVNKGzINGgAMwnIIIJJaRZPr1MNdelAfm0XNk9lWp1HTrC/e9s iZ/Q== X-Gm-Message-State: AGRZ1gI9arD7/rnSE9TqRvqT1yYO61jUt67exmDHRAlGxHnId0lG52ik EU6W0ABe5dky986D5oznuo+9rRkCWKLNVw== X-Received: by 2002:a62:5547:: with SMTP id j68-v6mr24020877pfb.166.1541461849136; Mon, 05 Nov 2018 15:50:49 -0800 (PST) Received: from sspatil-workstation.mtv.corp.google.com ([2620:0:1000:1601:1a43:e60e:c432:d19c]) by smtp.gmail.com with ESMTPSA id c70-v6sm27133925pfg.97.2018.11.05.15.50.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:50:47 -0800 (PST) From: Sandeep Patil To: ltp@lists.linux.it Date: Mon, 5 Nov 2018 15:50:16 -0800 Message-Id: <20181105235019.254846-3-sspatil@google.com> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181105235019.254846-1-sspatil@google.com> References: <20181105235019.254846-1-sspatil@google.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-14.9 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: kernel-team@android.com, rpalethorpe@suse.com Subject: [LTP] [PATCH 2/5] syscalls/chmod07: Use new ltp 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: , Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" Use SPDX-Licence-Identifier and delete dead comments / code. Side benefit of making sure the test runs on Android when using SAFE_GETGRNAM_FALLBACK() Signed-off-by: Sandeep Patil --- testcases/kernel/syscalls/chmod/chmod07.c | 174 ++++++---------------- 1 file changed, 42 insertions(+), 132 deletions(-) diff --git a/testcases/kernel/syscalls/chmod/chmod07.c b/testcases/kernel/syscalls/chmod/chmod07.c index 6a3938840..4e43f2e32 100644 --- a/testcases/kernel/syscalls/chmod/chmod07.c +++ b/testcases/kernel/syscalls/chmod/chmod07.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.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 */ /* @@ -31,43 +17,6 @@ * Expected Result: * chmod() 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: - * chmod07 [-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 @@ -80,75 +29,46 @@ #include #include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.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 FILE_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) +#define PERMS 01777 /* Permissions with sticky bit set. */ #define TESTFILE "testfile" -char *TCID = "chmod07"; -int TST_TOTAL = 1; - -void setup(); /* Main setup function for the test */ -void cleanup(); /* Main cleanup function for the test */ - -int main(int ac, char **av) +void test_chmod(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 chmod(2) with specified mode argument - * (sticky-bit set) on testfile. - */ - TEST(chmod(TESTFILE, PERMS)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL | TTERRNO, "chmod(%s, %#o) failed", - TESTFILE, PERMS); - continue; - } - /* - * Get the testfile information using - * stat(2). - */ - if (stat(TESTFILE, &stat_buf) == -1) - tst_brkm(TFAIL | TTERRNO, cleanup, - "stat failed"); + /* + * Call chmod(2) with specified mode argument + * (sticky-bit set) on testfile. + */ + TEST(chmod(TESTFILE, PERMS)); + if (TST_RET == -1) { + tst_brk(TFAIL | TTERRNO, "chmod(%s, %#o) failed", + TESTFILE, PERMS); + } - /* Check for expected mode permissions */ - if ((stat_buf.st_mode & PERMS) == PERMS) - tst_resm(TPASS, "Functionality of " - "chmod(%s, %#o) successful", - TESTFILE, PERMS); - else - tst_resm(TFAIL, "%s: Incorrect modes 0%03o; " - "expected 0%03o", TESTFILE, - stat_buf.st_mode, PERMS); + /* + * Get the testfile information using + * stat(2). + */ + if (stat(TESTFILE, &stat_buf) == -1) { + tst_brk(TFAIL | TTERRNO, "stat failed"); } - cleanup(); - tst_exit(); + /* Check for expected mode permissions */ + if ((stat_buf.st_mode & PERMS) == PERMS) { + tst_res(TPASS, "Functionality of chmod(%s, %#o) successful", + TESTFILE, PERMS); + } else { + tst_res(TFAIL, "%s: Incorrect modes 0%03o; expected 0%03o", + TESTFILE, stat_buf.st_mode, PERMS); + } } /* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and change directory to it. + * setup() - performs all ONE TIME setup for this test. * Create a test file under temporary directory and close it * Change the ownership of test file to that of "ltpuser1" user. */ @@ -160,32 +80,22 @@ void setup(void) gid_t group1_gid; /* user and process group id's */ uid_t user1_uid; - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_require_root(); - - tst_tmpdir(); - - /* Get the uid of guest user - ltpuser1 */ - if ((ltpuser = getpwnam(LTPUSER)) == NULL) - tst_brkm(TBROK, cleanup, "getpwnam failed"); + /* Get the uid of guest user - nobody */ + ltpuser = SAFE_GETPWNAM("nobody"); user1_uid = ltpuser->pw_uid; - /* Get the group id of guest user - ltpuser1 */ - if ((ltpgroup = getgrnam(LTPGRP)) == NULL) - tst_brkm(TBROK, cleanup, "getgrnam failed"); + ltpgroup = SAFE_GETGRNAM_FALLBACK("users", "daemon"); group1_gid = ltpgroup->gr_gid; - fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE); - SAFE_CLOSE(cleanup, fd); - SAFE_CHOWN(cleanup, TESTFILE, user1_uid, group1_gid); - - SAFE_SETGID(cleanup, group1_gid); + fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, FILE_MODE); + SAFE_CLOSE(fd); + SAFE_CHOWN(TESTFILE, user1_uid, group1_gid); + SAFE_SETGID(group1_gid); } -void cleanup(void) -{ - tst_rmdir(); -} +static struct tst_test test = { + .needs_root = 1, + .needs_tmpdir = 1, + .setup = setup, + .test_all = test_chmod, +};