From patchwork Fri Apr 19 14:04:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Po-Hsu Lin X-Patchwork-Id: 10909837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6DA1D14DB for ; Fri, 19 Apr 2019 22:45:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EEA2289CE for ; Fri, 19 Apr 2019 22:45:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5067528ABF; Fri, 19 Apr 2019 22:45:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27385289CE for ; Fri, 19 Apr 2019 22:45:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725817AbfDSWpk (ORCPT ); Fri, 19 Apr 2019 18:45:40 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:46987 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbfDSWpi (ORCPT ); Fri, 19 Apr 2019 18:45:38 -0400 Received: from mail-pf1-f200.google.com ([209.85.210.200]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hHU8R-0005jC-0e for linux-kselftest@vger.kernel.org; Fri, 19 Apr 2019 14:04:59 +0000 Received: by mail-pf1-f200.google.com with SMTP id n63so3546461pfb.14 for ; Fri, 19 Apr 2019 07:04:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=lMAujf26FHR5J5s/vTp3XaTt+DwmocRMaUpglBlnuGA=; b=JYkvGjHIfl82B/yqE/7tY4KkqpSsKAJ8ytzDw+7SMHk4l6I0m9NsSXXc3MnlwEAWLr pU5cCN+gT9s/vSrECcVH+aOLetIMGNud9AVtr+4YmEnjyq1Q5ikCbTJF+wgVHssfKbix FVL8wunUSMtNe9WqQbTimVyMz/zYXwQhuO+4B86N1+jcvPpI7iO5EEXfdIwQ5xHNGy5x 4iZbUW/FvM7qUh8EgEgeiW+1BGcP7xotuhpNCcRBFuYuXIk7ajox4yDj1SzmzvlVJfwb L1AQq2ZCSsaABJO+YrQGafRWFP0Layl0Wajqizehe8M3LzuMfoHh3aBlAl7WhPcgoGGD KbWg== X-Gm-Message-State: APjAAAV6PwdQz7mq/6LS9EQkYdjtzFzxOfHyY9Non23SDwm11fBRIMj2 9NY6u4QIVTD5PTFYuZLC5h12gODxn9x73lBhoaHL8cChZehXiMxbTB3Q8ZxRbmYg4TnkThJTXJw xwndRWEIt5VNylZIRarm3Bwxr59DABKmDpySS5QTJ4qgH X-Received: by 2002:a65:5286:: with SMTP id y6mr3958624pgp.79.1555682697486; Fri, 19 Apr 2019 07:04:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxua4yzSBhQWEDfBc/5SPy9AETjb+1xDyJ5Q5XBifmwqMVKhpPVzKtpdCopq6EmvY9AqmRfBg== X-Received: by 2002:a65:5286:: with SMTP id y6mr3958574pgp.79.1555682696973; Fri, 19 Apr 2019 07:04:56 -0700 (PDT) Received: from Leggiero.taipei.internal (61-220-137-37.HINET-IP.hinet.net. [61.220.137.37]) by smtp.gmail.com with ESMTPSA id h16sm7642922pgj.85.2019.04.19.07.04.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Apr 2019 07:04:56 -0700 (PDT) From: Po-Hsu Lin To: shuah@kernel.org, zhangxiaoxu5@huawei.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCHv3] selftests/efivarfs: clean up test files from test_create*() Date: Fri, 19 Apr 2019 22:04:49 +0800 Message-Id: <20190419140449.31259-1-po-hsu.lin@canonical.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Test files created by test_create() and test_create_empty() tests will stay in the $efivarfs_mount directory until the system was rebooted. When the tester tries to run this efivarfs test again on the same system, the immutable characteristics in that directory will cause some "Operation not permitted" noises, and a false-positve test result as the file was created in previous run. -------------------- running test_create -------------------- ./efivarfs.sh: line 59: /sys/firmware/efi/efivars/test_create-210be57c-9849-4fc7-a635-e6382d1aec27: Operation not permitted [PASS] -------------------- running test_create_empty -------------------- ./efivarfs.sh: line 78: /sys/firmware/efi/efivars/test_create_empty-210be57c-9849-4fc7-a635-e6382d1aec27: Operation not permitted [PASS] -------------------- Create a file_cleanup() to remove those test files in the end of each test to solve this issue. For the test_create_read, we can move the clean up task to the end of the test to ensure the system is clean. Also, use this function to replace the existing file removal code. Signed-off-by: Po-Hsu Lin --- tools/testing/selftests/efivarfs/efivarfs.sh | 32 +++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/efivarfs/efivarfs.sh b/tools/testing/selftests/efivarfs/efivarfs.sh index d386610..a90f394 100755 --- a/tools/testing/selftests/efivarfs/efivarfs.sh +++ b/tools/testing/selftests/efivarfs/efivarfs.sh @@ -7,6 +7,12 @@ test_guid=210be57c-9849-4fc7-a635-e6382d1aec27 # Kselftest framework requirement - SKIP code is 4. ksft_skip=4 +file_cleanup() +{ + chattr -i $1 + rm -f $1 +} + check_prereqs() { local msg="skip all tests:" @@ -58,8 +64,10 @@ test_create() if [ $(stat -c %s $file) -ne 5 ]; then echo "$file has invalid size" >&2 + file_cleanup $file exit 1 fi + file_cleanup $file } test_create_empty() @@ -72,16 +80,14 @@ test_create_empty() echo "$file can not be created without writing" >&2 exit 1 fi + file_cleanup $file } test_create_read() { local file=$efivarfs_mount/$FUNCNAME-$test_guid - if [ -f $file]; then - chattr -i $file - rm -rf $file - fi ./create-read $file + file_cleanup $file } test_delete() @@ -96,11 +102,7 @@ test_delete() exit 1 fi - rm $file 2>/dev/null - if [ $? -ne 0 ]; then - chattr -i $file - rm $file - fi + file_cleanup $file if [ -e $file ]; then echo "$file couldn't be deleted" >&2 @@ -154,11 +156,7 @@ test_valid_filenames() echo "$file could not be created" >&2 ret=1 else - rm $file 2>/dev/null - if [ $? -ne 0 ]; then - chattr -i $file - rm $file - fi + file_cleanup $file fi done @@ -191,11 +189,7 @@ test_invalid_filenames() if [ -e $file ]; then echo "Creating $file should have failed" >&2 - rm $file 2>/dev/null - if [ $? -ne 0 ]; then - chattr -i $file - rm $file - fi + file_cleanup $file ret=1 fi done