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: 150229 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3231097ljp; Mon, 5 Nov 2018 15:50:57 -0800 (PST) X-Google-Smtp-Source: AJdET5ffWmNYZGYLjMlKVT+ersuHAxQOuKT9qQocA8ZQT02T5qLUFLyqmMRLVID9Ymbiv1X2NOF8 X-Received: by 2002:a17:906:94c3:: with SMTP id d3-v6mr15625869ejy.104.1541461857789; Mon, 05 Nov 2018 15:50:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541461857; cv=none; d=google.com; s=arc-20160816; b=sBYRrPc0de5MqDJaPTd+1NKEBiM2qe/p+YnJIzNHdSY+jcdVrxM3IS4FzDm8IKHYdg rtArhFtHtTJ47AW5dPXV5CsbeixX0dCXJiF/A10HUX3nDmQ6bJh58H2EyR8O6uDkmnc2 AsXiGMXWxXLKLtIKq/T9/VB1432Wb1VqPO5hKLcY7uMGpRENrSni00DRDl26nyAbwSYl J27wLI0D2V1bFy9uM2Pat0T4RZj7GDrTEJ3tnMWW5gXW/ket7NNbkiwuB5I5kFDEmh0Q hR9bWVThyOAiplhrUBaKXcbIukiEtmmXGT1szzM17f4gN701+tu32OOF6OatTp3ifSGc 9rAg== 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=BU1Abu6UE5N2QzcdKRJghRFU0BrUy26nGDQSyyWi2wg=; b=QHdGgnItpufuCz5BtpW6SUj2M+0mTxBNbeyDqae/MD54affFHcNTRwU0E3diOu7CNu HyDQxz08geLZaJBqM6foLl+FNM+f2SvbXRT1IlSO9diO+1rivtYIDgUevXhbwwK/MmSd wuS1YsWZz84mOv9P7yzRLzYU+q50xvlIFyJ+Y/UAO5JNC666+bHCT3JDDn/TGteECZhA IHQMGnUAiJwZtXCwqnRDCIkNUXlZ2u8gYGNbf7PWC8axrzj7v034OkWdUT+vD4Z0LRGV BJ+ErFqsWInoB39b4LzWQAoJ2JucyCMFFJD8qE5Gt64TmO6rkYge31PWiPK0mjlJEzPE 8cfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=luUs0fJL; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 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. [213.254.12.146]) by mx.google.com with ESMTPS id d6-v6si783955edl.8.2018.11.05.15.50.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:50:57 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=luUs0fJL; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 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 713183E6377 for ; Tue, 6 Nov 2018 00:50:57 +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-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+patch=linaro.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: 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, +}; 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: 150231 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3231200ljp; Mon, 5 Nov 2018 15:51:06 -0800 (PST) X-Google-Smtp-Source: AJdET5dN/Z31Rl50YgeVRGa2Tg6dSIVHJqSORe/q+AvoyzU9+HB+KMi3XzMWTySZPD8Z40FXHdg0 X-Received: by 2002:aa7:cf1a:: with SMTP id a26-v6mr19132617edy.91.1541461866685; Mon, 05 Nov 2018 15:51:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541461866; cv=none; d=google.com; s=arc-20160816; b=MlOqQLJLH9IibiJYQ/z/wXX+6sbLbgDJTC3Uq1NgS4O3H6DzEYUl6F03k3FV91SvGx WmR6h/v3oj7VhFPEjNk7saKOj/bi0a7Xmc3rR0Wki27jUq4BOZJoZ6vTWchWZSicopdA ZhqDszo8MllYCbwyNLPHnT4AKQ28rnWaydPOTGU7oO5VI6REVLIVrb8LsPdN7Hb3OWn/ 6hW+FBskwS8y2kZxaFrmVgPsWQKOgZvW98qNK5HS6vjLkNmtXe72XN7Q5t/ZfZ8W9ONN aFQE2ziEmuTwKn3mGtj3p/ZDvStt/dZ0npPbGQ2tkvgB6mv1fQ76PijSARhiUVTMSNJN yL5A== 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=I8y+j/3Arhim0VYfW/OlROTofQ5M7vM2+UuKNl7pCwA=; b=tYyEfyOiOnjGLFjQRKiF+5X1Mb+f4/+cJ9Y6VQRrGN+zIFWx07NDB9yXxbizw4W8mp sYm1qWoFGzE3ERbvZkYu0Fyu7oWJuJIVgBSTvfmGb3Qox+zxP/OC7bg0jRPdcucmN0ff DQkMYb4bmfO9VyRt/dGTbTLgVGVK3s5/hrGlEfZPTe003t54bWJtsd6tuw5VazLMXO02 hNbyRD1CYc/oFq1TZvy2wHEPRUIK5JnsMEdE3D6FQYzMSxznuI5jaSjT/qloln/xlcUt +XP2BrSh5bu/RihVYmiWax3YzXARnT0bUzSpmsuf2Xzer7kd5QjUl2B2bguc0Dt3XC3d Ry2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=rNyD7wT+; 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 e1-v6si3088375eja.164.2018.11.05.15.51.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:51:06 -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=rNyD7wT+; 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 57E4E3E78EC for ; Tue, 6 Nov 2018 00:51:06 +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-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+patch=linaro.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: 150232 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3231254ljp; Mon, 5 Nov 2018 15:51:10 -0800 (PST) X-Google-Smtp-Source: AJdET5ejirxhikYzUI0CZyB6UgMwhbSQS+eTM5/tpdwQpBm26Wqt5rt1SKFhoQlrE9Ymd043wWFu X-Received: by 2002:a50:ca47:: with SMTP id e7-v6mr19590749edi.56.1541461870463; Mon, 05 Nov 2018 15:51:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541461870; cv=none; d=google.com; s=arc-20160816; b=uMCfj5u8e5zURJifsmnazfGXqacljql7PS4S0TTgzfhc9+tOB+YxMJS8CJF5YTok0l O58IzraIFU0xThd0WMuKuuwp3A8NU5QcHHh6cjHfK45gJyLV7pbSHjOx8ZoxKpjdrPsl 1zyKV960DyIeIHCt9OuQ7cQgZpq09zVHKxhkCcJPdPw75Cs6G3UYY70pdKJi4SIIsugR uCy2T4rsNgywmMvPJn2KzYbFjrnSjUzcUk8xWO41ICYGMJowR8rZZ8YqMZ/Km02xSnXT pQGAo3lYnjUchnHjo1WDOIgEOHVOX4WwsmLe85CpXCgY+69+IBrpIcC+ioROwOCoTGfe 3itQ== 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=lNMuS7I0bnUn90Umtq6WIkaF/0/Rtlg6Lv/aeRLokoU=; b=pbaOAvWXKRAoJeV6e2/k8dcLzzI8DSdBx+krhp+mdbFwecZD4rzI/ecu3xLyQOpELV tR8BnK7HePoZW8ZnYXUpsrxD3GqYjY/JQWfj/zwLFJbMnaic9W7qPDtLs3YdSTNTMJtO VM3FfEXTCRXf0JO6o73FQsnaKoJpXz0pU06lyZ3+7Hj3KEF8Rfg42iYEJibIVdnfpGxG zB7uakpwl15EhghcwzVa+Rmo9puT2aGN7H0wylxwQhJdVif4Zw4b/Chb+chXGp+IQ9RW 5cgrpNnWB8wPz56Gq2J/NTxAhl5PSN6Kc7CX9JJckoDgqRioO5XnDEv31yATM8S+Nqqp eWlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b="TMmO/vtA"; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 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. [213.254.12.146]) by mx.google.com with ESMTPS id b12si430546edx.434.2018.11.05.15.51.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:51:10 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b="TMmO/vtA"; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 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 194693E790E for ; Tue, 6 Nov 2018 00:51:10 +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-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+patch=linaro.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: 150233 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3231307ljp; Mon, 5 Nov 2018 15:51:14 -0800 (PST) X-Google-Smtp-Source: AJdET5f6ltWNdnQYXaOsE4yLyoXufxzK2ZUVeHhSfqWbn5doxGhwP7bP26vQIs/uJIYsWMrM+5Vv X-Received: by 2002:a50:904a:: with SMTP id z10-v6mr19314574edz.216.1541461874952; Mon, 05 Nov 2018 15:51:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541461874; cv=none; d=google.com; s=arc-20160816; b=JhfFty+izDgHz0Bop93BsujwX/qtc3zRe6xw8K6pK1NPwf2irMM4TomHb1tIf9G4JA JinwB/mmFSEDtOsLd4T6WEbIwFfmEDHhCLMc5SUTNnqTHPsz2V69unqKzR/rDQnT8087 CCzk7afjS+jFbguD4mkUuJRMwGR8TGE+n3s2RPbtH6nQo0aJCLKDuZ3hLVvYXwDQ+d8d kPGGPbe3P/+GTzlS3ZRzWlyisjPK5gH5ekwosyP/v1HWIa0FgTEQ3uT6kmS8gsNtDSia 7Wfy6NM3qBOFz6EVEUo7LbuGVUNwvYYkkXAUXnO3uPaUGIOgRs0NKAdKuqjn9UXsL9Af 6Gdg== 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=msgkk+qggrQuc7nwPdr3QG5/M60YV8IwBj3/0HfyjBI=; b=FcHMTSZzf0zDiUb87UXXHXfYfvcq9S/ZbxMCIYCp54BJrqDUNRXGnxydy9bYJiot7t Z2F+yzGSQn9NHiKYeFevp72pNAZ/q/FiZNoWXucUAAvLTLlSJ9g7rX3AkJpXdOvB+GZe gLuEvXO+Y4K8B/mqSZ9neNdBHSYgmSpIDhEF3quNdJemfUGVv1SD9/42VGfxnq3jDDbZ hvtdd7u+0SeRtMkckWU+MxNumQBMaQmdtTLhcg7W6/V5OrlRPmw+j3Zl7I+RlOJIYgqB fm25wL/R8CzueFBTu0XGA7rsb6Y22+WXTI06v7s7YBkMYpvUDOmMMftdrOJ4ruZK/JH5 J4bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=EHxNXogo; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 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. [213.254.12.146]) by mx.google.com with ESMTPS id i23-v6si348592edj.23.2018.11.05.15.51.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Nov 2018 15:51:14 -0800 (PST) Received-SPF: pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 as permitted sender) client-ip=213.254.12.146; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.s=20161025 header.b=EHxNXogo; spf=pass (google.com: domain of ltp-bounces+patch=linaro.org@lists.linux.it designates 213.254.12.146 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 8F64C3E7905 for ; Tue, 6 Nov 2018 00:51:14 +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-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+patch=linaro.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, +};