common: factor out common opts to all scripts

This commit is contained in:
Ciro Santilli
2018-08-14 00:27:55 +01:00
parent 0f5c5a9912
commit 63ec42f72f
14 changed files with 84 additions and 145 deletions

31
build
View File

@@ -18,11 +18,8 @@ kernel_config_fragments=
post_script_args=
qemu_sdl='--enable-sdl --with-sdlabi=2.0'
v=0
while getopts 'a:B:b:C:c:fGgj:hIiK:kL:lM:p:Q:qSs:t:v' OPT; do
while getopts "B:b:C:c:fGj:hIiK:klp:qSs:v${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
B)
echo "$OPTARG" >> "$br2_cli_file"
;;
@@ -38,11 +35,6 @@ while getopts 'a:B:b:C:c:fGgj:hIiK:kL:lM:p:Q:qSs:t:v' OPT; do
f)
configure=false
;;
g)
extra_make_args="${extra_make_args} gem5-reconfigure \\
"
common_gem5=true
;;
h)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#build" 2>&1
exit
@@ -71,23 +63,14 @@ BR2_TARGET_ROOTFS_INITRAMFS=n
extra_make_args="${extra_make_args} kernel_module-reconfigure \\
"
;;
L)
common_linux_variant="$OPTARG"
;;
l)
linux_reconfigure=true
extra_make_args="${extra_make_args} linux-reconfigure \\
"
;;
M)
common_gem5_variant="$OPTARG"
;;
p)
post_script_args="$OPTARG"
;;
Q)
common_qemu_variant="$OPTARG"
;;
q)
extra_make_args="${extra_make_args} host-qemu-reconfigure \\
"
@@ -95,21 +78,19 @@ BR2_TARGET_ROOTFS_INITRAMFS=n
S)
qemu_sdl=
;;
s)
common_suffix="$OPTARG"
;;
t)
common_gem5_build_type="$OPTARG"
;;
v)
v=1
;;
?)
exit 2
common_getopts_case "$OPT"
;;
esac
done
shift $(($OPTIND - 1))
if "$common_gem5"; then
extra_make_args="${extra_make_args} gem5-reconfigure \\
"
fi
extra_make_args="${extra_make_args} $@"
common_setup
config_file="${common_buildroot_out_dir}/.config"

38
common
View File

@@ -24,6 +24,44 @@ common_bench_cmd() (
printf "exit_status $?\n" >> "$results_file"
)
# Handle options common across multiple scripts.
common_getopts_case() {
case "$1" in
a)
common_arch="$OPTARG"
;;
g)
common_gem5=true
;;
L)
common_linux_variant="$OPTARG"
;;
M)
common_gem5_variant="$OPTARG"
;;
N)
common_gem5_worktree="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
Q)
common_qemu_variant="$OPTARG"
;;
s)
common_suffix="$OPTARG"
;;
t)
common_gem5_build_type="$OPTARG"
;;
?)
exit 2
;;
esac
}
common_getopts_flags='a:gL:M:N:n:Q:s:t:'
# Setup several variables and do other initialization common to most scripts.
# Typically done after getting inputs from the command line arguments.
common_setup() {

View File

@@ -2,20 +2,20 @@
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true
generate_checkpoints=true
while getopts a:C OPT; do
while getopts "C${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
C)
generate_checkpoints=false
;;
?)
common_getopts_case "$OPT"
;;
esac
done
shift "$(($OPTIND - 1))"
common_setup
# Vars
common_setup
cmd="./run -a ${common_arch} -g"
cache_small='--caches --l2cache --l1d_size=1024 --l1i_size=1024 --l2_size=1024 --l3_size=1024 '
cache_large='--caches --l2cache --l1d_size=1024kB --l1i_size=1024kB --l2_size=1024kB --l3_size=1024kB'

View File

@@ -1,16 +1,10 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true
while getopts M:n: OPT; do
while getopts "${common_getopts_flags}" OPT; do
case "$OPT" in
M)
common_gem5_variant="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
?)
exit 2
common_getopts_case "$OPT"
;;
esac
done

View File

@@ -1,11 +1,8 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
common_gem5=true
while getopts a:hs: OPT; do
while getopts "h${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
h)
printf "\
usage: $0 [-a arch] [stat=system.cpu.numCycles]
@@ -13,6 +10,9 @@ Get the value for a gem5 stat from the stats.txt file.
" 1>&2
exit
;;
?)
common_getopts_case "$OPT"
;;
esac
done
shift "$(($OPTIND - 1))"

28
getvar
View File

@@ -1,37 +1,13 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts ha:gL:M:N:n:Q:t: OPT; do
while getopts "h${common_getopts_flags}" OPT; do
case "$OPT" in
h)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#getvar" 2>&1
exit
;;
a)
common_arch="$OPTARG"
;;
g)
common_gem5=true
;;
L)
common_linux_variant="$OPTARG"
;;
M)
common_gem5_variant="$OPTARG"
;;
N)
common_gem5_worktree="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
Q)
common_qemu_variant="$OPTARG"
;;
t)
common_gem5_build_type="$OPTARG"
;;
?)
exit 2
common_getopts_case "$OPT"
;;
esac
done

