1
0
Fork 0

add function for task spawning

This commit is contained in:
Jan Christoph Uhde 2017-05-13 10:12:09 +02:00
parent b63c35db71
commit 933a8ed2e5
1 changed files with 71 additions and 54 deletions

View File

@ -1,22 +1,51 @@
#!/bin/bash #!/bin/bash
# Author Jan Christoph Uhde
# change into build dir main(){
#cd .. || die "can not change directory"
die(){ #TODO check that we are in source dir
echo "FATAL: ${1-this should not happen}" local session_name=integrationtest
exit 1 local tasks=task_all #FIXME add taks selection
local panes=$($tasks)
kill_old_session "$session_name"
tmux kill-session -t $session_name #kill session hard for testing
tmux new-session -d -s "$session_name" || die "unable to spawn session"
local rows=$(( (panes+1) / 2 ))
local cols=$((((panes>1)) * 2))
spawn_panes "$session_name" $rows $cols
tmux select-pane -t $session_name.0
execute_tasks "$(pwd)" $tasks
tmux -2 attach-session -t $session_name
} }
# task definitions
cores(){ task_all(){
# Determine automatically on Mac or Linux ## FIXME ask jan or max for good grouping for all
if [[ $(uname) == 'Darwin' ]]; then local count="$1"
echo "$(sysctl hw.ncpu | awk '{print $2}')" local args_default=""
else local args="$2"
echo "$(nproc)" if [[ -z $1 ]]; then
echo "4" #return number of required panes
return
fi fi
case $1 in
0)
echo "./scripts/unittest shell_server $args_default $args && exit 0"
;;
1)
echo "./scripts/unittest shell_server_aql $args_defaults $args && exit 0"
;;
2)
echo "./scripts/unittest shell_server $args_default $args && exit 0"
;;
*)
echo "spawn task $count"
;;
esac
} }
# tmux
kill_old_session(){ kill_old_session(){
local session_name="$1" local session_name="$1"
if tmux has-session -t $session_name 2> /dev/null; then if tmux has-session -t $session_name 2> /dev/null; then
@ -34,68 +63,56 @@ kill_old_session(){
spawn_panes(){ spawn_panes(){
local session_name="$1" local session_name="$1"
local rows=$2 local rows=$2
local cols=$3 local cols=$3
# Create rows # Create rows
local row=$rows local row=$rows
while (( row > 1 )); do while (( row > 1 )); do
frac=$(echo "scale=2;1/$row" | bc) frac=$(echo "scale=2;1/$row" | bc)
percent=$(echo "($frac * 100)/1" | bc) percent=$(echo "($frac * 100)/1" | bc)
echo "frac $frac percent $percent" tmux select-pane -t $session_name.0 || die "could not select pane 0 of session $session_name"
tmux select-pane -t $session_name.0
tmux split-window -v -p $percent tmux split-window -v -p $percent
((row--)) ((row--))
done done
# Create columns # Create columns
if ((cols > 1)); then if ((cols > 1)); then
local count=$((rows - 1)) local count=$((rows - 1))
# Floor function to round down if odd while ((count >= 0)); do
while ((count >= 0)); do tmux select-pane -t $session_name.$count || die "could not select pane $session_name.$count"
echo "count $count" tmux split-window -h -p 50
tmux select-pane -t $session_name.$count (( count-- ))
tmux split-window -h -p 50 done
(( count-- )) fi
done
fi
} }
execute_tasks(){ execute_tasks(){
cd $1 || die cd $1 || die
local tasks=$2 local tasks=$2
local args="$3"
local count=0 local count=0
while (( count < tasks )); do while (( count < $($tasks) )); do
local exec_cmd= local exec_cmd="$($tasks $count "$args")"
echo "task: $count"
case $count in
0)
local exec_cmd=( './scripts/unittest' 'shell_server' )
# we can not use the former as tmux's escaping is broken
local exec_cmd=( './scripts/unittest shell_server && exit 0' )
;;
*)
local exec_cmd=("echo 'spawn task $count'")
;;
esac
tmux send-keys -t $session_name.$count "${exec_cmd[@]}" Enter tmux send-keys -t $session_name.$count "${exec_cmd[@]}" Enter
(( count++ )) (( count++ ))
done done
} }
main(){ # helper
#cd .. || die "can not change directory" die(){
local session_name=integrationtest echo "FATAL: ${1-this should not happen}"
local tasks=5 exit 1
#kill_old_session "$session_name"
tmux kill-session -t $session_name
tmux new-session -d -s "$session_name" || die "unable to spawn session"
local rows=$(( (tasks+1) / 2 ))
local cols=$((((tasks>1)) * 2))
spawn_panes "$session_name" $rows $cols
tmux select-pane -t $session_name.0
echo "$(pwd)"
execute_tasks "$(pwd)" $tasks
tmux -2 attach-session -t $session_name
} }
cores(){
# Determine automatically on Mac or Linux
if [[ $(uname) == 'Darwin' ]]; then
echo "$(sysctl hw.ncpu | awk '{print $2}')"
else
echo "$(nproc)"
fi
}
main "$@" main "$@"
exit 0 exit 0