public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Joerg Vehlow <lkml@jv-coder.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 2/3] tst_test.sh: Make public tst_require_root command public
Date: Tue, 10 Dec 2019 09:04:18 +0100	[thread overview]
Message-ID: <20191210080419.128773-3-lkml@jv-coder.de> (raw)
In-Reply-To: <20191210080419.128773-1-lkml@jv-coder.de>

From: Joerg Vehlow <joerg.vehlow@aox-tech.de>

If a test requires root only under certain circumstances, TST_NEEDS_ROOT
is not sufficient, because it always requires root.

Signed-off-by: Joerg Vehlow <joerg.vehlow@aox-tech.de>
---
 doc/test-writing-guidelines.txt |  3 ++-
 testcases/lib/tst_net.sh        | 12 ++----------
 testcases/lib/tst_security.sh   |  4 ++--
 testcases/lib/tst_test.sh       |  4 ++--
 4 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index 3360f0920..d0c49dc9c 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -2118,7 +2118,8 @@ simply by setting right '$TST_NEEDS_FOO'.
 [options="header"]
 |=============================================================================
 | Variable name      | Action done
-| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root
+| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
+|                    | Alternatively the tst_require_root command can be used
 | 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
 | 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
                        device is stored in '$TST_DEVICE' variable.
diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
index 59ceb3352..dd0c712c3 100644
--- a/testcases/lib/tst_net.sh
+++ b/testcases/lib/tst_net.sh
@@ -97,14 +97,6 @@ tst_brk_()
 {
 	[ -z "$TST_USE_LEGACY_API" ] && tst_brk $@ || tst_brkm $@
 }
-tst_require_root_()
-{
-	if [ -z "$TST_USE_LEGACY_API" ]; then
-		_tst_require_root
-	else
-		tst_require_root
-	fi
-}
 
 init_ltp_netspace()
 {
@@ -112,7 +104,7 @@ init_ltp_netspace()
 
 	if [ ! -f /var/run/netns/ltp_ns -a -z "$LTP_NETNS" ]; then
 		tst_require_cmds ip
-		tst_require_root_
+		tst_require_root
 
 		ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
 		pid="$(ROD ns_create net,mnt)"
@@ -577,7 +569,7 @@ tst_del_ipaddr()
 tst_restore_ipaddr()
 {
 	tst_require_cmds ip
-	tst_require_root_
+	tst_require_root
 
 	local type="${1:-lhost}"
 	local link_num="${2:-0}"
diff --git a/testcases/lib/tst_security.sh b/testcases/lib/tst_security.sh
index 7d033bbc5..af7c81bb5 100644
--- a/testcases/lib/tst_security.sh
+++ b/testcases/lib/tst_security.sh
@@ -95,7 +95,7 @@ tst_selinux_used_profile()
 tst_disable_apparmor()
 {
 	tst_res TINFO "trying to disable AppArmor (requires super/root)"
-	_tst_require_root
+	tst_require_root
 
 	local f="aa-teardown"
 	local action
@@ -115,7 +115,7 @@ tst_disable_apparmor()
 tst_disable_selinux()
 {
 	tst_res TINFO "trying to disable SELinux (requires super/root)"
-	_tst_require_root
+	tst_require_root
 
 	local f="$(_tst_get_enforce)"
 
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index afee6aac5..c93ab7dbe 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -454,7 +454,7 @@ _tst_setup_timer()
 	_tst_setup_timer_pid=$!
 }
 
-_tst_require_root()
+tst_require_root()
 {
 	if [ "$(id -ru)" != 0 ]; then
 		tst_brk TCONF "Must be super/root for this test!"
@@ -529,7 +529,7 @@ tst_run()
 		tst_brk TBROK "Number of iterations (-i) must be > 0"
 	fi
 
-	[ "$TST_NEEDS_ROOT" = 1 ] && _tst_require_root
+	[ "$TST_NEEDS_ROOT" = 1 ] && tst_require_root
 
 	[ "$TST_DISABLE_APPARMOR" = 1 ] && tst_disable_apparmor
 	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
-- 
2.20.1


  parent reply	other threads:[~2019-12-10  8:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-10  8:04 [LTP] [PATCH v4] lsmod01: Add kernel module Joerg Vehlow
2019-12-10  8:04 ` [LTP] [PATCH v4 1/3] tst_test.sh: Add tst_require_module command Joerg Vehlow
2019-12-10  8:04 ` Joerg Vehlow [this message]
2019-12-10  8:04 ` [LTP] [PATCH v4 3/3] lsmod01: Add kernel module Joerg Vehlow
2020-03-05 13:08   ` Petr Vorel

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=20191210080419.128773-3-lkml@jv-coder.de \
    --to=lkml@jv-coder.de \
    --cc=ltp@lists.linux.it \
    /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