linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: SeongJae Park <sj38.park@gmail.com>
To: shuah@kernel.org
Cc: linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
	akpm@linux-foundation.org, gregkh@linuxfoundation.org,
	SeongJae Park <sjpark@amazon.de>
Subject: [PATCH] selftests/kselftest/runner/run_one(): Allow running non-executable files
Date: Tue, 10 Aug 2021 14:04:59 +0000	[thread overview]
Message-ID: <20210810140459.23990-1-sj38.park@gmail.com> (raw)

From: SeongJae Park <sjpark@amazon.de>

When running a test program, 'run_one()' checks if the program has the
execution permission and fails if it doesn't.  However, it's easy to
mistakenly missing the permission, as some common tools like 'diff'
don't support the permission change well[1].  Compared to that, making
mistakes in the test program's path would only rare, as those are
explicitly listed in 'TEST_PROGS'.  Therefore, it might make more sense
to resolve the situation on our own and run the program.

For the reason, this commit makes the test program runner function to
still print the warning message but run the program after giving the
execution permission in the case.  To make nothing corrupted, it also
restores the permission after running it.

[1] https://lore.kernel.org/mm-commits/YRJisBs9AunccCD4@kroah.com/

Suggested-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: SeongJae Park <sjpark@amazon.de>
---
 tools/testing/selftests/kselftest/runner.sh | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
index cc9c846585f0..2eb31e945709 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -65,15 +65,16 @@ run_one()
 
 	TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
 	echo "# $TEST_HDR_MSG"
-	if [ ! -x "$TEST" ]; then
-		echo -n "# Warning: file $TEST is "
-		if [ ! -e "$TEST" ]; then
-			echo "missing!"
-		else
-			echo "not executable, correct this."
-		fi
+	if [ ! -e "$TEST" ]; then
+		echo "# Warning: file $TEST is missing!"
 		echo "not ok $test_num $TEST_HDR_MSG"
 	else
+		permission_added="false"
+		if [ ! -x "$TEST" ]; then
+			echo "# Warning: file $TEST is not executable"
+			chmod u+x "$TEST"
+			permission_added="true"
+		fi
 		cd `dirname $TEST` > /dev/null
 		((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) |
 			tap_prefix >&4) 3>&1) |
@@ -88,6 +89,9 @@ run_one()
 		else
 			echo "not ok $test_num $TEST_HDR_MSG # exit=$rc"
 		fi)
+		if [ "$permission_added" = "true" ]; then
+			chmod u-x "$TEST"
+		fi
 		cd - >/dev/null
 	fi
 }
-- 
2.17.1


             reply	other threads:[~2021-08-10 14:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10 14:04 SeongJae Park [this message]
2021-08-10 15:07 ` [PATCH] selftests/kselftest/runner/run_one(): Allow running non-executable files Greg KH
2021-08-10 16:43   ` SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210810140459.23990-1-sj38.park@gmail.com \
    --to=sj38.park@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=sjpark@amazon.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).