run: use getopt

This commit is contained in:
Ciro Santilli
2018-08-20 09:18:15 +01:00
parent 0f6917410c
commit 036225b268
15 changed files with 268 additions and 171 deletions

View File

@@ -8459,7 +8459,7 @@ patch -d gem5/gem5 -p1 < patches/manual/gem5-biglittle.patch
then: then:
.... ....
./run -a A -g -X-b ./run -a A -g --gem5-biglittle
.... ....
Advantages over `fs.py`: Advantages over `fs.py`:
@@ -9544,8 +9544,6 @@ Otherwise, it becomes very difficult to keep everything working across path refa
|`-X` |`EXTRA_OPTS` |Extra options that did not fit into `A-z`! |`-X` |`EXTRA_OPTS` |Extra options that did not fit into `A-z`!
This string is parsed by `getopt` on a separate parse step with different This string is parsed by `getopt` on a separate parse step with different
meanings for each flag. meanings for each flag.
|`-X-b` | |Use `fs_bigLITTLE.py` instead of `fs.py` on gem5 simulation.
Ignored by QEMU.
|`-x` | |Run in graphic mode. Mnemonic: X11. |`-x` | |Run in graphic mode. Mnemonic: X11.
|=== |===

82
build
View File

@@ -18,75 +18,101 @@ kernel_config_fragments=
post_script_args= post_script_args=
qemu_sdl='--enable-sdl --with-sdlabi=2.0' qemu_sdl='--enable-sdl --with-sdlabi=2.0'
v=0 v=0
while getopts "B:b:C:c:fGj:hIiK:klp:qSs:v${common_getopts_flags}" OPT; do parsed=$(getopt \
case "$OPT" in -o "B:b:C:c:fGj:hIiK:klp:qSs:v${common_getopt_flags}" \
B) -l "\
echo "$OPTARG" >> "$br2_cli_file" br-config,\
br-config-fragment,\
help,\
kernel-config,\
kernel-config-fragment,\
${common_getopt_flags_long}\
" \
-- "$@")
eval set -- "$parsed"
while true; do
case "$1" in
-B|--br-config)
echo "$2" >> "$br2_cli_file"
shift 2
;; ;;
b) -b|--br-config-fragment)
config_fragments="${config_fragments} $(common_abspath "${OPTARG}")" config_fragments="${config_fragments} $(common_abspath "$2")"
shift 2
;; ;;
C) -C|--kernel-config)
echo "$OPTARG" >> "$kernel_config_fragment_cli_file_tmp" echo "$2" >> "$kernel_config_fragment_cli_file_tmp"
shift 2
;; ;;
c) -c|--kernel-config-fragment)
kernel_config_fragments="${kernel_config_fragments} $(common_abspath "${OPTARG}")" kernel_config_fragments="${kernel_config_fragments} $(common_abspath "$2")"
shift 2
;; ;;
f) -f)
configure=false configure=false
shift
;; ;;
h) -h)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#build" 2>&1 echo "https://github.com/cirosantilli/linux-kernel-module-cheat#build" 2>&1
exit exit
;; ;;
I) -I)
echo " echo "
BR2_TARGET_ROOTFS_CPIO=n BR2_TARGET_ROOTFS_CPIO=n
BR2_TARGET_ROOTFS_EXT2=n BR2_TARGET_ROOTFS_EXT2=n
BR2_TARGET_ROOTFS_INITRAMFS=y BR2_TARGET_ROOTFS_INITRAMFS=y
" >> "$br2_cli_file" " >> "$br2_cli_file"
shift
;; ;;
i) -i)
echo " echo "
BR2_TARGET_ROOTFS_CPIO=y BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_EXT2=n BR2_TARGET_ROOTFS_EXT2=n
BR2_TARGET_ROOTFS_INITRAMFS=n BR2_TARGET_ROOTFS_INITRAMFS=n
" >> "$br2_cli_file" " >> "$br2_cli_file"
shift
;; ;;
j) -j)
j="$OPTARG" j="$2"
shift 2
;; ;;
K) -K)
linux_kernel_custom_config_file="$(common_abspath "${OPTARG}")" linux_kernel_custom_config_file="$(common_abspath "$2")"
shift 2
;; ;;
k) -k)
extra_make_args="${extra_make_args} kernel_module-reconfigure \\ extra_make_args="${extra_make_args} kernel_module-reconfigure \\
" "
shift
;; ;;
l) -l)
linux_reconfigure=true linux_reconfigure=true
extra_make_args="${extra_make_args} linux-reconfigure \\ extra_make_args="${extra_make_args} linux-reconfigure \\
" "
shift
;; ;;
p) -p)
post_script_args="$OPTARG" post_script_args="$2"
shift 2
;; ;;
q) -q)
extra_make_args="${extra_make_args} host-qemu-reconfigure \\ extra_make_args="${extra_make_args} host-qemu-reconfigure \\
" "
shift
;; ;;
S) -S)
qemu_sdl= qemu_sdl=
shift
;; ;;
v) -v)
v=1 v=1
shift
;; ;;
?) *)
common_getopts_case "$OPT" common_getopt_case "$@"
;; ;;
esac esac
done done
shift $(($OPTIND - 1))
if "$common_gem5"; then if "$common_gem5"; then
extra_make_args="${extra_make_args} gem5-reconfigure \\ extra_make_args="${extra_make_args} gem5-reconfigure \\
" "

