From patchwork Thu Aug 9 01:22:12 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: 143639 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1479062ljj; Wed, 8 Aug 2018 18:22:23 -0700 (PDT) X-Google-Smtp-Source: AA+uWPzXVKQvLHvuabz89q1/xqHhIsNOH2hUDhkesKtKJ7Ojv44/9HHyo0w74WrV1kPzOYaH7y7P X-Received: by 2002:a1c:b286:: with SMTP id b128-v6mr176091wmf.121.1533777743319; Wed, 08 Aug 2018 18:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533777743; cv=none; d=google.com; s=arc-20160816; b=EfeAuvl5e1k6LrS5NyRGkgO95/aZIDwkhcqbd46zvav3qBAe0FkkNzeR6zAbSjeAX8 bBU8a8sETi5pXtsFLysdW8usIEr3TGFw4oihqpuG7VlOv3bMGHOQr0rqrLX/GUBwoBt1 M8nwY9jkAiCkGLkfIE/42PnlcUZC6nfDx1CGfbUZr5TRq9qV4Nf6r5W714or94FCOUzU D1jJMxKwqCq2CQy76hkCm38H9ObYvh3ZkWIh99d4BawoNmLN7cG3eioGobR6QxJDpeFo MnTSYue8v1zdrX+bn2zvhjVL+7msC88UTmislIl1JkgtWcH/LZ4ktxgZL32vj3oVvC2e orSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=8fsPFgJP7pgzBXP1jIL0eUKu61DLIuOA2yt+/P5uLuA=; b=ptkCZjyz+PWkucJAt6hSEBf/8M3fUhDTUlV4AMRmTtX2JWiNBsE1C8MZJhanyU9sjA G07NJChnKrkUl5uBbAOOVBWWsY9PNYUOEpF9BqzxDFWhyGreP6g3VOwYEaBXwk2XAZ/c 79cfTdh7XLw0f9ZLcGsa6a+gCbG0Z618zI55jtvytHf3lliKF4eE97WVyC/hLrv+AWvN y1hmpz/+z0wkbj5G9cWEc9TOaJPxpYOsgjidGbh7+nUtnm5tyK9YIUO42npzgRL0HPv4 Gvbd7hxzqUVdAvuVM/qiNy4DNuAZML5ves99bXOdIDWzowLYwDDuWrnz5qh2Q2ZOSFNh VuPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=OZxDUXLY; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from picard.linux.it (picard.linux.it. [2001:1418:10:5::2]) by mx.google.com with ESMTPS id t10-v6si3764815wrv.272.2018.08.08.18.22.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 18:22:23 -0700 (PDT) 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=@linaro.org header.s=google header.b=OZxDUXLY; 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=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 D5CD21A9614 for ; Thu, 9 Aug 2018 03:22:22 +0200 (CEST) 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 A50D03E772B for ; Thu, 9 Aug 2018 03:22:18 +0200 (CEST) Received: from mail-qk0-x241.google.com (mail-qk0-x241.google.com [IPv6:2607:f8b0:400d:c09::241]) (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 C8C5414004F4 for ; Thu, 9 Aug 2018 03:22:17 +0200 (CEST) Received: by mail-qk0-x241.google.com with SMTP id c192-v6so2939383qkg.12 for ; Wed, 08 Aug 2018 18:22:17 -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; bh=jo4FizPXEWV0iWI4PFRw8H6B1Mf7cWaeEd23GFbF0SQ=; b=OZxDUXLYFp2vOA8yhNWbN59bZ9ZPh1gFxm2U9q7E7KE0/c4KUxr5I/jJV1EavhPlwy qFFegPW2+mn5L4SIYsrpVMy1m+YF+iB0NxMjrjkRLcXYjWnWP9En/ulmT57TPzSFjlBV Yycletzx+vVzykPygxES8PMObnsrX/aRUlq+Y= 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; bh=jo4FizPXEWV0iWI4PFRw8H6B1Mf7cWaeEd23GFbF0SQ=; b=SI20yrt2iIdX5rPpJDzuB6t9St7kYvBbcy5qmU0tQeqSFGYIL5d/pSdnE6LIKekMZS V4TFEirbYi6WmQ9kown0LBGOQpSEMJRsbICV2jIWH8XS8or2AMhEpcyWuj2FsMIfK6Pr H21r/FuAEoY15Okz5wZb4aBj9uyFEDDU1GpcsgPgaovYiHsDtmalpngsZy+TxXKWUV2D w8NECL2qPkgsIBO/4u6KpTDjzDYwB9VU4o9opzULzTflA97nKR6vZ7KezS4WHyZ+Jciy 3wQV6lW6pgIOnDg72hATQ+HcFGM8hd0YsxZ5TheHam0NWsX54baVeSdCu2qgym83Zs4r zeGA== X-Gm-Message-State: AOUpUlEfttV6wIq6PGGleI0Xo4RG3EmXtuFoPJtkOQzMDQ3eKgQc4/Bi 2tN1iycqpL1TdIvrkkgkgYdqhuZKcgA= X-Received: by 2002:a37:d60f:: with SMTP id t15-v6mr70144qki.316.1533777736335; Wed, 08 Aug 2018 18:22:16 -0700 (PDT) Received: from mobile.celeiro.br ([138.204.25.2]) by smtp.gmail.com with ESMTPSA id o18-v6sm2697020qtm.84.2018.08.08.18.22.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 18:22:15 -0700 (PDT) From: Rafael David Tinoco To: ltp@lists.linux.it Date: Wed, 8 Aug 2018 22:22:12 -0300 Message-Id: <20180809012212.1884-1-rafael.tinoco@linaro.org> X-Mailer: git-send-email 2.18.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: chrubis@suze.cz, rafael.tinoco@linaro.org Subject: [LTP] [PATCH] syscalls/setxattr: fix iterations and missing coverage 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: , MIME-Version: 1.0 Errors-To: ltp-bounces+patch=linaro.org@lists.linux.it Sender: "ltp" During issue #274 resolution, the following was observed: setxattr(2) tests are not considering iterations on files that are not re-created in between subsequent iterations. This leads to false results due to existing attributes not cleaned in between the calls. setxattr(2) tests were not considering 2 cases, now added: - new attr with a key with length 0 - new attr with a key that is NULL This commit makes setxattr(2) tests to behave like newly created fsetxattr(2) tests. Signed-off-by: Rafael David Tinoco --- .../kernel/syscalls/setxattr/setxattr01.c | 61 ++++++++++++++++--- .../kernel/syscalls/setxattr/setxattr02.c | 45 +++++++++++--- 2 files changed, 89 insertions(+), 17 deletions(-) diff --git a/testcases/kernel/syscalls/setxattr/setxattr01.c b/testcases/kernel/syscalls/setxattr/setxattr01.c index b9797df2c..c1ac84846 100644 --- a/testcases/kernel/syscalls/setxattr/setxattr01.c +++ b/testcases/kernel/syscalls/setxattr/setxattr01.c @@ -41,6 +41,10 @@ * setxattr(2) should return -1 and set errno to EEXIST * 7. Replace attr value with XATTR_REPLACE flag being set, * setxattr(2) should succeed + * 8. Create new attr whose key length is zero, + * setxattr(2) should return -1 and set errno to ERANGE + * 9. Create new attr whose key is NULL, + * setxattr(2) should return -1 and set errno to EFAULT */ #include "config.h" @@ -79,10 +83,11 @@ struct test_case { size_t size; int flags; int exp_err; + int keyneeded; }; struct test_case tc[] = { { /* case 00, invalid flags */ - .key = long_key, + .key = XATTR_TEST_KEY, .value = &xattr_value, .size = XATTR_TEST_VALUE_SIZE, .flags = ~0, @@ -122,6 +127,7 @@ struct test_case tc[] = { .size = XATTR_TEST_VALUE_SIZE, .flags = XATTR_CREATE, .exp_err = EEXIST, + .keyneeded = 1, }, { /* case 06, replace existing attribute */ .key = XATTR_TEST_KEY, @@ -129,43 +135,77 @@ struct test_case tc[] = { .size = XATTR_TEST_VALUE_SIZE, .flags = XATTR_REPLACE, .exp_err = 0, + .keyneeded = 1, + }, + { /* case 07, zero length key */ + .key = "", + .value = &xattr_value, + .size = XATTR_TEST_VALUE_SIZE, + .flags = XATTR_CREATE, + .exp_err = ERANGE, + }, + { /* case 08, NULL key */ + .value = &xattr_value, + .size = XATTR_TEST_VALUE_SIZE, + .flags = XATTR_CREATE, + .exp_err = EFAULT, }, }; static void verify_setxattr(unsigned int i) { + /* some tests might require existing keys for each iteration */ + if (tc[i].keyneeded) { + SAFE_SETXATTR(FNAME, tc[i].key, tc[i].value, tc[i].size, + XATTR_CREATE); + } + TEST(setxattr(FNAME, tc[i].key, *tc[i].value, tc[i].size, tc[i].flags)); if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) - tst_brk(TCONF, "setxattr() not supported"); + tst_brk(TCONF, "setxattr(2) not supported"); + + /* success */ if (!tc[i].exp_err) { if (TST_RET) { tst_res(TFAIL | TTERRNO, - "setxattr() failed with %li", TST_RET); + "setxattr(2) failed with %li", TST_RET); return; } - tst_res(TPASS, "setxattr() passed"); + /* this is needed for subsequent iterations */ + SAFE_REMOVEXATTR(FNAME, tc[i].key); + + tst_res(TPASS, "setxattr(2) passed"); + return; } if (TST_RET == 0) { - tst_res(TFAIL, "setxattr() passed unexpectedly"); + tst_res(TFAIL, "setxattr(2) passed unexpectedly"); return; } - if (TST_ERR != tc[i].exp_err) { - tst_res(TFAIL | TTERRNO, "setxattr() should fail with %s", + /* error */ + + if (tc[i].exp_err != TST_ERR) { + tst_res(TFAIL | TTERRNO, "setxattr(2) should fail with %s", tst_strerrno(tc[i].exp_err)); return; } - tst_res(TPASS | TTERRNO, "setxattr() failed"); + /* key might have been added AND test might have failed, remove it */ + if (tc[i].keyneeded) + SAFE_REMOVEXATTR(FNAME, tc[i].key); + + tst_res(TPASS | TTERRNO, "setxattr(2) failed"); } static void setup(void) { + size_t i = 0; + snprintf(long_key, 6, "%s", "user."); memset(long_key + 5, 'k', XATTR_NAME_LEN - 5); long_key[XATTR_NAME_LEN - 1] = '\0'; @@ -175,6 +215,11 @@ static void setup(void) long_value[XATTR_SIZE_MAX + 1] = '\0'; SAFE_TOUCH(FNAME, 0644, NULL); + + for (i = 0; i < ARRAY_SIZE(tc); i++) { + if (!tc[i].key) + tc[i].key = tst_get_bad_addr(NULL); + } } static struct tst_test test = { diff --git a/testcases/kernel/syscalls/setxattr/setxattr02.c b/testcases/kernel/syscalls/setxattr/setxattr02.c index aa80c1e5e..b947990b6 100644 --- a/testcases/kernel/syscalls/setxattr/setxattr02.c +++ b/testcases/kernel/syscalls/setxattr/setxattr02.c @@ -64,6 +64,7 @@ #define XATTR_TEST_VALUE "this is a test value" #define XATTR_TEST_VALUE_SIZE 20 +#define OFFSET 10 #define FILENAME "setxattr02testfile" #define DIRNAME "setxattr02testdir" #define SYMLINK "setxattr02symlink" @@ -79,6 +80,7 @@ struct test_case { size_t size; int flags; int exp_err; + int needskeyset; }; static struct test_case tc[] = { { /* case 00, set attr to reg */ @@ -104,6 +106,7 @@ static struct test_case tc[] = { .size = XATTR_TEST_VALUE_SIZE, .flags = XATTR_CREATE, .exp_err = EEXIST, + .needskeyset = 1, }, { /* case 03, set attr to fifo */ .fname = FIFO, @@ -141,34 +144,58 @@ static struct test_case tc[] = { static void verify_setxattr(unsigned int i) { - TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size, tc[i].flags)); + /* some tests might require existing keys for each iteration */ + if (tc[i].needskeyset) { + SAFE_SETXATTR(tc[i].fname, tc[i].key, tc[i].value, tc[i].size, + XATTR_CREATE); + } + + TEST(setxattr(tc[i].fname, tc[i].key, tc[i].value, tc[i].size, + tc[i].flags)); if (TST_RET == -1 && TST_ERR == EOPNOTSUPP) - tst_brk(TCONF, "setxattr() not supported"); + tst_brk(TCONF, "setxattr(2) not supported"); + + /* success */ if (!tc[i].exp_err) { if (TST_RET) { tst_res(TFAIL | TTERRNO, - "setxattr() failed with %li", TST_RET); + "setxattr(2) on %s failed with %li", + tc[i].fname + OFFSET, TST_RET); return; } - tst_res(TPASS, "setxattr() passed"); + /* this is needed for subsequent iterations */ + SAFE_REMOVEXATTR(tc[i].fname, tc[i].key); + + tst_res(TPASS, "setxattr(2) on %s passed", + tc[i].fname + OFFSET); return; } if (TST_RET == 0) { - tst_res(TFAIL, "setxattr() passed unexpectedly"); + tst_res(TFAIL, "setxattr(2) on %s passed unexpectedly", + tc[i].fname + OFFSET); return; } - if (TST_ERR != tc[i].exp_err) { - tst_res(TFAIL | TTERRNO, "setxattr() should fail with %s", - tst_strerrno(tc[i].exp_err)); + /* fail */ + + if (tc[i].exp_err != TST_ERR) { + tst_res(TFAIL | TTERRNO, + "setxattr(2) on %s should have failed with %s", + tc[i].fname + OFFSET, + tst_strerrno(tc[i].exp_err)); return; } - tst_res(TPASS | TTERRNO, "setxattr() failed"); + /* key might have been added AND test might have failed, remove it */ + if (tc[i].needskeyset) + SAFE_REMOVEXATTR(tc[i].fname, tc[i].key); + + tst_res(TPASS | TTERRNO, "setxattr(2) on %s failed", + tc[i].fname + OFFSET); } static void setup(void)