View File

@@ -1,9 +1,9 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts a: OPT; do
while getopts "${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
?)
common_getopts_case "$OPT"
;;
esac
done

28
run
View File

@@ -34,11 +34,8 @@ trace_enabled=false
# just to prevent QEMU from emitting a warning that '' is not valid.
trace_type=pr_manager_run
vnc=
while getopts a:c:DdE:e:F:f:G:ghIiKkL:l:M:m:N:n:PQ:RrT:t:U:uVX:x OPT; do
while getopts "c:DdE:e:F:f:G:hIiKkl:m:PRrT:U:uVX:x${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
c)
cpus="$OPTARG"
;;
@@ -67,9 +64,6 @@ while getopts a:c:DdE:e:F:f:G:ghIiKkL:l:M:m:N:n:PQ:RrT:t:U:uVX:x OPT; do
gem5opts="$OPTARG \\
"
;;
g)
common_gem5=true
;;
h)
cat build-usage.adoc 1>&2
exit
@@ -93,30 +87,15 @@ while getopts a:c:DdE:e:F:f:G:ghIiKkL:l:M:m:N:n:PQ:RrT:t:U:uVX:x OPT; do
#extra_append="$extra_append kgdbwait kgdboc=kbd"
kgdb=true
;;
L)
common_linux_variant="$OPTARG"
;;
l)
gem5_restore_last_checkpoint="${OPTARG}"
;;
M)
common_gem5_variant="$OPTARG"
;;
m)
memory="$OPTARG"
;;
N)
common_gem5_worktree="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
P)
prebuilt=true
;;
Q)
common_qemu_variant="$OPTARG"
;;
R)
rr=replay
;;
@@ -127,9 +106,6 @@ while getopts a:c:DdE:e:F:f:G:ghIiKkL:l:M:m:N:n:PQ:RrT:t:U:uVX:x OPT; do
trace_enabled=true
trace_type="$OPTARG"
;;
t)
common_gem5_build_type="$OPTARG"
;;
U)
tmux_args="$OPTARG"
;;
@@ -147,7 +123,7 @@ while getopts a:c:DdE:e:F:f:G:ghIiKkL:l:M:m:N:n:PQ:RrT:t:U:uVX:x OPT; do
"
;;
?)
exit 2
common_getopts_case "$OPT"
;;
esac
done

16
rungdb
View File

@@ -6,14 +6,11 @@ lx_symbols="-ex 'lx-symbols ../kernel_module-1.0/' \\
"
kgdb=false
docontinue=true
while getopts A:a:b:CgkL:n:X OPT; do
while getopts "A:a:b:CgkL:n:X${common_getopts_flags}" OPT; do
case "$OPT" in
A)
after="$OPTARG"
;;
a)
common_arch="$OPTARG"
;;
b)
before="$OPTARG"
;;
@@ -21,23 +18,14 @@ while getopts A:a:b:CgkL:n:X OPT; do
# No Continue.
docontinue=false
;;
g)
common_gem5=true
;;
k)
kgdb=true
;;
L)
common_linux_variant="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
X)
lx_symbols=
;;
?)
exit 2
common_getopts_case "$OPT"
;;
esac
done

View File

@@ -1,22 +1,14 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
usage="$0 <exec-relative-path> [<brk-symbol>]"
gem5_opt=
while getopts a:gh OPT; do
while getopts "h${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
g)
common_gem5=true
gem5_opt=-g
;;
h)
echo "$usage"
exit 0
echo "$0 <exec-relative-path> [<brk-symbol>]"
exit
;;
?)
exit 2
common_getopts_case "$OPT"
;;
esac
done
@@ -30,6 +22,9 @@ else
brk=
fi
common_setup
if "$common_gem5"; then
gem5_opt=-g
fi
executable="${common_build_dir}/${executable_rel}"
addr="$("${common_root_dir}/runtc" readelf -h "$executable" | awk '/Entry/{ print $NF }' )"
ex="-ex \"add-symbol-file $executable $addr\""

View File

@@ -1,12 +1,9 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts a:g OPT; do
while getopts "${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
g)
common_gem5=true
?)
common_getopts_case "$OPT"
;;
esac
done

8
runtc
View File

@@ -1,14 +1,14 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts a:gh OPT; do
while getopts "h${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
h)
echo "https://github.com/cirosantilli/linux-kernel-module-cheat#runtc" 2>&1
exit
;;
?)
common_getopts_case "$OPT"
;;
esac
done
shift "$(($OPTIND - 1))"

View File

@@ -1,12 +1,9 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts a:g OPT; do
while getopts "${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
g)
common_gem5=true
?)
common_getopts_case "$OPT"
;;
esac
done

View File

@@ -1,12 +1,9 @@
#!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common"
while getopts a:g OPT; do
while getopts "${common_getopts_flags}" OPT; do
case "$OPT" in
a)
common_arch="$OPTARG"
;;
g)
common_gem5=true
?)
common_getopts_case "$OPT"
;;
esac
done