59
common
View File

@@ -26,41 +26,60 @@ common_bench_cmd() (
# Handle options common across multiple scripts. # Handle options common across multiple scripts.
common_getopts_case() { common_getopt_case() {
case "$1" in case "$1" in
a) -a|--arch)
common_arch="$OPTARG" common_arch="$2"
shift 2
;; ;;
g) -g|--gem5)
common_gem5=true common_gem5=true
shift
;; ;;
L) -L|--linux-variant)
common_linux_variant="$OPTARG" common_linux_variant="$2"
shift 2
;; ;;
M) -M|--gem5-variant)
common_gem5_variant="$OPTARG" common_gem5_variant="$2"
shift 2
;; ;;
N) -N|--gem5-worktree)
common_gem5_worktree="$OPTARG" common_gem5_worktree="$2"
shift 2
;; ;;
n) -n|--run-id)
common_run_id="$OPTARG" common_run_id="$2"
shift 2
;; ;;
Q) -Q|--qemu-variant)
common_qemu_variant="$OPTARG" common_qemu_variant="$2"
shift 2
;; ;;
s) -s|--suffix)
common_suffix="$OPTARG" common_suffix="$2"
shift 2
;; ;;
t) -t|--gem5-build-type)
common_gem5_build_type="$OPTARG" common_gem5_build_type="$2"
shift 2
;; ;;
?) *)
exit 2 exit 2
;; ;;
esac esac
} }
common_getopts_flags='a:gL:M:N:n:Q:s:t:' common_getopt_flags='a:gL:M:N:n:Q:s:t:'
common_getopt_flags_long="\
arch:,\
gem5,\
linux-variant:,\
gem5-variant:,\
gem5-worktree:,\:
qemu-variant:,\
suffix:,\
gem5-build-type:'
"
# Setup several variables and do other initialization common to most scripts. # Setup several variables and do other initialization common to most scripts.
# Typically done after getting inputs from the command line arguments. # Typically done after getting inputs from the command line arguments.

View File

@@ -2,17 +2,20 @@
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true common_gem5=true
generate_checkpoints=true generate_checkpoints=true
while getopts "C${common_getopts_flags}" OPT; do
case "$OPT" in parsed=$(getopt -o "C${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
C) eval set -- "$parsed"
while true; do
case "$1" in
-C)
generate_checkpoints=false generate_checkpoints=false
shift
;; ;;
?) *)
common_getopts_case "$OPT" common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
common_setup common_setup
# Vars # Vars

View File

@@ -1,13 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true common_gem5=true
while getopts "${common_getopts_flags}" OPT; do parsed=$(getopt -o "${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
?) while true; do
common_getopts_case "$OPT" case "$1" in
*)
common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
common_setup common_setup
"${common_gem5_m5term}" localhost "$common_gem5_telnet_port" "${common_gem5_m5term}" localhost "$common_gem5_telnet_port"

View File

@@ -1,21 +1,22 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true common_gem5=true
while getopts "h${common_getopts_flags}" OPT; do parsed=$(getopt -o "h${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
h) while true; do
case "$1" in
-h)
printf "\ printf "\
usage: $0 [-a arch] [stat=system.cpu.numCycles] usage: $0 [-a arch] [stat=system.cpu.numCycles]
Get the value for a gem5 stat from the stats.txt file. Get the value for a gem5 stat from the stats.txt file.
" 1>&2 " 1>&2
exit exit
;; ;;
?) *)
common_getopts_case "$OPT" common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
stat="$1" stat="$1"
else else

13
getvar
View File

@@ -1,16 +1,17 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "h${common_getopts_flags}" OPT; do parsed=$(getopt -o "h${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
h) while true; do
case "$1" in
-h)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#getvar" 2>&1 echo "https://github.com/cirosantilli/linux-kernel-module-cheat#getvar" 2>&1
exit exit
;; ;;
?) *)
common_getopts_case "$OPT" common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
common_setup common_setup
eval "echo \$common_${1}" eval "echo \$common_${1}"

