[igt-dev] [PATCH i-g-t v2 1/4] run-tests.sh: allow to run without sudo

Lucas De Marchi lucas.demarchi at intel.com
Fri Apr 20 16:11:50 UTC 2018


On Fri, Apr 20, 2018 at 02:00:30PM +0300, Jani Nikula wrote:
> On Wed, 14 Mar 2018, Lucas De Marchi <lucas.demarchi at intel.com> wrote:
> > If the script is already running as root, it doens't need to be
> > executed through sudo. This also moves the calls to exec piglit to a
> > common function.
> >
> > Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
> > ---
> >  scripts/run-tests.sh | 23 +++++++++++++++++++----
> >  1 file changed, 19 insertions(+), 4 deletions(-)
> >
> > diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh
> > index a98e06ce..1c3f2805 100755
> > --- a/scripts/run-tests.sh
> > +++ b/scripts/run-tests.sh
> > @@ -44,6 +44,21 @@ function download_piglit {
> >  	git clone git://anongit.freedesktop.org/piglit "$ROOT/piglit"
> >  }
> >  
> > +function run_piglit # as-root <args>
> > +{
> > +	local need_root=$1
> > +	shift
> > +	local sudo
> > +
> > +	export IGT_TEST_ROOT IGT_CONFIG_PATH
> > +
> > +	if [ "$need_root" -ne 0 -a "$EUID" -ne 0 ]; then
> > +		sudo="sudo --preserve-env=IGT_TEST_ROOT,IGT_CONFIG_PATH"
> > +	fi
> 
> sudo: option '--preserve-env' doesn't allow an argument
> 
> $ sudo --version
> Sudo version 1.8.19p1

This has been added on 1.8.21:
https://www.sudo.ws/stable.html#1.8.21

	The --preserve-env command line option has been extended to
	accept a comma-separated list of environment variables to
	preserve.

I didn't know it was that new. So for compatibility purposes maybe it's
better to do:
sudo="sudo  <options> IGT_TEST_ROOT=$IGT_TEST_ROOT ... <cmd>"

Lucas De Marchi

> 
> BR,
> Jani.
> 
> > +
> > +	$sudo $PIGLIT "$@"
> > +}
> > +
> >  function print_help {
> >  	echo "Usage: run-tests.sh [options]"
> >  	echo "Available options:"
> > @@ -111,18 +126,18 @@ if [ ! -x "$PIGLIT" ]; then
> >  fi
> >  
> >  if [ "x$LIST_TESTS" != "x" ]; then
> > -	IGT_TEST_ROOT="$IGT_TEST_ROOT" IGT_CONFIG_PATH="$IGT_CONFIG_PATH" "$PIGLIT" print-cmd --format "{name}" igt
> > +	run_piglit 0 print-cmd --format "{name}" igt
> >  	exit
> >  fi
> >  
> >  if [ "x$RESUME" != "x" ]; then
> > -	sudo IGT_TEST_ROOT="$IGT_TEST_ROOT" IGT_CONFIG_PATH="$IGT_CONFIG_PATH" "$PIGLIT" resume "$RESULTS" $NORETRY
> > +	run_piglit 1 resume "$RESULTS" $NORETRY
> >  else
> >  	mkdir -p "$RESULTS"
> > -	sudo IGT_TEST_ROOT="$IGT_TEST_ROOT" IGT_CONFIG_PATH="$IGT_CONFIG_PATH" "$PIGLIT" run igt --ignore-missing -o "$RESULTS" -s $VERBOSE $EXCLUDE $FILTER
> > +	run_piglit 1 run igt --ignore-missing -o "$RESULTS" -s $VERBOSE $EXCLUDE $FILTER
> >  fi
> >  
> >  if [ "$SUMMARY" == "html" ]; then
> > -	"$PIGLIT" summary html --overwrite "$RESULTS/html" "$RESULTS"
> > +	run_piglit 0 summary html --overwrite "$RESULTS/html" "$RESULTS"
> >  	echo "HTML summary has been written to $RESULTS/html/index.html"
> >  fi
> 
> -- 
> Jani Nikula, Intel Open Source Technology Center


More information about the igt-dev mailing list