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= 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 '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 case "$OPT" in
a)
common_arch="$OPTARG"
;;
B) B)
echo "$OPTARG" >> "$br2_cli_file" 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) f)
configure=false configure=false
;; ;;
g)
extra_make_args="${extra_make_args} gem5-reconfigure \\
"
common_gem5=true
;;
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
@@ -71,23 +63,14 @@ BR2_TARGET_ROOTFS_INITRAMFS=n
extra_make_args="${extra_make_args} kernel_module-reconfigure \\ extra_make_args="${extra_make_args} kernel_module-reconfigure \\
" "
;; ;;
L)
common_linux_variant="$OPTARG"
;;
l) l)
linux_reconfigure=true linux_reconfigure=true
extra_make_args="${extra_make_args} linux-reconfigure \\ extra_make_args="${extra_make_args} linux-reconfigure \\
" "
;; ;;
M)
common_gem5_variant="$OPTARG"
;;
p) p)
post_script_args="$OPTARG" post_script_args="$OPTARG"
;; ;;
Q)
common_qemu_variant="$OPTARG"
;;
q) q)
extra_make_args="${extra_make_args} host-qemu-reconfigure \\ extra_make_args="${extra_make_args} host-qemu-reconfigure \\
" "
@@ -95,21 +78,19 @@ BR2_TARGET_ROOTFS_INITRAMFS=n
S) S)
qemu_sdl= qemu_sdl=
;; ;;
s)
common_suffix="$OPTARG"
;;
t)
common_gem5_build_type="$OPTARG"
;;
v) v)
v=1 v=1
;; ;;
?) ?)
exit 2 common_getopts_case "$OPT"
;; ;;
esac esac
done done
shift $(($OPTIND - 1)) shift $(($OPTIND - 1))
if "$common_gem5"; then
extra_make_args="${extra_make_args} gem5-reconfigure \\
"
fi
extra_make_args="${extra_make_args} $@" extra_make_args="${extra_make_args} $@"
common_setup common_setup
config_file="${common_buildroot_out_dir}/.config" config_file="${common_buildroot_out_dir}/.config"

38
common
View File

@@ -24,6 +24,44 @@ common_bench_cmd() (
printf "exit_status $?\n" >> "$results_file" 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. # 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.
common_setup() { common_setup() {

View File

@@ -2,20 +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 a:C OPT; do while getopts "C${common_getopts_flags}" OPT; do
case "$OPT" in case "$OPT" in
a)
common_arch="$OPTARG"
;;
C) C)
generate_checkpoints=false generate_checkpoints=false
;; ;;
?)
common_getopts_case "$OPT"
;;
esac esac
done done
shift "$(($OPTIND - 1))" shift "$(($OPTIND - 1))"
common_setup
# Vars # Vars
common_setup
cmd="./run -a ${common_arch} -g" cmd="./run -a ${common_arch} -g"
cache_small='--caches --l2cache --l1d_size=1024 --l1i_size=1024 --l2_size=1024 --l3_size=1024 ' 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' 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 #!/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 M:n: OPT; do while getopts "${common_getopts_flags}" OPT; do
case "$OPT" in case "$OPT" in
M)
common_gem5_variant="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
?) ?)
exit 2 common_getopts_case "$OPT"
;; ;;
esac esac
done done

View File

@@ -1,11 +1,8 @@
#!/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 a:hs: OPT; do while getopts "h${common_getopts_flags}" OPT; do
case "$OPT" in case "$OPT" in
a)
common_arch="$OPTARG"
;;
h) h)
printf "\ printf "\
usage: $0 [-a arch] [stat=system.cpu.numCycles] 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 " 1>&2
exit exit
;; ;;
?)
common_getopts_case "$OPT"
;;
esac esac
done done
shift "$(($OPTIND - 1))" shift "$(($OPTIND - 1))"

28
getvar
View File

@@ -1,37 +1,13 @@
#!/usr/bin/env bash #!/usr/bin/env bash
. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/common" . "$(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 case "$OPT" in
h) 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
;; ;;
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 esac
done done

View File

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

28
run
View File

@@ -34,11 +34,8 @@ 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 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 case "$OPT" in
a)
common_arch="$OPTARG"
;;
c) c)
cpus="$OPTARG" 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 \\ gem5opts="$OPTARG \\
" "
;; ;;
g)
common_gem5=true
;;
h) h)
cat build-usage.adoc 1>&2 cat build-usage.adoc 1>&2
exit 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" #extra_append="$extra_append kgdbwait kgdboc=kbd"
kgdb=true kgdb=true
;; ;;
L)
common_linux_variant="$OPTARG"
;;
l) l)
gem5_restore_last_checkpoint="${OPTARG}" gem5_restore_last_checkpoint="${OPTARG}"
;; ;;
M)
common_gem5_variant="$OPTARG"
;;
m) m)
memory="$OPTARG" memory="$OPTARG"
;; ;;
N)
common_gem5_worktree="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
P) P)
prebuilt=true prebuilt=true
;; ;;
Q)
common_qemu_variant="$OPTARG"
;;
R) R)
rr=replay 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_enabled=true
trace_type="$OPTARG" trace_type="$OPTARG"
;; ;;
t)
common_gem5_build_type="$OPTARG"
;;
U) U)
tmux_args="$OPTARG" 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 esac
done done

16
rungdb
View File

@@ -6,14 +6,11 @@ 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 OPT; do while getopts "A:a:b:CgkL:n:X${common_getopts_flags}" OPT; do
case "$OPT" in case "$OPT" in
A) A)
after="$OPTARG" after="$OPTARG"
;; ;;
a)
common_arch="$OPTARG"
;;
b) b)
before="$OPTARG" before="$OPTARG"
;; ;;
@@ -21,23 +18,14 @@ while getopts A:a:b:CgkL:n:X OPT; do
# No Continue. # No Continue.
docontinue=false docontinue=false
;; ;;
g)
common_gem5=true
;;
k) k)
kgdb=true kgdb=true
;; ;;
L)
common_linux_variant="$OPTARG"
;;
n)
common_run_id="$OPTARG"
;;
X) X)
lx_symbols= lx_symbols=
;; ;;
?) ?)
exit 2 common_getopts_case "$OPT"
;; ;;
esac esac
done done

View File

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

View File

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

8
runtc
View File

@@ -1,14 +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 a:gh OPT; do while getopts "h${common_getopts_flags}" OPT; do
case "$OPT" in case "$OPT" in
a)
common_arch="$OPTARG"
;;
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"
;;
esac esac
done done
shift "$(($OPTIND - 1))" shift "$(($OPTIND - 1))"

View File

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

View File

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