1 #!/bin/sh 2 # SPDX-License-Identifier: GPL-2.0+ 3 # 4 # Parse arguments common to the various script 5 # 6 # . scripts/parseargs.sh 7 # 8 # Include into other Linux kernel tools/memory 9 # 10 # Copyright IBM Corporation, 2018 11 # 12 # Author: Paul E. McKenney <paulmck@linux.ibm.c 13 14 T=/tmp/parseargs.sh.$$ 15 mkdir $T 16 17 # Initialize one parameter: initparam name def 18 initparam () { 19 echo if test -z '"$'$1'"' > $T/s 20 echo then >> $T/s 21 echo $1='"'$2'"' >> $T/s 22 echo export $1 >> $T/s 23 echo fi >> $T/s 24 echo $1_DEF='$'$1 >> $T/s 25 . $T/s 26 } 27 28 initparam LKMM_DESTDIR "." 29 initparam LKMM_HERD_OPTIONS "-conf linux-kerne 30 initparam LKMM_HW_MAP_FILE "" 31 initparam LKMM_JOBS `getconf _NPROCESSORS_ONLN 32 initparam LKMM_PROCS "3" 33 initparam LKMM_TIMEOUT "1m" 34 35 scriptname=$0 36 37 usagehelp () { 38 echo "Usage $scriptname [ arguments ]" 39 echo " --destdir path (place for 40 echo " --herdopts -conf linux-ker 41 echo " --hw AArch64" 42 echo " --jobs N (number of jobs, 43 echo " --procs N (litmus tests wi 44 echo " --timeout N (herd7 timeout 45 echo "Defaults: --destdir '$LKMM_DESTD 46 exit 1 47 } 48 49 usage () { 50 usagehelp 1>&2 51 } 52 53 # checkarg --argname argtype $# arg mustmatch 54 checkarg () { 55 if test $3 -le 1 56 then 57 echo $1 needs argument $2 matc 58 usage 59 fi 60 if echo "$4" | grep -q -e "$5" 61 then 62 : 63 else 64 echo $1 $2 \"$4\" must match \ 65 usage 66 fi 67 if echo "$4" | grep -q -e "$6" 68 then 69 echo $1 $2 \"$4\" must not mat 70 usage 71 fi 72 } 73 74 while test $# -gt 0 75 do 76 case "$1" in 77 --destdir) 78 checkarg --destdir "(path to d 79 LKMM_DESTDIR="$2" 80 mkdir $LKMM_DESTDIR > /dev/nul 81 if ! test -e "$LKMM_DESTDIR" 82 then 83 echo "Cannot create di 84 usage 85 fi 86 if test -d "$LKMM_DESTDIR" -a 87 then 88 : 89 else 90 echo "Directory --dest 91 usage 92 fi 93 shift 94 ;; 95 --herdopts|--herdopt) 96 checkarg --destdir "(herd7 opt 97 LKMM_HERD_OPTIONS="$2" 98 shift 99 ;; 100 --hw) 101 checkarg --hw "(.map file arch 102 LKMM_HW_MAP_FILE="$2" 103 shift 104 ;; 105 -j[1-9]*) 106 njobs="`echo $1 | sed -e 's/^- 107 trailchars="`echo $njobs | sed 108 if test -n "$trailchars" 109 then 110 echo $1 trailing chara 111 usagehelp 112 fi 113 LKMM_JOBS="`echo $njobs | sed 114 ;; 115 --jobs|--job|-j) 116 checkarg --jobs "(number)" "$# 117 LKMM_JOBS="$2" 118 shift 119 ;; 120 --procs|--proc) 121 checkarg --procs "(number)" "$ 122 LKMM_PROCS="$2" 123 shift 124 ;; 125 --timeout) 126 checkarg --timeout "(timeout s 127 LKMM_TIMEOUT="$2" 128 shift 129 ;; 130 --) 131 shift 132 break 133 ;; 134 *) 135 echo Unknown argument $1 136 usage 137 ;; 138 esac 139 shift 140 done 141 if test -z "$LKMM_TIMEOUT" 142 then 143 LKMM_TIMEOUT_CMD=""; export LKMM_TIMEO 144 else 145 LKMM_TIMEOUT_CMD="timeout $LKMM_TIMEOU 146 fi 147 rm -rf $T
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.