^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # the corresponding .litmus.out file, and does not judge the result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) # . scripts/parseargs.sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # Include into other Linux kernel tools/memory-model scripts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) # Copyright IBM Corporation, 2018
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) T=/tmp/parseargs.sh.$$
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) mkdir $T
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) # Initialize one parameter: initparam name default
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) initparam () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) echo if test -z '"$'$1'"' > $T/s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) echo then >> $T/s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) echo $1='"'$2'"' >> $T/s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) echo export $1 >> $T/s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) echo fi >> $T/s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) echo $1_DEF='$'$1 >> $T/s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) . $T/s
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) initparam LKMM_DESTDIR "."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) initparam LKMM_HERD_OPTIONS "-conf linux-kernel.cfg"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) initparam LKMM_JOBS `getconf _NPROCESSORS_ONLN`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) initparam LKMM_PROCS "3"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) initparam LKMM_TIMEOUT "1m"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) scriptname=$0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) usagehelp () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) echo "Usage $scriptname [ arguments ]"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) echo " --destdir path (place for .litmus.out, default by .litmus)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) echo " --herdopts -conf linux-kernel.cfg ..."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) echo " --jobs N (number of jobs, default one per CPU)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) echo " --procs N (litmus tests with at most this many processes)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) echo " --timeout N (herd7 timeout (e.g., 10s, 1m, 2hr, 1d, '')"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) echo "Defaults: --destdir '$LKMM_DESTDIR_DEF' --herdopts '$LKMM_HERD_OPTIONS_DEF' --jobs '$LKMM_JOBS_DEF' --procs '$LKMM_PROCS_DEF' --timeout '$LKMM_TIMEOUT_DEF'"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) exit 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) usage () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) usagehelp 1>&2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) # checkarg --argname argtype $# arg mustmatch cannotmatch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) checkarg () {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if test $3 -le 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) echo $1 needs argument $2 matching \"$5\"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if echo "$4" | grep -q -e "$5"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) echo $1 $2 \"$4\" must match \"$5\"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if echo "$4" | grep -q -e "$6"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) echo $1 $2 \"$4\" must not match \"$6\"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) while test $# -gt 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) case "$1" in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) --destdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) checkarg --destdir "(path to directory)" "$#" "$2" '.\+' '^--'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) LKMM_DESTDIR="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) mkdir $LKMM_DESTDIR > /dev/null 2>&1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if ! test -e "$LKMM_DESTDIR"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) echo "Cannot create directory --destdir '$LKMM_DESTDIR'"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) if test -d "$LKMM_DESTDIR" -a -w "$LKMM_DESTDIR" -a -x "$LKMM_DESTDIR"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) echo "Directory --destdir '$LKMM_DESTDIR' insufficient permissions to create files"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) --herdopts|--herdopt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) checkarg --destdir "(herd7 options)" "$#" "$2" '.*' '^--'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) LKMM_HERD_OPTIONS="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) -j[1-9]*)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) njobs="`echo $1 | sed -e 's/^-j//'`"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) trailchars="`echo $njobs | sed -e 's/[0-9]\+\(.*\)$/\1/'`"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if test -n "$trailchars"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) echo $1 trailing characters "'$trailchars'"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) usagehelp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) LKMM_JOBS="`echo $njobs | sed -e 's/^\([0-9]\+\).*$/\1/'`"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) --jobs|--job|-j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) checkarg --jobs "(number)" "$#" "$2" '^[1-9][0-9]\+$' '^--'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) LKMM_JOBS="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) --procs|--proc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) checkarg --procs "(number)" "$#" "$2" '^[0-9]\+$' '^--'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) LKMM_PROCS="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) --timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) checkarg --timeout "(timeout spec)" "$#" "$2" '^\([0-9]\+[smhd]\?\|\)$' '^--'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) LKMM_TIMEOUT="$2"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) echo Unknown argument $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) usage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ;;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) esac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) shift
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if test -z "$LKMM_TIMEOUT"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) LKMM_TIMEOUT_CMD=""; export LKMM_TIMEOUT_CMD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) LKMM_TIMEOUT_CMD="timeout $LKMM_TIMEOUT"; export LKMM_TIMEOUT_CMD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) fi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) rm -rf $T