View File

@@ -1,9 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "${common_getopts_flags}" OPT; do parsed=$(getopt -o "${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
?) while true; do
common_getopts_case "$OPT" case "$1" in
*)
common_getopt_case "$@"
;; ;;
esac esac
done done

138
run
View File

@@ -15,7 +15,6 @@ extra_append='console_msg_format=syslog nokaslr norandmaps panic=-1 printk.devkm
extra_append_after_dash= extra_append_after_dash=
extra_flags= extra_flags=
extra_flags_qemu= extra_flags_qemu=
extra_opts=
gem5opts= gem5opts=
gem5_fsbiglittle=false gem5_fsbiglittle=false
gem5_restore_last_checkpoint= gem5_restore_last_checkpoint=
@@ -34,109 +33,136 @@ trace_enabled=false
# just to prevent QEMU from emitting a warning that '' is not valid. # just to prevent QEMU from emitting a warning that '' is not valid.
trace_type=pr_manager_run trace_type=pr_manager_run
vnc= vnc=
while getopts "c:DdE:e:F:f:G:hIiKkl:m:PRrT:U:uVX:x${common_getopts_flags}" OPT; do
case "$OPT" in parsed=$(getopt \
c) -o "c:DdE:e:F:f:G:hIiKkl:m:PRrT:U:uVx${common_getopt_flags}" \
cpus="$OPTARG" -l "\
append,\
cpus:,\
debug,\
debug-vm,\
eval:,\
help:,\
gem5-biglittle,\
${common_getopt_flags_long}\
" \
-- "$@")
eval set -- "$parsed"
while true; do
case "$1" in
-c|--cpus)
cpus="$2"
shift 2
;; ;;
D) -D|--debug-vm)
debug_vm="gdb -q -ex start --args \\ debug_vm="gdb -q -ex start --args \\
" "
shift
;; ;;
d) -d|--debug)
debug=true debug=true
extra_flags_qemu="${extra_flags_qemu} -S \\ extra_flags_qemu="${extra_flags_qemu} -S \\
" "
shift
;; ;;
E) -E|--eval)
lkmc_eval="$OPTARG" lkmc_eval="$2"
shift 2
;; ;;
e) -e|--append)
extra_append="${extra_append} ${OPTARG}" extra_append="${extra_append} ${2}"
shift 2
;; ;;
F) -F)
extra_append_after_dash="${extra_append_after_dash} lkmc_eval_base64=\"$(printf "${OPTARG}" | base64)\"" extra_append_after_dash="${extra_append_after_dash} lkmc_eval_base64=\"$(printf "${2}" | base64)\""
;; shift 2
f)
extra_append_after_dash="${extra_append_after_dash} ${OPTARG}"
;; ;;
G) -f)
gem5opts="$OPTARG \\ extra_append_after_dash="${extra_append_after_dash} ${2}"
shift 2
;;
-G)
gem5opts="$2 \\
" "
shift 2
;; ;;
h) --gem5-biglittle)
gem5_fsbiglittle=true
;;
-h|--help)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#run" 2>&1 echo "https://github.com/cirosantilli/linux-kernel-module-cheat#run" 2>&1
exit exit
;; ;;
I) -I)
initramfs=true initramfs=true
shift
;; ;;
i) -i)
initrd=true initrd=true
shift
;; ;;
K) -K)
kvm=true kvm=true
shift
;; ;;
k) -k)
extra_append="$extra_append kgdbwait" extra_append="$extra_append kgdbwait"
# For those who want to try KDB. # For those who want to try KDB.
#extra_append="$extra_append kgdbwait kgdboc=kbd" #extra_append="$extra_append kgdbwait kgdboc=kbd"
kgdb=true kgdb=true
shift
;; ;;
l) -l)
gem5_restore_last_checkpoint="${OPTARG}" gem5_restore_last_checkpoint="${2}"
shift 2
;; ;;
m) -m)
memory="$OPTARG" memory="$2"
shift 2
;; ;;
P) -P)
prebuilt=true prebuilt=true
shift
;; ;;
R) -R)
rr=replay rr=replay
shift
;; ;;
r) -r)
rr=record rr=record
shift
;; ;;
T) -T)
trace_enabled=true trace_enabled=true
trace_type="$OPTARG" trace_type="$2"
shift 2
;; ;;
U) -U)
tmux_args="$OPTARG" tmux_args="$2"
shift 2
;; ;;
u) -u)
tmux=true tmux=true
shift
;; ;;
X) -x)
extra_opts="${extra_opts} ${OPTARG}"
;;
x)
nographic=false nographic=false
shift
;; ;;
V) -V)
vnc="-vnc :0 \\ vnc="-vnc :0 \\
" "
shift
;; ;;
?) --)
common_getopts_case "$OPT" shift
break
;;
*)
common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
OPTIND=1
if [ -n "$extra_opts" ]; then
while getopts b OPT $extra_opts; do
case "$OPT" in
b)
gem5_fsbiglittle=true
;;
?)
exit 2
;;
esac
done
fi
common_setup common_setup
if "$debug" && "$kvm"; then if "$debug" && "$kvm"; then
echo 'error: -d and -K are incompatible' 1>&2 echo 'error: -d and -K are incompatible' 1>&2

