Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0+
0003 #
0004 # the corresponding .litmus.out file, and does not judge the result.
0005 #
0006 # . scripts/parseargs.sh
0007 #
0008 # Include into other Linux kernel tools/memory-model scripts.
0009 #
0010 # Copyright IBM Corporation, 2018
0011 #
0012 # Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
0013 
0014 T=/tmp/parseargs.sh.$$
0015 mkdir $T
0016 
0017 # Initialize one parameter: initparam name default
0018 initparam () {
0019         echo if test -z '"$'$1'"' > $T/s
0020         echo then >> $T/s
0021         echo    $1='"'$2'"' >> $T/s
0022         echo    export $1 >> $T/s
0023         echo fi >> $T/s
0024         echo $1_DEF='$'$1  >> $T/s
0025         . $T/s
0026 }
0027 
0028 initparam LKMM_DESTDIR "."
0029 initparam LKMM_HERD_OPTIONS "-conf linux-kernel.cfg"
0030 initparam LKMM_JOBS `getconf _NPROCESSORS_ONLN`
0031 initparam LKMM_PROCS "3"
0032 initparam LKMM_TIMEOUT "1m"
0033 
0034 scriptname=$0
0035 
0036 usagehelp () {
0037         echo "Usage $scriptname [ arguments ]"
0038         echo "      --destdir path (place for .litmus.out, default by .litmus)"
0039         echo "      --herdopts -conf linux-kernel.cfg ..."
0040         echo "      --jobs N (number of jobs, default one per CPU)"
0041         echo "      --procs N (litmus tests with at most this many processes)"
0042         echo "      --timeout N (herd7 timeout (e.g., 10s, 1m, 2hr, 1d, '')"
0043         echo "Defaults: --destdir '$LKMM_DESTDIR_DEF' --herdopts '$LKMM_HERD_OPTIONS_DEF' --jobs '$LKMM_JOBS_DEF' --procs '$LKMM_PROCS_DEF' --timeout '$LKMM_TIMEOUT_DEF'"
0044         exit 1
0045 }
0046 
0047 usage () {
0048         usagehelp 1>&2
0049 }
0050 
0051 # checkarg --argname argtype $# arg mustmatch cannotmatch
0052 checkarg () {
0053         if test $3 -le 1
0054         then
0055                 echo $1 needs argument $2 matching \"$5\"
0056                 usage
0057         fi
0058         if echo "$4" | grep -q -e "$5"
0059         then
0060                 :
0061         else
0062                 echo $1 $2 \"$4\" must match \"$5\"
0063                 usage
0064         fi
0065         if echo "$4" | grep -q -e "$6"
0066         then
0067                 echo $1 $2 \"$4\" must not match \"$6\"
0068                 usage
0069         fi
0070 }
0071 
0072 while test $# -gt 0
0073 do
0074         case "$1" in
0075         --destdir)
0076                 checkarg --destdir "(path to directory)" "$#" "$2" '.\+' '^--'
0077                 LKMM_DESTDIR="$2"
0078                 mkdir $LKMM_DESTDIR > /dev/null 2>&1
0079                 if ! test -e "$LKMM_DESTDIR"
0080                 then
0081                         echo "Cannot create directory --destdir '$LKMM_DESTDIR'"
0082                         usage
0083                 fi
0084                 if test -d "$LKMM_DESTDIR" -a -w "$LKMM_DESTDIR" -a -x "$LKMM_DESTDIR"
0085                 then
0086                         :
0087                 else
0088                         echo "Directory --destdir '$LKMM_DESTDIR' insufficient permissions to create files"
0089                         usage
0090                 fi
0091                 shift
0092                 ;;
0093         --herdopts|--herdopt)
0094                 checkarg --destdir "(herd7 options)" "$#" "$2" '.*' '^--'
0095                 LKMM_HERD_OPTIONS="$2"
0096                 shift
0097                 ;;
0098         -j[1-9]*)
0099                 njobs="`echo $1 | sed -e 's/^-j//'`"
0100                 trailchars="`echo $njobs | sed -e 's/[0-9]\+\(.*\)$/\1/'`"
0101                 if test -n "$trailchars"
0102                 then
0103                         echo $1 trailing characters "'$trailchars'"
0104                         usagehelp
0105                 fi
0106                 LKMM_JOBS="`echo $njobs | sed -e 's/^\([0-9]\+\).*$/\1/'`"
0107                 ;;
0108         --jobs|--job|-j)
0109                 checkarg --jobs "(number)" "$#" "$2" '^[1-9][0-9]\+$' '^--'
0110                 LKMM_JOBS="$2"
0111                 shift
0112                 ;;
0113         --procs|--proc)
0114                 checkarg --procs "(number)" "$#" "$2" '^[0-9]\+$' '^--'
0115                 LKMM_PROCS="$2"
0116                 shift
0117                 ;;
0118         --timeout)
0119                 checkarg --timeout "(timeout spec)" "$#" "$2" '^\([0-9]\+[smhd]\?\|\)$' '^--'
0120                 LKMM_TIMEOUT="$2"
0121                 shift
0122                 ;;
0123         *)
0124                 echo Unknown argument $1
0125                 usage
0126                 ;;
0127         esac
0128         shift
0129 done
0130 if test -z "$LKMM_TIMEOUT"
0131 then
0132         LKMM_TIMEOUT_CMD=""; export LKMM_TIMEOUT_CMD
0133 else
0134         LKMM_TIMEOUT_CMD="timeout $LKMM_TIMEOUT"; export LKMM_TIMEOUT_CMD
0135 fi
0136 rm -rf $T