From patchwork Thu Nov 1 22:05:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael David Tinoco X-Patchwork-Id: 149994 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1325262ljp; Thu, 1 Nov 2018 15:05:27 -0700 (PDT) X-Google-Smtp-Source: AJdET5eQzFlxgdcADHVa8qObE1N6jucHJ+k/tzA6+dwKSTCi4oCK0dHQMA45hry2hys9+DPuJPj9 X-Received: by 2002:a5d:4844:: with SMTP id n4-v6mr8388436wrs.28.1541109927905; Thu, 01 Nov 2018 15:05:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541109927; cv=none; d=google.com; s=arc-20160816; b=JTkMJI/IR9WGOPVgwu5c+kV0UrF1A2tvU7as9pvKhwKpchgXiGPm88SldXBPorOTo5 VCIgsr2Qpin4EOkfylWmPGi2pb7Xj5ViIZzNzymPZIYRBgSpl7ZBEvft12WdEa0FnOq7 7QohiN7h9VyOTyq+uQxpinm+3gUstNUMadzSxORRKI5eysr1fdytbwxNoLDyLlrOp51D Gazs5k+oSjEwJDM01tflk52ev3zqx1AZcxaz1EK+vhTlbJQphMEIquhvxZTQGzgXQXV8 Lcr4ylb/ZMcLPgnhz8f/XjKfvITklNjbr/20/PiZzv2EWZ7owp56JJaW4raqqD/4kwLu 3nAg== 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:message-id:date:to:from:dkim-signature:delivered-to; bh=iZ+RVdQYfBJx9daxX4BIjng6IBiU/c9NV0tAwBEh2hw=; b=0GbskjiSXyMnVSDTOY8iFVb8ekC8ivsixnUe0ESeq7e005dzZMFgqGewO3Oz8HU1DB N8Xb6rWroBHGzvYhEY1ziAUZR59L39DFFiXjqYLNg6id8XB6X+FQxd2z7LJZHjIyHml8 3XSaQsJZb1oBvrkw/nA5LuOWHg0AmW75MWcpOVRuGTttvvZ2fzIZaxOru0arNj+euwTH 140LQ71HmSJDZ6Im4SSp4RaWcsq6gxz2Ymf59gOHcTl1d17fQMJcHHM9cyQzf2q8JiMh 8uAZXbcUiVd1rVP1R+LMNYjm64kZhZZyWN+yfoGzxppAixMZd0j2jk+O1ehv5uuK923k EnkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZEGtT4De; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [213.254.12.146]) by mx.google.com with ESMTPS id x2-v6si25232022wrc.249.2018.11.01.15.05.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 15:05:27 -0700 (PDT) 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=@linaro.org header.s=google header.b=ZEGtT4De; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 263623E75AF for ; Thu, 1 Nov 2018 23:05:27 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id A38F93E7449 for ; Thu, 1 Nov 2018 23:05:23 +0100 (CET) Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 544D514002BC for ; Thu, 1 Nov 2018 23:05:22 +0100 (CET) Received: by mail-qk1-x744.google.com with SMTP id v68-v6so42321qka.2 for ; Thu, 01 Nov 2018 15:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=7KvaVnZq2KRJZSP3kD3IGgepjQpz9F3fxu8BLT630nA=; b=ZEGtT4De/dEi20MzSQH4Rn4lFMdkSreNVzpCGIarutFbC2eNxflAWWMiEo4XM02rUC HB+c5dR87h+pcywCB7J7od4ja2iHVQo4NPo6BmvkgTmjfPsRxJ3wftCVuGEq27KtwYAL i6vj51oWogRP6o4ahaPwf1capjdTI0ZEszz+A= 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:mime-version :content-transfer-encoding; bh=7KvaVnZq2KRJZSP3kD3IGgepjQpz9F3fxu8BLT630nA=; b=cLnaG/fHIz5aRIJ5+J0oMyCsJIQl2J946HGzsJcTfS1OlXdULYdFeKqQhjA5m/ycwy S7hhcE6h6OcA0sLzSRfrTjfr4eJ3s1g+ZJ3TwMeOf1tsGObnrdl/9Av+hI9iRJAXDSoO zkMSIs/suZ9KwvnYGOrCgdKvYzr9HH1f/4AncDKbrlcNO266X/yX+IuYkd3mnAmm2LF+ i+bgXBU1A4bV3mke0q2jRlP6/JjxSQUDFS+wtSOKcSWBITFKmg+3ZQY0t7ob4IlG8kqM 5KweokrLMJuo08sow2RGRcP9Nz+yeAK2D04fekcZAEMLOKbyiECwyyrXECRliOgzzr1P sgoQ== X-Gm-Message-State: AGRZ1gJ/cvV6nXaAulBCJn2AKeOgDTE2i30jX8FY2UQPgDHoZCiLdzOf 0cDSPcSaUrXfh0LHRkOosyxFVN/DJMvZJA== X-Received: by 2002:a37:6801:: with SMTP id d1mr8281578qkc.217.1541109920750; Thu, 01 Nov 2018 15:05:20 -0700 (PDT) Received: from workstation.celeiro.br ([138.204.25.64]) by smtp.gmail.com with ESMTPSA id f80-v6sm24409133qka.90.2018.11.01.15.05.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Nov 2018 15:05:20 -0700 (PDT) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Thu, 1 Nov 2018 19:05:17 -0300 Message-Id: <20181101220517.19785-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Cc: rafael.tinoco@linaro.org Subject: [LTP] [PATCH] syscalls/fremovexattr: Add fremovexattr() tests 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" Fixes: #276 Following the same logic and tests used to test removexattr() syscall, this commit implements tests for fremovexattr(). It only differs from removexattr() on the given arguments: using a file descriptor instead of the filename. Kernel has different entry points for both, with slightly different execution paths, mainly related to dealing with the passed file descriptor. Signed-off-by: Rafael David Tinoco --- runtest/syscalls | 3 + .../kernel/syscalls/fremovexattr/.gitignore | 2 + .../kernel/syscalls/fremovexattr/Makefile | 8 ++ .../syscalls/fremovexattr/fremovexattr01.c | 105 ++++++++++++++ .../syscalls/fremovexattr/fremovexattr02.c | 130 ++++++++++++++++++ 5 files changed, 248 insertions(+) create mode 100644 testcases/kernel/syscalls/fremovexattr/.gitignore create mode 100644 testcases/kernel/syscalls/fremovexattr/Makefile create mode 100644 testcases/kernel/syscalls/fremovexattr/fremovexattr01.c create mode 100644 testcases/kernel/syscalls/fremovexattr/fremovexattr02.c diff --git a/runtest/syscalls b/runtest/syscalls index 2ac9f7665..c48ada707 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -319,6 +319,9 @@ fork14 fork14 fpathconf01 fpathconf01 +fremovexattr01 fremovexattr01 +fremovexattr02 fremovexattr02 + fstat01 fstat01 fstat01_64 fstat01_64 fstat02 fstat02 diff --git a/testcases/kernel/syscalls/fremovexattr/.gitignore b/testcases/kernel/syscalls/fremovexattr/.gitignore new file mode 100644 index 000000000..455a9db2e --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/.gitignore @@ -0,0 +1,2 @@ +fremovexattr01 +fremovexattr02 diff --git a/testcases/kernel/syscalls/fremovexattr/Makefile b/testcases/kernel/syscalls/fremovexattr/Makefile new file mode 100644 index 000000000..f71e4fc25 --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/Makefile @@ -0,0 +1,8 @@ +# Copyright (c) 2018 - Linaro Limited. All rights reserved. +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk \ No newline at end of file diff --git a/testcases/kernel/syscalls/fremovexattr/fremovexattr01.c b/testcases/kernel/syscalls/fremovexattr/fremovexattr01.c new file mode 100644 index 000000000..f51a434cc --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/fremovexattr01.c @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Test Name: fremovexattr01 + * + * Description: + * Like removexattr(2), fremovexattr(2) also removes an extended attribute, + * identified by a name, from a file but, instead of using a filename path, it + * uses a descriptor. This test verifies that a simple call to fremovexattr(2) + * removes, indeed, a previously set attribute key/value from a file. + */ + +#include "config.h" +#include +#include + +#ifdef HAVE_SYS_XATTR_H +# include +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define ENOATTR ENODATA + +#define XATTR_TEST_KEY "user.testkey" +#define XATTR_TEST_VALUE "this is a test value" +#define XATTR_TEST_VALUE_SIZE 20 + +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/fremovexattr01testfile" + +static int fd = -1; +static char *got_value; + +static void verify_fremovexattr(void) +{ + SAFE_FSETXATTR(fd, XATTR_TEST_KEY, XATTR_TEST_VALUE, + XATTR_TEST_VALUE_SIZE, XATTR_CREATE); + + TEST(fremovexattr(fd, XATTR_TEST_KEY)); + + if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) { + tst_brk(TCONF, "fremovexattr(2) not supported"); + return; + } + + if (TST_RET != 0) { + tst_res(TFAIL | TTERRNO, "fremovexattr(2) failed with %li", + TST_RET); + return; + } + + memset(got_value, 0, XATTR_TEST_VALUE_SIZE); + + TEST(fgetxattr(fd, XATTR_TEST_KEY, got_value, XATTR_TEST_VALUE_SIZE)); + + if (TST_RET >= 0) { + tst_res(TFAIL, "fremovexattr(2) did not remove attribute"); + return; + } + + if (TST_RET < 0 && TST_ERR != ENOATTR) { + tst_brk(TBROK, "fremovexattr(2) could not verify removal"); + return; + } + + tst_res(TPASS, "fremovexattr(2) removed attribute as expected"); +} + +static void cleanup(void) +{ + free(got_value); + + close(fd); +} + +static void setup(void) +{ + SAFE_TOUCH(FNAME, 0644, NULL); + + fd = SAFE_OPEN(FNAME, O_RDWR, NULL); + + got_value = SAFE_MALLOC(XATTR_TEST_VALUE_SIZE); +} + +static struct tst_test test = { + .setup = setup, + .test_all = verify_fremovexattr, + .cleanup = cleanup, + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, + .needs_tmpdir = 1, + .needs_root = 1, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF(" does not exist"); +#endif diff --git a/testcases/kernel/syscalls/fremovexattr/fremovexattr02.c b/testcases/kernel/syscalls/fremovexattr/fremovexattr02.c new file mode 100644 index 000000000..5585b6abe --- /dev/null +++ b/testcases/kernel/syscalls/fremovexattr/fremovexattr02.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2018 Linaro Limited. All rights reserved. + * Author: Rafael David Tinoco + */ + +/* + * Test Name: fremovexattr02 + * + * Test cases:: + * 1) fremovexattr(2) fails if the named attribute does not exist. + * 2) fremovexattr(2) fails if file descriptor is not valid. + * 3) fremovexattr(2) fails if named attribute has an invalid address. + * + * Expected Results: + * fremovexattr(2) should return -1 and set errno to ENODATA. + * fremovexattr(2) should return -1 and set errno to EBADF. + * fremovexattr(2) should return -1 and set errno to EFAULT. + */ + +#include "config.h" +#include +#include +#include +#include + +#ifdef HAVE_SYS_XATTR_H +# include +#endif + +#include "tst_test.h" + +#ifdef HAVE_SYS_XATTR_H + +#define XATTR_TEST_KEY "user.testkey" + +#define MNTPOINT "mntpoint" +#define FNAME MNTPOINT"/fremovexattr02testfile" + +static int fd = -1; + +struct test_case { + int fd; + char *key; + char *value; + char *gotvalue; + int size; + int exp_ret; + int exp_err; +}; + +struct test_case tc[] = { + { /* case 1: attribute does not exist */ + .key = XATTR_TEST_KEY, + .exp_ret = -1, + .exp_err = ENODATA, + }, + { /* case 2: file descriptor is invalid */ + .fd = -1, + .key = XATTR_TEST_KEY, + .exp_ret = -1, + .exp_err = EBADF, + }, + { /* case 3: bad name attribute */ + .exp_ret = -1, + .exp_err = EFAULT, + }, +}; + +static void verify_fremovexattr(unsigned int i) +{ + TEST(fremovexattr(tc[i].fd, tc[i].key)); + + if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) + tst_brk(TCONF, "fremovexattr(2) not supported"); + + if (tc[i].exp_ret == TST_RET) { + + if (tc[i].exp_err) { + if (tc[i].exp_err == TST_ERR) { + tst_res(TPASS, "fremovexattr(2) passed"); + return; + } + } else { + tst_res(TPASS, "fremovexattr(2) passed"); + return; + } + } + + tst_res(TFAIL | TTERRNO, "fremovexattr(2) failed"); +} + +static void cleanup(void) +{ + if (fd > 0) + SAFE_CLOSE(fd); +} + +static void setup(void) +{ + size_t i = 0; + + SAFE_TOUCH(FNAME, 0644, NULL); + fd = SAFE_OPEN(FNAME, O_RDWR, NULL); + + for (i = 0; i < ARRAY_SIZE(tc); i++) { + + if (tc[i].fd != -1) + tc[i].fd = fd; + + if (!tc[i].key && tc[i].exp_err == EFAULT) + tc[i].key = tst_get_bad_addr(cleanup); + } +} + +static struct tst_test test = { + .setup = setup, + .test = verify_fremovexattr, + .cleanup = cleanup, + .tcnt = ARRAY_SIZE(tc), + .mntpoint = MNTPOINT, + .mount_device = 1, + .all_filesystems = 1, + .needs_tmpdir = 1, + .needs_root = 1, +}; + +#else /* HAVE_SYS_XATTR_H */ +TST_TEST_TCONF(" does not exist"); +#endif