Path: blob/master/tools/memory-model/scripts/parseargs.sh
29266 views
#!/bin/sh1# SPDX-License-Identifier: GPL-2.0+2#3# Parse arguments common to the various scripts.4#5# . scripts/parseargs.sh6#7# Include into other Linux kernel tools/memory-model scripts.8#9# Copyright IBM Corporation, 201810#11# Author: Paul E. McKenney <[email protected]>1213T=/tmp/parseargs.sh.$$14mkdir $T1516# Initialize one parameter: initparam name default17initparam () {18echo if test -z '"$'$1'"' > $T/s19echo then >> $T/s20echo $1='"'$2'"' >> $T/s21echo export $1 >> $T/s22echo fi >> $T/s23echo $1_DEF='$'$1 >> $T/s24. $T/s25}2627initparam LKMM_DESTDIR "."28initparam LKMM_HERD_OPTIONS "-conf linux-kernel.cfg"29initparam LKMM_HW_MAP_FILE ""30initparam LKMM_JOBS `getconf _NPROCESSORS_ONLN`31initparam LKMM_PROCS "3"32initparam LKMM_TIMEOUT "1m"3334scriptname=$03536usagehelp () {37echo "Usage $scriptname [ arguments ]"38echo " --destdir path (place for .litmus.out, default by .litmus)"39echo " --herdopts -conf linux-kernel.cfg ..."40echo " --hw AArch64"41echo " --jobs N (number of jobs, default one per CPU)"42echo " --procs N (litmus tests with at most this many processes)"43echo " --timeout N (herd7 timeout (e.g., 10s, 1m, 2hr, 1d, '')"44echo "Defaults: --destdir '$LKMM_DESTDIR_DEF' --herdopts '$LKMM_HERD_OPTIONS_DEF' --hw '$LKMM_HW_MAP_FILE' --jobs '$LKMM_JOBS_DEF' --procs '$LKMM_PROCS_DEF' --timeout '$LKMM_TIMEOUT_DEF'"45exit 146}4748usage () {49usagehelp 1>&250}5152# checkarg --argname argtype $# arg mustmatch cannotmatch53checkarg () {54if test $3 -le 155then56echo $1 needs argument $2 matching \"$5\"57usage58fi59if echo "$4" | grep -q -e "$5"60then61:62else63echo $1 $2 \"$4\" must match \"$5\"64usage65fi66if echo "$4" | grep -q -e "$6"67then68echo $1 $2 \"$4\" must not match \"$6\"69usage70fi71}7273while test $# -gt 074do75case "$1" in76--destdir)77checkarg --destdir "(path to directory)" "$#" "$2" '.\+' '^--'78LKMM_DESTDIR="$2"79mkdir $LKMM_DESTDIR > /dev/null 2>&180if ! test -e "$LKMM_DESTDIR"81then82echo "Cannot create directory --destdir '$LKMM_DESTDIR'"83usage84fi85if test -d "$LKMM_DESTDIR" -a -x "$LKMM_DESTDIR"86then87:88else89echo "Directory --destdir '$LKMM_DESTDIR' insufficient permissions to create files"90usage91fi92shift93;;94--herdopts|--herdopt)95checkarg --destdir "(herd7 options)" "$#" "$2" '.*' '^--'96LKMM_HERD_OPTIONS="$2"97shift98;;99--hw)100checkarg --hw "(.map file architecture name)" "$#" "$2" '^[A-Za-z0-9_-]\+' '^--'101LKMM_HW_MAP_FILE="$2"102shift103;;104-j[1-9]*)105njobs="`echo $1 | sed -e 's/^-j//'`"106trailchars="`echo $njobs | sed -e 's/[0-9]\+\(.*\)$/\1/'`"107if test -n "$trailchars"108then109echo $1 trailing characters "'$trailchars'"110usagehelp111fi112LKMM_JOBS="`echo $njobs | sed -e 's/^\([0-9]\+\).*$/\1/'`"113;;114--jobs|--job|-j)115checkarg --jobs "(number)" "$#" "$2" '^[1-9][0-9]*$' '^--'116LKMM_JOBS="$2"117shift118;;119--procs|--proc)120checkarg --procs "(number)" "$#" "$2" '^[0-9]\+$' '^--'121LKMM_PROCS="$2"122shift123;;124--timeout)125checkarg --timeout "(timeout spec)" "$#" "$2" '^\([0-9]\+[smhd]\?\|\)$' '^--'126LKMM_TIMEOUT="$2"127shift128;;129--)130shift131break132;;133*)134echo Unknown argument $1135usage136;;137esac138shift139done140if test -z "$LKMM_TIMEOUT"141then142LKMM_TIMEOUT_CMD=""; export LKMM_TIMEOUT_CMD143else144LKMM_TIMEOUT_CMD="timeout $LKMM_TIMEOUT"; export LKMM_TIMEOUT_CMD145fi146rm -rf $T147148149