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:
....
./run -a A -g -X-b
./run -a A -g --gem5-biglittle
....
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`!
This string is parsed by `getopt` on a separate parse step with different
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.
|===

82
build
View File

@@ -18,75 +18,101 @@ kernel_config_fragments=
post_script_args=
qemu_sdl='--enable-sdl --with-sdlabi=2.0'
v=0
while getopts "B:b:C:c:fGj:hIiK:klp:qSs:v${common_getopts_flags}" OPT; do
case "$OPT" in
B)
echo "$OPTARG" >> "$br2_cli_file"
parsed=$(getopt \
-o "B:b:C:c:fGj:hIiK:klp:qSs:v${common_getopt_flags}" \
-l "\
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)
config_fragments="${config_fragments} $(common_abspath "${OPTARG}")"
-b|--br-config-fragment)
config_fragments="${config_fragments} $(common_abspath "$2")"
shift 2
;;
C)
echo "$OPTARG" >> "$kernel_config_fragment_cli_file_tmp"
-C|--kernel-config)
echo "$2" >> "$kernel_config_fragment_cli_file_tmp"
shift 2
;;
c)
kernel_config_fragments="${kernel_config_fragments} $(common_abspath "${OPTARG}")"
-c|--kernel-config-fragment)
kernel_config_fragments="${kernel_config_fragments} $(common_abspath "$2")"
shift 2
;;
f)
-f)
configure=false
shift
;;
h)
-h)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#build" 2>&1
exit
;;
I)
-I)
echo "
BR2_TARGET_ROOTFS_CPIO=n
BR2_TARGET_ROOTFS_EXT2=n
BR2_TARGET_ROOTFS_INITRAMFS=y
" >> "$br2_cli_file"
shift
;;
i)
-i)
echo "
BR2_TARGET_ROOTFS_CPIO=y
BR2_TARGET_ROOTFS_EXT2=n
BR2_TARGET_ROOTFS_INITRAMFS=n
" >> "$br2_cli_file"
shift
;;
j)
j="$OPTARG"
-j)
j="$2"
shift 2
;;
K)
linux_kernel_custom_config_file="$(common_abspath "${OPTARG}")"
-K)
linux_kernel_custom_config_file="$(common_abspath "$2")"
shift 2
;;
k)
-k)
extra_make_args="${extra_make_args} kernel_module-reconfigure \\
"
shift
;;
l)
-l)
linux_reconfigure=true
extra_make_args="${extra_make_args} linux-reconfigure \\
"
shift
;;
p)
post_script_args="$OPTARG"
-p)
post_script_args="$2"
shift 2
;;
q)
-q)
extra_make_args="${extra_make_args} host-qemu-reconfigure \\
"
shift
;;
S)
-S)
qemu_sdl=
shift
;;
v)
-v)
v=1
shift
;;
?)
common_getopts_case "$OPT"
*)
common_getopt_case "$@"
;;
esac
done
shift $(($OPTIND - 1))
if "$common_gem5"; then
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.
common_getopts_case() {
common_getopt_case() {
case "$1" in
a)
common_arch="$OPTARG"
-a|--arch)
common_arch="$2"
shift 2
;;
g)
-g|--gem5)
common_gem5=true
shift
;;
L)
common_linux_variant="$OPTARG"
-L|--linux-variant)
common_linux_variant="$2"
shift 2
;;
M)
common_gem5_variant="$OPTARG"
-M|--gem5-variant)
common_gem5_variant="$2"
shift 2
;;
N)
common_gem5_worktree="$OPTARG"
-N|--gem5-worktree)
common_gem5_worktree="$2"
shift 2
;;
n)
common_run_id="$OPTARG"
-n|--run-id)
common_run_id="$2"
shift 2
;;
Q)
common_qemu_variant="$OPTARG"
-Q|--qemu-variant)
common_qemu_variant="$2"
shift 2
;;
s)
common_suffix="$OPTARG"
-s|--suffix)
common_suffix="$2"
shift 2
;;
t)
common_gem5_build_type="$OPTARG"
-t|--gem5-build-type)
common_gem5_build_type="$2"
shift 2
;;
?)
*)
exit 2
;;
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.
# Typically done after getting inputs from the command line arguments.

View File

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

View File

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

View File

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

13
getvar
View File

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

View File

@@ -1,9 +1,11 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts "${common_getopts_flags}" OPT; do
case "$OPT" in
?)
common_getopts_case "$OPT"
parsed=$(getopt -o "${common_getopt_flags}" -l "$common_getopt_flags_long" -- "$@")
eval set -- "$parsed"
while true; do
case "$1" in
*)
common_getopt_case "$@"
;;
esac
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_flags=
extra_flags_qemu=
extra_opts=
gem5opts=
gem5_fsbiglittle=false
gem5_restore_last_checkpoint=
@@ -34,109 +33,136 @@ trace_enabled=false
# just to prevent QEMU from emitting a warning that '' is not valid.
trace_type=pr_manager_run
vnc=
while getopts "c:DdE:e:F:f:G:hIiKkl:m:PRrT:U:uVX:x${common_getopts_flags}" OPT; do
case "$OPT" in
c)
cpus="$OPTARG"
parsed=$(getopt \
-o "c:DdE:e:F:f:G:hIiKkl:m:PRrT:U:uVx${common_getopt_flags}" \
-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 \\
"
shift
;;
d)
-d|--debug)
debug=true
extra_flags_qemu="${extra_flags_qemu} -S \\
"
shift
;;
E)
lkmc_eval="$OPTARG"
-E|--eval)
lkmc_eval="$2"
shift 2
;;
e)
extra_append="${extra_append} ${OPTARG}"
-e|--append)
extra_append="${extra_append} ${2}"
shift 2
;;
F)
extra_append_after_dash="${extra_append_after_dash} lkmc_eval_base64=\"$(printf "${OPTARG}" | base64)\""
;;
f)
extra_append_after_dash="${extra_append_after_dash} ${OPTARG}"
-F)
extra_append_after_dash="${extra_append_after_dash} lkmc_eval_base64=\"$(printf "${2}" | base64)\""
shift 2
;;
G)
gem5opts="$OPTARG \\
-f)
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
exit
;;
I)
-I)
initramfs=true
shift
;;
i)
-i)
initrd=true
shift
;;
K)
-K)
kvm=true
shift
;;
k)
-k)
extra_append="$extra_append kgdbwait"
# For those who want to try KDB.
#extra_append="$extra_append kgdbwait kgdboc=kbd"
kgdb=true
shift
;;
l)
gem5_restore_last_checkpoint="${OPTARG}"
-l)
gem5_restore_last_checkpoint="${2}"
shift 2
;;
m)
memory="$OPTARG"
-m)
memory="$2"
shift 2
;;
P)
-P)
prebuilt=true
shift
;;
R)
-R)
rr=replay
shift
;;
r)
-r)
rr=record
shift
;;
T)
-T)
trace_enabled=true
trace_type="$OPTARG"
trace_type="$2"
shift 2
;;
U)
tmux_args="$OPTARG"
-U)
tmux_args="$2"
shift 2
;;
u)
-u)
tmux=true
shift
;;
X)
extra_opts="${extra_opts} ${OPTARG}"
;;
x)
-x)
nographic=false
shift
;;
V)
-V)
vnc="-vnc :0 \\
"
shift
;;
?)
common_getopts_case "$OPT"
--)
shift
break
;;
*)
common_getopt_case "$@"
;;
esac
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
if "$debug" && "$kvm"; then
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
docontinue=true
while getopts "A:a:b:CgkL:n:X${common_getopts_flags}" OPT; do
case "$OPT" in
A)
after="$OPTARG"
parsed=$(getopt \
-o "A:a:b:CgkL:n:X${common_getopt_flags}" \
-l "\
after:,
before:,
kgdb:,
${common_getopt_flags_long}\
" \
-- "$@")
eval set -- "$parsed"
while true; do
case "$1" in
-A|--after)
after="$2"
shift 2
;;
b)
before="$OPTARG"
-b|--before)
before="$2"
shift 2
;;
C)
-C)
# No Continue.
docontinue=false
shift
;;
k)
-k|--kgdb)
kgdb=true
shift
;;
X)
-X)
lx_symbols=
shift
;;
?)
common_getopts_case "$OPT"
*)
common_getopt_case "$@"
;;
esac
done
shift "$(($OPTIND - 1))"
if [ "$#" -gt 0 ]; then
brk="-ex 'break ${1}' \\
"

View File

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

View File

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

11
runtc
View File

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

View File

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

View File

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