From patchwork Mon Nov 5 23:50:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Patil X-Patchwork-Id: 993478 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=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="luUs0fJL"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42pqFK4B0Qz9sMp for ; Tue, 6 Nov 2018 10:50:58 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 743EB3E783B for ; Tue, 6 Nov 2018 00:50:55 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id 30D943E6377 for ; Tue, 6 Nov 2018 00:50:49 +0100 (CET) Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 4E9E6600864 for ; Tue, 6 Nov 2018 00:50:49 +0100 (CET) Received: by mail-pf1-x444.google.com with SMTP id g7-v6so2927469pfo.10 for ; Mon, 05 Nov 2018 15:50:49 -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=kJx4gECE6XdbT+XGmmQoxoToWPqPtSL5LatA3vczjiQ=; b=luUs0fJLCnApVtE1jH7E9+OeR0kNTeDkXq4rhcNUhR6Yku2ajcbvvcX3QhVxafb3SS gq31OPVMT+a0dN/tV8C0X1yJo9XPbbg4eISfY3twb1oyHyr3jWFhBGmi1cIa6tO+Lsks KaYF50nVcz96ksWTrlGoEC3o/eKfVKsogWIupiHsyu+CXmexnCf3vLumZYSPT4UAocBL 269ShUObtQQWdwPLx8eyDsvj6+8LL6Dh4M7V1iHbqWS8ka+XZ+cpZA2v8BizCAWAvxhF oKd7FTiUZbckIjVQA02fWqOB50H40kI2yC7lPysU2gZUsMNyzh+uo0LWIrecItFlwRfU MSgg== 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=kJx4gECE6XdbT+XGmmQoxoToWPqPtSL5LatA3vczjiQ=; b=MO8zASFWwCfLxhkJz8FM30kAUvAIYZDpAYLv/tfUOfIaSLXHBHw91YlTFKOgndwd/s UPAAlJ/dki06+Gn7Q9g1jMJEwF4W8zitC9goXPHBbZ/oYHGf3ZDQonNtI7XR1geGWZNc 6a/a5XnAqS/ml5qSp0p6fWLMMPTjgwdlQgR+jC4bqXv3RruY3Bfjm+hImCdPClWCpVhA qj4MQUJSTrRKakSBYrigxQckrD7O2yFQuqWy5b6qBun4TmdPGk3HQjh4OgdiB5YVuvn0 12IKoYcUa2j0gsj6ZQCTsukKkkYYQOVszxBPk9FO/GMs4mWeOxyKEkCVY/XFsXdnb36/ nvyA== X-Gm-Message-State: AGRZ1gJcyBWijX5XZtUBr5XGGmcURowjuKOlg11Kr9EjC1oPFAANEeJN Mc6zfCK42K018/tTgPuuh43wNAowj4xzAg== X-Google-Smtp-Source: AJdET5f7hxlgRhdvbBZ6qF9sOJP9wVGFTVL7UkvAG3QE7mOluGIQy9p79N9q2HH0gKlFQY3wVDx4tg== X-Received: by 2002:a62:198c:: with SMTP id 134-v6mr16910027pfz.33.1541461847156; Mon, 05 Nov 2018 15:50:47 -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.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:50:45 -0800 (PST) From: Sandeep Patil To: ltp@lists.linux.it Date: Mon, 5 Nov 2018 15:50:15 -0800 Message-Id: <20181105235019.254846-2-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-5.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-5.smtp.seeweb.it Cc: kernel-team@android.com, rpalethorpe@suse.com Subject: [LTP] [PATCH 1/5] chroot01: Use the 'tmpdir' we create. 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" Remove hard coded use of /tmp that breaks this test for Android and use the tmpdir() we create in the setup() instead. Signed-off-by: Sandeep Patil --- testcases/kernel/syscalls/chroot/chroot01.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/syscalls/chroot/chroot01.c b/testcases/kernel/syscalls/chroot/chroot01.c index 9b0c30cf1..a1db5e157 100644 --- a/testcases/kernel/syscalls/chroot/chroot01.c +++ b/testcases/kernel/syscalls/chroot/chroot01.c @@ -54,7 +54,7 @@ char *TCID = "chroot01"; int TST_TOTAL = 1; int fail; -char path[] = "/tmp"; +char *path; char nobody_uid[] = "nobody"; struct passwd *ltpuser; @@ -94,6 +94,7 @@ void setup(void) tst_require_root(); tst_tmpdir(); + path = tst_get_tmpdir(); if ((ltpuser = getpwnam(nobody_uid)) == NULL) tst_brkm(TBROK | TERRNO, cleanup, @@ -110,5 +111,6 @@ void cleanup(void) { SAFE_SETEUID(NULL, 0); + free(path); tst_rmdir(); } 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: 993480 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=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="Zhb6PwGi"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42pqFM3s60z9sMp for ; Tue, 6 Nov 2018 10:51:03 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DD71D3E7886 for ; Tue, 6 Nov 2018 00:51:00 +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-Google-Smtp-Source: AJdET5dTnitpHAPbDVJaNMeQYkR9gkldW2ydP8/eLKMvXJ5FoRa/kGFybyRwp63mjGjzOef/IShJhQ== 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+incoming=patchwork.ozlabs.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, +}; From patchwork Mon Nov 5 23:50:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Patil X-Patchwork-Id: 993481 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=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="rNyD7wT+"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42pqFR3Jb3z9sN1 for ; Tue, 6 Nov 2018 10:51:07 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id EBDBF3E7823 for ; Tue, 6 Nov 2018 00:51:04 +0100 (CET) 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 D056D3E7847 for ; Tue, 6 Nov 2018 00:50:53 +0100 (CET) Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 37974200A03 for ; Tue, 6 Nov 2018 00:50:53 +0100 (CET) Received: by mail-pg1-x543.google.com with SMTP id w7so4936074pgp.13 for ; Mon, 05 Nov 2018 15:50:53 -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=EY5+fCIcAYaDYRl3gZpnxIBfpRx+tzQagGkEakksPRA=; b=rNyD7wT+T+6MzugwnmBbsxqHhcsU4wL3qLpTEVegU2tUNDc+V/Qh5MiTvALnF+TLxD arfOAKIS1h3YFZ0vAaiTn1LldAOWGLAzFYkg7ZMJ7KiI0+bTVK1r7bgQX4sL1CNP6hQh UOuJTySkIVs4OfCz5EnPFzGTAmfXC3rB5Be3zXljtISQOG3TXHUG30sggHotDtUGUplf RD6ucsLFrjr+9XyB4ZD7nPnYstNB8Tj4hS92ZFVGqr4i8U9tD2Lxm/udGcyr6WygbOPM ez9xwoL3lB/rD7Fu2AIy7ZZsKR+mHuXF5O2nvF/+yy1UhGH/4fHF79U4kgn6kDJlX9zH UZnw== 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=EY5+fCIcAYaDYRl3gZpnxIBfpRx+tzQagGkEakksPRA=; b=JujXgxQLExQpQ+7N2d1Zn1hUdQyRxf0KGvkNYVVDvEZdhbO1Guy+Zz4N0WzIl6KbBy VJJ23lasohjpETwO2rk8avpd8q1jNz5QVNo2W0e9FsOEELkRczYJ/pQl0vNXOQQXPT/x +OUmq10LmuL5jetYerCc93qkXnyidMNxpUaAwoaNSrEOz6U9BM9DVyeV2OgLA5VIIWDA AG9NbeoAmCxM4yGdkQO0yOuSBZglf3q+xTyKzZxC0VhyZF20TwuOaBlPfhd3PvJgkSpB eqdtEChyn/ATEqy81bnt30PD6PCUimMZbRDpbTa+RHL9ay2thlePs76tEmHxD3318WBA 5Q9Q== X-Gm-Message-State: AGRZ1gIfr8h2eetYl/xfJUgERPDNSB0SOaeVGUqlpy9uVei/YbGyL0GJ 1eIB3IwAFKfM8qmgVD2cDsvwEPQrhjOklQ== X-Google-Smtp-Source: AJdET5fVfQfqJuqyYZR22FabbmD3XlQao/HKCB8ydDF+t6PpbyrwhkMoV2LgB0YdsMTlUGrogx5y0g== X-Received: by 2002:a62:1308:: with SMTP id b8-v6mr23382302pfj.215.1541461850743; Mon, 05 Nov 2018 15:50:50 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:50:49 -0800 (PST) From: Sandeep Patil To: ltp@lists.linux.it Date: Mon, 5 Nov 2018 15:50:17 -0800 Message-Id: <20181105235019.254846-4-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-7.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-7.smtp.seeweb.it Cc: kernel-team@android.com, rpalethorpe@suse.com Subject: [LTP] [PATCH 3/5] syscalls/fchmod02: fall back to use "daemon" group if "users" is absent. 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" This makes the test work successfully on Android systems where "users" group doesn't exist. Signed-off-by: Sandeep Patil --- testcases/kernel/syscalls/fchmod/fchmod02.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/testcases/kernel/syscalls/fchmod/fchmod02.c b/testcases/kernel/syscalls/fchmod/fchmod02.c index d0b35db12..e60cb33a6 100644 --- a/testcases/kernel/syscalls/fchmod/fchmod02.c +++ b/testcases/kernel/syscalls/fchmod/fchmod02.c @@ -22,9 +22,6 @@ #include "tst_test.h" #include "fchmod.h" -#define LTPUSER "nobody" -#define LTPGRP "users" - static int fd; static void verify_fchmod(void) @@ -53,8 +50,8 @@ static void setup(void) struct passwd *ltpuser; struct group *ltpgroup; - ltpuser = SAFE_GETPWNAM(LTPUSER); - ltpgroup = SAFE_GETGRNAM(LTPGRP); + ltpuser = SAFE_GETPWNAM("nobody"); + ltpgroup = SAFE_GETGRNAM_FALLBACK("users", "daemon"); fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, FILE_MODE); SAFE_CHOWN(TESTFILE, ltpuser->pw_uid, ltpgroup->gr_gid); From patchwork Mon Nov 5 23:50:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Patil X-Patchwork-Id: 993482 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=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="TMmO/vtA"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42pqFW1jYbz9sMp for ; Tue, 6 Nov 2018 10:51:11 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BAA563E78D0 for ; Tue, 6 Nov 2018 00:51:08 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id EACB53E7844 for ; Tue, 6 Nov 2018 00:50:55 +0100 (CET) Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id CC8A5600864 for ; Tue, 6 Nov 2018 00:50:54 +0100 (CET) Received: by mail-pl1-x643.google.com with SMTP id g59-v6so5226822plb.10 for ; Mon, 05 Nov 2018 15:50:54 -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=zU8XyZL7u1AEj41rMw76j0le0mwfuRmLIfSkrFXb7RI=; b=TMmO/vtAjtxyQ77PsPA4KDWsaXdoXGAtMX/Q3fL/kSQdTizrTlP8zPRfb161k+Tzz4 r7pfFpzGlGxWiCZrKiDgOrWHLgg7t+/sRmEljXRD2DLg9hK4gQij30BtQbtghu+ZYB03 UibU79YtQV5rePfK14H8AfMaZWTBfrjBVf3edMMM4dv7VWXcZL7811qPAe24ympYgnok iFwXjghZcJSWR0qR27dd8LI/fiSJ/kucR4L5tHr8X2cjWViMU7UgCpfgGwpiHoP9/T92 Bc+bwWC3SJgYbP6e+EPm/NcqPsbbfty1HXUiN3duHLgGyyAniXbLMqEVA5JhXgmQFJdz chfA== 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=zU8XyZL7u1AEj41rMw76j0le0mwfuRmLIfSkrFXb7RI=; b=huvoU0agT/ECOpC0UhYNI0aDxfedLzkoDRkSx0bwfBSM4XJsJw1PRedy5T6HuPhUHC qw6eG+l/Sgvq4p0mwaTqsPf/NC7FS8Mo0d6VfPedEJKKLAqzkwvYLGmYt8BWwFiyyAwJ G4jP3BmLiOVqfP8Q45TxzEx2L9En0yiYrMRD4hOMVlFGersv6Sbtojk9ArC7ojm2FBvX YXUKjip1/jfcSH+O5DmtzYG7Z5sSRMoIpQKysCUhdq8dV37typQpi4enKJ/OihQc2NJC NAKGx6qXF2SUPqK3ty2fCLnNQXYzY9USmzUNBL0W/YIf1c8kBzTbJrfj3KLEBnWiXJ+B GwgQ== X-Gm-Message-State: AGRZ1gJNpaFTvgHt0fjtov3sBY7mDGVCwIwnUQWy90DoxlyCl/XLMyMn tFka/NJ06tWJwl8IGZe9j5Bxuz7wc6caPQ== X-Google-Smtp-Source: AJdET5eGivbEFtuOq/KQCNglGnLUEJ5VbdUnZRrh/zC/JgMMq1O5+7x0WeE7umzgkTj4hsCQZ/xrww== X-Received: by 2002:a17:902:544:: with SMTP id 62-v6mr22979606plf.73.1541461852337; Mon, 05 Nov 2018 15:50:52 -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.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:50:51 -0800 (PST) From: Sandeep Patil To: ltp@lists.linux.it Date: Mon, 5 Nov 2018 15:50:18 -0800 Message-Id: <20181105235019.254846-5-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-5.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-5.smtp.seeweb.it Cc: kernel-team@android.com, rpalethorpe@suse.com Subject: [LTP] [PATCH 4/5] syscalls/chmod05: 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+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Use SPDX-Licence-Identifier and delete dead comments / code while at it. Signed-off-by: Sandeep Patil --- testcases/kernel/syscalls/chmod/chmod05.c | 187 ++++------------------ 1 file changed, 33 insertions(+), 154 deletions(-) diff --git a/testcases/kernel/syscalls/chmod/chmod05.c b/testcases/kernel/syscalls/chmod/chmod05.c index 3cf4db5d0..c18a4778a 100644 --- a/testcases/kernel/syscalls/chmod/chmod05.c +++ b/testcases/kernel/syscalls/chmod/chmod05.c @@ -1,30 +1,12 @@ +/// 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 */ /* * Test Name: chmod05 * * Test Description: -//wjh -//This test seems to be invalid see comments below -//The man page for chmod doesn't seem to indicate that the setgid bit can -//only be set by root * Verify that, chmod(2) will succeed to change the mode of a directory * but fails to set the setgid bit on it if invoked by non-root (uid != 0) * process with the following constraints, @@ -36,48 +18,6 @@ * chmod() should return value 0 on success and though succeeds to change * the mode of a directory but fails to set setgid bit on it. * - * 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: - * chmod05 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -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 - * 05/2002 Fixes by wjhuie and Ferhan Shareef - * changed conditional to check for valid tests only and - * in a more logically understandable way - * 07/2002 Additional fixes to #defines to allow comparisions to work. - * -Robbie Williamson - * - * RESTRICTIONS: - * This test should be run by root. - * */ #ifndef _GNU_SOURCE @@ -96,126 +36,65 @@ #include #include -#include "test.h" -#include "safe_macros.h" - -#define DEBUG 0 +#include "tst_test.h" #define MODE_RWX (mode_t)(S_IRWXU | S_IRWXG | S_IRWXO) #define DIR_MODE (mode_t)(S_ISVTX | S_ISGID | S_IFDIR) #define PERMS (mode_t)(MODE_RWX | DIR_MODE) #define TESTDIR "testdir" -char *TCID = "chmod05"; -int TST_TOTAL = 1; - -void setup(); /* Main setup function for test */ -void cleanup(); /* Main cleanup function for test */ - -int main(int ac, char **av) +void test_chmod(void) { struct stat stat_buf; /* stat struct */ - int lc; mode_t dir_mode; /* mode permissions set on test directory */ - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - TEST(chmod(TESTDIR, PERMS)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "chmod(%s, %#o) failed", - TESTDIR, PERMS); - continue; - } - /* - * Get the directory information using - * stat(2). - */ - if (stat(TESTDIR, &stat_buf) < 0) { - tst_brkm(TFAIL | TERRNO, cleanup, - "stat(%s) failed", TESTDIR); - } - dir_mode = stat_buf.st_mode; -#if DEBUG - printf("DIR_MODE = 0%03o\n", DIR_MODE); - printf("MODE_RWX = 0%03o\n", MODE_RWX); - printf("PERMS = 0%03o\n", PERMS); - printf("dir_mode = 0%03o\n", dir_mode); -#endif - if ((PERMS & ~S_ISGID) != dir_mode) - tst_resm(TFAIL, "%s: Incorrect modes 0%03o, " - "Expected 0%03o", TESTDIR, dir_mode, - PERMS & ~S_ISGID); - else - tst_resm(TPASS, - "Functionality of chmod(%s, %#o) successful", - TESTDIR, PERMS); + TEST(chmod(TESTDIR, PERMS)); + if (TST_RET == -1) { + tst_res(TFAIL, "chmod(%s, %#o) failed", TESTDIR, PERMS); } - cleanup(); - tst_exit(); + /* Get the directory information using stat(2) and compare with + * expected results. + */ + SAFE_STAT(TESTDIR, &stat_buf); + dir_mode = stat_buf.st_mode; + if ((PERMS & ~S_ISGID) != dir_mode) { + tst_res(TFAIL, "%s: Incorrect modes 0%03o, " + "Expected 0%03o", TESTDIR, dir_mode, + PERMS & ~S_ISGID); + } else { + tst_res(TPASS, "Functionality of chmod(%s, %#o) successful", + TESTDIR, PERMS); + } } -/* - * void - * setup() - performs all ONE TIME setup for this test. - * Create a temporary directory and cd to it. - * Create a test directory under temporary directory. -//wjh we are root so do we really need this kluged helper program? - * Invoke setuid to root program to modify group ownership - * on test directory. - */ void setup(void) { struct passwd *nobody_u; - struct group *bin_group; - - tst_require_root(); + struct group *bin_gr; - TEST_PAUSE; - - tst_tmpdir(); - - nobody_u = getpwnam("nobody"); - if (nobody_u == NULL) - tst_brkm(TBROK | TERRNO, cleanup, - "getpwnam(\"nobody\") failed"); - - bin_group = getgrnam("bin"); - if (bin_group == NULL) - tst_brkm(TBROK | TERRNO, cleanup, "getgrnam(\"bin\") failed"); + nobody_u = SAFE_GETPWNAM("nobody"); + bin_gr = SAFE_GETGRNAM("bin"); /* * Create a test directory under temporary directory with specified * mode permissions and change the gid of test directory to nobody's * gid. */ - SAFE_MKDIR(cleanup, TESTDIR, MODE_RWX); - + SAFE_MKDIR(TESTDIR, MODE_RWX); if (setgroups(1, &nobody_u->pw_gid) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "setgroups to nobody's gid failed"); + tst_brk(TBROK | TERRNO, "setgroups to nobody's gid failed"); - SAFE_CHOWN(cleanup, TESTDIR, nobody_u->pw_uid, bin_group->gr_gid); + SAFE_CHOWN(TESTDIR, nobody_u->pw_uid, bin_group->gr_gid); /* change to nobody:nobody */ - if (setegid(nobody_u->pw_gid) == -1 || seteuid(nobody_u->pw_uid) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "Couldn't switch to nobody:nobody"); + SAGE_SETEGID(nobody_u->pw_gid); + SAFE_SETEUID(nobody_u->pw_uid); } -void cleanup(void) -{ - if (setegid(0) == -1) - tst_resm(TWARN | TERRNO, "setegid(0) failed"); - if (seteuid(0) == -1) - tst_resm(TWARN | TERRNO, "seteuid(0) failed"); - - tst_rmdir(); -} +static struct tst_test test = { + .needs_root = 1, + .needs_tmpdir = 1, + .setup = setup, + .test_all = test_chmod, +}; From patchwork Mon Nov 5 23:50:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sandeep Patil X-Patchwork-Id: 993483 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=fail (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="EHxNXogo"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42pqFb3Z7Sz9sN1 for ; Tue, 6 Nov 2018 10:51:15 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E04C93E7909 for ; Tue, 6 Nov 2018 00:51:12 +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 [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id A36713E7842 for ; Tue, 6 Nov 2018 00:50:57 +0100 (CET) Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (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 706FC1000A00 for ; Tue, 6 Nov 2018 00:50:56 +0100 (CET) Received: by mail-pl1-x644.google.com with SMTP id n4-v6so5242971plp.2 for ; Mon, 05 Nov 2018 15:50:56 -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=Y1uVXm8xwLChwVNc0rHIYamwK3nvuQbaYsEAwdr6jqo=; b=EHxNXogotySw0Rv8zgLqVHfkxxIpqa1wcX5CSQK7F3fUBSDGoEZn4bM+aAKEI2ShO/ Nbva4/IL91PBGHpnmAA6YS5eaeAlf62eypphCIS/Bvj2r/w/TH+y1zzgC8j5B3JGH8oH sMYOiH0SNxHQ7ZnaKVkqj6an9j3KbBU/098GtNtOr8yCv/G1pc14IcJONqEje7hw/Jnp ySaiov3AbG5zA0IFbvdKxaOa3qC7yyNIwq6mvypg8m6Nvud10qt2IIXWTQi6JtXGWRkX R1vXwI5jLm/C1JeHay9wxjz4FwkRFaIp0QasJYkpqToPhBntbbfrQ/A1OUI0QTzLnUvV 9i/Q== 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=Y1uVXm8xwLChwVNc0rHIYamwK3nvuQbaYsEAwdr6jqo=; b=J/7JMtzmdJTOjce3Ep88lTYYBFsi62zQbmR04T2CLXtnGPOiQRBjHWsk+HlZDid3R7 JtVSClllj4+ynm9ZrIroAmK4fNBH1/mIHvyc88ab0dDnepPseVdPn08fct31LqpUHryI LDzMw9ykAY49Eg+8mdcCQ6gs5P9exByH2m15arrqQADGoPEeb6JAQsFTWJpiqZt300nT 8RhEsoMcFgx2ENJFVL87Qf6MSWp6YCZ7J3yIkYRBtu6V/1xBMcVt8ya9gQC3Fg/3ItLe 5Z+bTUDNMZtBqU+sKUpkS829WsiVO06ORcdFixsgQK6BrnLzQD5CU4q4pVqISfcMEdhF zzjw== X-Gm-Message-State: AGRZ1gKJf6ljsfB2+dMJP1FWZe8YhA7Xoc38+2mk5jg3hEMXsH4vgsfw ndOqEgWp6YUkCbzgjR3ezRPe6xA/gRo5Pg== X-Google-Smtp-Source: AJdET5ff1ZCRYOGg2GpsOp+7gfv2+8VG5uALz2qey7lqN8/DxIzx23SH4L8X+HKme49/509xrrKOwA== X-Received: by 2002:a17:902:8c86:: with SMTP id t6-v6mr24380666plo.55.1541461854242; Mon, 05 Nov 2018 15:50:54 -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.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:50:52 -0800 (PST) From: Sandeep Patil To: ltp@lists.linux.it Date: Mon, 5 Nov 2018 15:50:19 -0800 Message-Id: <20181105235019.254846-6-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 5/5] syscalls/posix_fadvise0[13]: Start using 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Use SPDX-Licence-Identifier and delete dead comments / code while at it. Make sure the tests can work on any system by creating its own file and using it for testing. Signed-off-by: Sandeep Patil --- .../kernel/syscalls/fadvise/posix_fadvise01.c | 135 ++++----------- .../kernel/syscalls/fadvise/posix_fadvise03.c | 163 ++++-------------- 2 files changed, 68 insertions(+), 230 deletions(-) diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c index c12f0563c..ad139a66b 100644 --- a/testcases/kernel/syscalls/fadvise/posix_fadvise01.c +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise01.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* - * * Copyright (c) Red Hat Inc., 2007 - * - * 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 */ /* @@ -34,15 +20,13 @@ * None */ -#define _XOPEN_SOURCE 600 #include #include #include #include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "lapi/syscalls.h" #ifndef _FILE_OFFSET_BITS @@ -53,15 +37,8 @@ #define __NR_fadvise64 0 #endif -void setup(); -void cleanup(); - -TCID_DEFINE(posix_fadvise01); - -char fname[] = "/bin/cat"; /* test executable to open */ -int fd = -1; /* initialized in open */ - -int expected_return = 0; +const char *fname = "testfile"; +int fd = -1; int defined_advise[] = { POSIX_FADV_NORMAL, @@ -72,91 +49,41 @@ int defined_advise[] = { POSIX_FADV_DONTNEED, }; -#define defined_advise_total ARRAY_SIZE(defined_advise) - -int TST_TOTAL = defined_advise_total; - -int main(int ac, char **av) +void test_posix_fadvise(unsigned int nr) { - int lc; - int i; - - /* Check this system has fadvise64 system which is used - in posix_fadvise. */ - if ((_FILE_OFFSET_BITS != 64) && (__NR_fadvise64 == 0)) { - tst_resm(TWARN, - "This test can only run on kernels that implements "); - tst_resm(TWARN, "fadvise64 which is used from posix_fadvise"); - exit(0); + TEST(posix_fadvise(fd, 0, 0, defined_advise[nr])); + if (TST_RET == 0) { + tst_res(TPASS, "call succeeded expectedly"); + } else { + tst_res(TFAIL, "unexpected return - %ld w/ advise %d", + TST_RET, defined_advise[nr]); } - - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given on the command line - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* loop through the test cases */ - for (i = 0; i < defined_advise_total; i++) { - - TEST(posix_fadvise(fd, 0, 0, defined_advise[i])); - - /* Man page says: - "On error, an error number is returned." */ - if (TEST_RETURN == expected_return) { - tst_resm(TPASS, "call succeeded expectedly"); - } else { - tst_resm(TFAIL, - "unexpected return value - %ld : %s, advise %d - " - "expected %d", - TEST_RETURN, - strerror(TEST_RETURN), - defined_advise[i], expected_return); - } - } - } - - /* - * cleanup and exit - */ - cleanup(); - - tst_exit(); } -/* - * setup() - performs all ONE TIME setup for this test. - */ void setup(void) { + unsigned long pagesz = getpagesize(); + char buf[10 * pagesz]; - tst_sig(NOFORK, DEF_HANDLER, cleanup); + /* Check this system has fadvise64 system which is used + in posix_fadvise. */ + if ((_FILE_OFFSET_BITS != 64) && (__NR_fadvise64 == 0)) { + tst_brk(TCONF, + "This test can only run on kernels that implements " + "fadvise64 which is used from posix_fadvise"); + } - TEST_PAUSE; + /* create 10 x pagesize file to be used for fadvise checks */ + fd = SAFE_CREAT(fname, 0644); + SAFE_WRITE(1, fd, buf, 10 * pagesz); + SAFE_CLOSE(fd); - fd = SAFE_OPEN(cleanup, fname, O_RDONLY); + fd = SAFE_OPEN(fname, O_RDONLY); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - if (fd != -1) { - close(fd); - } - -} +struct tst_test test = { + .tcnt = ARRAY_SIZE(defined_advise), + .needs_tmpdir = 1, + .setup = setup, + .test = test_posix_fadvise, +}; diff --git a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c index 4aa3a8cd1..ffb196743 100644 --- a/testcases/kernel/syscalls/fadvise/posix_fadvise03.c +++ b/testcases/kernel/syscalls/fadvise/posix_fadvise03.c @@ -1,20 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* - * * Copyright (c) Red Hat Inc., 2007 - * - * 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 */ /* @@ -34,14 +20,12 @@ * None */ -#define _XOPEN_SOURCE 600 #include #include #include #include #include -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "lapi/syscalls.h" #ifndef _FILE_OFFSET_BITS @@ -52,14 +36,10 @@ #define __NR_fadvise64 0 #endif -void setup(); -void cleanup(); - -TCID_DEFINE(posix_fadvise03); - -char fname[] = "/bin/cat"; /* test executable to open */ -int fd = -1; /* initialized in open */ +#define ADVISE_LIMIT (32) +const char *fname = "testfile"; +int fd = -1; int expected_error = EINVAL; int defined_advise[] = { @@ -87,24 +67,10 @@ int defined_advise[] = { #endif }; -#define defined_advise_total ARRAY_SIZE(defined_advise) - -#if 0 -/* Too many test cases. */ -int TST_TOTAL = (INT_MAX - defined_advise_total); -int advise_limit = INT_MAX; -#else -int TST_TOTAL = (32 - defined_advise_total); -int advise_limit = 32; -#endif /* 0 */ - -/* is_defined_advise: - Return 1 if advise is in defined_advise. - Return 0 if not. */ static int is_defined_advise(int advise) { int i; - for (i = 0; i < defined_advise_total; i++) { + for (i = 0; i < ARRAY_SIZE(defined_advise); i++) { if (defined_advise[i] == advise) return 1; } @@ -112,101 +78,46 @@ static int is_defined_advise(int advise) return 0; } -int main(int ac, char **av) +int test_posix_fadvise(unsigned int nr) { - int lc; - int advise; - - /* Check this system has fadvise64 system which is used - in posix_fadvise. */ - if ((_FILE_OFFSET_BITS != 64) && (__NR_fadvise64 == 0)) { - tst_resm(TWARN, - "This test can only run on kernels that implements "); - tst_resm(TWARN, "fadvise64 which is used from posix_fadvise"); - exit(0); + int advise = nr; + + /* Don't use defined advise as an argument. */ + if (is_defined_advise(advise)) { + return; } - /* - * parse standard options - */ - tst_parse_opts(ac, av, NULL, NULL); - - /* - * perform global setup for test - */ - setup(); - - /* - * check looping state if -i option given on the command line - */ - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* loop through the test cases */ - for (advise = 0; advise < advise_limit; advise++) { - - /* Don't use defiend advise as an argument. */ - if (is_defined_advise(advise)) { - continue; - } - - TEST(posix_fadvise(fd, 0, 0, advise)); - - if (TEST_RETURN == 0) { - tst_resm(TFAIL, "call succeeded unexpectedly"); - continue; - } - - /* Man page says: - "On error, an error number is returned." */ - if (TEST_RETURN == expected_error) { - tst_resm(TPASS, - "expected failure - " - "returned value = %ld, advise = %d : %s", - TEST_RETURN, - advise, strerror(TEST_RETURN)); - } else { - tst_resm(TFAIL, - "unexpected return value - %ld : %s, advise %d - " - "expected %d", - TEST_RETURN, - strerror(TEST_RETURN), - advise, expected_error); - } - } + TEST(posix_fadvise(fd, 0, 0, advise)); + if (TST_RET == 0) { + tst_res(TFAIL, "call succeeded unexpectedly"); + return; } - /* - * cleanup and exit - */ - cleanup(); - - tst_exit(); + if (TST_RET == expected_error) { + tst_res(TPASS, "expected failure - returned %ld for advise %d", + TST_RET, advise); + } else { + tst_res(TFAIL, "unexpected return - %ld for advise %d", + TST_RET, advise); + } } -/* - * setup() - performs all ONE TIME setup for this test. - */ void setup(void) { - - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - fd = SAFE_OPEN(cleanup, fname, O_RDONLY); -} - -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) -{ - - if (fd != -1) { - close(fd); + /* Check this system has fadvise64 system which is used + in posix_fadvise. */ + if ((_FILE_OFFSET_BITS != 64) && (__NR_fadvise64 == 0)) { + tst_brk(TCONF, + "This test can only run on kernels that implements " + "fadvise64 which is used from posix_fadvise"); } + fd = SAFE_OPEN(, fname, O_RDONLY); } + +struct tst_test test = { + .tcnt = ADVISE_LIMIT, + .needs_tmpdir = 1, + .setup = setup, + .test = test_posix_fadvise, +};