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, +};