38
rungdb
View File

@@ -6,30 +6,44 @@ lx_symbols="-ex 'lx-symbols ../kernel_module-1.0/' \\
" "
kgdb=false kgdb=false
docontinue=true docontinue=true
while getopts "A:a:b:CgkL:n:X${common_getopts_flags}" OPT; do parsed=$(getopt \
case "$OPT" in -o "A:a:b:CgkL:n:X${common_getopt_flags}" \
A) -l "\
after="$OPTARG" after:,
before:,
kgdb:,
${common_getopt_flags_long}\
" \
-- "$@")
eval set -- "$parsed"
while true; do
case "$1" in
-A|--after)
after="$2"
shift 2
;; ;;
b) -b|--before)
before="$OPTARG" before="$2"
shift 2
;; ;;
C) -C)
# No Continue. # No Continue.
docontinue=false docontinue=false
shift
;; ;;
k) -k|--kgdb)
kgdb=true kgdb=true
shift
;; ;;
X) -X)
lx_symbols= lx_symbols=
shift
;; ;;
?) *)
common_getopts_case "$OPT" common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
if [ "$#" -gt 0 ]; then if [ "$#" -gt 0 ]; then
brk="-ex 'break ${1}' \\ brk="-ex 'break ${1}' \\
" "

View File

@@ -1,18 +1,19 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
gem5_opt= gem5_opt=
while getopts "h${common_getopts_flags}" OPT; do parsed=$(getopt -o "h${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
while true; do
case "$1" in
h) h)
echo "$0 <exec-relative-path> [<brk-symbol>]" echo "$0 <exec-relative-path> [<brk-symbol>]" 2>&1
exit exit
;; ;;
?) *)
common_getopts_case "$OPT" common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
executable_rel="$1" executable_rel="$1"
shift shift
if [ "$#" -gt 0 ]; then if [ "$#" -gt 0 ]; then

View File

@@ -1,13 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "${common_getopts_flags}" OPT; do parsed=$(getopt -o "${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
?) while true; do
common_getopts_case "$OPT" case "$1" in
*)
common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
executable="$1" executable="$1"
common_setup common_setup
"${common_host_dir}/usr/bin/${common_arch}-linux-gdb" \ "${common_host_dir}/usr/bin/${common_arch}-linux-gdb" \

11
runtc
View File

@@ -1,17 +1,18 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "h${common_getopts_flags}" OPT; do parsed=$(getopt -o "h${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
while true; do
case "$1" in
h) h)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#runtc" 2>&1 echo "https://github.com/cirosantilli/linux-kernel-module-cheat#runtc" 2>&1
exit exit
;; ;;
?) *)
common_getopts_case "$OPT" common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
tool="$1" tool="$1"
shift shift
common_setup common_setup

View File

@@ -1,13 +1,14 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "${common_getopts_flags}" OPT; do parsed=$(getopt -o "${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
?) while true; do
common_getopts_case "$OPT" case "$1" in
*)
common_getopt_case "$@"
;; ;;
esac esac
done done
shift "$(($OPTIND - 1))"
common_setup common_setup
if "$common_gem5"; then if "$common_gem5"; then
time ./run -a "$common_arch" -E 'm5 exit' -g -T 'Exec,-ExecSymbol,-ExecMicro' "$@" time ./run -a "$common_arch" -E 'm5 exit' -g -T 'Exec,-ExecSymbol,-ExecMicro' "$@"

View File

@@ -1,9 +1,11 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "${common_getopts_flags}" OPT; do parsed=$(getopt -o "${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
case "$OPT" in eval set -- "$parsed"
?) while true; do
common_getopts_case "$OPT" case "$1" in
*)
common_getopt_case "$@"
;; ;;
esac esac
done done