]> rtime.felk.cvut.cz Git - can-benchmark.git/blob - gw-tests/lib.sh
More appropriate graph titles
[can-benchmark.git] / gw-tests / lib.sh
1 set -e
2
3 COUNT=10000
4
5 OPT_TRAFFIC=oneatatime
6
7 error() {
8     echo $1 >&2
9     exit 1
10 }
11
12 while [ $# -gt 0 ]; do
13     case "$1" in
14         -P) OPT_PLOT_DISABLE=1; shift;;
15         -p) OPT_PLOT_ONLY=1; shift;;
16         -X|--no-x11-plot) OPT_NO_X11=1; shift;;
17         -t) case "$2" in
18                 all|floof|50|oneatatime) OPT_TRAFFIC=$2;;
19                 *) error "Unknown traffic specification: $2";;
20             esac;
21             shift 2;;
22     esac
23 done
24
25 PATH=$PWD/../_compiled/bin/:$PATH
26
27 sshgw() {
28     local socket="$HOME/.ssh/cangw-connection"
29
30     if [[ ! -S $socket ]]; then
31         # Create master connection to speed up subsequenct command.
32         # The ssh is put into background and the connection is closed
33         # after 10 minutes)
34         ssh -f -M -S $socket root@192.168.2.3 sleep 600 > /dev/null 2>&1
35     fi
36     ssh -x -a -S $socket root@192.168.2.3 "$@"
37 }
38
39 cleanupgw() {
40     sshgw 'cangw -F'
41 }
42
43 _plot() {
44     local testname=`basename $0 .sh`
45
46     plot_cmds | sed -e "/set title/ s/[\"']\(.*\)[\"']/\"\1\\\\n($kvers)\"/" > plot.gp
47     if [ -z "$OPT_NO_X11" ]; then
48         echo "set terminal x11 enhanced; $(< plot.gp)" | gnuplot -persist
49     fi
50     I=''
51     echo 'set terminal postscript color eps enhanced size 6cm,4cm lw 1 "Times-Roman" 10;' \
52         'set lmargin 8;' \
53         "$(< plot.gp)" | gnuplot > ${testname}$I.eps
54     echo "set terminal postscript color eps enhanced;" \
55         "$(< plot.gp)" | gnuplot | epstopdf --filter > ${testname}$I.pdf
56     mkdir -p thumb
57     convert -density 30  -gamma 0.5 -quality 90 -type Palette -depth 8 ${testname}$I.pdf thumb/${testname}$I.png
58     convert -density 150 -gamma 0.7 -quality 90 -type Palette -depth 8 ${testname}$I.pdf ${testname}$I.png
59
60 }
61
62 create_dirs() {
63     local kver=$1
64     local traffic=$2
65     local test=$3
66
67     local  d=results/$kver/$traffic/$test
68     mkdir -p $d
69     echo $d
70 }
71
72 echo_plot() {
73     plot=$1
74     [[ "$_plot_separator" ]] && echo ", \\"
75     _plot_separator=t
76     echo -n "    " $plot
77 }
78
79 traffic_and_length() {
80     local opts
81     case $OPT_TRAFFIC in
82         flood) opts='';;
83         50)        opts="-p $((2*(44+$1*8)))";;
84         oneatatime)        opts="-o";;
85         *) error "Unknown traffic specification"
86     esac
87     echo $opts -l $1
88 }
89
90 _run() {
91     if [[ ! "$OPT_PLOT_ONLY" ]]
92     then kernel_versions=$(sshgw uname -r)
93     else kernel_versions=$(ls results/by-kern)
94     fi
95     if [[ $OPT_TRAFFIC = all ]]
96     then traffics="flood 50 oneatatime"
97     else traffics=$OPT_TRAFFIC
98     fi
99     for OPT_TRAFFIC in $traffics; do
100     for kvers in $kernel_versions; do
101         dir=$(create_dirs $kvers $OPT_TRAFFIC $(basename $0 .sh))
102         script=$PWD/$0
103         cd $dir
104         echo "Working directory: $dir"
105         if [[ ! "$OPT_PLOT_ONLY" ]]; then
106             # Remove data from the last measurement
107             rm -rf *
108             # Set can interfaces up
109             sshgw 'for i in 0 1; do ip link show dev can$i|grep -q UP || ip link set can$i up type can bitrate 1000000; done'
110             # Delete all vcan interfaces
111             sshgw 'for dev in $(ip l|grep -o vcan[^:]\\+); do ip link del dev $dev; done'
112             # Reset priorities
113             sshgw 'chrt -p -f 50 `pidof irq/145-can0` > /dev/null || :'
114             sshgw 'chrt -p -f 50 `pidof irq/146-can1` > /dev/null || :'
115             sshgw 'chrt -p -f 49 `pidof sirq-net-rx/0` > /dev/null || :'
116             sshgw 'chrt -p -f 49 `pidof sirq-net-tx/0` > /dev/null || :'
117             cleanupgw
118
119             main
120             cp $script .
121         fi
122         if [[ ! "$OPT_PLOT_DISABLE" ]]; then
123             _plot
124         fi
125     done
126     done
127 }
128
129 test_end() {
130     test_end_called=t
131     exit_ok=
132     _run
133     exit_ok=t
134 }
135
136 _myexit() {
137     code=$?
138     cmd=$BASH_COMMAND
139     if [[ ! "$test_end_called" ]]; then
140         test_end_called=t
141         error "bug in the test script: No test_end called"
142     fi
143     if ! test -n "$exit_ok"; then
144         error "FATAL: Command '$cmd' exit with code $code"
145     fi
146 }
147
148 trap '_myexit' EXIT